fips.Covariance.quadratic_form#
- Covariance.quadratic_form(x)[source]#
Return \(x^T S^{-1} x\), the squared Mahalanobis length of x.
- Parameters:
x (
Vector) – A vector on the covariance’s space, in any order.- Returns:
The quadratic form of the inverse covariance.
- Return type:
- Raises:
ValueError – If the labels of x do not match the covariance’s.
numpy.linalg.LinAlgError – If the covariance is singular.
Examples
>>> import pandas as pd >>> from fips import Covariance, Space, Vector >>> space = Space({"co2": pd.Index(["a", "b"], name="site")}) >>> S = Covariance.diagonal([4.0, 1.0], space) >>> S.quadratic_form(Vector([2.0, 1.0], space)) 2.0