mirror of
https://gitlab.science.ru.nl/mthesis-edeboone/m-thesis-introduction.git
synced 2024-12-21 11:03:37 +01:00
ZH: figlib: report chi**2 when fitting
This commit is contained in:
parent
06e4cd9f00
commit
84b7280a8b
1 changed files with 15 additions and 0 deletions
|
@ -98,6 +98,7 @@ def phase_comparison_figure(
|
|||
def fitted_histogram_figure(
|
||||
amplitudes,
|
||||
fit_distr = None,
|
||||
calc_chisq = True,
|
||||
text_kwargs={},
|
||||
hist_kwargs={},
|
||||
mean_snr = None,
|
||||
|
@ -169,6 +170,14 @@ def fitted_histogram_figure(
|
|||
|
||||
ax.plot(xs, fit_ys*scale, label=label)
|
||||
|
||||
chisq_strs = []
|
||||
if calc_chisq:
|
||||
ct = np.diff(distr_func.cdf(bins, *fit_params))*np.sum(counts)
|
||||
c2t = stats.chisquare(counts, ct, ddof=len(fit_params))
|
||||
chisq_strs = [
|
||||
f"$\\chi^2$/dof = {c2t[0]: .2g}/{len(fit_params)}"
|
||||
]
|
||||
|
||||
# change parameters if needed
|
||||
text_fit_params = fit_params2text_params(fit_params)
|
||||
|
||||
|
@ -176,6 +185,8 @@ def fitted_histogram_figure(
|
|||
[label]
|
||||
+
|
||||
[ f"{param} = {value: .2e}" for param, value in zip_longest(param_names, text_fit_params, fillvalue='?') ]
|
||||
+
|
||||
chisq_strs
|
||||
)
|
||||
|
||||
this_info = {
|
||||
|
@ -185,6 +196,10 @@ def fitted_histogram_figure(
|
|||
'text_str': text_str,
|
||||
}
|
||||
|
||||
if chisq_strs:
|
||||
this_info['chisq'] = c2t[0]
|
||||
this_info['dof'] = len(fit_params)
|
||||
|
||||
fit_info.append(this_info)
|
||||
|
||||
loc = (0.02, 0.95)
|
||||
|
|
Loading…
Reference in a new issue