nskinetics.ReactionSystem.fit_reaction_kinetic_parameters_to_data#
- ReactionSystem.fit_reaction_kinetic_parameters_to_data(data, bounds, solve_method='BDF', de_workers=1, de_popsize=200, de_maxiter=10, do_basinhop=True, bh_niter=10, bh_stepsize=0.25, local_method='L-BFGS-B', polish_top_k=7, seed=42, p0=None, all_species_tracked=False, use_only=None, normalize=True, show_output=True, show_progress=False, plot_during_fit=False, call_before_each_solve=None, timeout_solve_ivp=0.5, **kwargs)[source]#
Fit reaction kinetic parameters to experimental time-series data. (i.e., inverse modeling).
This method optimizes the reaction kinetic parameters of the system to best fit provided concentration data over time using nonlinear least squares optimization. The function assumes a shared set of parameters governing all species.
- Parameters:
data (pandas.DataFrame, dict, str, or list) – A pandas DataFrame, a dictionary, a path to a .csv or .xlsx file, or a list containing any combination of those items. Each item represents data containing time (‘t’) and concentrations of one or more species as columns. Time should be in the column labeled ‘t’; all other columns are interpreted as species concentrations. If data is a list of data items, each data item must have the same format (i.e., the same columns and order of columns).
p0 (array_like, optional) – Initial guess for the kinetic parameters. If not provided, the current reaction_kinetic_params will be used if they are finite and not NaN.
all_species_tracked (bool, default False) – If True, assumes all species are tracked and uses the full concentration vector when computing predictions. Otherwise, uses only individual species.
show_output (bool, default True) – If True, prints fit summary including R² score and success status.
use_only (list of str or Species, optional) – List of Species object or species IDs to fit against. If not provided, all species in the input data will be used. It is recommended to include at least one species involved in each reaction in reactions.
method (str, default 'Powell') – Optimization method to use for parameter fitting. Passed to scipy.optimize.minimize.
n_minimize_runs (int, optional) – Number of local optimization (minimization) runs to perform, each with a different starting point (first uses p0, others use DE output).
n_de_runs (int, optional) – Number of differential evolution runs per minimization run to generate good starting guesses; the best DE result is used to initialize the local minimization.
minimize_kwargs (dict) – Additional keyword arguments passed to scipy.optimize.minimize.
differential_evolution_kwargs (dict) – Additional keyword arguments passed to scipy.optimize.differential_evolution_kwargs.
timeout_solve_ivp (float, int, or None, optional) – Enforce timeout of scipy.integrate.solve_ivp when it exceeds this value. Creates and passes a timeout_function as an event to scipy.integrate.solve_ivp. Defaults to 0.5 (seconds).
- Returns:
Updates the reaction kinetic parameters of the system in place and stores the fit result in self._fitsol as a tuple: (best-fit parameters, R² score, success flag).
- Return type:
None
Notes
The fit is performed by normalizing each species’ concentration to its maximum observed value to ensure scale invariance.
The objective function maximizes the mean R² score across selected species.
This method relies on solve() and C_at_t() methods to simulate the system under trial parameters and look up interpolated results, and on fit_multiple_dependent_variables() to perform optimization.