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_monte_carlo  (  x y sigma_x = None sigma_y = None corr = None optimize_cov = True n_samples = None n_accepted = None optimize_sampling = True return_samples = False method = 'py' report = True ** kwargs  )[source]

Maximum likelihood Monte-Carlo sampling of a straight line through points $\vec{\mu}_i\in\mathbb{R}^2$ with covariances $\mathbf{\Sigma}_i\in\mathbb{R}^{2\times 2}$, assuming $2$-dimensional multivariate normal distributions $\mathcal{N}(\vec{\mu}_i, \mathbf{\Sigma}_i)$. TThis is a wrapper for the more general linear_nd_monte_carlo function. The algorithm is described in the supplementary material of [Gebert et al., Phys. Rev. Lett. 115, 053003 (2015)].

Parameters:
xndarray | Iterable

The $x$ data.

yndarray | Iterable

The $y$ data.

sigma_xndarray | Iterable

The standard deviation $\sigma_x$ of the x data.

sigma_yndarray | Iterable

The standard deviation $\sigma_y$ of the y data.

corrndarray | Iterable

The correlation coefficients $\rho_{xy}$ between the x and y data.

optimize_covbool

If True, the origin vector of the straight is optimized to yield the smallest covariances.

n_samplesint

The number of samples generated for each data point. If None and method == 'cpp', samples are generated until n_accepted samples get accepted.

n_acceptedint

The number of samples to be accepted for each data point. Only available if method == 'cpp'.

optimize_samplingbool

Whether to optimize the data sampling for acceptance efficiency.

return_samplesbool

Whether to also return the generated points $\vec{p}_i$ with shape (n_samples, k ,n).

methodstr

The method to generate the collinear points. Can be one of {'py', 'cpp'}. The 'py' version is faster but only allows to specify n_samples. The 'cpp' version is slower but allows to specify both n_accepted and n_samples.

reportbool

Whether to print the result of the fit.

kwargsNone

Additional keyword arguments to be passed to the chosen method. 'py': {}, 'cpp': {seed: None}.

Returns:
(popt, pcov, p)(ndarray, ndarray, Optional[ndarray])

The optimized parameters and their covariances. If return_samples == True, also the generated points $\vec{p}_i$ are returned. The resulting shapes are (2, ), (2, 2) and (n_samples, k, 2).

API navigation