- 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:
-
- xndarray | Iterable
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.- covndarray | Iterable
The covariance matrices $\mathbf{\Sigma}_i$ of the data vectors. Must have shape
(k, n, n). Usecovariance_matrixto construct covariance matrices.- p0ndarray | Iterable
The start parameters for the linear fit. Must have shape
(2 * n, ). The firstnelements specify the origin vector of the straight, the secondnelements specify the direction of the straight.- axisint
The index of the vector component of the n-dimensional vectors that are fixed for fitting. This is required since a straight 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 is normalized.- optimize_covbool
If
True, the origin vector of the straight is optimized to yield the smallest covariances.- kwargsNone
Additional keyword arguments.
- Returns:
-
- (popt, pcov)(ndarray, ndarray)
The optimized parameters and their covariances. The resulting shapes are
(2 * n, )and(2 * n, 2 * n).