Skip to content

fit.options

Main options for the parameter fitting.

In the optimization the cost is minimized for Nk curves with every curve having Nki data points.

sum(Nk)( w{k}^2 * sum(NKi) (w{i,k}^2 * res{i,k}))

OptimizationStrategy

Bases: StrEnum

Strategy for fitting a set of fit experiments.

ALL : fit all experiments together, i.e., one parameter set describes every experiment.

SINGLE : fit every experiment on its own, i.e., one parameter set per experiment. These are the individual parameters, see sbmlsim.fit.metrics.

OptimizationAlgorithmType

Bases: Enum

Type of optimization.

least square : Least square is a local optimization method and works well in combination with many start values, i.e., many repeats of the optimization problem. See https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.least_squares.html for more information.

differential evolution : Differential evolution is a global optimization method and normally is run with a limited number of repeats. See https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.differential_evolution.html#scipy.optimize.differential_evolution for more information.

ResidualType

Bases: Enum

Handling of the residuals.

How are the residuals calculated? Are the absolute residuals used, or are the residuals normalized based on the data points, i.e., relative residuals.

absolute (default) : uses the absolute data values for calculation of the residuals::

r(i,k) = y(i,k) - f(xi,k)

normalized : normalizing residuals of curve with 1/mean of the timecourse::

r(i,k) = (y(i,k) - f(xi,k))/mean(y(k))

This allows to use time courses with very different absolute values in a single optimization problem.

absolute_to_baseline (experimental) : uses the absolute changes to baseline with baseline being the first data point. This requires appropriate pre-simulations for the model to reach a baseline. Data and fits have to be checked carefully. Residuals are calculated as::

r(i,k) = (y(i,k) - ybase(k)) - (f(xi,k) - fbase(k))

normalized changes baseline (experimental): Uses the normalized changes to baseline with baseline being the first data point. This requires appropriate pre-simulations for the model to reach a baseline. Data and fits have to be checked carefully. The residuals are calculated as::

r(i,k) = (y(i,k) - ybase(k)) - (f(xi,k) - fbase(k))/mean(y(k))

LossFunctionType

Bases: Enum

Determines the loss function.

minimize F(x) = 0.5 * sum(rho(residuals_weighted(x)**2)

The following loss functions are supported are allowed:

‘linear’ (default) : rho(z) = z. Gives a standard least-squares problem.

‘soft_l1’ : rho(z) = 2 * ((1 + z)**0.5 - 1). The smooth approximation of l1 (absolute value) loss. Usually a good choice for robust least squares.

‘cauchy’ : rho(z) = ln(1 + z). Severely weakens outliers influence, but may cause difficulties in optimization process.

‘arctan’ : rho(z) = arctan(z). Limits a maximum loss on a single residual, has properties similar to ‘cauchy’.

WeightingCurvesType

Bases: Enum

Weighting w_{k} of the curves k.

Users can provide set of weightings for the individual curves. By default no weightings are applied, i.e. all curves are weighted equally if no weighting option is provided::

w_{k} = 1.0

mapping : curves k are weighted with the provided user weights in the fit mappings, e.g., counts::

w_{k} = wu_{k}

points : weighting with the number of data points. Often time courses contain different number of data points. The residuals should contribute equally per data point::

w_{k} = 1.0/count{k}

The various options can be combined, e.g. mapping and points results in::

w_{k} = wu_{k}/count{k}/mean{y(k)}

ParameterScaleType

Bases: Enum

Space the optimizer searches the parameters in.

A parameter of a model is a positive quantity which often spans orders of magnitude, e.g. a rate constant, and an optimizer which searches it on the linear scale spends its steps on the largest of them. Searching the logarithm makes the steps relative, which is what such a parameter needs.

The scale is a property of the optimization and not of the model or of the data: PEtab v2 removed the parameterScale of its parameter table for that reason, so it is part of the FitSettings here and is stored with them.

The bounds and the start value of a FitParameter are always on the linear scale, i.e. in the units of the model, and so are the fitted parameters a fit reports; only the search happens in the scaled space.

is_log property

is_log

Check whether the optimizer searches a logarithm.

to_scale

to_scale(x)

Transform parameters from the model into the space of the optimizer.

Parameters:

Name Type Description Default
x Any

parameters in the units of the model, positive for a logarithm.

required

Returns:

Type Description
Any

The parameters in the space the optimizer searches.

from_scale

from_scale(x)

Transform parameters of the optimizer back into the model.

Parameters:

Name Type Description Default
x Any

parameters in the space the optimizer searches.

required

Returns:

Type Description
Any

The parameters in the units of the model.

WeightingPointsType

Bases: Enum

Weighting w_{i,k} of the data points i within a single fit mapping k.

This decides how the data points within a single fit mapping are weighted.

no weighting (default) : all data points are weighted equally::

w_{i,k} = 1.0

error_weighting: data points are weighted as ~1/error

# FIXME: update documentation, These must probably be normalized also. if yerr{i,k}: w_{i,k} = 1.0/yerr{i,k} else: w_{i,k} = 1.0/yerr{i,k}

FitSettings dataclass

FitSettings(
    residual=ABSOLUTE,
    parameter_scale=LOG10,
    loss_function=LINEAR,
    weighting_curves=tuple(),
    weighting_points=NO_WEIGHTING,
    variable_step_size=True,
    relative_tolerance=1e-06,
    absolute_tolerance=1e-06,
)

Settings of a parameter fit.

The settings decide how the residuals of an optimization problem are calculated, so the same settings are needed to run a fit and to report it afterwards. They are stored with the result of a fit and read back by the report, see sbmlsim.fit.report.FitReport.

Attributes:

Name Type Description
residual ResidualType

handling of the residuals.

parameter_scale ParameterScaleType

space the optimizer searches the parameters in.

loss_function LossFunctionType

loss function applied to the squared residuals.

weighting_curves Sequence[WeightingCurvesType]

weighting of the curves (fit mappings).

weighting_points WeightingPointsType

weighting of the data points within a curve.

variable_step_size bool

use a variable step size in the solver.

relative_tolerance float

relative tolerance of the simulator.

absolute_tolerance float

absolute tolerance of the simulator.

to_dict

to_dict()

Convert to a dictionary of JSON serializable values.

from_dict staticmethod

from_dict(d)

Create settings from a dictionary, i.e., from the stored JSON.

Parameters:

Name Type Description Default
d dict[str, Any]

dictionary as created by to_dict.

required

Returns:

Type Description
FitSettings

The settings.