- qspec.analyze. linear_nd_fit ( x , cov=None , p0=None , axis=None , optimize_cov=False , **kwargs )[source]
-
Maximum likelihood fit for a straight line through points $\vec{\mu}_i\in\mathbb{R}^n$ with covariances $\mathbf{\Sigma}_i\in\mathbb{R}^{n\times n}$, assuming $n$-dimensional multivariate normal distributions $\mathcal{N}(\vec{\mu}_i, \mathbf{\Sigma}_i)$.
The algorithm is described in qspec's publication.
- Parameters:
-
- xarray_like
The data vectors $\vec{\mu}_i$. Must have shape
(k, n), wherekis the number of data points andnis the number of dimensions of each point.- covarray_like | None
The covariance matrices $\mathbf{\Sigma}_i$ of the data vectors. Must have shape
(k, n, n). Usecovariance_matrixto construct covariance matrices.- p0array_like | None
The start parameters for the linear fit. Must have shape
(2 * n, ). The firstnelements specify the origin vector of the straight line, the secondnelements specify the direction of the straight line.- axisint | None
The index of the vector component of the n-dimensional vectors that are fixed for fitting. This is required since a straight line in
ndimensions is fully described by2 * (n - 1)parameters. IfNone, the best axis is determined from the data, and the direction vector of the straight line is normalized.- optimize_covbool
If
True, the origin vector of the straight line is optimized to yield the smallest covariances.- kwargsAny
Additional keyword arguments are accepted for compatibility with
linear_nd_monte_carloand ignored.
- Returns:
- Raises:
-
- numpy.linalg.LinAlgError
If a covariance matrix cannot be inverted.