- 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)$.
This is a wrapper for the more general
linear_nd_monte_carlofunction. The algorithm is described in the supplementary material of [Gebert et al., Phys. Rev. Lett. 115, 053003 (2015)].- Parameters:
-
- xarray_like
The $x$ data.
- yarray_like
The $y$ data.
- sigma_xarray_like | None
The standard deviation $\sigma_x$ of the
xdata. IfNone, it is 1.- sigma_yarray_like | None
The standard deviation $\sigma_y$ of the
ydata. IfNone, it is 1.- corrarray_like | None
The correlation coefficients $\rho_{xy}$ between the
xandydata. IfNone, it is 0.- optimize_covbool
If
True, the origin vector of the straight line is optimized to yield the smallest covariances.- n_samplesint_like | None
The number of samples generated for each data point. If
Noneandmethod == "cpp", samples are generated untiln_acceptedsamples get accepted.- n_acceptedint_like | None
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_accepted, k, 2).- methodstr
The method to generate the collinear points. Can be one of
{"py", "cpp"}. The"py"version is faster but only allows to specifyn_samples. The"cpp"version is slower but allows to specify bothn_acceptedandn_samples.- reportbool
Whether to print the result of the fit.
- kwargsAny
Additional keyword arguments are accepted for compatibility with the other linear regression algorithms and ignored.
- Returns:
-
- (popt, pcov, p)Any
The best y-intercept and slope and their covariance matrix. If
return_samplesisTrue, also the generated points $\vec{p}_i$ are returned. The resulting shapes are(2, ),(2, 2)and(n_accepted, k, 2).
- Raises:
-
- ValueError
If
methodis not supported.