scippneutron.peaks.FitResult#

class scippneutron.peaks.FitResult(*, aic, assessment, background, message, p_value, peak, popt, red_chisq, window)[source]#

Optimized parameters and fit statistics for a single peak.

__init__(*, aic, assessment, background, message, p_value, peak, popt, red_chisq, window)#

Methods

__init__(*, aic, assessment, background, ...)

better_than(other)

Return True if this result is better than another.

eval_model(x)

Evaluate the model with optimized parameters.

eval_peak(x)

Evaluate the peak model with optimized parameters.

for_failure(*[, assessment, message])

Create a FitResult for a failed fit.

for_too_narrow_window(*, peak, background, ...)

Create a FitResult for a fit where the window is too narrow.

report()

Format an overview of the fit result.

Attributes

aic

Akaike Information Criterion.

assessment

Indicates whether the fit was successful or how if failed.

background

Model for the background.

message

Short message describing the fit assessment.

p_value

Probability of the given chi-squared or higher.

peak

Model for the peak.

popt

Optimized parameters.

red_chisq

Reduced chi-squared for the model and optimized parameters.

window

Fit window for this peak.

success

Return whether the fit was successful.

aic: Variable#

Akaike Information Criterion.

A relative estimate of fit quality. Defined as

\[\mathsf{AIC} = 2k - 2\ln(L)\]

Where \(k\) is the number of parameters and \(L\) the likelihood if the model with the optimized parameters.

assessment: FitAssessment#

Indicates whether the fit was successful or how if failed.

background: Model#

Model for the background.

better_than(other)[source]#

Return True if this result is better than another.

Uses aic to compare the results.

Parameters:

other (FitResult) – Another FitResult to compare to.

Returns:

bool – Whether this result is better than the other.

eval_model(x)[source]#

Evaluate the model with optimized parameters.

Parameters:

x (Variable) – Independent variable.

Returns:

Variable – The model evaluated at x with optimized parameters.

eval_peak(x)[source]#

Evaluate the peak model with optimized parameters.

Parameters:

x (Variable) – Independent variable.

Returns:

Variable – The peak model evaluated at x with optimized parameters.

classmethod for_failure(*, assessment=None, peak, background, window, message=None)[source]#

Create a FitResult for a failed fit.

Return type:

FitResult

classmethod for_too_narrow_window(*, peak, background, window)[source]#

Create a FitResult for a fit where the window is too narrow.

Return type:

FitResult

message: str#

Short message describing the fit assessment.

p_value: Variable#

Probability of the given chi-squared or higher.

The \(p\)-value is the probability to get the same \(\chi^2\) or higher when repeating the fit. It is defined as

\[p = 1 - F(\chi^2;\,\nu)\]

where \(F(\chi^2;\,\nu)\) is the cumulative distribution function of the \(\chi^2\)–distribution with \(\nu\) degrees of freedom.

peak: Model#

Model for the peak.

popt: dict[str, Variable]#

Optimized parameters.

red_chisq: Variable#

Reduced chi-squared for the model and optimized parameters.

\[\chi^2_{\nu} = \frac1{\nu} \sum_{i=0}^n\, \frac{(y_i - f(x_i))^2}{\sigma_i^2}\]

where \(\nu\) is the number of degrees of freedom.

report()[source]#

Format an overview of the fit result.

Return type:

str

property success: bool#

Return whether the fit was successful.

window: Variable#

Fit window for this peak.