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

A Monte-Carlo fitter that finds a straight line in n-dimensional space.

Parameters:
xndarray | Iterable

The data vectors. 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 of the data vectors. Must have shape (k, n, n). Use 'covariance_matrix' to construct covariance matrices. If None, samples are generated until n samples get accepted.

axisint

The component of the n-dimensional vectors which are fixed for fitting. This is required since a straight in n dimensions is fully described by 2 (n - 1) parameters.

optimize_covbool

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

n_samplesint

Maximum number of generated samples. 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 sampling from the data.

return_samplesbool

Whether to also return the generated points 'p'. 'p' has 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:
outNone

popt, pcov (, p). The optimized parameters and their covariances. If 'return_samples' is True, also returns the generated points 'p'. The resulting shapes are (2n, ), (2n, 2n) and (n_samples, k ,n).

API navigation