dynax.estimation

Functions for estimating parameters of dynamical systems.

Parameters of model.system can be constrained via the *_field functions.

Functions

estimate_spectra(u, y, sr[, with_dc])

Estimate cross- and autospectral densities using Welch's method.

fit_csd_matching(sys, f, Syu, Suu[, reg, ...])

Estimate parameters of linearized system by matching cross-spectral densities.

fit_least_squares(model, t, y[, u, batched, ...])

Fit evolution model with regularized, box-constrained nonlinear least-squares.

fit_multiple_shooting(model, t, y[, u, ...])

Fit evolution model with multiple shooting.

ravel_and_bounds(pytree)

transfer_function(sys[, to_states])

Compute transfer-function \(H(s)\) of the linearized system.

dynax.estimation.fit_least_squares(model, t, y, u=None, batched=False, sigma=None, absolute_sigma=False, reg_val=0, reg_bias=None, verbose_mse=True, **kwargs)[source]

Fit evolution model with regularized, box-constrained nonlinear least-squares.

For an example, see Fit a system of ordinary differential equations.

Parameters:
  • model (AbstractEvolution) – A concrete evolution object.

  • t (ArrayLike) – Times signal.

  • y (ArrayLike) – Output signal with time dimension along the first axis.

  • u (ArrayLike | None) – Optional input signal with time along the first axis.

  • batched (bool) – Whether t, y, and u have an additional first axis of equal length holding several trajectories. The loss is then computed over all trajectories.

  • sigma (ArrayLike | None) – The measurement standard deviation which is broadcasted against y. If None, it is assumed that the outputs have equal signal-to-noise ratios.

  • absolute_sigma (bool) – Whether sigma is used in an absolute sense and the estimated parameter covariance reflects these absolute values. Otherwise, only the relative magnitudes of the sigma values matter. See also scipy.optimize.curve_fit().

  • reg_val (float) – Weight of the \(L_2\) regularization.

  • reg_bias (Literal['initial'] | None) – Substractive bias term in the \(L_2\) regularization. If initial, uses the initial parameters.

  • verbose_mse (bool) – Whether the cost is scaled to the mean-squared error during logging with verbose=2.

  • kwargs – Optional parameters for scipy.optimize.least_squares().

Returns:

OptimizeResult – A Result object with the following additional attributes.

  • result: Fitted model.

  • pcov: Covariance matrix of the predicted parameters.

  • y_pred: Predicted outputs.

  • key_paths: Paths to free parameters of the model, see jax.tree_util.tree_flatten_with_path().

  • mse: Mean-squared error.

  • nmse: Normalized mean-squared error.

  • nrmse: Normalized root mean-squared error.

dynax.estimation.fit_multiple_shooting(model, t, y, u=None, num_shots=1, continuity_penalty=0.1, **kwargs)[source]

Fit evolution model with multiple shooting.

Multiple shooting subdivides the training problem into shooting segments and fits the initial states of the segments and the model parameters by minimizing the output error and a continuity loss of the states along the segment boundaries.

For an example, see Fit a system with multiple shooting.

Parameters:
  • model (AbstractEvolution) – Concrete evolution object.

  • t (ArrayLike) – Time signal.

  • y (ArrayLike) – Outputs with time dimension along the first axis.

  • u (ArrayLike | None) – Optional inputs with time along the first axis.

  • num_shots (int) – Number of shooting segments the training problem is divided into. If the length of the signals is not divisible by num_shots, the last few samples are ignored.

  • continuity_penalty (float) – Weights the penalty for discontinuities of the solution along shooting segment boundaries.

  • kwargs – Optional parameters for scipy.optimize.least_squares().

Returns:

OptimizeResult – Result object with the following additional attributes

  • result: The fitted model.

  • x0s: The initial states of the shooting segments.

  • ts: The times of the segments.

  • ts0: The times of the segments relative to the start of each segment.

  • us: The inputs of the segments. Only returned if u is not None.

dynax.estimation.transfer_function(sys, to_states=False, **kwargs)[source]

Compute transfer-function \(H(s)\) of the linearized system.

Parameters:
  • sys (AbstractSystem) – Concrete dynamical system.

  • to_states (bool) – Whether to return the transfer-function between input and states. Otherwise compute it between input and output.

  • kwargs – Optional arguments for AbstractSystem.linearize.

Returns:

Callable[[ArrayLike], Array] – A function that computes the transfer-function at a given complex frequency.

dynax.estimation.estimate_spectra(u, y, sr, with_dc=False, **kwargs)[source]

Estimate cross- and autospectral densities using Welch’s method.

Parameters:
  • u (ArrayLike) – Input signal.

  • y (ArrayLike) – Output signal.

  • sr (float) – Sampling rate.

  • with_dc (bool) – Whether or not to include zero frequency term.

  • kwargs – Passed to scipy.signal.csd.

Returns:

tuple[ndarray, ndarray, ndarray] – Tuple (f, S_yu, S_uu) of frequencies, cross- and autospectral densities.

dynax.estimation.fit_csd_matching(sys, f, Syu, Suu, reg=0, x_scale=True, verbose_mse=True, absolute_sigma=False, linearize_kwargs=None, **kwargs)[source]

Estimate parameters of linearized system by matching cross-spectral densities.

Parameters:
  • sys (AbstractSystem) – Concrete dynamical system.

  • f (ArrayLike) – Frequencies.

  • Syu (ArrayLike) – Cross-spectral density.

  • Suu (ArrayLike) – Auto-spectral density.

  • reg (float) – Weight of the \(L_2\) regularization.

  • x_scale (bool) – Whether parameters are scaled by the initial values.

  • verbose_mse (bool) – Whether the cost is scaled to the mean-squared error during logging with verbose=2.

  • absolute_sigma (bool) – Whether sigma is used in an absolute sense and the estimated parameter covariance reflects these absolute values. Otherwise, only the relative magnitudes of the sigma values matter. See also scipy.optimize.curve_fit().

  • linearize_kwargs (dict | None) – Arguments passed to linearize().

  • kwargs – Optional parameters for scipy.optimize.least_squares.

Returns:

OptimizeResult – Result object with these additional attributes.

  • result: Fitted model.

  • pcov: Estimated covariance of the parameters.

  • key_paths: Paths to free parameters of the model, see jax.tree_util.tree_flatten_with_path().

  • mse: Mean-squared error.

  • nmse: Normalized mean-squared error.

  • nrmse: Normalized root mean-squared error.