Skip to content

fitting#

Curve fitting with automatic algorithm and initial-guess selection.

Fit a builtin models.* function or your own model to a signal, spectrum, or (x, y) arrays.

analyze_model #

analyze_model(
    model: Callable[..., ndarray],
) -> FunctionAnalysisResult

Inspect a model function and report its detected type, confidence, and recommended fitting approach.

fit #

fit(
    data: Signal1D | Spectrum1D | tuple[ndarray, ndarray],
    model: Callable[..., ndarray],
    initial_guess: tuple[float, ...] | None = None,
    method: Literal[
        "auto", "robust", "fast", "accurate"
    ] = "auto",
    algorithm: Literal[
        "scipy", "linear", "varpro", "specialized"
    ]
    | None = None,
    n_components: int = 1,
    **kwargs: Any,
) -> SmartFittingResult

Fit a model to data, choosing algorithm and initial guess automatically.

Returns:

Type Description
SmartFittingResult

Result with .parameters, .loss, .data_info, .model_info.

get_predefined_models #

get_predefined_models() -> dict[
    str, Callable[..., ndarray]
]

Return the built-in model functions as a name-to-function mapping.

predict #

predict(
    x_data: ndarray,
    model: Callable[..., ndarray],
    parameters: tuple[float, ...] | list[float],
) -> ndarray

Evaluate a model at given x values using known parameters.

Returns the predicted y values, one per element of x_data.