From 4766aa5f0763835214109fb2d39d4bbffada6391 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A9d=C3=A9ric=20Boquien?= Date: Sun, 4 Mar 2018 18:41:47 -0300 Subject: [PATCH] Compute the valid models only once and use a slice when they are all valid. --- CHANGELOG.md | 1 + pcigale/analysis_modules/pdf_analysis/workers.py | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 547433644..bfb3e0c6a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ ### Changed ### Fixed ### Optimised +- The estimation of the physical properties is made a bit faster when all the models are valid. (Médéric Boquien) ## 0.12.1 (2018-02-27) ### Fixed diff --git a/pcigale/analysis_modules/pdf_analysis/workers.py b/pcigale/analysis_modules/pdf_analysis/workers.py index d56ef336a..7bb9de628 100644 --- a/pcigale/analysis_modules/pdf_analysis/workers.py +++ b/pcigale/analysis_modules/pdf_analysis/workers.py @@ -187,6 +187,10 @@ def analysis(idx, obs): # We use the exponential probability associated with the χ² as # likelihood function. likelihood = np.exp(-chi2 / 2.) + wlikely = np.where(np.isfinite(likelihood)) + # If all the models are valid, it is much more efficient to use a slice + if likelihood.size == wlikely[0].size: + wlikely = slice(None, None) gbl_results.bayes.weights[idx] = np.nansum(likelihood) # We compute the weighted average and standard deviation using the @@ -203,7 +207,6 @@ def analysis(idx, obs): else: values = _(gbl_models.properties[i, wz]) - wlikely = np.where(np.isfinite(likelihood)) mean, std = weighted_param(values[wlikely], likelihood[wlikely]) gbl_results.bayes.means[idx, i] = mean gbl_results.bayes.errors[idx, i] = std -- GitLab