Derivative Models
Derivative models parameterize the right hand side of an ODE in normal form: $$ \dot{\boldsymbol{x}} = \boldsymbol{f}(t, \boldsymbol{x}[, \boldsymbol{u}; \text{args}]) $$ where \(\boldsymbol{x}(t)\in\mathbb{R}^n\) is the systems state vector, \(t\) is time, \(\boldsymbol{u}(t)\in\mathbb{R}^m\) are external inputs (for example forces acting on a system), and \(\text{args}\) is a set of arbitrary parameters of the system.
They are most often combined with a numerical solver.
Port-Hamiltonian systems
dynax.ISOPHS
Input-State-Output port-Hamiltonian Systems (ISOPHS).
Implementation of an input-state-output port-Hamiltonian system:
where
- \(\boldsymbol{x}(t)\) is the state,
- \(\boldsymbol{u}(t)\) is the input,
- \(\boldsymbol{y}(t)\) is the output,
- \(\mathcal{H}(\boldsymbol{x}, \text{args})\) is the Hamiltonian function given by
hamiltonian, - \(\boldsymbol{J}(\boldsymbol{x}, \text{args})\) is the structure matrix given by
structure_matrix, - \(\boldsymbol{R}(\boldsymbol{x}, \text{args})\) is the dissipation matrix given by
dissipation_matrix, - \(\boldsymbol{G}(\boldsymbol{x}, \text{args})\) is the input matrix given by
input_matrix, - and \(\text{args}\) is an optional set of parameters.
Note
The usage of the output equation is optional, but requires that the input
matrix (input_matrix) is defined.
__init__(hamiltonian, structure_matrix, dissipation_matrix=None, input_matrix=None)
Initialize the ISOPHS.
| PARAMETER | DESCRIPTION |
|---|---|
hamiltonian
|
Function or submodel computing the Hamiltonian \(\mathcal{H}(\boldsymbol{x}, \text{args})\) as a function of the state vector and the parameters.
TYPE:
|
structure_matrix
|
Function or submodel computing the structure matrix \(\boldsymbol{J}(\boldsymbol{x}, \text{args})\) as a function of the state vector and the parameters. From the port-Hamiltonian modeling view the structure matrix is required to be skew-symmetric, i.e., \(\boldsymbol{J} = -\boldsymbol{J}^\intercal\).
TYPE:
|
dissipation_matrix
|
Function or submodel computing the dissipation
matrix \(\boldsymbol{R}(\boldsymbol{x}, \text{args})\) as a function of the state
vector. From the port-Hamiltonian modeling view the dissipation
matrix is required to be symmetric positive semi-definite, i.e.,
\(\boldsymbol{R} = \boldsymbol{R}^\intercal,\,\boldsymbol{R}\succ0\).
TYPE:
|
input_matrix
|
Function or submodel computing the input matrix
\(\boldsymbol{G}(\boldsymbol{x}, \text{args})\) as a function of the state vector.
TYPE:
|
__call__(t, x, u=None, args=None)
Return the time derivative of the state vector \(x\).
| PARAMETER | DESCRIPTION |
|---|---|
t
|
Scalar time for evaluation. This argument is unused, but required to
comply with the
TYPE:
|
x
|
State vector at time
TYPE:
|
u
|
Input vector at time
TYPE:
|
args
|
Additional arguments passed to \(\mathcal{H}, \boldsymbol{J}, \boldsymbol{R}\) and \(\boldsymbol{G}\).
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If a input is provided but the system does not have an input matrix. |
| RETURNS | DESCRIPTION |
|---|---|
Float[Array, n]
|
Time derivative of the state vector \(\boldsymbol{x}\) as a 1D array of shape |
dynax.MatrixWrapper
Compatibility layer for using klax matrices with the call interface required by ISOPHS.
Matrix-valued functions implemented in klax currently only support one
input argument x -> A. However, the matrix-valued functions required for
the input-state-output port-Hamiltonian system demand the
call signature (x, args) -> A. This class can wrap the klax matrix-valued
functions to comply with the latter call signature.
It supports 4 modes depending on state_dependent and parameter_dependent:
- If both
state_dependent=parameter_dependent=True, then thexandargsare combined usingjax.flatten_util.ravel_pytree([x, args])and the result is passed to the wrapped matrix-valued function. - If only
state_dependent=True, thenxis passed to the matrix-valued function. - If only
parameter_dependent=True, thenargsis passed to the matrix-valued function. - If both
state_dependent=parameter_dependent=False, thenNoneis passed to the matrix-valued function.
__init__(matrix, state_dependent=False, parameter_dependent=False)
Initialize self. See help(type(self)) for accurate signature.
__call__(x, args)
Physics-agnostic systems
dynax.NeuralODE
Derivative model for a neural ODE.
This implements the following equation: $$ \dot{y} = f(t, y, u; \text{args}) $$ where \(f\) is a multi-layer perceptron (MLP), depending on time \(t\in\mathbb{R}\), the state vector \(y(t)\in\mathbb{R}^n\), an input vector \(u(t)\in\mathbb{R}^m\) and a parameter vector \(\text{args}\in\mathbb{R}^m\).
__init__(state_size, input_size=None, parameter_size=None, *, time_dependent=False, state_dependent=True, width_sizes, weight_init=init, bias_init=zeros, activation=softplus, final_activation=<lambda>, use_bias=True, use_final_bias=True, weight_wrap=None, bias_wrap=None, dtype=None, key)
Create a neural ode.
| PARAMETER | DESCRIPTION |
|---|---|
state_size
|
Number of elements in the state vector
TYPE:
|
input_size
|
Number of elements in the input vector
TYPE:
|
parameter_size
|
Number of elements in the raveled parameter PyTree
TYPE:
|
time_dependent
|
If true then the time is fed as an additional array entry to the MLP. Defaults to False.
TYPE:
|
state_dependent
|
If true then the state is fed as an additional array entry to the MLP. Defaults to True.
TYPE:
|
width_sizes
|
The sizes of each hidden layer in a list.
TYPE:
|
weight_init
|
The weight initializer of type
TYPE:
|
bias_init
|
The bias initializer of type
TYPE:
|
activation
|
The activation function after each hidden layer.
(Defaults to
TYPE:
|
final_activation
|
The activation function after the output layer. (Defaults to the identity.)
TYPE:
|
use_bias
|
Whether to add on a bias to internal layers.
(Defaults to
TYPE:
|
use_final_bias
|
Whether to add on a bias to the final layer.
(Defaults to
TYPE:
|
weight_wrap
|
An optional wrapper that is passed to all weights.
TYPE:
|
bias_wrap
|
An optional wrapper that is passed to all biases.
TYPE:
|
dtype
|
The dtype to use for all the weights and biases in this MLP.
Defaults to either
TYPE:
|
key
|
A
TYPE:
|
__call__(t, x, u=None, args=None)
Evaluate the neural ODE's derivative.