Model Fitting¶
The fitting module is for actually performing fits to data using the previously defined fit models to estimate model parameters.
- class experimentalis.fitting.FitModelResult(initial_guess_graph=None, initial_guess_residuals_graph=None, autofit_graph=None, autofit_residuals_graph=None, chi2=None, covariance_matrix=None)¶
Bases:
objectA result structure for collecting and displaying fit results visually. Produced automatically after performing an
autofit.- Variables:
initial_guess_graph (Image) – A plot of the model pre-optimization, using the initial parameter guesses (if provided).
initial_guess_residuals_graph (Image) – A plot of the residuals of the initial values.
autofit_graph (Image) – A plot of the model post-optimization.
autofit_residuals_graph (Image) – A plot of the post-optimization model residuals.
chi2 (float) – The goodness-of-fit of the model post-optimization.
- autofit_graph = None¶
- autofit_residuals_graph = None¶
- chi2 = None¶
- covariance_matrix = None¶
- initial_guess_graph = None¶
- initial_guess_residuals_graph = None¶
- experimentalis.fitting.autofit(data, model, graphing_options)¶
Optimizes a model to fit a dataset (editing the model in-place), and plots the results to a
FitModelResultobject.- Parameters:
data (Dataset) – The dataset to fit to.
model (Model) – The model.
graphing_options (GraphingOptions) – The graphing options for plotting.
- Returns:
The results of the optimization.
- Return type:
- experimentalis.fitting.calculate_chi_squared(model, dataset)¶
Calculates the goodness-of-fit \(\chi^2\) for a given model post-fitting via the equation
\[\chi^2 = \frac{1}{N} \sum_{i=1}^{N} \left( \frac{y_i - f(x_i)}{dy} \right)^2\]given model \(f\) and dataset \(D_i=(x_i,y_i)\).
- experimentalis.fitting.print_results(model, results, print_cov=False, units=None)¶
Prints the results of a fitting in a tabulated format, with the optional inclusion of the covariance matrix for the parameters.
- Parameters:
model (Model) – The fit model, used to access the optimized parameters.
results (FitModelResults) – The results of the fitting. Used to access the covariance matrix and the goodness-of-fit.
print_cov (bool) – Whether or not to include the covariance matrix.
units (list[str]) – The (optional) ordered list of units for each parameter.