9. Random sampling¶
- lsqfitgp.raniter(mean, cov, n=None, eps=None, rng=None)[source]¶
Take random samples from a multivariate Gaussian.
This generator mimics the interface of
gvar.raniter
, but takes as input the mean and covariance separately instead of a collection of gvars.- Parameters:
- meanscalar, array, or dictionary of scalars/arrays
The mean of the Gaussian distribution.
- covscalar, array, or dictionary of scalars/arrays
The covariance matrix. If
mean
is a dictionary,cov
must be a dictionary with pair of keys frommean
as keys.- nint, optional
The maximum number of iterations. Default unlimited.
- epsfloat, optional
Used to correct the eigenvalues of the covariance matrix to handle non-positivity due to roundoff, relative to the largest eigenvalue. Default is number of variables times floating point epsilon.
- rngseed or random generator, optional
rng
is passed throughnumpy.random.default_rng
to produce a random number generator.
- Yields:
- sampscalar, array, or dictionary of scalars/arrays
The random sample in the same format of
mean
.
Examples
>>> mean = {'a': np.arange(3)} >>> cov = {('a', 'a'): np.eye(3)} >>> for sample in lgp.raniter(mean, cov, 3): >>> print(sample)