seq1d

deer.seq1d(func: Callable[[Array, Any, Any], Array], y0: Array, xinp: Any, params: Any, method: Seq1DMethod | None = None) Array[source]

Solve the discrete sequential equation

\[y_{i + 1} = f(y_i, x_i; \theta)\]

where \(f\) is a non-linear function, \(y_i\) is the output signal at time \(i\), \(x_i\) is the input signal at time \(i\), and \(\theta\) are the parameters of the function.

Parameters:
  • func (Callable[[jnp.ndarray, Any, Any], jnp.ndarray]) – Function to evaluate the next output signal \(y_{i+1}\) from the current output signal \(y_i\). The arguments are: signal \(y\) at the current time (ny,), input signal \(x\) at the current time (*nx,) in a pytree, and parameters \(\theta\) in a pytree. The return value is the next output signal \(y\) at the next time (ny,).

  • y0 (jnp.ndarray) – Initial condition on \(y\) (ny,).

  • xinp (Any) – The external input signal in a pytree of shape (nsamples, *nx)

  • params (Any) – The parameters of the function func.

  • method (Optional[Seq1DMethod]) – The method to solve the 1D sequence. If None, then use the DEER() method.

Returns:

res – The Result object where .value is the solution of the sequential model with shape (nsamples, ny) and .success is the boolean array indicating the convergence of the solver.

Return type:

Result

Examples

>>> import jax
>>> import jax.numpy as jnp
>>> from fseq1d import seq1d
>>> def func(y, x, params):
...     return y ** 2 + x * params[0]
>>> y0 = jnp.array([0.0])
>>> xinp = jnp.linspace(0, 1, 10).reshape(-1, 1)
>>> params = jnp.array([0.5])
>>> y = seq1d(func, y0, xinp, params, method=seq1d.Sequential()).value
>>> y
Array([[0.        ],
       [0.05555556],
       [0.11419753],
       [0.17970774],
       [0.2545171 ],
       [0.34255673],
       [0.45067845],
       [0.59199995],
       [0.79490839],
       [1.13187934]], dtype=float64)
method=seq1d.Sequential()
seq1d.Sequential(*args, **kwargs)

Compute the 1D sequence with traditional sequential method.

method=seq1d.DEER()
seq1d.DEER(yinit_guess: Optional[jax.Array] = None, max_iter: int = 10000, atol: Optional[float] = None, rtol: Optional[float] = None)

Compute the 1D sequential method using DEER method.

Parameters:
  • yinit_guess (Optional[jnp.ndarray]) – The initial guess of the output signal (nsamples, ny). If None, it will be initialized as all y0.

  • max_iter (int) – The maximum number of DEER iterations to perform.

  • atol (Optional[float]) – The absolute tolerance of the DEER iteration convergence.

  • rtol (Optional[float]) – The relative tolerance of the DEER iteration convergence.