diff options
author | tlatorre <tlatorre@uchicago.edu> | 2020-08-17 11:38:49 -0500 |
---|---|---|
committer | tlatorre <tlatorre@uchicago.edu> | 2020-08-17 11:38:49 -0500 |
commit | ed8e1cd3c1a88649f50449f5c64e305463f001a8 (patch) | |
tree | fa3e50f98189b1d53f42989403f5a07d629e2f3c | |
parent | 3bcde006dcff72bfb1f3dd7ff052b501393f1125 (diff) | |
download | sddm-ed8e1cd3c1a88649f50449f5c64e305463f001a8.tar.gz sddm-ed8e1cd3c1a88649f50449f5c64e305463f001a8.tar.bz2 sddm-ed8e1cd3c1a88649f50449f5c64e305463f001a8.zip |
simplify nllr() function
-rw-r--r-- | utils/sddm/stats.py | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/utils/sddm/stats.py b/utils/sddm/stats.py index 5324eea..ff2a6ad 100644 --- a/utils/sddm/stats.py +++ b/utils/sddm/stats.py @@ -8,7 +8,7 @@ particle_id = {20: 'e', 22: r'\mu'} def chi2(samples,expected): return np.sum((samples-expected)**2/expected,axis=-1) -def nllr(samples,expected): +def nllr(oi,ei): """ Returns 2 times the negative log likelihood ratio that the `samples` histogram was drawn from the histogram `expected`. The numerator in the @@ -22,14 +22,10 @@ def nllr(samples,expected): This likelihood ratio is supposed to give better results as a test statistic when computing p-values for histograms with low statistics. """ - samples = np.atleast_2d(samples) - n = samples.sum(axis=-1) - N = expected.sum() - p_samples = samples.astype(np.double) + 1e-10 - p_samples /= p_samples.sum(-1)[:,np.newaxis] - p_expected = expected.astype(np.double) + 1e-10 - p_expected /= p_expected.sum() - return 2*(N - n + (samples*np.log(np.where(samples == 0,1,samples)/expected)).sum(axis=-1)).squeeze()[()] + oi = np.atleast_2d(oi) + n = oi.sum(axis=-1) + N = ei.sum() + return 2*(N - n + (oi*np.log(np.where(oi == 0,1,oi)/ei)).sum(axis=-1)).squeeze()[()] def get_mc_hist_posterior(hist, data, norm): """ |