atomcloud.fits.multi_fit module
Created on Sat Mar 19 14:49:49 2022
@author: hofer
- class atomcloud.fits.multi_fit.MultiFunctionFit(function_names, multi_func, func_registry, fit_label, max_nfev_scalar=50, constraints=None, scipy_length=1000.0, fixed_length=None)[source]
Bases:
ABC- Parameters:
function_names (list[str]) –
multi_func (object) –
func_registry (dict) –
fit_label (str) –
max_nfev_scalar (int) –
constraints (list[str] | None) –
scipy_length (int) –
fixed_length (str | None) –
- fit_object_init(multi_func)[source]
Initialize the JAXFit object and function. This is only done if JAX is installed and SciPy length is not None.
- Parameters:
multi_func (object) – multi-function object to be used
- Return type:
None
- flatten_fit_data(coords, data)[source]
Flatten the data and coordinates to be fit.
- Parameters:
coords (ndarray | Iterable[ndarray]) – coordinates of the data
data (ndarray) – data to be fit (must be same shape as coords)
- Returns:
flattened coordinates of the data flat_data: flattened data to be fit
- Return type:
flat_coords
- get_default_bounds()[source]
Get the default bounds for the fit. This is a tuple of two lists one for the lower bounds and one for the upper bounds. The lower and upper bounds are each returned as a list of lists where each sublist is the bounds for a single function.
- Returns:
tuple of the lower and upper bounds
- Return type:
bounds
- get_default_seed(coords, data)[source]
Get the default seed for the fit. This is a list of lists where each sublist is the seed for a single function.
- Parameters:
coords (ndarray | Iterable[ndarray]) – coordinates of the data
data (ndarray) – data to be fit
- Returns:
list of the seed parameters
- Return type:
seed
- get_fit(coords, data, seed=None, bounds=None, sigma=None, mask=None, uncertainty=False, verbose=False)[source]
Fit the data to the multi-function
- Parameters:
coords (ndarray | Iterable[ndarray]) – coordinates of the data
data (ndarray) – data to be fit (must be same shape as coords)
seed (list[list[float]] | None) – initial seed for the fit in terms of the multi-functions individual functions (ie. list of lists where the top level list corresponds to the function and the second level list corresponds to the parameters of that function).
bounds (list[list[float]] | None) – tuple of min and max values for each parameter, but the
(see (min and max values are each formatted as a list of lists) –
formatting) (seed for) –
sigma (ndarray | None) – standard deviation of the data (must be same shape as data) or a covariance matrix with each axis the same length as the data.
mask (ndarray | None) – mask to be applied to the data which is the same shape as the data
uncertainty (bool) – whether to return the uncertainties of the fit
plot_it – whether to plot the fit
verbose (bool) – whether to print the fit information to the console.
- Returns:
list of the fit parameters info: dictionary of the fit information
- Return type:
params
- get_fit_metrics(params, func_eval, flat_data, sigma=None)[source]
Get the fit metrics for the fit. Currently only chi squared and reduced chi squared are calculated.
- Parameters:
params (list[list[float]]) – fit parameters
flat_coords – flattened coordinates of the data
flat_data (ndarray | Iterable[ndarray]) – flattened data that was fit
sigma (ndarray | None) – standard deviation of the data (must be same shape as data) or a covariance matrix with each axis the same length as the data.
func_eval (ndarray) –
- Returns:
dictionary of the fit metrics
- Return type:
fit_metrics
- get_fit_obj(flat_data)[source]
Returns the correct fit package to use based on the length of the data and whether JAX is installed.
- Parameters:
flat_data – flattened data to be fit
- Returns:
curvefit function to use fit_func: function to be fit print_label: label to print to console if Verbose is enabled
- Return type:
curvefit
- get_info_dict(fit_parameters, fit_metrics, data_sum)[source]
Get the fit information dictionary this will be saved and used throughout the package to do things like plotting, integrating, etc.
- Parameters:
fit_parameters (list[list[float]]) – fit parameters
fit_metrics (dict) – dictionary of the fit metrics
data_sum (float) – sum of the data that was fit
- Returns:
dictionary of the fit information
- Return type:
fit_dict
- handle_uncertainty(popt, pcov, func_params, uncertainty)[source]
Handle the uncertainty of the fit. If uncertainty is True, then the covariance matrix and the fit parameters are used to create the uncertainty fit parameters. The packages is designed to handle these uncertainty parameters throughout, but these are more difficult to work with due to limits on the accepted operations and thus the user might wish to neglect using them for their own custom functions.
- Parameters:
popt (ndarray) – fit parameters
pcov (ndarray) – covariance matrix for the fit parameters
func_params (list[list[float]]) – fit parameters in the format list of individual functions fit parameters
uncertainty (bool) – whether to return the uncertainty parameters
- Returns:
fit parameters to be saved in the info dictionary
- Return type:
save_params