mappy_ds.SystemFunction#

class mappy_ds.SystemFunction(fun, dom_dim, cod_dim, direction=0, name=None)#

A vector-valued function \(f(y, p)\) with symbolic derivatives.

Parameters:
funcallable

Python function fun(y, params). y is a one-dimensional array of length dom_dim and params a mapping of parameter values that must be read as params[key]. The return value must be convertible to a vector of length cod_dim.

dom_dimint

Dimension of the domain (length of y).

cod_dimint

Dimension of the codomain (length of the returned vector).

directionint, optional

Only meaningful for border functions: direction of the zero crossing that terminates a continuous mode (1, -1 or 0 for both), forwarded to scipy.integrate.solve_ivp() events.

namestr, optional

Name of the function, by default fun.__name__. Border names identify borders in transition rules.

Attributes:
param_keystuple of str

Names of the parameters the function reads (discovered by tracing).

Notes

The function is traced with SymPy on first use. The Jacobian follows the convention jac[i, j] = ∂f_i/∂y_j, the Hessian hes[i, j, k] = ∂²f_i/(∂y_j ∂y_k), the parameter Jacobian jac_p[i, m] = ∂f_i/∂p_m and the mixed Hessian hes_p[i, j, m] = ∂²f_i/(∂y_j ∂p_m), with m indexing param_keys.

Properties

expression

Symbolic expression of the function as a cod_dim × 1 matrix.

hessian_expression

Symbolic Hessian (cod_dim × dom_dim × dom_dim).

jacobian_expression

Symbolic Jacobian (cod_dim × dom_dim).

mixed_hessian_expression

Symbolic mixed derivative ∂²f/∂y∂p (cod_dim × dom_dim × k).

param_keys

Names of the parameters the function reads (discovered by tracing).

parameter_jacobian_expression

Symbolic derivative with respect to the parameters (cod_dim × k).

Methods

__call__(y[, params])

Evaluate the function numerically.

eval(y, p)

Evaluate with a pre-extracted parameter array (hot path).

eval_hessian(y, p)

Hessian with a pre-extracted parameter array (hot path).

eval_jacobian(y, p)

Jacobian with a pre-extracted parameter array (hot path).

eval_mixed_hessian(y, p)

Mixed Hessian with a pre-extracted parameter array (hot path).

eval_mixed_hessian_for(y, p, keys)

Mixed Hessian with the last axis laid out along keys.

eval_parameter_jacobian(y, p)

Parameter Jacobian with a pre-extracted parameter array (hot path).

eval_parameter_jacobian_for(y, p, keys)

Parameter Jacobian with columns laid out along keys.

hessian(y[, params])

Evaluate the Hessian tensor at y.

jacobian(y[, params])

Evaluate the Jacobian matrix at y.

mixed_hessian(y[, params])

Evaluate ∂²f/∂y∂p at y; last axis in the order of param_keys.

parameter_jacobian(y[, params])

Evaluate ∂f/∂p at y, columns in the order of param_keys.

params_array(params)

Extract param_keys from params as a float array.