pastas.model.Model.solve#
- pastas.model.Model.solve(tmin: pandas.Timestamp | str | None = None, tmax: pandas.Timestamp | str | None = None, freq: str | None = None, warmup: float | None = None, solver: pastas.typing.Solver | None = None, report: bool | Literal['full'] | dict = True, initial: bool = True, weights: pandas.Series | None = None, fit_constant: bool = True, freq_obs: str | None = None, initialize: bool = False, reset_settings: bool = False, noise: bool | None = None, **kwargs) None#
Solve the time series model.
- Parameters:
tmin (pandas.Timestamp or str, optional) – A string or pandas.Timestamp with the start date for the simulation period (E.g. ‘1980-01-01 00:00:00’). Strings are converted to pandas.Timestamp internally. If none is provided, the tmin from the oseries is used.
tmax (pandas.Timestamp or str, optional) – A string or pandas.Timestamp with the end date for the simulation period (E.g. ‘2020-01-01 00:00:00’). Strings are converted to pandas.Timestamp internally. If none is provided, the tmax from the oseries is used.
freq (str, optional) – String with the frequency the stressmodels are simulated. Must be one of the following (D, h, m, s, ms, us, ns) or a multiple of that e.g. “7D”. If None, the frequency from ml.settings is used (defaults to “D”).
warmup (float, optional) – Warmup period (in Days) for which the simulation is calculated, but not used for the calibration period. If None, the warmup from ml.settings is used (defaults to 3650 days).
solver (Class pastas.solver.Solver, optional) – Instance of a pastas Solver class used to solve the model. See pastas. solver for the options. The solver is stored in the ml.solver attribute. If None, the solver from ml.solver is used. If solver and ml.solver are both None, the default ps.solver.LeastSquares() is used.
report (bool | Literal["full"] | dict, optional) –
Print a report to the screen after optimization finished. Set to True (default) to print a standard report, set to “full” to print a report including the correlation matrix and standard errors of the parameters, or set to False to suppress the report.
Changed in version 2.0.0: To have full control over the report, a dictionary with the arguments of ml.solve.fit_report() can be provided: (i.e., ml.solve(report=dict(stderr=True, corr=False))).
initial (bool, optional) – Reset initial parameters from the individual stress models. Default is True. If False, the optimal values from an earlier optimization are used.
weights (pandas.Series, optional) – A pandas Series used to scale the residual or noise (in the case of a NoiseModel) during optimization. The weights must share the same DateTimeIndex as the observations (ml.observations()) to ensure proper alignment. These weights are applied such that the minimized objective function in least-squares solvers is
sum((weights * residuals)**2). This means that a residual with double the weight has four times as much influence. If None, equal weights are used. This can be used to put extra/less weight on certain periods (e.g., droughts) or measurements (i.e. outliers), and make more complex calibration schemes (see, for example, []). Note that the weights are only used during optimization and not when computing the goodness-of-fit metrics.fit_constant (bool, optional) – Argument that determines if the constant is fitted as a parameter. If it is set to False, the constant is set equal to the mean of the residuals.
freq_obs (str, optional) – String with the frequency of the observations that the model will be calibrated on. Must be one of the following (D, h, m, s, ms, us, ns) or a multiple of that e.g. “7D”. Should generally be larger than the frequency of the original observations and the model frequency (freq). If freq_obs is not set, the frequency of the model (freq) will be used.
initialize (bool, optional) –
If True, the model is initialized via the Model.initialize() method (setting certain model settings) before solving. If False, the model is not initialized before solving. Note that the latter is an advanced option since some model settings can be missing. Default is False and deprecated since version 2.0.0.
Deprecated since version 2.0.0: The initialize argument is deprecated in favor of the reset_settings argument.
reset_settings (bool = False,) – If True, the model settings are reset to their default values before solving. This calls the Model.set_settings() method with default values. Default is False. To reset the original parameters of the model, use initial=True instead.
**kwargs (dict, optional) – All keyword arguments will be passed onto minimization method from the solver. It depends on the solver used which arguments can be used.
Notes
The solver instance including some results are stored as ml.solver. From here one can access the specific attributes from the solver (i.e., the covariance matrix(ml.solver.pcov) for the LeastSquaresSolve).
Each solver returns a number of results after optimization. These solver specific results are stored in ml.solver.result and can be accessed from there.
See also
pastas.solverDifferent solver objects are available to estimate parameters.