NumericalError#

exception cultivars.exceptions.NumericalError[source]#

Bases: CultivarsError, RuntimeError

A computation failed numerically (non-finite input, singular system).

The specification and shapes were valid but the arithmetic could not be carried out or would return nonsense: a nan or inf in the data or a system matrix, a covariance that is not positive semidefinite, a lag polynomial exactly singular at some frequency, an unstable transition matrix where a stationary solution was asked for, an identification whose restrictions no factorization can honor. A RuntimeError rather than a ValueError because the failure is discovered in the computation, not in the argument, so a handler written for bad arguments does not swallow it.

See also

  • StabilityWarning – the warning category for a fit that succeeded but is non-stationary, which is not an error.

Example

>>> import numpy as np
>>> from cultivars.state_space.linear_gaussian import LinearGaussianSSM
>>> LinearGaussianSSM.stationary_covariance([[1.0]], [[1.0]], [[1.0]])
Traceback (most recent call last):
    ...
cultivars.exceptions.NumericalError: stationary_covariance requires a stable transition ...
>>> try:
...     LinearGaussianSSM.stationary_covariance([[1.0]], [[1.0]], [[1.0]])
... except ValueError:
...     print("argument handler")
... except RuntimeError:
...     print("computation handler")
computation handler