Logo

A physics toolbox for laser spectroscopy.

Static Badge Static Badge Static Badge

Static Badge Static Badge

© 2025 Patrick Müller. All rights reserved.

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), where k is the number of data points and n is 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). Use covariance_matrix to construct covariance matrices.

p0ndarray | Iterable

The start parameters for the linear fit. Must have shape (2 * n, ). The first n elements specify the origin vector of the straight, the second n elements 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 n dimensions is fully described by 2 * (n - 1) parameters. If None, 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).

API navigation