From b2a54d26624c71bb9ee2962f1c85bcd306098abb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?M=C3=A9d=C3=A9ric=20Boquien?=
Date: Fri, 9 Aug 2019 14:50:23 -0400
Subject: [PATCH] Speedup the computation of the weighted means and standard
deviation by normalising the likelihhod, simplifying the computation
---
CHANGELOG.md | 5 +++--
pcigale/analysis_modules/pdf_analysis/utils.py | 4 ++--
pcigale/analysis_modules/pdf_analysis/workers.py | 1 +
3 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8c6d5da6..d011258d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -25,9 +25,10 @@
- Some labels and the title for the SED plots has been improved to avoid overlaps and overflows. (Médéric Boquien)
- Ensure that best models are properly computed when models are computed by blocks and that no fit could be made in one or more blocks. This can be case if all the models in the block are older than the age of the universe. (Médéric)
### Optimised
-- Slight speedup of the computation of the likelihood from the χ² (Médéric Boquien)
-- Speedup of the computation of the χ² by ~10% (Médéric Boquien)
+- Slight speedup of the computation of the likelihood from the χ² using a multiplication rather than a division. (Médéric Boquien)
+- Speedup of the computation of the χ² by ~10% taking the opposite of a scalar rather than of an array. (Médéric Boquien)
- Thanks to a change in the layout of the models storage in RAM, the computation of the χ² is now massively faster when the run contains multiple redshifts. (Médéric Boquien)
+- The computation of the weighted means and standard deviations has been made ~50% faster by normalising the likelihood. (Médéric Boquien)
- The the fritz2006 module should now run faster thanks to an optimisation of the computation of the luminosity of the various AGN components (Médéric Boquien & Guang Yang)
## 2018.0 (2018-11-06)
diff --git a/pcigale/analysis_modules/pdf_analysis/utils.py b/pcigale/analysis_modules/pdf_analysis/utils.py
index b3f0ce6c..ce46b000 100644
--- a/pcigale/analysis_modules/pdf_analysis/utils.py
+++ b/pcigale/analysis_modules/pdf_analysis/utils.py
@@ -306,7 +306,7 @@ def weighted_param(param, weights):
"""
- mean = np.average(param, weights=weights)
- std = np.sqrt(np.average((param-mean)**2, weights=weights))
+ mean = np.sum(param * weights)
+ std = np.sqrt(np.sum((param - mean)**2 * weights))
return (mean, std)
diff --git a/pcigale/analysis_modules/pdf_analysis/workers.py b/pcigale/analysis_modules/pdf_analysis/workers.py
index 0e97e81c..04d882e5 100644
--- a/pcigale/analysis_modules/pdf_analysis/workers.py
+++ b/pcigale/analysis_modules/pdf_analysis/workers.py
@@ -168,6 +168,7 @@ def analysis(idx, obs):
scaling_l = scaling[wlikely]
gbl_results.bayes.weight[idx] = np.nansum(likelihood)
+ likelihood *= 1. / gbl_results.bayes.weight[idx]
# We compute the weighted average and standard deviation using the
# likelihood as weight.
--
2.22.0