aquakin.fit#
- aquakin.fit(reactor, C0, observations, t_obs, free_params, *, method='adjoint', initial_params=None, observed_species=None, time_unit=None)[source]#
Least-squares fit of selected parameters to time-series observations.
This is the lightweight fitter: box-constrained sum-of-squares least squares on a single batch, with no parameter transforms, priors, Laplace posterior, free initial conditions, or multi-batch support. For anything beyond a quick point estimate, prefer
aquakin.calibrate()(usecalibrate(..., laplace=False)for a bare point fit) — it is a strict superset of this function.Note
The reported losses are not comparable between the two.
fitreportsFitResult.lossas the sum of squared residuals (SciPyleast_squarescost), whereascalibratewithloss="mse"reports the mean squared error. The optima coincide (a positive constant factor does not move the minimiser); only the absolute loss value differs in scale.- Parameters:
reactor (BatchReactor) – The reactor to integrate. (Only batch reactors are supported here; the PFR case can be wrapped analogously.)
C0 (jnp.ndarray) – Initial concentration vector.
observations (jnp.ndarray) – Observed values. Shape
(n_t, n_observed)or(n_t,).t_obs (jnp.ndarray) – Observation times, shape
(n_t,).C0is taken to be the state att = 0; integration runs from0tot_obs[-1]and the solution is sampled att_obs. In the model’s native time unit unlesstime_unitis given.free_params (list[str]) – Namespaced parameter names to optimise. Other parameters are held at their default (or
initial_params) values.method (str) – Currently only
"adjoint"is supported, which uses Diffrax’s recursive-checkpoint adjoint viajax.grad()and SciPy L-BFGS-B.initial_params (jnp.ndarray, optional) – Starting parameter vector. Defaults to
reactor.model.default_parameters().observed_species (list[str], optional) – Species names corresponding to columns of
observations. IfNone,observationsis assumed to be over all species in model order.time_unit (str, optional) – The time unit
t_obsis expressed in ("s","min","h","d"), matchingBatchReactor.solve().t_obsis converted into the model’s native (rate-constant) time unit before the solve, so a user who standardises on e.g. hours can pass the same hour-valuedt_obshere as tosolve. DefaultNoneinterpretst_obsin the native unit. The fitted rate constants are always in native units.
- Return type:
Notes
Box bounds are applied per parameter from each parameter’s declared
bounds. A free parameter without declared bounds is left unbounded ((-inf, +inf)) while the others keep their boxes; a warning is emitted in that mixed case. If no free parameter has bounds, the solve is fully unconstrained.