mirror of
https://gitlab.science.ru.nl/mthesis-edeboone/m-thesis-introduction.git
synced 2024-12-22 11:33:32 +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(
|
def fitted_histogram_figure(
|
||||||
amplitudes,
|
amplitudes,
|
||||||
fit_distr = None,
|
fit_distr = None,
|
||||||
|
calc_chisq = True,
|
||||||
text_kwargs={},
|
text_kwargs={},
|
||||||
hist_kwargs={},
|
hist_kwargs={},
|
||||||
mean_snr = None,
|
mean_snr = None,
|
||||||
|
@ -169,6 +170,14 @@ def fitted_histogram_figure(
|
||||||
|
|
||||||
ax.plot(xs, fit_ys*scale, label=label)
|
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
|
# change parameters if needed
|
||||||
text_fit_params = fit_params2text_params(fit_params)
|
text_fit_params = fit_params2text_params(fit_params)
|
||||||
|
|
||||||
|
@ -176,6 +185,8 @@ def fitted_histogram_figure(
|
||||||
[label]
|
[label]
|
||||||
+
|
+
|
||||||
[ f"{param} = {value: .2e}" for param, value in zip_longest(param_names, text_fit_params, fillvalue='?') ]
|
[ f"{param} = {value: .2e}" for param, value in zip_longest(param_names, text_fit_params, fillvalue='?') ]
|
||||||
|
+
|
||||||
|
chisq_strs
|
||||||
)
|
)
|
||||||
|
|
||||||
this_info = {
|
this_info = {
|
||||||
|
@ -185,6 +196,10 @@ def fitted_histogram_figure(
|
||||||
'text_str': text_str,
|
'text_str': text_str,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if chisq_strs:
|
||||||
|
this_info['chisq'] = c2t[0]
|
||||||
|
this_info['dof'] = len(fit_params)
|
||||||
|
|
||||||
fit_info.append(this_info)
|
fit_info.append(this_info)
|
||||||
|
|
||||||
loc = (0.02, 0.95)
|
loc = (0.02, 0.95)
|
||||||
|
|
Loading…
Reference in a new issue