Commit 4766aa5f authored by Médéric Boquien's avatar Médéric Boquien

Compute the valid models only once and use a slice when they are all valid.

parent b1f763c7
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
### Changed ### Changed
### Fixed ### Fixed
### Optimised ### 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) ## 0.12.1 (2018-02-27)
### Fixed ### Fixed
......
...@@ -187,6 +187,10 @@ def analysis(idx, obs): ...@@ -187,6 +187,10 @@ def analysis(idx, obs):
# We use the exponential probability associated with the χ² as # We use the exponential probability associated with the χ² as
# likelihood function. # likelihood function.
likelihood = np.exp(-chi2 / 2.) 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) gbl_results.bayes.weights[idx] = np.nansum(likelihood)
# We compute the weighted average and standard deviation using the # We compute the weighted average and standard deviation using the
...@@ -203,7 +207,6 @@ def analysis(idx, obs): ...@@ -203,7 +207,6 @@ def analysis(idx, obs):
else: else:
values = _(gbl_models.properties[i, wz]) values = _(gbl_models.properties[i, wz])
wlikely = np.where(np.isfinite(likelihood))
mean, std = weighted_param(values[wlikely], likelihood[wlikely]) mean, std = weighted_param(values[wlikely], likelihood[wlikely])
gbl_results.bayes.means[idx, i] = mean gbl_results.bayes.means[idx, i] = mean
gbl_results.bayes.errors[idx, i] = std gbl_results.bayes.errors[idx, i] = std
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment