Warning
This is a review version of the documentation for PyOpenSci submission.
Mixed Data Fitter#
- class MixedDataFitter(x_values: List[int | float] | ndarray, y_values: List[int | float] | ndarray, model_list: List[str], fitter_dictionary: dict | None = None, model_dictionary: dict | None = None, max_iterations: int = 1000)[source]#
Bases:
objectClass to fit a mixture of different models to data.
- Parameters:
x_values – The x-values for the data.
y_values – The y-values for the data.
model_list – List of models to fit (e.g., LINE, GAUSSIAN, LOG_NORMAL)
max_iterations – The maximum number of iterations for fitting procedure.
Methods
fit(p0[, frozen])Fit the data.
Gets the y-values from the fitted model.
get_model_parameters([model, errors])Extracts parameters (and error) values for a specific model, or for all models if no model is specified.
get_value_error_pair([mean_values, std_values])Retrieve the value/error pairs for the fitted parameters.
plot_fit([show_individuals, x_label, ...])Plot the fitted models.
- _create_model_function() Callable[source]#
Creates a composite model function based on the specified models.
- Returns:
A composite model for fitting.
- _expected_param_count() int[source]#
Calculates the expected number of parameters based on the model list.
- Returns:
The number of parameters.
- static _format_param(value, t_low=0.001, t_high=10000) str[source]#
Formats the parameter value to scientific notation based on its magnitude.
- Parameters:
- value: float
The value of the parameter to be formatted.
- t_low: float, optional
The lower bound below which the formatting should be applied to the value. Defaults to 0.001.
- t_high: float, optional
The upper bound above which the formatting should be applied to the value. Defaults to 10,000.
- Returns:
- str:
A formatted string of the parameter value.
- _get_bounds()[source]#
Sets the bounds for each parameter based on the model list.
- Returns:
Lower and upper bounds for the parameters.
- _parameter_extractor(values: ndarray) dict[source]#
Extracts the parameters for each model in the model list.
- Parameters:
values – The values from which the model dictionary is to be extracted.
- Returns:
A dictionary where the keys are model names and the values are lists of parameters/error values.
- _params() ndarray[source]#
Store the fitted parameters of the fitted model.
- Returns:
- np.ndarray
The parameters obtained after performing the fit.
- Raises:
- RuntimeError
If the fit has not been performed yet (i.e.,
self.paramsisNone).
Notes
This method assumes that the fitting process assigns values to
self.params.
- _plot_individual_fitter(plotter)[source]#
Plot the individual fitters function.
- Parameters:
plotter – The plotting axis object
- _standard_errors() ndarray[source]#
Store the standard errors of the fitted parameters.
- Returns:
- np.ndarray
An array containing the standard errors of the fitted parameters.
- Raises:
- RuntimeError
If the fit has not been performed yet (i.e.,
self.covarianceisNone).
- fit(p0: List[Tuple[int | float, ...]] | ndarray, frozen: int | List[int] | None = None)[source]#
Fit the data.
- Parameters:
- Raises:
ValueError – If the length of the initial guess is not equal to the expected parameter count.
- get_fitted_curve() ndarray[source]#
Gets the y-values from the fitted model.
- Returns:
The y-values from the fitted model
- Raises:
ValueError – If the model has not been fitted yet.
- get_model_parameters(model: str | None = None, errors: bool = False)[source]#
Extracts parameters (and error) values for a specific model, or for all models if no model is specified.
- Parameters:
model – Model name to extract parameters for. If unspecified, extracts parameters for all models. Defaults to
None.errors – If
True, includes the errors in the returned output. Defaults toFalse.
- Returns:
A dictionary containing:
”parameters”: Nested dictionary of parameter values for each model if get_errors is True.
”errors”: Nested dictionary of errors for each model (if get_errors=True).
Otherwise, returns just the parameters directly.
- get_value_error_pair(mean_values: bool = True, std_values: bool = False) ndarray[source]#
Retrieve the value/error pairs for the fitted parameters.
This method provides the fitted parameter values and their corresponding standard errors as a combined array or individually based on the input flags.
- Parameters:
- mean_valuesbool, optional
If
True, return only the values of the fitted parameters. Defaults toTrue.- std_valuesbool, optional
If
True, return only the standard errors of the fitted parameters. Defaults toFalse.
- Returns:
- np.ndarray
- If
mean_valuesandstd_valuesare bothTrue: A 2D array of shape (n_parameters, 2), where each row is
[value, error].
- If
If
mean_valuesisTrueandstd_valuesisFalse: A 1D array of parameter values.If
std_valuesisTrueandmean_valuesisFalse: A 1D array of standard errors.If both flags are
False: An error message.
- Raises:
- ValueError
If both
mean_valuesandstd_valuesareFalse.
- plot_fit(show_individuals: bool = False, x_label: str | None = None, y_label: str | None = None, data_label: str | None = None, fit_label: str | None = None, title: str | None = None, axis: Axes | None = None)[source]#
Plot the fitted models.
- Parameters:
- show_individuals: bool, optional
Whether to show individually fitted models or not.
- x_label: str, optional
The label for the x-axis.
- y_label: str, optional
The label for the y-axis.
- title: str, optional
The title for the plot.
- data_label: str, optional
The label for the data.
- fit_label: str, optional
The label for the fitted model.
- axis: Axes, optional
Axes to plot instead of the entire figure. Defaults to None.
- Returns:
- plotter
The plotter handle for the drawn plot.
Currently the MixedDataFitter supports fitting the following models together,
Recommended Import#
from pymultifit.fitters import MixedDataFitter
Full Import#
from pymultifit.fitters.mixed_f import MixedDataFitter