anesthetic.examples package
Module for generating example data of nested sampling.
anesthetic.examples.perfect_ns module
Perfect nested sampling generators.
Perfect nested sampling run for a correlated gaussian likelihood.
This produces a perfect nested sampling run with a uniform prior over the unit hypercube. The algorithm proceeds by simultaneously rejection sampling from the prior and sampling exactly and uniformly from the known ellipsoidal contours.
This can produce perfect runs in up to around d~15 dimensions. Beyond this rejection sampling from a truncated gaussian in the early stage becomes too inefficient.
- Parameters:
- nliveint
minimum number of live points across the run
- mean1d array-like, shape (ndims,)
mean of gaussian in parameters. Length of array defines dimensionality of run.
- cov2d array-like, shape (ndims, ndims)
covariance of gaussian in parameters
- bounds2d array-like, shape (ndims, 2)
bounds of a gaussian, default
[[0, 1]]*ndims
- logLmaxfloat
maximum loglikelihood
- The remaining arguments are passed to the
- :class:`anesthetic.samples.NestedSamples` constructor.
- Returns:
- samples
anesthetic.samples.NestedSamples
Nested sampling run
- samples
- anesthetic.examples.perfect_ns.gaussian(nlive, ndims, sigma=0.1, R=1, logLmin=-0.01, logLmax=0, *args, **kwargs)[source]
Perfect nested sampling run for a spherical Gaussian & prior.
Up to normalisation this is identical to the example in John Skilling’s original paper https://doi.org/10.1214/06-BA127 . Both spherical Gaussian width sigma and spherical uniform prior width R are centered on zero
- Parameters:
- nliveint
number of live points
- ndimsint
dimensionality of gaussian
- sigmafloat
width of gaussian likelihood
- Rfloat
radius of gaussian prior
- logLminfloat
loglikelihood at which to terminate
- logLmaxfloat
maximum loglikelihood
- The remaining arguments are passed to the
- :class:`anesthetic.samples.NestedSamples` constructor.
- Returns:
- samples
anesthetic.samples.NestedSamples
Nested sampling run
- samples
- anesthetic.examples.perfect_ns.planck_gaussian(nlive=500)[source]
Gaussian likelihood with Planck-like posterior.
This is a gaussian likelihood with the same mean, parameter covariance and average loglikelihood as the Planck 2018 legacy chains
base/plikHM_TTTEEE_lowl_lowE_lensing
- Parameters:
- nliveint, optional
number of live points
- Returns:
- samples
anesthetic.samples.NestedSamples
Nested sampling run
- samples
- anesthetic.examples.perfect_ns.wedding_cake(nlive, ndims, sigma=0.01, alpha=0.5, *args, **kwargs)[source]
Perfect nested sampling run for a wedding cake likelihood.
This is a likelihood with nested hypercuboidal plateau regions of constant likelihood centered on 0.5, with geometrically decreasing volume by a factor of alpha. The value of the likelihood in these plateau regions has a gaussian profile with width sigma.
logL = - alpha^(2*floor(D*log_alpha(2|x-0.5|_infinity))/D) / (8sigma^2)
- Parameters:
- nliveint
number of live points
- ndimsint
dimensionality of the likelihood
- sigmafloat
width of gaussian profile
- alphafloat
volume compression between plateau regions
- The remaining arguments are passed to the
- :class:`anesthetic.samples.NestedSamples` constructor.
anesthetic.examples.utils module
Utility functions for nested sampling examples.
- anesthetic.examples.utils.log_volume_n_ball(n, r=1)[source]
Log-volume of an n dimensional ball, radius r.
- anesthetic.examples.utils.random_covariance(sigmas)[source]
Draw a randomly oriented covariance matrix with axes length sigmas.
- Parameters:
- sigmas1d array like
Lengths of the axes of the ellipsoid.
- Returns:
- Covariance matrix2d np.array
shape (len(sigmas), len(sigmas)).
- anesthetic.examples.utils.random_ellipsoid(mean, cov, size=None)[source]
Draw a point uniformly in an ellipsoid.
This is defined so that the volume of the ellipsoid is
sqrt(det(cov))*V_n
. whereV_n
is the volume of the unit n ball, and so that its axes have length equal to the square root of the eigenvalues of the covariance matrix.- Parameters:
- mean1d array-like
The center of mass of the ellipsoid
- cov2d array-like
The covariance structure of the ellipsoid. Axes have lengths equal to the square root of the eigenvalues of this matrix.
- sizeint or tuple of ints, optional
Given a shape of, for example, (m,n,k), m*n*k samples are generated, and packed in an m-by-n-by-k arrangement. Because each sample is N-dimensional, the output shape is (m,n,k,N). If no shape is specified, a single (N-D) sample is returned.
- Returns:
- pointsarray-like
The drawn samples, of shape size, if that was provided. If not, the shape is (N,). In other words, each entry
out[i,j,...,:]
is an N-dimensional value drawn uniformly from the ellipsoid.