pyrasa.utils.fit_funcs.AbstractFitFun#
- class pyrasa.utils.fit_funcs.AbstractFitFun(freq: ndarray, aperiodic_spectrum: ndarray, scale_factor: int | float)[source]#
Abstract base class for fitting functions used to model aperiodic spectra.
This class provides a framework for defining and fitting models to aperiodic spectra. It handles common functionality required for fitting a model, such as scaling and goodness-of-fit computation. Subclasses should implement the
func
method to define the specific fitting function used for curve fitting.- freq#
The frequency values associated with the aperiodic spectrum data.
- Type:
np.ndarray
- aperiodic_spectrum#
The aperiodic spectrum data to which the model will be fit.
- Type:
np.ndarray
- scale_factor#
A scaling factor used to adjust the fit results.
- Type:
int | float
- label#
A label to identify the type of fit or model used. Default is ‘custom’.
- Type:
ClassVar[str]
- log10_aperiodic#
If True, the aperiodic spectrum values will be transformed using log10. Default is False.
- Type:
ClassVar[bool]
- log10_freq#
If True, the frequency values will be transformed using log10. Default is False.
- Type:
ClassVar[bool]
- __attrs_post_init__()[source]#
Post-initialization method to apply log10 transformations if specified.
- func(x: np.ndarray, \*args: float) np.ndarray [source]#
Abstract method to define the model function. Must be implemented by subclasses and should be applicable to scipy.optimize.curve_fit.
- curve_kwargs() dict[str, Any] #
Returns keyword arguments for the curve fitting process.
- add_infos_to_df(df_params: pd.DataFrame) pd.DataFrame [source]#
Method to add additional information to the parameters DataFrame. Can be overridden by subclasses.
- handle_scaling(df_params: pd.DataFrame, scale_factor: float) pd.DataFrame [source]#
Adjusts the parameters DataFrame based on the scaling factor. Can be overridden by subclasses.
- fit_func() tuple[pd.DataFrame, pd.DataFrame] [source]#
Fits the model to the data and returns DataFrames containing the model parameters and goodness-of-fit metrics.
Notes
Subclasses must implement the
func
method to define the model’s functional form.The
curve_kwargs
method can be overridden to customize curve fitting options.The
add_infos_to_df
andhandle_scaling
methods are intended to be overridden if additional functionality or specific scaling behavior is required.
References
For details on goodness-of-fit metrics and their calculations, see the documentation for
_get_gof
.- Attributes:
- aperiodic_spectrum
- curve_kwargs
- freq
- scale_factor
Methods
add_infos_to_df
fit_func
func
handle_scaling
- __hash__ = None#