API
This page details the methods and classes provided by the dynesty module.
Top-Level Interface
The top-level interface (defined natively upon initialization) that
provides access to the two main sampler “super-classes” via
NestedSampler() and DynamicNestedSampler().
- class dynesty.dynesty.DynamicNestedSampler(loglikelihood, prior_transform, ndim, nlive=500, bound='multi', sample='auto', periodic=None, reflective=None, update_interval=None, first_update=None, rstate=None, queue_size=None, pool=None, use_pool=None, logl_args=None, logl_kwargs=None, ptform_args=None, ptform_kwargs=None, enlarge=None, bootstrap=None, walks=None, facc=0.5, slices=None, ncdim=None, blob=False, history_filename=None, save_evaluation_history=False)
Bases:
DynamicSamplerThe main class for performing dynamic nested sampling. It inherits all the methods from dynesty.dynamicsampler.DynamicSampler
Initializes a sampler object for Dynamic Nested Sampling.
- Parameters:
- loglikelihoodfunction
Function returning ln(likelihood) given parameters as a 1-d
numpyarray of lengthndim.- prior_transformfunction
Function translating a unit cube to the parameter space according to the prior. The input is a 1-d
numpyarray with lengthndim, where each value is in the range [0, 1). The return value should also be a 1-dnumpyarray with lengthndim, where each value is a parameter. The return value is passed to the loglikelihood function. For example, for a 2 parameter model with flat priors in the range [0, 2), the function would be:def prior_transform(u): return 2.0 * u
- ndimint
Number of parameters returned by
prior_transformand accepted byloglikelihood.- nliveint, optional
Number of “live” points. Larger numbers result in a more finely sampled posterior (more accurate evidence), but also a larger number of iterations required to converge. Default is
500.- bound{
'none','single','multi','balls','cubes'}, optional Method used to approximately bound the prior using the current set of live points. Conditions the sampling methods used to propose new live points. Choices are no bound (
'none'), a single bounding ellipsoid ('single'), multiple bounding ellipsoids ('multi'), balls centered on each live point ('balls'), and cubes centered on each live point ('cubes'). Default is'multi'.- sample{
'auto','unif','rwalk','slice','rslice'}, optional Method used to sample uniformly within the likelihood constraint, conditioned on the provided bounds. Unique methods available are: uniform sampling within the bounds(
'unif'), random walks with fixed proposals ('rwalk'), multivariate slice sampling along preferred orientations ('slice'), “random” slice sampling along all orientations ('rslice'),'auto'selects the sampling method based on the dimensionality of the problem (fromndim). Whenndim < 10, this defaults to'unif'. When10 <= ndim <= 20, this defaults to'rwalk'. Whenndim > 20, this defaults to`’rslice’`'slice'is provided as alternative for`’rslice’Default is `'auto'.- periodiciterable, optional
A list of indices for parameters with periodic boundary conditions. These parameters will not have their positions constrained to be within the unit cube, enabling smooth behavior for parameters that may wrap around the edge. Default is
None(i.e. no periodic boundary conditions).- reflectiveiterable, optional
A list of indices for parameters with reflective boundary conditions. These parameters will not have their positions constrained to be within the unit cube, enabling smooth behavior for parameters that may reflect at the edge. Default is
None(i.e. no reflective boundary conditions).- update_intervalint or float, optional
If an integer is passed, only update the proposal distribution every
update_interval-th likelihood call. If a float is passed, update the proposal after everyround(update_interval * nlive)-th likelihood call. Larger update intervals larger can be more efficient when the likelihood function is quick to evaluate. Default behavior is to target a roughly constant change in prior volume, with1.5for'unif',0.15 * walksfor'rwalk'.0.9 * ndim * slicesfor'slice',2.0 * slicesfor'rslice'.- first_updatedict, optional
A dictionary containing parameters governing when the sampler should first update the bounding distribution from the unit cube (
'none') to the one specified bysample. Options are the minimum number of likelihood calls ('min_ncall') and the minimum allowed overall efficiency in percent ('min_eff'). Defaults are2 * nliveand10., respectively.- rstate
Generator, optional - queue_sizeint, optional
Carry out likelihood evaluations in parallel by queueing up new live point proposals using (at most)
queue_sizemany threads. Each thread independently proposes new live points until the proposal distribution is updated. If no value is passed, this defaults topool.size(if apoolhas been provided) and1otherwise (no parallelism).- pooluser-provided pool, optional
Use this pool of workers to execute operations in parallel.
- use_pooldict, optional
A dictionary containing flags indicating where a pool should be used to execute operations in parallel. These govern whether
prior_transformis executed in parallel during initialization ('prior_transform'),loglikelihoodis executed in parallel during initialization ('loglikelihood'), live points are proposed in parallel during a run ('propose_point'), and bounding distributions are updated in parallel during a run ('update_bound'). Default isTruefor all options.- live_pointslist of 3
ndarrayeach with shape (nlive, ndim) A set of live points used to initialize the nested sampling run. Contains
live_u, the coordinates on the unit cube,live_v, the transformed variables, andlive_logl, the associated loglikelihoods. By default, if these are not provided the initial set of live points will be drawn uniformly from the unitndim-cube. WARNING: It is crucial that the initial set of live points have been sampled from the prior. Failure to provide a set of valid live points will result in incorrect results.- logl_argsiterable, optional
Additional arguments that can be passed to
loglikelihood.- logl_kwargsdict, optional
Additional keyword arguments that can be passed to
loglikelihood.- ptform_argsiterable, optional
Additional arguments that can be passed to
prior_transform.- ptform_kwargsdict, optional
Additional keyword arguments that can be passed to
prior_transform.- enlargefloat, optional
Enlarge the volumes of the specified bounding object(s) by this fraction. The preferred method is to determine this organically using bootstrapping. If
bootstrap > 0, this defaults to1.0. Ifbootstrap = 0, this instead defaults to1.25.- bootstrapint, optional
Compute this many bootstrapped realizations of the bounding objects. Use the maximum distance found to the set of points left out during each iteration to enlarge the resulting volumes. Can lead to unstable bounding ellipsoids. Default is
None(no bootstrap unless the sampler is uniform). If bootstrap is set to zero, bootstrap is disabled.- walksint, optional
For the
'rwalk'sampling option, the minimum number of steps (minimum 2) before proposing a new live point. Default is25.- faccfloat, optional
The target acceptance fraction for the
'rwalk'sampling option. Default is0.5. Bounded to be between[1. / walks, 1.].- slicesint, optional
For the
'slice','rslice'sampling options, the number of times to execute a “slice update” before proposing a new live point. Default is 3 for'slice'and 3+ndim for rslice. Note that'slice'cycles through all dimensions when executing a “slice update”.- ncdim: int, optional
The number of clustering dimensions. The first ncdim dimensions will be sampled using the sampling method, the remaining dimensions will just sample uniformly from the prior distribution. If this is
None(default), this will default to ndim.- blob: bool, optional
The default value is False. If it is true, then the log-likelihood should return the tuple of logl and a numpy-array “blob” that will stored as part of the chain. That blob can contain auxiliary information computed inside the likelihood function.
- Returns:
- samplera
dynesty.DynamicSamplerinstance An initialized instance of the dynamic nested sampler.
- samplera
- class dynesty.dynesty.NestedSampler(loglikelihood, prior_transform, ndim, nlive=500, bound='multi', sample='auto', periodic=None, reflective=None, update_interval=None, first_update=None, rstate=None, queue_size=None, pool=None, use_pool=None, live_points=None, logl_args=None, logl_kwargs=None, ptform_args=None, ptform_kwargs=None, enlarge=None, bootstrap=None, walks=None, facc=0.5, slices=None, ncdim=None, blob=False, save_evaluation_history=False, history_filename=None)
Bases:
SamplerThe main class performing the static nested sampling. It inherits all the methods of the dynesty.sampler.Sampler.
Initializes and returns a sampler object for Static Nested Sampling.
- Parameters:
- loglikelihoodfunction
Function returning ln(likelihood) given parameters as a 1-d
numpyarray of lengthndim.- prior_transformfunction
Function translating a unit cube to the parameter space according to the prior. The input is a 1-d
numpyarray with lengthndim, where each value is in the range [0, 1). The return value should also be a 1-dnumpyarray with lengthndim, where each value is a parameter. The return value is passed to the loglikelihood function. For example, for a 2 parameter model with flat priors in the range [0, 2), the function would be:def prior_transform(u): return 2.0 * u
- ndimint
Number of parameters returned by
prior_transformand accepted byloglikelihood.- nliveint, optional
Number of “live” points. Larger numbers result in a more finely sampled posterior (more accurate evidence), but also a larger number of iterations required to converge. Default is
500.- bound{
'none','single','multi','balls','cubes'}, optional Method used to approximately bound the prior using the current set of live points. Conditions the sampling methods used to propose new live points. Choices are no bound (
'none'), a single bounding ellipsoid ('single'), multiple bounding ellipsoids ('multi'), balls centered on each live point ('balls'), and cubes centered on each live point ('cubes'). Default is'multi'.- sample{
'auto','unif','rwalk','slice','rslice'}, optional Method used to sample uniformly within the likelihood constraint, conditioned on the provided bounds. Unique methods available are: uniform sampling within the bounds(
'unif'), random walks with fixed proposals ('rwalk'), multivariate slice sampling along preferred orientations ('slice'), “random” slice sampling along all orientations ('rslice'),'auto'selects the sampling method based on the dimensionality of the problem (fromndim). Whenndim < 10, this defaults to'unif'. When10 <= ndim <= 20, this defaults to'rwalk'. Whenndim > 20, this defaults to`’rslice’`'slice'is provided as alternative for`’rslice’Default is `'auto'.- periodiciterable, optional
A list of indices for parameters with periodic boundary conditions. These parameters will not have their positions constrained to be within the unit cube, enabling smooth behavior for parameters that may wrap around the edge. Default is
None(i.e. no periodic boundary conditions).- reflectiveiterable, optional
A list of indices for parameters with reflective boundary conditions. These parameters will not have their positions constrained to be within the unit cube, enabling smooth behavior for parameters that may reflect at the edge. Default is
None(i.e. no reflective boundary conditions).- update_intervalint or float, optional
If an integer is passed, only update the proposal distribution every
update_interval-th likelihood call. If a float is passed, update the proposal after everyround(update_interval * nlive)-th likelihood call. Larger update intervals larger can be more efficient when the likelihood function is quick to evaluate. Default behavior is to target a roughly constant change in prior volume, with1.5for'unif',0.15 * walksfor'rwalk'.0.9 * ndim * slicesfor'slice',2.0 * slicesfor'rslice'.- first_updatedict, optional
A dictionary containing parameters governing when the sampler should first update the bounding distribution from the unit cube (
'none') to the one specified bysample. Options are the minimum number of likelihood calls ('min_ncall') and the minimum allowed overall efficiency in percent ('min_eff'). Defaults are2 * nliveand10., respectively.- rstate
Generator, optional - queue_sizeint, optional
Carry out likelihood evaluations in parallel by queueing up new live point proposals using (at most)
queue_sizemany threads. Each thread independently proposes new live points until the proposal distribution is updated. If no value is passed, this defaults topool.size(if apoolhas been provided) and1otherwise (no parallelism).- pooluser-provided pool, optional
Use this pool of workers to execute operations in parallel.
- use_pooldict, optional
A dictionary containing flags indicating where a pool should be used to execute operations in parallel. These govern whether
prior_transformis executed in parallel during initialization ('prior_transform'),loglikelihoodis executed in parallel during initialization ('loglikelihood'), live points are proposed in parallel during a run ('propose_point'), and bounding distributions are updated in parallel during a run ('update_bound'). Default isTruefor all options.- live_pointslist of 3
ndarrayeach with shape (nlive, ndim) A set of live points used to initialize the nested sampling run. Contains
live_u, the coordinates on the unit cube,live_v, the transformed variables, andlive_logl, the associated loglikelihoods. By default, if these are not provided the initial set of live points will be drawn uniformly from the unitndim-cube. WARNING: It is crucial that the initial set of live points have been sampled from the prior. Failure to provide a set of valid live points will result in incorrect results.- logl_argsiterable, optional
Additional arguments that can be passed to
loglikelihood.- logl_kwargsdict, optional
Additional keyword arguments that can be passed to
loglikelihood.- ptform_argsiterable, optional
Additional arguments that can be passed to
prior_transform.- ptform_kwargsdict, optional
Additional keyword arguments that can be passed to
prior_transform.- enlargefloat, optional
Enlarge the volumes of the specified bounding object(s) by this fraction. The preferred method is to determine this organically using bootstrapping. If
bootstrap > 0, this defaults to1.0. Ifbootstrap = 0, this instead defaults to1.25.- bootstrapint, optional
Compute this many bootstrapped realizations of the bounding objects. Use the maximum distance found to the set of points left out during each iteration to enlarge the resulting volumes. Can lead to unstable bounding ellipsoids. Default is
None(no bootstrap unless the sampler is uniform). If bootstrap is set to zero, bootstrap is disabled.- walksint, optional
For the
'rwalk'sampling option, the minimum number of steps (minimum 2) before proposing a new live point. Default is25.- faccfloat, optional
The target acceptance fraction for the
'rwalk'sampling option. Default is0.5. Bounded to be between[1. / walks, 1.].- slicesint, optional
For the
'slice','rslice'sampling options, the number of times to execute a “slice update” before proposing a new live point. Default is 3 for'slice'and 3+ndim for rslice. Note that'slice'cycles through all dimensions when executing a “slice update”.- ncdim: int, optional
The number of clustering dimensions. The first ncdim dimensions will be sampled using the sampling method, the remaining dimensions will just sample uniformly from the prior distribution. If this is
None(default), this will default to ndim.- blob: bool, optional
The default value is False. If it is true, then the log-likelihood should return the tuple of logl and a numpy-array “blob” that will stored as part of the chain. That blob can contain auxiliary information computed inside the likelihood function.
- Returns:
- samplersampler from
nestedsamplers An initialized instance of the chosen sampler specified via
bound.
- samplersampler from
Bounding
Bounding classes used when proposing new live points, along with a number of useful helper functions. Bounding objects include:
- UnitCube:
The unit N-cube (unconstrained draws from the prior).
- Ellipsoid:
Bounding ellipsoid.
- MultiEllipsoid:
A set of (possibly overlapping) bounding ellipsoids.
- RadFriends:
A set of (possibly overlapping) balls centered on each live point.
- SupFriends:
A set of (possibly overlapping) cubes centered on each live point.
- class dynesty.bounding.Bound(ndim)
Bases:
objectThis is is master class for the all the bounds listing the key methods required from the bound
- contains(x)
Checks if unit cube contains the point
x.
- get_random_axes(rstate)
- sample(rstate=None)
Draw a sample uniformly distributed within the unit cube.
- Returns:
- x
ndarraywith shape (ndim,) A coordinate within the unit cube.
- x
- samples(nsamples, rstate=None)
Draw
nsamplessamples randomly distributed within the unit cube.- Returns:
- x
ndarraywith shape (nsamples, ndim) A collection of coordinates within the unit cube.
- x
- scale_to_logvol(rstate)
- update(points, rstate=None, bootstrap=0, pool=None)
- class dynesty.bounding.Ellipsoid(ndim, ctr=None, cov=None, am=None, axes=None)
Bases:
BoundAn N-dimensional ellipsoid defined by:
(x - v)^T A (x - v) = 1
where the vector
vis the center of the ellipsoid andAis a symmetric, positive-definiteN x Nmatrix.- Parameters:
- contains(x)
Checks if ellipsoid contains
x.
- distance(x)
Compute the normalized distance to
xfrom the center of the ellipsoid.
- distance_many(x)
Compute the normalized distance to
xfrom the center of the ellipsoid.
- get_random_axes(rstate)
- major_axis_endpoints()
Return the endpoints of the major axis.
- sample(rstate=None)
Draw a sample uniformly distributed within the ellipsoid.
- Returns:
- x
ndarraywith shape (ndim,) A coordinate within the ellipsoid.
- x
- samples(nsamples, rstate=None)
Draw
nsamplessamples uniformly distributed within the ellipsoid.- Returns:
- x
ndarraywith shape (nsamples, ndim) A collection of coordinates within the ellipsoid.
- x
- scale_to_logvol(logvol)
Scale ellipsoid to a target volume.
- unitcube_overlap(ndraws=10000, rstate=None)
Using
ndrawsMonte Carlo draws, estimate the fraction of overlap between the ellipsoid and the unit cube.
- update(points, rstate=None, bootstrap=0, pool=None, mc_integrate=False)
Update the ellipsoid to bound the collection of points.
- Parameters:
- points
ndarraywith shape (npoints, ndim) The set of points to bound.
- rstate
Generator, optional Generatorinstance.- bootstrapint, optional
The number of bootstrapped realizations of the ellipsoid. The maximum distance to the set of points “left out” during each iteration is used to enlarge the resulting volumes. Default is
0.- pooluser-provided pool, optional
Use this pool of workers to execute operations in parallel.
- mc_integratebool, optional
Whether to use Monte Carlo methods to compute the effective overlap of the final ellipsoid with the unit cube. Default is
False.
- points
- class dynesty.bounding.MultiEllipsoid(ndim, ells=None, ctrs=None, covs=None)
Bases:
BoundA collection of M N-dimensional ellipsoids.
- Parameters:
- ellslist of
Ellipsoidobjects with length M, optional A set of
Ellipsoidobjects that make up the collection of N-ellipsoids. Used to initializeMultiEllipsoidif provided.- ctrs
ndarraywith shape (M, N), optional Collection of coordinates of ellipsoid centers. Used to initialize
MultiEllipsoidifamsis also provided.- covs
ndarraywith shape (M, N, N), optional Collection of matrices describing the axes of the ellipsoids. Used to initialize
MultiEllipsoidifctrsalso provided.
- ellslist of
- __update_arrays()
Update internal arrays to ensure that in sync with ells
- contains(x)
Checks if the set of ellipsoids contains
x.
- get_random_axes(rstate)
- major_axis_endpoints()
Return the endpoints of the major axis of each ellipsoid.
- monte_carlo_logvol(ndraws=10000, rstate=None, return_overlap=True)
Using
ndrawsMonte Carlo draws, estimate the log volume of the union of ellipsoids. Ifreturn_overlap=True, also returns the estimated fractional overlap with the unit cube.
- overlap(x, j=None)
Checks how many ellipsoid(s)
xfalls within, skipping thej-th ellipsoid.
- sample(rstate=None, return_q=False)
Sample a point uniformly distributed within the union of ellipsoids.
- Returns:
- x
ndarraywith shape (ndim,) A coordinate within the set of ellipsoids.
- idxint
The index of the ellipsoid
xwas sampled from.- qint, optional
The number of ellipsoids
xfalls within.
- x
- samples(nsamples, rstate=None)
Draw
nsamplessamples uniformly distributed within the union of ellipsoids.- Returns:
- xs
ndarraywith shape (nsamples, ndim) A collection of coordinates within the set of ellipsoids.
- xs
- scale_to_logvol(logvol)
Scale ellipoids to a corresponding set of target volumes or to a new total volume If the argument is scalar this is assumed to be new logvol, if it’s iterable it’s assumed to be array of log volumes
- update(points, rstate=None, bootstrap=0, pool=None, mc_integrate=False)
Update the set of ellipsoids to bound the collection of points.
- Parameters:
- points
ndarraywith shape (npoints, ndim) The set of points to bound.
- rstate
Generator, optional Generatorinstance.- bootstrapint, optional
The number of bootstrapped realizations of the ellipsoids. The maximum distance to the set of points “left out” during each iteration is used to enlarge the resulting volumes. Default is
0.- pooluser-provided pool, optional
Use this pool of workers to execute operations in parallel.
- mc_integratebool, optional
Whether to use Monte Carlo methods to compute the effective volume and fractional overlap of the final union of ellipsoids with the unit cube. Default is
False.
- points
- within(x, j=None)
Checks which ellipsoid(s)
xfalls within, skipping thej-th ellipsoid if need be.
- class dynesty.bounding.RadFriends(ndim, cov=None)
Bases:
BoundA collection of N-balls of identical size centered on each live point. Importantly this class requires that the centers of the balls are set in the .ctrs attribute.
- Parameters:
- ndimint
The number of dimensions of each ball.
- cov
ndarraywith shape(ndim, ndim), optional Covariance structure (correlation and size) of each ball.
- _get_covariance_from_all_points(points)
Compute covariance using all points.
- _get_covariance_from_clusters(points)
Compute covariance from re-centered clusters.
- contains(x)
Check if the set of balls contains
x.
- get_random_axes(rstate)
- monte_carlo_logvol(ndraws=10000, rstate=None, return_overlap=True)
Using
ndrawsMonte Carlo draws, estimate the log volume of the union of balls. Ifreturn_overlap=True, also returns the estimated fractional overlap with the unit cube.
- overlap(x)
Check how many balls
xfalls within.
- sample(rstate=None, return_q=False)
Sample a point uniformly distributed within the union of balls.
- Returns:
- x
ndarraywith shape (ndim,) A coordinate within the set of balls.
- qint, optional
The number of balls
xfalls within.
- x
- samples(nsamples, rstate=None)
Draw
nsamplessamples uniformly distributed within the union of balls.- Returns:
- xs
ndarraywith shape (nsamples, ndim) A collection of coordinates within the set of balls.
- xs
- scale_to_logvol(logvol)
Scale ball to encompass a target volume.
- update(points, rstate=None, bootstrap=0, pool=None, mc_integrate=False, use_clustering=True)
Update the radii of our balls.
- Parameters:
- points
ndarraywith shape (npoints, ndim) The set of points to bound.
- rstate
Generator, optional Generatorinstance.- bootstrapint, optional
The number of bootstrapped realizations of the ellipsoids. The maximum distance to the set of points “left out” during each iteration is used to enlarge the resulting volumes. Default is
0.- pooluser-provided pool, optional
Use this pool of workers to execute operations in parallel.
- mc_integratebool, optional
Whether to use Monte Carlo methods to compute the effective volume and fractional overlap of the final union of balls with the unit cube. Default is
False.- use_clusteringbool, optional
Whether to use clustering to avoid issues with widely-seperated modes. Default is
True.
- points
- within(x)
Check which balls
xfalls within.
- class dynesty.bounding.SupFriends(ndim, cov=None)
Bases:
BoundA collection of N-cubes of identical size centered on each live point. Importantly this class requires that the centers of the cubes are set in the .ctrs attribute.
- Parameters:
- ndimint
The number of dimensions of the cube.
- cov
ndarraywith shape(ndim, ndim), optional Covariance structure (correlation and size) of each cube.
- _get_covariance_from_all_points(points)
Compute covariance using all points.
- _get_covariance_from_clusters(points)
Compute covariance from re-centered clusters.
- contains(x)
Checks if the set of cubes contains
x.
- get_random_axes(rstate)
- monte_carlo_logvol(ndraws=10000, rstate=None, return_overlap=True)
Using
ndrawsMonte Carlo draws, estimate the log volume of the union of cubes. Ifreturn_overlap=True, also returns the estimated fractional overlap with the unit cube.
- overlap(x)
Checks how many cubes
xfalls within, skipping thej-th cube.
- sample(rstate=None, return_q=False)
Sample a point uniformly distributed within the union of cubes.
- Returns:
- x
ndarraywith shape (ndim,) A coordinate within the set of cubes.
- qint, optional
The number of cubes
xfalls within.
- x
- samples(nsamples, rstate=None)
Draw
nsamplessamples uniformly distributed within the union of cubes.- Returns:
- xs
ndarraywith shape (nsamples, ndim) A collection of coordinates within the set of cubes.
- xs
- scale_to_logvol(logvol)
Scale cube to encompass a target volume.
- update(points, rstate=None, bootstrap=0, pool=None, mc_integrate=False, use_clustering=True)
Update the half-side-lengths of our cubes.
- Parameters:
- points
ndarraywith shape (npoints, ndim) The set of points to bound.
- rstate
Generator, optional Generatorinstance.- bootstrapint, optional
The number of bootstrapped realizations of the ellipsoids. The maximum distance to the set of points “left out” during each iteration is used to enlarge the resulting volumes. Default is
0.- pooluser-provided pool, optional
Use this pool of workers to execute operations in parallel.
- mc_integratebool, optional
Whether to use Monte Carlo methods to compute the effective volume and fractional overlap of the final union of cubes with the unit cube. Default is
False.- use_clusteringbool, optional
Whether to use clustering to avoid issues with widely-seperated modes. Default is
True.
- points
- within(x)
Checks which cubes
xfalls within.
- class dynesty.bounding.UnitCube(ndim)
Bases:
BoundAn N-dimensional unit cube.
- Parameters:
- ndimint
The number of dimensions of the unit cube.
- contains(x)
Checks if unit cube contains the point
x.
- get_random_axes(rstate)
- sample(rstate=None)
Draw a sample uniformly distributed within the unit cube.
- Returns:
- x
ndarraywith shape (ndim,) A coordinate within the unit cube.
- x
- samples(nsamples, rstate=None)
Draw
nsamplessamples randomly distributed within the unit cube.- Returns:
- x
ndarraywith shape (nsamples, ndim) A collection of coordinates within the unit cube.
- x
- scale_to_logvol(logvol)
- update(points, rstate=None, bootstrap=0, pool=None)
Filler function.
- dynesty.bounding._bounding_ellipsoids(points, ell, scale=None)
Internal method used to compute a set of bounding ellipsoids when a bounding ellipsoid for the entire set has already been calculated.
- Parameters:
- points
ndarraywith shape (npoints, ndim) A set of coordinates.
- ellEllipsoid
The bounding ellipsoid containing
points.
- points
- Returns:
- ellslist of
Ellipsoidobjects List of
Ellipsoidobjects used to bound the collection of points. Used to initialize theMultiEllipsoidobject returned inbounding_ellipsoids().
- ellslist of
- dynesty.bounding._ellipsoid_bootstrap_expand(args)
Internal method used to compute the expansion factor for a bounding ellipsoid or ellipsoids based on bootstrapping. The argument is a tuple: multi: boolean flag if we are doing multiell or single ell decomposition points: 2d array of points rseed: seed to initialize the random generator
- dynesty.bounding._friends_bootstrap_radius(args)
Internal method used to compute the radius (half-side-length) for each ball (cube) used in
RadFriends(SupFriends) using bootstrapping.
- dynesty.bounding._friends_leaveoneout_radius(points, ftype)
Internal method used to compute the radius (half-side-length) for each ball (cube) used in
RadFriends(SupFriends) using leave-one-out (LOO) cross-validation.
- dynesty.bounding.bounding_ellipsoid(points)
Calculate the bounding ellipsoid containing a collection of points.
- dynesty.bounding.bounding_ellipsoids(points)
Calculate a set of ellipsoids that bound the collection of points.
- Parameters:
- points
ndarraywith shape (npoints, ndim) A set of coordinates.
- points
- Returns:
- mell
MultiEllipsoidobject The
MultiEllipsoidobject used to bound the collection of points.
- mell
- dynesty.bounding.logvol_prefactor(n, p=2.0)
Returns the ln(volume constant) for an
n-dimensional sphere with an \(L^p\) norm. The constant is defined as:lnf = n * ln(2.) + n * LogGamma(1./p + 1) - LogGamma(n/p + 1.)
By default the
p=2.norm is used (i.e. the standard Euclidean norm).
- dynesty.bounding.randsphere(n, rstate=None)
Draw a point uniformly within an
n-dimensional unit sphere.
Sampling
Functions for proposing new live points used by
Sampler
DynamicSampler.
- class dynesty.internal_samplers.InternalSampler(**kwargs)
Bases:
objectBase class for all internal samplers.
This class is not meant to be used directly. The basic interface of the class is to provide sampling that can be distributed over workers.
The key methods are
prepare_sampler,sampleandtune.The
prepare_samplermethod constructs the list of SamplerArguments objects.The
samplemethod is called by the workers to sample a new point. Importantly thesamplemethod is a static method and does not have access to the class instance.The
tunemethod is called by the parent process to adjust things, such as scale of the proposal distribution. Thetunemethod is not a static method and has access to the class instance.Initialize the internal sampler.
Importantely this sets up the sampler_kwargs that is being passed to each .sample() call
- Parameters:
- kwargsdict
A dictionary of additional method-specific parameters. This common keywords:
- nonboundedarray
Array of boolean values indicating which dimensions are non-bounded.
- periodicarray
Array of boolean values indicating which dimensions are periodic.
- reflectivearray
Array of boolean values indicating which dimensions are reflective.
- ndim: int
Number of dimensions.
- _new_from_template(template_kwargs)
Create a new sampler from a template.
- property citations
- prepare_sampler(loglstar=None, points=None, axes=None, seeds=None, prior_transform=None, loglikelihood=None, nested_sampler=None)
Prepare the list of arguments for sampling.
- Parameters:
- loglstarfloat
Ln(likelihood) bound.
- points
ndarraywith shape (n, ndim) Initial sample points.
- axes
ndarraywith shape (ndim, ndim) Axes used to propose new points.
- seeds
ndarraywith shape (n,) Random number generator seeds.
- prior_transformfunction
Function transforming a sample from the a unit cube to the parameter space of interest according to the prior.
- loglikelihoodfunction
Function returning ln(likelihood) given parameters as a 1-d
numpyarray of lengthndim.- nested_sampler
Sampler The nested sampler object used to sample.
- Returns:
- arglist:
List of
SamplerArgumentobjects containing the parameters needed for sampling.
- static sample(args)
Sample a new live point.
- Parameters:
- args
SamplerArgument The arguments needed for sampling.
- args
- Returns:
- u
ndarraywith shape (ndim,) Position of the final proposed point within the unit cube.
- v
ndarraywith shape (ndim,) Position of the final proposed point in the target parameter space.
- loglfloat
Ln(likelihood) of the final proposed point.
- ncint
Number of function calls used to generate the sample.
- tuning_infodict
Collection of ancillary quantities used to tune
scale.
- u
- tune(tuning_info, update=False)
Accumulate sampling info and optionally update the proposal scale and other tuning parameters.
- Parameters:
- tuning_infodict
Dictionary containing the sampling information.
- updatebool
Whether to update the proposal scale or not (default: False).
- property update_bound_interval_ratio
How often to force updating the bounds The value is in units of ncall per nlive. I.e. the value of 10 means for N live points, the bound will be updated every 10 * N calls
- class dynesty.internal_samplers.RSliceSampler(**kwargs)
Bases:
InternalSamplerInitialize the internal sampler.
Importantely this sets up the sampler_kwargs that is being passed to each .sample() call
- Parameters:
- kwargsdict
A dictionary of additional method-specific parameters. This common keywords:
- nonboundedarray
Array of boolean values indicating which dimensions are non-bounded.
- periodicarray
Array of boolean values indicating which dimensions are periodic.
- reflectivearray
Array of boolean values indicating which dimensions are reflective.
- ndim: int
Number of dimensions.
- property citations
- static sample(args)
Return a new live point proposed by a series of random slices away from an existing live point. Standard “random” implementation where each slice is along a random direction based on the provided axes.
- Parameters:
- u
ndarraywith shape (ndim,) Position of the initial sample. This is a copy of an existing live point.
- loglstarfloat
Ln(likelihood) bound.
- axes
ndarraywith shape (ndim, ndim) Axes used to propose new slice directions.
- scalefloat
Value used to scale the provided axes.
- prior_transformfunction
Function transforming a sample from the a unit cube to the parameter space of interest according to the prior.
- loglikelihoodfunction
Function returning ln(likelihood) given parameters as a 1-d
numpyarray of lengthndim.- kwargsdict
A dictionary of additional method-specific parameters.
- u
- Returns:
- u
ndarraywith shape (ndim,) Position of the final proposed point within the unit cube.
- v
ndarraywith shape (ndim,) Position of the final proposed point in the target parameter space.
- loglfloat
Ln(likelihood) of the final proposed point.
- ncint
Number of function calls used to generate the sample.
- tuning_infodict
Collection of ancillary quantities used to tune
scale.
- u
- tune(sampler_info, update=True)
Accumulate sampling info and optionally update the proposal scale and other tuning parameters.
- Parameters:
- tuning_infodict
Dictionary containing the sampling information.
- updatebool
Whether to update the proposal scale or not (default: False).
- property update_bound_interval_ratio
How often to force updating the bounds The value is in units of ncall per nlive. I.e. the value of 10 means for N live points, the bound will be updated every 10 * N calls
- class dynesty.internal_samplers.RWalkSampler(**kwargs)
Bases:
InternalSamplerInitialize the internal sampler.
Importantely this sets up the sampler_kwargs that is being passed to each .sample() call
- Parameters:
- kwargsdict
A dictionary of additional method-specific parameters. This common keywords:
- nonboundedarray
Array of boolean values indicating which dimensions are non-bounded.
- periodicarray
Array of boolean values indicating which dimensions are periodic.
- reflectivearray
Array of boolean values indicating which dimensions are reflective.
- ndim: int
Number of dimensions.
- property citations
- static sample(args)
Return a new live point proposed by random walking away from an existing live point.
- Parameters:
- u
ndarraywith shape (ndim,) Position of the initial sample. This is a copy of an existing live point.
- loglstarfloat
Ln(likelihood) bound.
- axes
ndarraywith shape (ndim, ndim) Axes used to propose new points. For random walks new positions are proposed using the
Ellipsoidwhose shape is defined by axes.- scalefloat
Value used to scale the provided axes.
- prior_transformfunction
Function transforming a sample from the a unit cube to the parameter space of interest according to the prior.
- loglikelihoodfunction
Function returning ln(likelihood) given parameters as a 1-d
numpyarray of lengthndim.- kwargsdict
A dictionary of additional method-specific parameters.
- u
- Returns:
- u
ndarraywith shape (ndim,) Position of the final proposed point within the unit cube.
- v
ndarraywith shape (ndim,) Position of the final proposed point in the target parameter space.
- loglfloat
Ln(likelihood) of the final proposed point.
- ncint
Number of function calls used to generate the sample.
- tuning_infodict
Collection of ancillary quantities used to tune
scale.
- u
- tune(tuning_info, update=True)
Update the random walk proposal scale based on the current number of accepted/rejected steps. For rwalk the scale is important because it determines the speed of diffusion of points. I.e. if scale is too large, the proposal efficiency will be very low so it’s likely that we’ll only do one random walk step at the time, thus producing very correlated chain. The keyword update determines if we are just accumulating the number of steps or actually adjusting the scale
- property update_bound_interval_ratio
How often to force updating the bounds The value is in units of ncall per nlive. I.e. the value of 10 means for N live points, the bound will be updated every 10 * N calls
- class dynesty.internal_samplers.SliceSampler(**kwargs)
Bases:
InternalSamplerInitialize the internal sampler.
Importantely this sets up the sampler_kwargs that is being passed to each .sample() call
- Parameters:
- kwargsdict
A dictionary of additional method-specific parameters. This common keywords:
- nonboundedarray
Array of boolean values indicating which dimensions are non-bounded.
- periodicarray
Array of boolean values indicating which dimensions are periodic.
- reflectivearray
Array of boolean values indicating which dimensions are reflective.
- ndim: int
Number of dimensions.
- property citations
- static sample(args)
Return a new live point proposed by a series of random slices away from an existing live point. Standard “Gibbs-like” implementation where a single multivariate “slice” is a combination of
ndimunivariate slices through each axis.- Parameters:
- u
ndarraywith shape (ndim,) Position of the initial sample. This is a copy of an existing live point.
- loglstarfloat
Ln(likelihood) bound.
- axes
ndarraywith shape (ndim, ndim) Axes used to propose new points. For slices new positions are proposed along the arthogonal basis defined by
axes.- scalefloat
Value used to scale the provided axes.
- prior_transformfunction
Function transforming a sample from the a unit cube to the parameter space of interest according to the prior.
- loglikelihoodfunction
Function returning ln(likelihood) given parameters as a 1-d
numpyarray of lengthndim.- kwargsdict
A dictionary of additional method-specific parameters.
- u
- Returns:
- u
ndarraywith shape (ndim,) Position of the final proposed point within the unit cube.
- v
ndarraywith shape (ndim,) Position of the final proposed point in the target parameter space.
- loglfloat
Ln(likelihood) of the final proposed point.
- ncint
Number of function calls used to generate the sample.
- tuning_infodict
Collection of ancillary quantities used to tune
scale.
- u
- tune(sampler_info, update=True)
Accumulate sampling info and optionally update the proposal scale and other tuning parameters.
- Parameters:
- tuning_infodict
Dictionary containing the sampling information.
- updatebool
Whether to update the proposal scale or not (default: False).
- property update_bound_interval_ratio
How often to force updating the bounds The value is in units of ncall per nlive. I.e. the value of 10 means for N live points, the bound will be updated every 10 * N calls
- class dynesty.internal_samplers.UniformBoundSampler(**kwargs)
Bases:
InternalSamplerUniformly sample within a bounding proposal distribution.
Initialize the internal sampler.
Importantely this sets up the sampler_kwargs that is being passed to each .sample() call
- Parameters:
- kwargsdict
A dictionary of additional method-specific parameters. This common keywords:
- nonboundedarray
Array of boolean values indicating which dimensions are non-bounded.
- periodicarray
Array of boolean values indicating which dimensions are periodic.
- reflectivearray
Array of boolean values indicating which dimensions are reflective.
- ndim: int
Number of dimensions.
- prepare_sampler(loglstar=None, points=None, axes=None, seeds=None, prior_transform=None, loglikelihood=None, nested_sampler=None)
Prepare the list of arguments for sampling.
This is is overriding the base class method and providing the bound itself to the sampler through kwargs.
- static sample(args)
Return a new live point sampling uniformly within the boundary.
- Parameters:
- u
ndarraywith shape (ndim,) Initial sample (not used)
- loglstarfloat
Ln(likelihood) bound.
- axes
ndarraywith shape (ndim, ndim) Axes used to propose new points. (not used)
- scalefloat
Value used to scale the provided axes. (not used)
- prior_transformfunction
Function transforming a sample from the a unit cube to the parameter space of interest according to the prior.
- loglikelihoodfunction
Function returning ln(likelihood) given parameters as a 1-d
numpyarray of lengthndim.- kwargsdict
A dictionary of additional method-specific parameters. This method requires keywords: bound (dynesty.bounding object) ndim (number of dimensions) n_cluster (number of dimensions that are clustered) nonbounded array
- u
- Returns:
- u
ndarraywith shape (ndim,) Position of the final proposed point within the unit cube.
- v
ndarraywith shape (ndim,) Position of the final proposed point in the target parameter space.
- loglfloat
Ln(likelihood) of the final proposed point.
- ncint
Number of function calls used to generate the sample.
- tuning_infodict
Collection of ancillary quantities used to tune
scale.
- u
- class dynesty.internal_samplers.UnitCubeSampler(**kwargs)
Bases:
InternalSamplerInitialize the internal sampler.
Importantely this sets up the sampler_kwargs that is being passed to each .sample() call
- Parameters:
- kwargsdict
A dictionary of additional method-specific parameters. This common keywords:
- nonboundedarray
Array of boolean values indicating which dimensions are non-bounded.
- periodicarray
Array of boolean values indicating which dimensions are periodic.
- reflectivearray
Array of boolean values indicating which dimensions are reflective.
- ndim: int
Number of dimensions.
- prepare_sampler(loglstar=None, points=None, axes=None, seeds=None, prior_transform=None, loglikelihood=None, nested_sampler=None)
Prepare the list of arguments for sampling.
- Parameters:
- loglstarfloat
Ln(likelihood) bound.
- points
ndarraywith shape (n, ndim) Initial sample points.
- axes
ndarraywith shape (ndim, ndim) Axes used to propose new points.
- seeds
ndarraywith shape (n,) Random number generator seeds.
- prior_transformfunction
Function transforming a sample from the a unit cube to the parameter space of interest according to the prior.
- loglikelihoodfunction
Function returning ln(likelihood) given parameters as a 1-d
numpyarray of lengthndim.- nested_sampler
Sampler The nested sampler object used to sample.
- Returns:
- arglist:
List of
SamplerArgumentobjects containing the parameters needed for sampling.
- static sample(args)
Return a new live point sampling uniformly within the boundary.
- Parameters:
- u
ndarraywith shape (ndim,) Initial sample (not used)
- loglstarfloat
Ln(likelihood) bound.
- axes
ndarraywith shape (ndim, ndim) Axes used to propose new points. (not used)
- scalefloat
Value used to scale the provided axes. (not used)
- prior_transformfunction
Function transforming a sample from the a unit cube to the parameter space of interest according to the prior.
- loglikelihoodfunction
Function returning ln(likelihood) given parameters as a 1-d
numpyarray of lengthndim.- kwargsdict
A dictionary of additional method-specific parameters. This method requires keywords: bound (dynesty.bounding object) ndim (number of dimensions) n_cluster (number of dimensions that are clustered) nonbounded array
- u
- Returns:
- u
ndarraywith shape (ndim,) Position of the final proposed point within the unit cube.
- v
ndarraywith shape (ndim,) Position of the final proposed point in the target parameter space.
- loglfloat
Ln(likelihood) of the final proposed point.
- ncint
Number of function calls used to generate the sample.
- tuning_infodict
Collection of ancillary quantities used to tune
scale.
- u
Baseline Sampler
The base Sampler class containing various helpful functions. All other
samplers inherit this class either explicitly or implicitly.
- class dynesty.sampler.Sampler(loglikelihood, prior_transform, ndim, live_points, sampling, bounding, ncdim=None, rstate=None, pool=None, use_pool=None, queue_size=None, bound_update_interval=None, first_bound_update=None, bound_bootstrap=None, bound_enlarge=None, blob=False, cite=None, logvol_init=0)
Bases:
objectThe basic sampler object that performs the actual nested sampling. It is used for the initial sampling and also for each batch.
- Parameters:
- loglikelihoodfunction
Function returning ln(likelihood) given parameters as a 1-d
numpyarray of lengthndim.- prior_transformfunction
Function transforming a sample from the a unit cube to the parameter space of interest according to the prior.
- ndimint, optional
Number of parameters accepted by
prior_transform.- live_pointslist of 3 or 4
ndarray Each with shape (nlive, ndim) for the first three arrays. If
blob=True, a fourth array of blobs (arbitrary shape) may be included.- sampling{
'unif','rwalk','slice','rslice'} Sampling Method used to sample uniformly within the likelihood constraint, conditioned on the provided bounds.
- bound_update_intervalint
Only update the bounding distribution every
update_interval-th likelihood call.- first_updatedict
A dictionary containing parameters governing when the sampler should first update the bounding distribution from the unit cube to the one specified by the user.
- rstate
Generator Generatorinstance.- queue_size: int
Carry out likelihood evaluations in parallel by queueing up new live point proposals using (at most) this many threads/members.
- pool: pool
Use this pool of workers to execute operations in parallel.
- use_pooldict, optional
A dictionary containing flags indicating where the provided
poolshould be used to execute operations in parallel.- kwargsdict, optional
A dictionary of additional parameters.
- ncdim: int, optional
The number of clustering dimensions. The first ncdim dimensions will be sampled using the sampling method, the remaining dimensions will just sample uniformly from the prior distribution. If this is
None(default), this will default to ndim.- logvol_init: float, optional
The initial log of volume when starting sampling. This is relevant when the log(L) is finite only within a fraction of prior volume.
Initializes and returns a sampler object for Static Nested Sampling.
- Parameters:
- loglikelihoodfunction
Function returning ln(likelihood) given parameters as a 1-d
numpyarray of lengthndim.- prior_transformfunction
Function translating a unit cube to the parameter space according to the prior. The input is a 1-d
numpyarray with lengthndim, where each value is in the range [0, 1). The return value should also be a 1-dnumpyarray with lengthndim, where each value is a parameter. The return value is passed to the loglikelihood function. For example, for a 2 parameter model with flat priors in the range [0, 2), the function would be:def prior_transform(u): return 2.0 * u
- ndimint
Number of parameters returned by
prior_transformand accepted byloglikelihood.- nliveint, optional
Number of “live” points. Larger numbers result in a more finely sampled posterior (more accurate evidence), but also a larger number of iterations required to converge. Default is
500.- bound{
'none','single','multi','balls','cubes'}, optional Method used to approximately bound the prior using the current set of live points. Conditions the sampling methods used to propose new live points. Choices are no bound (
'none'), a single bounding ellipsoid ('single'), multiple bounding ellipsoids ('multi'), balls centered on each live point ('balls'), and cubes centered on each live point ('cubes'). Default is'multi'.- sample{
'auto','unif','rwalk','slice','rslice'}, optional Method used to sample uniformly within the likelihood constraint, conditioned on the provided bounds. Unique methods available are: uniform sampling within the bounds(
'unif'), random walks with fixed proposals ('rwalk'), multivariate slice sampling along preferred orientations ('slice'), “random” slice sampling along all orientations ('rslice'),'auto'selects the sampling method based on the dimensionality of the problem (fromndim). Whenndim < 10, this defaults to'unif'. When10 <= ndim <= 20, this defaults to'rwalk'. Whenndim > 20, this defaults to`’rslice’`'slice'is provided as alternative for`’rslice’Default is `'auto'.- periodiciterable, optional
A list of indices for parameters with periodic boundary conditions. These parameters will not have their positions constrained to be within the unit cube, enabling smooth behavior for parameters that may wrap around the edge. Default is
None(i.e. no periodic boundary conditions).- reflectiveiterable, optional
A list of indices for parameters with reflective boundary conditions. These parameters will not have their positions constrained to be within the unit cube, enabling smooth behavior for parameters that may reflect at the edge. Default is
None(i.e. no reflective boundary conditions).- update_intervalint or float, optional
If an integer is passed, only update the proposal distribution every
update_interval-th likelihood call. If a float is passed, update the proposal after everyround(update_interval * nlive)-th likelihood call. Larger update intervals larger can be more efficient when the likelihood function is quick to evaluate. Default behavior is to target a roughly constant change in prior volume, with1.5for'unif',0.15 * walksfor'rwalk'.0.9 * ndim * slicesfor'slice',2.0 * slicesfor'rslice'.- first_updatedict, optional
A dictionary containing parameters governing when the sampler should first update the bounding distribution from the unit cube (
'none') to the one specified bysample. Options are the minimum number of likelihood calls ('min_ncall') and the minimum allowed overall efficiency in percent ('min_eff'). Defaults are2 * nliveand10., respectively.- rstate
Generator, optional - queue_sizeint, optional
Carry out likelihood evaluations in parallel by queueing up new live point proposals using (at most)
queue_sizemany threads. Each thread independently proposes new live points until the proposal distribution is updated. If no value is passed, this defaults topool.size(if apoolhas been provided) and1otherwise (no parallelism).- pooluser-provided pool, optional
Use this pool of workers to execute operations in parallel.
- use_pooldict, optional
A dictionary containing flags indicating where a pool should be used to execute operations in parallel. These govern whether
prior_transformis executed in parallel during initialization ('prior_transform'),loglikelihoodis executed in parallel during initialization ('loglikelihood'), live points are proposed in parallel during a run ('propose_point'), and bounding distributions are updated in parallel during a run ('update_bound'). Default isTruefor all options.- live_pointslist of 3
ndarrayeach with shape (nlive, ndim) A set of live points used to initialize the nested sampling run. Contains
live_u, the coordinates on the unit cube,live_v, the transformed variables, andlive_logl, the associated loglikelihoods. By default, if these are not provided the initial set of live points will be drawn uniformly from the unitndim-cube. WARNING: It is crucial that the initial set of live points have been sampled from the prior. Failure to provide a set of valid live points will result in incorrect results.- logl_argsiterable, optional
Additional arguments that can be passed to
loglikelihood.- logl_kwargsdict, optional
Additional keyword arguments that can be passed to
loglikelihood.- ptform_argsiterable, optional
Additional arguments that can be passed to
prior_transform.- ptform_kwargsdict, optional
Additional keyword arguments that can be passed to
prior_transform.- enlargefloat, optional
Enlarge the volumes of the specified bounding object(s) by this fraction. The preferred method is to determine this organically using bootstrapping. If
bootstrap > 0, this defaults to1.0. Ifbootstrap = 0, this instead defaults to1.25.- bootstrapint, optional
Compute this many bootstrapped realizations of the bounding objects. Use the maximum distance found to the set of points left out during each iteration to enlarge the resulting volumes. Can lead to unstable bounding ellipsoids. Default is
None(no bootstrap unless the sampler is uniform). If bootstrap is set to zero, bootstrap is disabled.- walksint, optional
For the
'rwalk'sampling option, the minimum number of steps (minimum 2) before proposing a new live point. Default is25.- faccfloat, optional
The target acceptance fraction for the
'rwalk'sampling option. Default is0.5. Bounded to be between[1. / walks, 1.].- slicesint, optional
For the
'slice','rslice'sampling options, the number of times to execute a “slice update” before proposing a new live point. Default is 3 for'slice'and 3+ndim for rslice. Note that'slice'cycles through all dimensions when executing a “slice update”.- ncdim: int, optional
The number of clustering dimensions. The first ncdim dimensions will be sampled using the sampling method, the remaining dimensions will just sample uniformly from the prior distribution. If this is
None(default), this will default to ndim.- blob: bool, optional
The default value is False. If it is true, then the log-likelihood should return the tuple of logl and a numpy-array “blob” that will stored as part of the chain. That blob can contain auxiliary information computed inside the likelihood function.
- Returns:
- samplersampler from
nestedsamplers An initialized instance of the chosen sampler specified via
bound.
- samplersampler from
- _fill_queue(loglstar)
Sequentially add new live point proposals to the queue.
- _get_point_value(loglstar)
Grab the first live point proposal in the queue.
- _new_point(loglstar)
Propose points until a new point that satisfies the log-likelihood constraint
loglstaris found.
- _remove_live_points()
Remove the final set of live points if they were previously added to the current set of dead points.
- add_final_live(print_progress=True, print_func=None)
A wrapper that executes the loop adding the final live points. Adds the final set of live points to the pre-existing sequence of dead points from the current nested sampling run.
- Parameters:
- print_progressbool, optional
Whether or not to output a simple summary of the current run that updates with each iteration. Default is
True.- print_funcfunction, optional
A function that prints out the current state of the sampler. If not provided, the default
results.print_fn()is used.
- add_live_points()
Add the remaining set of live points to the current set of dead points. Instantiates a generator that will be called by the user. Returns the same outputs as
sample().
- property citations
Return list of papers that should be cited given the specified configuration of the sampler.
- property n_effective
Estimate the effective number of posterior samples using the Kish Effective Sample Size (ESS) where
ESS = sum(wts)^2 / sum(wts^2). Note that this islen(wts)whenwtsare uniform and1if there is only one non-zero element inwts.
- propose_live(*args)
Return a live point/axes to be used by other sampling methods. If args is not empty, it contains the subset of indices of points to sample from.
- reset()
Re-initialize the sampler.
- static restore(fname, pool=None)
Restore the sampler from a file. It is assumed that the file was created using .save() method of a sampler or as a result of checkpointing during run_nested()
- Parameters:
- fname: string
Filename of the save file.
- pool: object(optional)
The multiprocessing pool-like object that supports map() calls that will be used in the restored object.
- property results
Saved results from the nested sampling run. If bounding distributions were saved, those are also returned.
- run_nested(maxiter=None, maxcall=None, dlogz=None, logl_max=inf, add_live=True, print_progress=True, print_func=None, save_bounds=True, checkpoint_file=None, checkpoint_every=60, resume=False)
A wrapper that executes the main nested sampling loop. Iteratively replace the worst live point with a sample drawn uniformly from the prior until the provided stopping criteria are reached.
- Parameters:
- maxiterint, optional
Maximum number of iterations. Iteration may stop earlier if the termination condition is reached. Default is
sys.maxsize(no limit).- maxcallint, optional
Maximum number of likelihood evaluations. Iteration may stop earlier if termination condition is reached. Default is
sys.maxsize(no limit).- dlogzfloat, optional
Iteration will stop when the estimated contribution of the remaining prior volume to the total evidence falls below this threshold. Explicitly, the stopping criterion is
ln(z + z_est) - ln(z) < dlogz, wherezis the current evidence from all saved samples andz_estis the estimated contribution from the remaining volume. Ifadd_liveisTrue, the default is1e-3 * (nlive - 1) + 0.01. Otherwise, the default is0.01.- logl_maxfloat, optional
Iteration will stop when the sampled ln(likelihood) exceeds the threshold set by
logl_max. Default is no bound (np.inf).- add_livebool, optional
Whether or not to add the remaining set of live points to the list of samples at the end of each run. Default is
True.- print_progressbool, optional
Whether or not to output a simple summary of the current run that updates with each iteration. Default is
True.- print_funcfunction, optional
A function that prints out the current state of the sampler. If not provided, the default
results.print_fn()is used.- save_boundsbool, optional
Whether or not to save past bounding distributions used to bound the live points internally. Default is True.
- checkpoint_file: string, optional
if not None The state of the sampler will be saved into this file every checkpoint_every seconds
- checkpoint_every: float, optional
The number of seconds between checkpoints that will save the internal state of the sampler. The sampler will also be saved in the end of the run irrespective of checkpoint_every.
- sample(maxiter=None, maxcall=None, dlogz=0.01, logl_max=inf, add_live=True, save_bounds=True, resume=False)
The main nested sampling loop. Iteratively replace the worst live point with a sample drawn uniformly from the prior until the provided stopping criteria are reached. Instantiates a generator that will be called by the user.
- Parameters:
- maxiterint, optional
Maximum number of iterations. Iteration may stop earlier if the termination condition is reached. Default is
sys.maxsize(no limit).- maxcallint, optional
Maximum number of likelihood evaluations. Iteration may stop earlier if termination condition is reached. Default is
sys.maxsize(no limit).- dlogzfloat, optional
Iteration will stop when the estimated contribution of the remaining prior volume to the total evidence falls below this threshold. Explicitly, the stopping criterion is
ln(z + z_est) - ln(z) < dlogz, wherezis the current evidence from all saved samples andz_estis the estimated contribution from the remaining volume. Default is0.01.- logl_maxfloat, optional
Iteration will stop when the sampled ln(likelihood) exceeds the threshold set by
logl_max. Default is no bound (np.inf).- add_livebool, optional
Whether or not to add the remaining set of live points to the list of samples when calculating
n_effective. Default isTrue.- save_boundsbool, optional
Whether or not to save past distributions used to bound the live points internally. Default is
True.
- Returns:
- worstint
Index of the live point with the worst likelihood. This is our new dead point sample.
- ustar
ndarraywith shape (ndim,) Position of the sample.
- vstar
ndarraywith shape (ndim,) Transformed position of the sample.
- loglstarfloat
Ln(likelihood) of the sample.
- logvolfloat
Ln(prior volume) within the sample.
- logwtfloat
Ln(weight) of the sample.
- logzfloat
Cumulative ln(evidence) up to the sample (inclusive).
- logzvarfloat
Estimated cumulative variance on
logz(inclusive).- hfloat
Cumulative information up to the sample (inclusive).
- ncint
Number of likelihood calls performed before the new live point was accepted.
- worst_itint
Iteration when the live (now dead) point was originally proposed.
- boundidxint
Index of the bound the dead point was originally drawn from.
- bounditerint
Index of the bound being used at the current iteration.
- efffloat
The cumulative sampling efficiency (in percent).
- delta_logzfloat
The estimated remaining evidence expressed as the ln(ratio) of the current evidence.
- save(fname)
Save the state of the sampler in a file
- Parameters:
- fname: string
Filename of the save file.
- update_bound(subset=slice(None, None, None))
Update the bounds using the current set of live points.
- update_bound_if_needed(loglstar, ncall=None, force=False)
Here we update the bound depending on the situation The arguments are the loglstar and number of calls if force is true we update the bound no matter what
Dynamic Nested Sampler
Contains the dynamic nested sampler class DynamicSampler used to
dynamically allocate nested samples. Note that DynamicSampler
implicitly wraps a sampler from nestedsamplers. Also contains
the weight function weight_function() and stopping function
stopping_function(). These are used by default within
DynamicSampler if corresponding functions are not provided
by the user.
- class dynesty.dynamicsampler.DynamicSampler(loglikelihood, prior_transform, ndim, sampling, bounding, nlive0=None, ncdim=None, rstate=None, pool=None, use_pool=None, queue_size=None, bound_update_interval_ratio=None, first_bound_update=None, bound_bootstrap=None, bound_enlarge=None, blob=None, cite=None)
Bases:
objectA dynamic nested sampler that allocates live points adaptively during a single run according to a specified weight function until a specified stopping criteria is reached.
- Parameters:
- loglikelihoodfunction
Function returning ln(likelihood) given parameters as a 1-d
numpyarray of lengthndim.- prior_transformfunction
Function transforming a sample from the a unit cube to the parameter space of interest according to the prior.
- ndimint, optional
Number of parameters accepted by
prior_transform.- bound{
'none','single','multi','balls','cubes'}, optional Method used to approximately bound the prior using the current set of live points. Conditions the sampling methods used to propose new live points.
- method{
'unif','rwalk', 'slice','rslice'}, optional Method used to sample uniformly within the likelihood constraint, conditioned on the provided bounds.- update_intervalint
Only update the bounding distribution every
update_interval-th likelihood call.- first_updatedict
A dictionary containing parameters governing when the sampler should first update the bounding distribution from the unit cube to the one specified by the user.
- rstate
Generator Generatorinstance.- queue_size: int
Carry out likelihood evaluations in parallel by queueing up new live point proposals using (at most) this many threads/members.
- pool: pool
Use this pool of workers to execute operations in parallel.
- use_pooldict
A dictionary containing flags indicating where the provided
poolshould be used to execute operations in parallel.- ncdim: int
Number of clustered dimensions
- nlive0: int
Default number of live points to use
- kwargsdict, optional
A dictionary of additional parameters (described below).
- __get_update_interval(update_interval, nlive)
- add_batch(nlive=500, dlogz=0.01, mode='weight', wt_function=None, wt_kwargs=None, maxiter=None, maxcall=None, logl_bounds=None, save_bounds=True, print_progress=True, print_func=None, stop_val=None, resume=False, checkpoint_file=None, checkpoint_every=None)
Allocate an additional batch of (nested) samples based on the combined set of previous samples using the specified weight function.
- Parameters:
- nliveint, optional
The number of live points used when adding additional samples in the batch. Default is
500.- mode: string, optional
How to allocate a new batch. The possible values are ‘auto’, ‘weight’, ‘full’, ‘manual’ ‘weight’ means to use the weight_function to decide the optimal logl range. ‘full’ means sample the whole posterior again ‘auto’ means choose automatically, which currently means using ‘weight’ ‘manual’ means that logl_bounds need to be explicitely specified
- wt_functionfunc, optional
A cost function that takes a
Resultsinstance and returns a log-likelihood range over which a new batch of samples should be generated. The default function simply computes a weighted average of the posterior and evidence information content as:weight = pfrac * pweight + (1. - pfrac) * zweight
- wt_kwargsdict, optional
Extra arguments to be passed to the weight function.
- maxiterint, optional
Maximum number of iterations allowed. Default is
sys.maxsize(no limit).- maxcallint, optional
Maximum number of likelihood evaluations allowed. Default is
sys.maxsize(no limit).- logl_boundstuple of size (2,), optional
The ln(likelihood) bounds used to bracket the run. If
None, the providedwt_functionwill be used to determine the bounds (this is the default behavior).- save_boundsbool, optional
Whether or not to save distributions used to bound the live points internally during dynamic live point allocations. Default is
True.- print_progressbool, optional
Whether to output a simple summary of the current run that updates each iteration. Default is
True.- print_funcfunction, optional
A function that prints out the current state of the sampler. If not provided, the default
results.print_fn()is used.- stop_valfloat, optional
The value of the stopping criteria to be passed to
print_func(). Used internally withinrun_nested()to keep track of progress.- resume: bool, optional
If resume is set to true, we will try to resume a previously interrupted run
- checkpoint_file: string, optional
if not None The state of the sampler will be saved into this file every checkpoint_every seconds
- checkpoint_every: float, optional
The number of seconds between checkpoints that will save the internal state of the sampler. If this is None, we we will use the timer created in run_nested()
- property citations
Return list of papers that should be cited given the specified configuration of the sampler.
- combine_runs()
Merge the most recent run into the previous (combined) run by “stepping through” both runs simultaneously.
- property n_effective
Estimate the effective number of posterior samples using the Kish Effective Sample Size (ESS) where
ESS = sum(wts)^2 / sum(wts^2). Note that this islen(wts)whenwtsare uniform and1if there is only one non-zero element inwts.
- reset()
Re-initialize the sampler.
- static restore(fname, pool=None)
Restore the dynamic sampler from a file. It is assumed that the file was created using .save() method of DynamicNestedSampler or as a result of checkpointing during run_nested()
- Parameters:
- fname: string
Filename of the save file.
- pool: object(optional)
The multiprocessing pool-like object that supports map() calls that will be used in the restored object.
- property results
Saved results from the dynamic nested sampling run. All saved bounds are also returned.
- run_nested(nlive_init=None, maxiter_init=None, maxcall_init=None, dlogz_init=0.01, logl_max_init=inf, nlive_batch=None, wt_function=None, wt_kwargs=None, maxiter_batch=None, maxcall_batch=None, maxiter=None, maxcall=None, maxbatch=None, n_effective=None, stop_function=None, stop_kwargs=None, use_stop=True, save_bounds=True, print_progress=True, print_func=None, live_points=None, resume=False, checkpoint_file=None, checkpoint_every=60)
The main dynamic nested sampling loop. After an initial “baseline” run using a constant number of live points, dynamically allocates additional (nested) samples to optimize a specified weight function until a specified stopping criterion is reached.
- Parameters:
- nlive_initint, optional
The number of live points used during the initial (“baseline”) nested sampling run. Default is the number provided at initialization
- maxiter_initint, optional
Maximum number of iterations for the initial baseline nested sampling run. Iteration may stop earlier if the termination condition is reached. Default is
sys.maxsize(no limit).- maxcall_initint, optional
Maximum number of likelihood evaluations for the initial baseline nested sampling run. Iteration may stop earlier if the termination condition is reached. Default is
sys.maxsize(no limit).- dlogz_initfloat, optional
The baseline run will stop when the estimated contribution of the remaining prior volume to the total evidence falls below this threshold. Explicitly, the stopping criterion is
ln(z + z_est) - ln(z) < dlogz, wherezis the current evidence from all saved samples andz_estis the estimated contribution from the remaining volume. The default is0.01.- logl_max_initfloat, optional
The baseline run will stop when the sampled ln(likelihood) exceeds this threshold. Default is no bound (
np.inf).- nlive_batchint, optional
The number of live points used when adding additional samples from a nested sampling run within each batch. Default is the number provided at init
- wt_functionfunc, optional
A cost function that takes a
Resultsinstance and returns a log-likelihood range over which a new batch of samples should be generated. The default function simply computes a weighted average of the posterior and evidence information content as:weight = pfrac * pweight + (1. - pfrac) * zweight
- wt_kwargsdict, optional
Extra arguments to be passed to the weight function.
- maxiter_batchint, optional
Maximum number of iterations for the nested sampling run within each batch. Iteration may stop earlier if the termination condition is reached. Default is
sys.maxsize(no limit).- maxcall_batchint, optional
Maximum number of likelihood evaluations for the nested sampling run within each batch. Iteration may stop earlier if the termination condition is reached. Default is
sys.maxsize(no limit).- maxiterint, optional
Maximum number of iterations allowed. Default is
sys.maxsize(no limit).- maxcallint, optional
Maximum number of likelihood evaluations allowed. Default is
sys.maxsize(no limit).- maxbatchint, optional
Maximum number of batches allowed. Default is
sys.maxsize(no limit).- n_effective: int, optional
Minimum number of effective posterior samples needed during the entire run. If the estimated “effective sample size” (ESS) exceeds this number, sampling will terminate. Default is max(10000, ndim^2)
- stop_functionfunc, optional
A function that takes a
Resultsinstance and returns a boolean indicating that we should terminate the run because we’ve collected enough samples.- stop_kwargsfloat, optional
Extra arguments to be passed to the stopping function.
- use_stopbool, optional
Whether to evaluate our stopping function after each batch. Disabling this can improve performance if other stopping criteria such as
maxcallare already specified. Default isTrue.- save_boundsbool, optional
Whether or not to save distributions used to bound the live points internally during dynamic live point allocation. Default is
True.- print_progressbool, optional
Whether to output a simple summary of the current run that updates each iteration. Default is
True.- print_funcfunction, optional
A function that prints out the current state of the sampler. If not provided, the default
results.print_fn()is used.- live_points: list of 3 `~numpy.ndarray` each with shape (nlive, ndim)
and optionally list of blobs associated with these likelihood calls (if blob=True in the sampler) A set of live points used to initialize the nested sampling run. Contains
live_u, the coordinates on the unit cube,live_v, the transformed variables, andlive_logl, the associated loglikelihoods. By default, if these are not provided the initial set of live points will be drawn from the unitndim-cube. WARNING: It is crucial that the initial set of live points have been sampled from the prior. Failure to provide a set of valid live points will lead to incorrect results.- resume: bool, optional
If resume is set to true, we will try to resume a previously interrupted run
- checkpoint_file: string, optional
if not None The state of the sampler will be saved into this file every checkpoint_every seconds
- checkpoint_every: float, optional
The number of seconds between checkpoints that will save the internal state of the sampler
- sample_batch(dlogz=0.01, nlive_new=None, update_interval=None, logl_bounds=None, maxiter=None, maxcall=None, save_bounds=True, resume=False)
Generate an additional series of nested samples that will be combined with the previous set of dead points. Works by hacking the internal
samplerobject. Instantiates a generator that will be called by the user.- Parameters:
- nlive_newint
Number of new live points to be added. Default is
500.- update_intervalint or float, optional
If an integer is passed, only update the bounding distribution every
update_interval-th likelihood call. If a float is passed, update the bound after everyround(update_interval * nlive)-th likelihood call. Larger update intervals can be more efficient when the likelihood function is quick to evaluate. If no value is provided, defaults to the value passed during initialization.- logl_boundstuple of size (2,), optional
The ln(likelihood) bounds used to bracket the run. If
None, the default bounds span the entire range covered by the original run.- maxiterint, optional
Maximum number of iterations. Iteration may stop earlier if the termination condition is reached. Default is
sys.maxsize(no limit).- maxcallint, optional
Maximum number of likelihood evaluations. Iteration may stop earlier if termination condition is reached. Default is
sys.maxsize(no limit).- save_boundsbool, optional
Whether or not to save past distributions used to bound the live points internally. Default is
True.- dlogzfloat, optional
The stopping point in terms of remaining delta(logz)
- Returns:
- worstint
Index of the live point with the worst likelihood. This is our new dead point sample. Negative values indicate the index of a new live point generated when initializing a new batch.
- ustar
ndarraywith shape (ndim,) Position of the sample.
- vstar
ndarraywith shape (ndim,) Transformed position of the sample.
- loglstarfloat
Ln(likelihood) of the sample.
- ncint
Number of likelihood calls performed before the new live point was accepted.
- worst_itint
Iteration when the live (now dead) point was originally proposed.
- boundidxint
Index of the bound the dead point was originally drawn from.
- bounditerint
Index of the bound being used at the current iteration.
- efffloat
The cumulative sampling efficiency (in percent).
- sample_initial(nlive=None, update_interval=None, first_update=None, maxiter=None, maxcall=None, logl_max=inf, dlogz=0.01, live_points=None, resume=False)
Generate a series of initial samples from a nested sampling run using a fixed number of live points using an internal sampler from
nestedsamplers. Instantiates a generator that will be called by the user.- Parameters:
- nliveint, optional
The number of live points to use for the baseline nested sampling run. Default is either nlive0 parameter of 500
- update_intervalint or float, optional
If an integer is passed, only update the bounding distribution every
update_interval-th likelihood call. If a float is passed, update the bound after everyround(update_interval * nlive)-th likelihood call. Larger update intervals can be more efficient when the likelihood function is quick to evaluate. If no value is provided, defaults to the value passed during initialization.- first_updatedict, optional
A dictionary containing parameters governing when the sampler will first update the bounding distribution from the unit cube (
'none') to the one specified bysample.- maxiterint, optional
Maximum number of iterations. Iteration may stop earlier if the termination condition is reached. Default is
sys.maxsize(no limit).- maxcallint, optional
Maximum number of likelihood evaluations. Iteration may stop earlier if termination condition is reached. Default is
sys.maxsize(no limit).- dlogzfloat, optional
Iteration will stop when the estimated contribution of the remaining prior volume to the total evidence falls below this threshold. Explicitly, the stopping criterion is
ln(z + z_est) - ln(z) < dlogz, wherezis the current evidence from all saved samples andz_estis the estimated contribution from the remaining volume. The default is0.01.- logl_maxfloat, optional
Iteration will stop when the sampled ln(likelihood) exceeds the threshold set by
logl_max. Default is no bound (np.inf).- live_points: list of 3 `~numpy.ndarray` each with shape (nlive, ndim)
and optionally list of blobs associated with these likelihood calls (if blob=True in the sampler) A set of live points used to initialize the nested sampling run. Contains
live_u, the coordinates on the unit cube,live_v, the transformed variables, andlive_logl, the associated loglikelihoods. By default, if these are not provided the initial set of live points will be drawn from the unitndim-cube. WARNING: It is crucial that the initial set of live points have been sampled from the prior. Failure to provide a set of valid live points will lead to incorrect results.
- Returns:
- worstint
Index of the live point with the worst likelihood. This is our new dead point sample.
- ustar
ndarraywith shape (ndim,) Position of the sample.
- vstar
ndarraywith shape (ndim,) Transformed position of the sample.
- loglstarfloat
Ln(likelihood) of the sample.
- logvolfloat
Ln(prior volume) within the sample.
- logwtfloat
Ln(weight) of the sample.
- logzfloat
Cumulative ln(evidence) up to the sample (inclusive).
- logzvarfloat
Estimated cumulative variance on
logz(inclusive).- hfloat
Cumulative information up to the sample (inclusive).
- ncint
Number of likelihood calls performed before the new live point was accepted.
- worst_itint
Iteration when the live (now dead) point was originally proposed.
- boundidxint
Index of the bound the dead point was originally drawn from.
- bounditerint
Index of the bound being used at the current iteration.
- efffloat
The cumulative sampling efficiency (in percent).
- delta_logzfloat
The estimated remaining evidence expressed as the ln(ratio) of the current evidence.
- save(fname)
Save the state of the dynamic sampler in a file
- Parameters:
- fname: string
Filename of the save file.
- dynesty.dynamicsampler.stopping_function(results, args=None, rstate=None, mapper=None, return_vals=False)
The default stopping function utilized by
DynamicSampler. Zipped parameters are passed to the function viaargs. Assigns the run a stopping value based on a weighted average of the stopping values for the posterior and evidence:stop = pfrac * stop_post + (1.- pfrac) * stop_evid
The evidence stopping value is based on the estimated evidence error (i.e. standard deviation) relative to a given threshold:
stop_evid = evid_std / evid_thresh
The posterior stopping value is based on the estimated effective number of samples.
stop_post = target_n_effective / n_effective
Estimates of the mean and standard deviation are computed using
n_mcrealizations of the input using a provided'error'keyword (either'jitter'or'resample', which call related functionsjitter_run()andresample_run()indynesty.utils, respectively.Returns the boolean
stop <= 1. IfTrue, theDynamicSamplerwill stop adding new samples to our results.- Parameters:
- results
Resultsinstance Resultsinstance.- argsdictionary of keyword arguments, optional
Arguments used to set the stopping values. Default values are
pfrac = 1.0,evid_thresh = 0.1,target_n_effective = 10000,n_mc = 0,error = 'jitter', andapprox = True.- rstate
Generator, optional Generatorinstance.- mapper
mapfunction, optional An alias to a
map-like function. This allows users to pass functions from pools (e.g.,pool.map) to compute realizations in parallel. By default the standardmapfunction is used.- return_valsbool, optional
Whether to return the stopping value (and its components). Default is
False.
- results
- Returns:
- stop_flagbool
Boolean flag indicating whether we have passed the desired stopping criteria.
- stop_valstuple of shape (3,), optional
The individual stopping values
(stop_post, stop_evid, stop)used to determine the stopping criteria.
- dynesty.dynamicsampler.weight_function(results, args=None, return_weights=False)
The default weight function utilized by
DynamicSampler. Zipped parameters are passed to the function viaargs. Assigns each point a weight based on a weighted average of the posterior and evidence information content:weight = pfrac * pweight + (1. - pfrac) * zweight
where
pfracis the fractional importance placed on the posterior, the evidence weightzweightis based on the estimated remaining posterior mass, and the posterior weightpweightis the sample’s importance weight.Returns a set of log-likelihood bounds set by the earliest/latest samples where
weight > maxfrac * max(weight), with additional left/right padding based onpad.- Parameters:
- results
Resultsinstance Resultsinstance.- argsdictionary of keyword arguments, optional
Arguments used to set the log-likelihood bounds used for sampling, as described above. Default values are
pfrac = 0.8,maxfrac = 0.8, andpad = 1.- return_weightsbool, optional
Whether to return the individual weights (and their components) used to compute the log-likelihood bounds. Default is
False.
- results
- Returns:
- logl_boundstuple with shape (2,)
Log-likelihood bounds
(logl_min, logl_max)determined by the weights.- weightstuple with shape (3,), optional
The individual weights
(pweight, zweight, weight)used to determinelogl_bounds.
Sampling Results
Utilities for handling results.
- class dynesty.results.Results(key_values)
Bases:
objectContains the full output of a run along with a set of helper functions for summarizing the output. The object is meant to be unchangeable record of the static or dynamic nested run.
Results attributes (name, type, description, array size):
(‘logl’, ‘array[float]’, ‘Log likelihood’, ‘niter’)(‘samples_it’, ‘array[int]’, ‘the sampling iteration when the sample was proposed (e.g., iteration 570)’, ‘niter’)(‘samples_id’, ‘array[int]’, ‘The unique ID of the sample XXX (within nlive points)’, None)(‘samples_n’, ‘array[int]’, ‘The number of live points at the point when the sample was proposed’, ‘niter’)(‘samples_u’, ‘array[float]’, ‘The coordinates of live points in then unit cube coordinate system’, ‘niter,ndim’)(‘samples_v’, ‘array[float]’, ‘The coordinates of live points’, ‘niter,ndim’)(‘samples’, ‘array’, ‘the location (in original coordinates). Identical to samples_v’, ‘niter,ndim’)(‘niter’, ‘int’, ‘number of iterations’, None)(‘ncall’, ‘int’, ‘Total number likelihood calls’, None)(‘logz’, ‘array’, ‘Array of cumulative log(Z) integrals’, ‘niter’)(‘logzerr’, ‘array’, ‘Array of uncertainty of log(Z)’, ‘niter’)(‘logwt’, ‘array’, ‘Array of log-posterior weights’, ‘niter’)(‘eff’, ‘float’, ‘Sampling efficiency’, None)(‘nlive’, ‘int’, ‘Number of live points for a static run’, None)(‘logvol’, ‘array[float]’, ‘Logvolumes of dead points’, ‘niter’)(‘information’, ‘array[float]’, ‘Information Integral H’, ‘niter’)(‘bound’, ‘array[object]’, ‘the set of bounding objects used to condition proposals for the base run’, ‘nbound’)(‘bound_iter’, ‘array[int]’, ‘index of the bound being used for an iteration that generated the point’, ‘niter’)(‘samples_bound’, ‘array[int]’, ‘The index of the bound that the corresponding sample was drawn from’, ‘niter’)(‘samples_batch’, ‘array[int]’, ‘Tracks the batch during which the samples were proposed’, ‘niter’)(‘batch_logl_bounds’, ‘array[tuple]’, ‘The log-likelihood bounds used to run a batch.’, ‘nbatch’)(‘batch_nlive’, ‘array[int]’, ‘The number of live points used for given batch’, ‘nbatch’)(‘scale’, ‘array[float]’, ‘Scalar scale applied for proposals’, ‘niter’)(‘blob’, ‘array[]’, ‘The auxiliary blobs computed by the log-likelihood function’, ‘niter’)(‘proposal_stats’, ‘array[]’, ‘Information from the inner sampler’, ‘niter’)Initialize the results using the list of key value pairs or a dictionary Results([(‘logl’, [1, 2, 3]), (‘samples_it’,[1,2,3])]) Results(dict(logl=[1, 2, 3], samples_it=[1,2,3]))
- _ALLOWED = {'batch_logl_bounds', 'batch_nlive', 'blob', 'bound', 'bound_iter', 'eff', 'information', 'logl', 'logvol', 'logwt', 'logz', 'logzerr', 'ncall', 'niter', 'nlive', 'proposal_stats', 'samples', 'samples_batch', 'samples_bound', 'samples_id', 'samples_it', 'samples_n', 'samples_u', 'samples_v', 'scale'}
- asdict()
Return contents of the Results object as dictionary
- copy()
return a copy of the object all numpy arrays will be copied too
- importance_weights()
Return the importance weights for the each sample.
- isdynamic()
Return true if the results was constructed using dynamic nested sampling run with (potentially) variable number of live-points
- items()
Return the list of items in the results object as list of key,value pairs
- keys()
Return the list of attributes/keys stored in Results
- samples_equal(rstate=None)
Return the equally weighted samples in random order.
- summary()
Return a formatted string giving a quick summary of the results.
- dynesty.results.print_fn(itresult, niter, ncall, add_live_it=None, dlogz=None, stop_val=None, nbatch=None, logl_min=-inf, logl_max=inf, pbar=None)
The default function used to print out results in real time.
- Parameters:
- itresultIteratorResult or IteratorResultShort
Single iterator output record from the sampler loop that is used for progress/status printing.
- niterint
The current iteration of the sampler.
- ncallint
The total number of function calls at the current iteration.
- add_live_itint, optional
If the last set of live points are being added explicitly, this quantity tracks the sorted index of the current live point being added.
- dlogzfloat, optional
The evidence stopping criterion. If not provided, the provided stopping value will be used instead.
- stop_valfloat, optional
The current stopping criterion (for dynamic nested sampling). Used if the
dlogzvalue is not specified.- nbatchint, optional
The current batch (for dynamic nested sampling).
- logl_minfloat, optional
The minimum log-likelihood used when starting sampling. Default is
-np.inf.- logl_maxfloat, optional
The maximum log-likelihood used when stopping sampling. Default is
np.inf.
Useful Helper Functions
A collection of useful functions.
- class dynesty.utils.DelayTimer(delay)
Bases:
objectUtility class that allows us to detect a certain time has passed
Initialise the time with delay of dt seconds
- Parameters:
- delay: float
The number of seconds in the timer
- is_time()
Returns true if more than self.dt seconds has passed since the initialization or last call of successful is_time()
- Returns:
- ret: bool
True if specified amout of time has passed since the initialization or last successful is_time() call
- class dynesty.utils.LogLikelihood(loglikelihood, ndim, blob=False, history_filename=None, save_evaluation_history=False)
Bases:
objectClass that calls the likelihood function (using a pool if provided) Also if requested it saves the history of evaluations
Initialize the object.
- Parameters:
- loglikelihood: function
- ndim: int
Dimensionality
- history_filename: string
The filename where the history will go
- blob: boolean
if True we expect the logl output to be a tuple of logl value and a blob, otherwise it’ll be logl value only
- save_evaluation_history: bool
if True, evaluation history (intermediate points) will also be saved. This automatically enables basic history saving.
- append_evaluation_history(evaluation_history)
Append evaluation history from samplers to the centralized storage. This method is called by samplers to add their evaluation history.
- Parameters:
- evaluation_historylist of SamplerHistoryItem
The evaluation history from a sampler
- finalize_history()
Finalize and save any remaining history data to file. Call this at the end of sampling to ensure all data is saved.
- history_init()
Initialize the hdf5 storage of evaluations
- history_save()
Save the actual history from an internal buffer into the file
- class dynesty.utils.LoglOutput(v, blob_flag)
Bases:
objectClass that encapsulates the output of the likelihood function. The reason we need this wrapper is to preserve the blob associated with the likelihood function.
Initialize the object
- Parameters:
- v: float or tuple
if blob_flag is true v have to be a tuple of logl and blob if it is False v is just logl
- blob_flag: boolean
flag to mark whether the v has a blob or not
- class dynesty.utils.RunRecord(dynamic=False)
Bases:
objectThis is the dictionary like class that saves the results of the nested run so it is basically a collection of various lists of quantities
If dynamic is true. We initialize the class for a dynamic nested run
- append(newD)
append new information to the RunRecord in the form a dictionary i.e. run.append(dict(batch=3, niter=44))
- keys()
- dynesty.utils.jitter_run(res, rstate=None, approx=False)
Probes statistical uncertainties on a nested sampling run by explicitly generating a realization of the prior volume associated with each sample (dead point). Companion function to
resample_run().- Parameters:
- Returns:
- dynesty.utils.kld_error(res, error='jitter', rstate=None, return_new=False, approx=False)
Computes the Kullback-Leibler (KL) divergence from the discrete probability distribution defined by
resto the discrete probability distribution defined by a realization ofres.- Parameters:
- res
Resultsinstance Resultsinstance for the distribution we are computing the KL divergence from.- error{
'jitter','resample'}, optional The error method employed, corresponding to
jitter_run()orresample_run(). Default is'jitter'.- rstate
Generator, optional Generatorinstance.- return_newbool, optional
Whether to return the realization of the run used to compute the KL divergence. Default is
False.- approxbool, optional
Whether to approximate all sets of uniform order statistics by their associated marginals (from the Beta distribution). Default is
False.
- res
- Returns:
- dynesty.utils.mean_and_cov(samples, weights)
Compute the weighted mean and covariance of the samples.
- Parameters:
- Returns:
Notes
Implements the formulae found here.
- dynesty.utils.merge_runs(res_list, print_progress=True)
Merges a set of runs with differing (possibly variable) numbers of live points into one run.
- dynesty.utils.quantile(x, q, weights=None)
Compute (weighted) quantiles from an input set of samples.
- Parameters:
- Returns:
- quantiles
ndarraywith shape (nquantiles,) The weighted sample quantiles computed at
q.
- quantiles
- dynesty.utils.resample_equal(samples, weights, rstate=None)
Resample a set of points from the weighted set of inputs such that they all have equal weight. The points are also randomly shuffled.
Each input sample appears in the output array either
floor(weights[i] * nsamples)orceil(weights[i] * nsamples)times, withfloororceilrandomly selected (weighted by proximity).- Parameters:
- Returns:
- equal_weight_samples
ndarraywith shape (nsamples,) New set of samples with equal weights in random order.
- equal_weight_samples
Notes
Implements the systematic resampling method described in Hol, Schon, and Gustafsson (2006).
Examples
>>> x = np.array([[1., 1.], [2., 2.], [3., 3.], [4., 4.]]) >>> w = np.array([0.6, 0.2, 0.15, 0.05]) >>> utils.resample_equal(x, w) array([[ 1., 1.], [ 1., 1.], [ 1., 1.], [ 3., 3.]])
- dynesty.utils.resample_run(res, rstate=None, return_idx=False)
Probes sampling uncertainties on a nested sampling run using bootstrap resampling techniques to generate a realization of the (expected) prior volume(s) associated with each sample (dead point). This effectively splits a nested sampling run with
Kparticles (live points) into a series ofK“strands” (i.e. runs with a single live point) which are then bootstrapped to construct a new “resampled” run. Companion function tojitter_run().- Parameters:
- Returns:
- dynesty.utils.reweight_run(res, logp_new, logp_old=None)
Reweight a given run based on a new target distribution.
- Parameters:
- res
Resultsinstance The
Resultsinstance taken from a previous nested sampling run.- logp_new
ndarraywith shape (nsamps,) New target distribution evaluated at the location of the samples.
- logp_old
ndarraywith shape (nsamps,) Old target distribution evaluated at the location of the samples. If not provided, the
loglvalues fromreswill be used.
- res
- Returns:
- dynesty.utils.unitcheck(u, nonbounded=None)
Check whether
uis inside the unit cube. Given a masked arraynonbounded, also allows periodic boundaries conditions to exceed the unit cube.
- dynesty.utils.unravel_run(res, print_progress=True)
Unravels a run with
Klive points intoK“strands” (a nested sampling run with only 1 live point). WARNING: the anciliary quantities provided with each unraveled “strand” are only valid if the point was initialized from the prior.
Plotting Utilities
A set of built-in plotting functions to help visualize dynesty nested
sampling Results.
- dynesty.plotting._hist2d(x, y, smooth=0.02, span=None, weights=None, levels=None, ax=None, color='gray', plot_datapoints=False, plot_density=True, plot_contours=True, no_fill_contours=False, fill_contours=True, contour_kwargs=None, contourf_kwargs=None, data_kwargs=None)
Internal function called by
cornerplot()used to generate a a 2-D histogram/contour of samples.- Parameters:
- xinterable with shape (nsamps,)
Sample positions in the first dimension.
- yiterable with shape (nsamps,)
Sample positions in the second dimension.
- spaniterable with shape (ndim,), optional
A list where each element is either a length-2 tuple containing lower and upper bounds or a float from
(0., 1.]giving the fraction of (weighted) samples to include. If a fraction is provided, the bounds are chosen to be equal-tailed. An example would be:span = [(0., 10.), 0.95, (5., 6.)]
Default is
0.999999426697(5-sigma credible interval).- weightsiterable with shape (nsamps,)
Weights associated with the samples. Default is
None(no weights).- levelsiterable, optional
The contour levels to draw. Default are
[0.5, 1, 1.5, 2]-sigma.- ax
Axes, optional An
axesinstance on which to add the 2-D histogram. If not provided, a figure will be generated.- colorstr, optional
The
matplotlib-style color used to draw lines and color cells and contours. Default is'gray'.- plot_datapointsbool, optional
Whether to plot the individual data points. Default is
False.- plot_densitybool, optional
Whether to draw the density colormap. Default is
True.- plot_contoursbool, optional
Whether to draw the contours. Default is
True.- no_fill_contoursbool, optional
Whether to add absolutely no filling to the contours. This differs from
fill_contours=False, which still adds a white fill at the densest points. Default isFalse.- fill_contoursbool, optional
Whether to fill the contours. Default is
True.- contour_kwargsdict
Any additional keyword arguments to pass to the
contourmethod.- contourf_kwargsdict
Any additional keyword arguments to pass to the
contourfmethod.- data_kwargsdict
Any additional keyword arguments to pass to the
plotmethod when adding the individual data points.
- dynesty.plotting.boundplot(results, dims, it=None, idx=None, prior_transform=None, periodic=None, reflective=None, ndraws=5000, color='gray', plot_kwargs=None, labels=None, label_kwargs=None, max_n_ticks=5, use_math_text=False, show_live=False, live_color='darkviolet', live_kwargs=None, span=None, fig=None)
Return the bounding distribution used to propose either (1) live points at a given iteration or (2) a specific dead point during the course of a run, projected onto the two dimensions specified by
dims.- Parameters:
- results
Resultsinstance A
Resultsinstance from a nested sampling run.- dimslength-2 tuple
The dimensions used to plot the bounding.
- itint, optional
If provided, returns the bounding distribution at the specified iteration of the nested sampling run. Note that this option and `idx` are mutually exclusive.
- idxint, optional
If provided, returns the bounding distribution used to propose the dead point at the specified iteration of the nested sampling run. Note that this option and `it` are mutually exclusive.
- prior_transformfunc, optional
The function transforming samples within the unit cube back to samples in the native model space. If provided, the transformed bounding distribution will be plotted in the native model space.
- periodiciterable, optional
A list of indices for parameters with periodic boundary conditions. These parameters will not have their positions constrained to be within the unit cube, enabling smooth behavior for parameters that may wrap around the edge. Default is
None(i.e. no periodic boundary conditions).- reflectiveiterable, optional
A list of indices for parameters with reflective boundary conditions. These parameters will not have their positions constrained to be within the unit cube, enabling smooth behavior for parameters that may reflect at the edge. Default is
None(i.e. no reflective boundary conditions).- ndrawsint, optional
The number of random samples to draw from the bounding distribution when plotting. Default is
5000.- colorstr, optional
The color of the points randomly sampled from the bounding distribution. Default is
'gray'.- plot_kwargsdict, optional
Extra keyword arguments used when plotting the bounding draws.
- labelsiterable with shape (ndim,), optional
A list of names for each parameter. If not provided, the default name used when plotting will follow \(x_i\) style.
- label_kwargsdict, optional
Extra keyword arguments that will be sent to the
set_xlabelandset_ylabelmethods.- max_n_ticksint, optional
Maximum number of ticks allowed. Default is
5.- use_math_textbool, optional
Whether the axis tick labels for very large/small exponents should be displayed as powers of 10 rather than using
e. Default isFalse.- show_livebool, optional
Whether the live points at a given iteration (for
it) or associated with the bounding (foridx) should be highlighted. Default isFalse. In the dynamic case, only the live points associated with the batch used to construct the relevant bound are plotted.- live_colorstr, optional
The color of the live points. Default is
'darkviolet'.- live_kwargsdict, optional
Extra keyword arguments used when plotting the live points.
- spaniterable with shape (2,), optional
A list where each element is a length-2 tuple containing lower and upper bounds. Default is
None(no bound).- fig(
Figure,Axes), optional If provided, overplot the draws onto the provided figure. Otherwise, by default an internal figure is generated.
- results
- Returns:
- dynesty.plotting.cornerbound(results, it=None, idx=None, dims=None, prior_transform=None, periodic=None, reflective=None, ndraws=5000, color='gray', plot_kwargs=None, labels=None, label_kwargs=None, max_n_ticks=5, use_math_text=False, show_live=False, live_color='darkviolet', live_kwargs=None, span=None, fig=None)
Return the bounding distribution used to propose either (1) live points at a given iteration or (2) a specific dead point during the course of a run, projected onto all pairs of dimensions.
- Parameters:
- results
Resultsinstance A
Resultsinstance from a nested sampling run.- itint, optional
If provided, returns the bounding distribution at the specified iteration of the nested sampling run. Note that this option and `idx` are mutually exclusive.
- idxint, optional
If provided, returns the bounding distribution used to propose the dead point at the specified iteration of the nested sampling run. Note that this option and `it` are mutually exclusive.
- dimsiterable of shape (ndim,), optional
The subset of dimensions that should be plotted. If not provided, all dimensions will be shown.
- prior_transformfunc, optional
The function transforming samples within the unit cube back to samples in the native model space. If provided, the transformed bounding distribution will be plotted in the native model space.
- periodiciterable, optional
A list of indices for parameters with periodic boundary conditions. These parameters will not have their positions constrained to be within the unit cube, enabling smooth behavior for parameters that may wrap around the edge. Default is
None(i.e. no periodic boundary conditions).- reflectiveiterable, optional
A list of indices for parameters with reflective boundary conditions. These parameters will not have their positions constrained to be within the unit cube, enabling smooth behavior for parameters that may reflect at the edge. Default is
None(i.e. no reflective boundary conditions).- ndrawsint, optional
The number of random samples to draw from the bounding distribution when plotting. Default is
5000.- colorstr, optional
The color of the points randomly sampled from the bounding distribution. Default is
'gray'.- plot_kwargsdict, optional
Extra keyword arguments used when plotting the bounding draws.
- labelsiterable with shape (ndim,), optional
A list of names for each parameter. If not provided, the default name used when plotting will be in \(x_i\) style.
- label_kwargsdict, optional
Extra keyword arguments that will be sent to the
set_xlabelandset_ylabelmethods.- max_n_ticksint, optional
Maximum number of ticks allowed. Default is
5.- use_math_textbool, optional
Whether the axis tick labels for very large/small exponents should be displayed as powers of 10 rather than using
e. Default isFalse.- show_livebool, optional
Whether the live points at a given iteration (for
it) or associated with the bounding (foridx) should be highlighted. Default isFalse. In the dynamic case, only the live points associated with the batch used to construct the relevant bound are plotted.- live_colorstr, optional
The color of the live points. Default is
'darkviolet'.- live_kwargsdict, optional
Extra keyword arguments used when plotting the live points.
- spaniterable with shape (2,), optional
A list where each element is a length-2 tuple containing lower and upper bounds. Default is
None(no bound).- fig(
Figure,Axes), optional If provided, overplot the draws onto the provided figure. Otherwise, by default an internal figure is generated.
- results
- Returns:
- dynesty.plotting.cornerplot(results, dims=None, span=None, quantiles=(0.025, 0.5, 0.975), color='black', smooth=0.02, quantiles_2d=None, hist_kwargs=None, hist2d_kwargs=None, labels=None, label_kwargs=None, show_titles=False, title_quantiles=(0.025, 0.5, 0.975), title_fmt='.2f', title_kwargs=None, truths=None, truth_color='red', truth_kwargs=None, max_n_ticks=5, top_ticks=False, use_math_text=False, verbose=False, fig=None)
Generate a corner plot of the 1-D and 2-D marginalized posteriors.
- Parameters:
- results
Resultsinstance A
Resultsinstance from a nested sampling run. Compatible with results derived from nestle.- dimsiterable of shape (ndim,), optional
The subset of dimensions that should be plotted. If not provided, all dimensions will be shown.
- spaniterable with shape (ndim,), optional
A list where each element is either a length-2 tuple containing lower and upper bounds or a float from
(0., 1.]giving the fraction of (weighted) samples to include. If a fraction is provided, the bounds are chosen to be equal-tailed. An example would be:span = [(0., 10.), 0.95, (5., 6.)]
Default is
0.999999426697(5-sigma credible interval).- quantilesiterable, optional
A list of fractional quantiles to overplot on the 1-D marginalized posteriors as vertical dashed lines. Default is
[0.025, 0.5, 0.975](spanning the 95%/2-sigma credible interval).- colorstr or iterable with shape (ndim,), optional
A
matplotlib-style color (either a single color or a different value for each subplot) used when plotting the histograms. Default is'black'.- smoothfloat or iterable with shape (ndim,), optional
The standard deviation (either a single value or a different value for each subplot) for the Gaussian kernel used to smooth the 1-D and 2-D marginalized posteriors, expressed as a fraction of the span. Default is
0.02(2% smoothing). If an integer is provided instead, this will instead default to a simple (weighted) histogram withbins=smooth.- quantiles_2diterable with shape (nquant,), optional
The quantiles used for plotting the smoothed 2-D distributions. If not provided, these default to 0.5, 1, 1.5, and 2-sigma contours roughly corresponding to quantiles of
[0.1, 0.4, 0.65, 0.85].- hist_kwargsdict, optional
Extra keyword arguments to send to the 1-D (smoothed) histograms.
- hist2d_kwargsdict, optional
Extra keyword arguments to send to the 2-D (smoothed) histograms.
- labelsiterable with shape (ndim,), optional
A list of names for each parameter. If not provided, the default name used when plotting will follow \(x_i\) style.
- label_kwargsdict, optional
Extra keyword arguments that will be sent to the
set_xlabelandset_ylabelmethods.- show_titlesbool, optional
Whether to display a title above each 1-D marginalized posterior showing the 0.5 quantile along with the upper/lower bounds associated with the 0.025 and 0.975 (95%/2-sigma credible interval) quantiles. Default is
False.- title_quantilesiterable, optional
A list of fractional quantiles to use in the title. Default is
[0.025, 0.5, 0.975](median plus 95%/2-sigma credible interval).- title_fmtstr, optional
The format string for the quantiles provided in the title. Default is
'.2f'.- title_kwargsdict, optional
Extra keyword arguments that will be sent to the
set_titlecommand.- truthsiterable with shape (ndim,), optional
A list of reference values that will be overplotted on the traces and marginalized 1-D posteriors as solid horizontal/vertical lines. Individual values can be exempt using
None. Default isNone.- truth_colorstr or iterable with shape (ndim,), optional
A
matplotlib-style color (either a single color or a different value for each subplot) used when plottingtruths. Default is'red'.- truth_kwargsdict, optional
Extra keyword arguments that will be used for plotting the vertical and horizontal lines with
truths.- max_n_ticksint, optional
Maximum number of ticks allowed. Default is
5.- top_ticksbool, optional
Whether to label the top (rather than bottom) ticks. Default is
False.- use_math_textbool, optional
Whether the axis tick labels for very large/small exponents should be displayed as powers of 10 rather than using
e. Default isFalse.- verbosebool, optional
Whether to print the values of the computed quantiles associated with each parameter. Default is
False.- fig(
Figure,Axes), optional If provided, overplot the traces and marginalized 1-D posteriors onto the provided figure. Otherwise, by default an internal figure is generated.
- results
- Returns:
- dynesty.plotting.cornerpoints(results, dims=None, thin=1, span=None, cmap='plasma', color=None, kde=True, nkde=1000, plot_kwargs=None, labels=None, label_kwargs=None, truths=None, truth_color='red', truth_kwargs=None, max_n_ticks=5, use_math_text=False, fig=None)
Generate a (sub-)corner plot of (weighted) samples.
- Parameters:
- results
Resultsinstance A
Resultsinstance from a nested sampling run. Compatible with results derived from nestle.- dimsiterable of shape (ndim,), optional
The subset of dimensions that should be plotted. If not provided, all dimensions will be shown.
- thinint, optional
Thin the samples so that only each
thin-th sample is plotted. Default is1(no thinning).- spaniterable with shape (ndim,), optional
A list where each element is either a length-2 tuple containing lower and upper bounds or a float from
(0., 1.]giving the fraction of (weighted) samples to include. If a fraction is provided, the bounds are chosen to be equal-tailed. An example would be:span = [(0., 10.), 0.95, (5., 6.)]
Default is
1.for all parameters (no bound).- cmapstr, optional
A
matplotlib-style colormap used when plotting the points, where each point is colored according to its weight. Default is'plasma'.- colorstr, optional
A
matplotlib-style color used when plotting the points. This overrides thecmapoption by giving all points the same color. Default isNone(not used).- kdebool, optional
Whether to use kernel density estimation to estimate and plot the PDF of the importance weights as a function of log-volume (as opposed to the importance weights themselves). Default is
True.- nkdeint, optional
The number of grid points used when plotting the kernel density estimate. Default is
1000.- plot_kwargsdict, optional
Extra keyword arguments that will be used for plotting the points.
- labelsiterable with shape (ndim,), optional
A list of names for each parameter. If not provided, the default name used when plotting will follow \(x_i\) style.
- label_kwargsdict, optional
Extra keyword arguments that will be sent to the
set_xlabelandset_ylabelmethods.- truthsiterable with shape (ndim,), optional
A list of reference values that will be overplotted on the traces and marginalized 1-D posteriors as solid horizontal/vertical lines. Individual values can be exempt using
None. Default isNone.- truth_colorstr or iterable with shape (ndim,), optional
A
matplotlib-style color (either a single color or a different value for each subplot) used when plottingtruths. Default is'red'.- truth_kwargsdict, optional
Extra keyword arguments that will be used for plotting the vertical and horizontal lines with
truths.- max_n_ticksint, optional
Maximum number of ticks allowed. Default is
5.- use_math_textbool, optional
Whether the axis tick labels for very large/small exponents should be displayed as powers of 10 rather than using
e. Default isFalse.- fig(
Figure,Axes), optional If provided, overplot the points onto the provided figure object. Otherwise, by default an internal figure is generated.
- results
- Returns:
- dynesty.plotting.runplot(results, span=None, logplot=False, kde=True, nkde=1000, color='blue', plot_kwargs=None, label_kwargs=None, lnz_error=True, lnz_truth=None, truth_color='red', truth_kwargs=None, max_x_ticks=8, max_y_ticks=3, use_math_text=True, mark_final_live=True, fig=None)
Plot live points, ln(likelihood), ln(weight), and ln(evidence) as a function of ln(prior volume).
- Parameters:
- results
Resultsinstance A
Resultsinstance from a nested sampling run.- spaniterable with shape (4,), optional
A list where each element is either a length-2 tuple containing lower and upper bounds or a float from
(0., 1.]giving the fraction below the maximum. If a fraction is provided, the bounds are chosen to be equal-tailed. An example would be:span = [(0., 10.), 0.001, 0.2, (5., 6.)]
Default is
(0., 1.05 * max(data))for each element.- logplotbool, optional
Whether to plot the evidence on a log scale. Default is
False.- kdebool, optional
Whether to use kernel density estimation to estimate and plot the PDF of the importance weights as a function of log-volume (as opposed to the importance weights themselves). Default is
True.- nkdeint, optional
The number of grid points used when plotting the kernel density estimate. Default is
1000.- colorstr or iterable with shape (4,), optional
A
matplotlib-style color (either a single color or a different value for each subplot) used when plotting the lines in each subplot. Default is'blue'.- plot_kwargsdict, optional
Extra keyword arguments that will be passed to
plot.- label_kwargsdict, optional
Extra keyword arguments that will be sent to the
set_xlabelandset_ylabelmethods.- lnz_errorbool, optional
Whether to plot the 1, 2, and 3-sigma approximate error bars derived from the ln(evidence) error approximation over the course of the run. Default is
True.- lnz_truthfloat, optional
A reference value for the evidence that will be overplotted on the evidence subplot if provided.
- truth_colorstr or iterable with shape (ndim,), optional
A
matplotlib-style color used when plottinglnz_truth. Default is'red'.- truth_kwargsdict, optional
Extra keyword arguments that will be used for plotting
lnz_truth.- max_x_ticksint, optional
Maximum number of ticks allowed for the x axis. Default is
8.- max_y_ticksint, optional
Maximum number of ticks allowed for the y axis. Default is
4.- use_math_textbool, optional
Whether the axis tick labels for very large/small exponents should be displayed as powers of 10 rather than using
e. Default isFalse.- mark_final_livebool, optional
Whether to indicate the final addition of recycled live points (if they were added to the resulting samples) using a dashed vertical line. Default is
True.- fig(
Figure,Axes), optional If provided, overplot the run onto the provided figure. Otherwise, by default an internal figure is generated.
- results
- Returns:
- dynesty.plotting.traceplot(results, span=None, quantiles=(0.025, 0.5, 0.975), smooth=0.02, thin=1, dims=None, post_color='blue', post_kwargs=None, kde=True, nkde=1000, trace_cmap='plasma', trace_color=None, trace_kwargs=None, connect=False, connect_highlight=10, connect_color='red', connect_kwargs=None, max_n_ticks=5, use_math_text=False, labels=None, label_kwargs=None, show_titles=False, title_quantiles=(0.025, 0.5, 0.975), title_fmt='.2f', title_kwargs=None, truths=None, truth_color='red', truth_kwargs=None, verbose=False, fig=None)
Plot traces and marginalized posteriors for each parameter.
- Parameters:
- results
Resultsinstance A
Resultsinstance from a nested sampling run. Compatible with results derived from nestle.- spaniterable with shape (ndim,), optional
A list where each element is either a length-2 tuple containing lower and upper bounds or a float from
(0., 1.]giving the fraction of (weighted) samples to include. If a fraction is provided, the bounds are chosen to be equal-tailed. An example would be:span = [(0., 10.), 0.95, (5., 6.)]
Default is
0.999999426697(5-sigma credible interval) for each parameter.- quantilesiterable, optional
A list of fractional quantiles to overplot on the 1-D marginalized posteriors as vertical dashed lines. Default is
[0.025, 0.5, 0.975](the 95%/2-sigma credible interval).- smoothfloat or iterable with shape (ndim,), optional
The standard deviation (either a single value or a different value for each subplot) for the Gaussian kernel used to smooth the 1-D marginalized posteriors, expressed as a fraction of the span. Default is
0.02(2% smoothing). If an integer is provided instead, this will instead default to a simple (weighted) histogram withbins=smooth.- thinint, optional
Thin the samples so that only each
thin-th sample is plotted. Default is1(no thinning).- dimsiterable of shape (ndim,), optional
The subset of dimensions that should be plotted. If not provided, all dimensions will be shown.
- post_colorstr or iterable with shape (ndim,), optional
A
matplotlib-style color (either a single color or a different value for each subplot) used when plotting the histograms. Default is'blue'.- post_kwargsdict, optional
Extra keyword arguments that will be used for plotting the marginalized 1-D posteriors.
- kdebool, optional
Whether to use kernel density estimation to estimate and plot the PDF of the importance weights as a function of log-volume (as opposed to the importance weights themselves). Default is
True.- nkdeint, optional
The number of grid points used when plotting the kernel density estimate. Default is
1000.- trace_cmapstr or iterable with shape (ndim,), optional
A
matplotlib-style colormap (either a single colormap or a different colormap for each subplot) used when plotting the traces, where each point is colored according to its weight. Default is'plasma'.- trace_colorstr or iterable with shape (ndim,), optional
A
matplotlib-style color (either a single color or a different color for each subplot) used when plotting the traces. This overrides thetrace_cmapoption by giving all points the same color. Default isNone(not used).- trace_kwargsdict, optional
Extra keyword arguments that will be used for plotting the traces.
- connectbool, optional
Whether to draw lines connecting the paths of unique particles. Default is
False.- connect_highlightint or iterable, optional
If
connect=True, highlights the paths of a specific set of particles. If an integer is passed,connect_highlightrandom particle paths will be highlighted. If an iterable is passed, then the particle paths corresponding to the provided indices will be highlighted.- connect_colorstr, optional
The color of the highlighted particle paths. Default is
'red'.- connect_kwargsdict, optional
Extra keyword arguments used for plotting particle paths.
- max_n_ticksint, optional
Maximum number of ticks allowed. Default is
5.- use_math_textbool, optional
Whether the axis tick labels for very large/small exponents should be displayed as powers of 10 rather than using
e. Default isFalse.- labelsiterable with shape (ndim,), optional
A list of names for each parameter. If not provided, the default name used when plotting will follow \(x_i\) style.
- label_kwargsdict, optional
Extra keyword arguments that will be sent to the
set_xlabelandset_ylabelmethods.- show_titlesbool, optional
Whether to display a title above each 1-D marginalized posterior showing the 0.5 quantile along with the upper/lower bounds associated with the 0.025 and 0.975 (95%/2-sigma credible interval) quantiles. Default is
False.- title_quantilesiterable, optional
A list of fractional quantiles to use in the title. Default is
[0.025, 0.5, 0.975](median plus 95%/2-sigma credible interval).- title_fmtstr, optional
The format string for the quantiles provided in the title. Default is
'.2f'.- title_kwargsdict, optional
Extra keyword arguments that will be sent to the
set_titlecommand.- truthsiterable with shape (ndim,), optional
A list of reference values that will be overplotted on the traces and marginalized 1-D posteriors as solid horizontal/vertical lines. Individual values can be exempt using
None. Default isNone.- truth_colorstr or iterable with shape (ndim,), optional
A
matplotlib-style color (either a single color or a different value for each subplot) used when plottingtruths. Default is'red'.- truth_kwargsdict, optional
Extra keyword arguments that will be used for plotting the vertical and horizontal lines with
truths.- verbosebool, optional
Whether to print the values of the computed quantiles associated with each parameter. Default is
False.- fig(
Figure,Axes), optional If provided, overplot the traces and marginalized 1-D posteriors onto the provided figure. Otherwise, by default an internal figure is generated.
- results
- Returns:
Parallelization helpers
The wrapper around multiprocessing pool that can be helpful with dynesty since it avoids some overhead that one would get with standard pool
- class dynesty.pool.Pool(njobs, loglike, prior_transform, logl_args=None, logl_kwargs=None, ptform_args=None, ptform_kwargs=None)
Bases:
objectThe multiprocessing pool wrapper class It is intended to be used as a context manager for dynesty sampler only.
- Parameters:
- njobs: int
The number of multiprocessing jobs/processes
- loglike: function
ln(likelihood) function
- prior_transform: function
Function transforming from a unit cube to the parameter space of interest according to the prior
- logl_args: tuple(optional)
The optional arguments to be added to the likelihood function call. Note that if you specify the additional arguments here, you do not need to provide them again to the sampler.
- logl_kwargs: tuple(optional)
The optional keywords to be added to the likelihood function call
- ptform_args: tuple(optional)
The optional arguments to be added to the prior transform function call
- ptform_kwargs: tuple(optional)
The optional keywords to be added to the prior transform function call
Examples
To use the dynesty pool you have to use it with the context manager:
with dynesty.pool.Pool(16, loglike, prior_transform) as pool: dns = DynamicNestedSampler(pool.loglike, pool.prior_transform, ndim, pool=pool)
Also note that you have to provide the .loglike/.prior_transform attributes from the pool object to the Nested samper rather than your original functions!
If your likelihood function takes additional arguments, it is better to pass them when creating the pool, rather then to nested sampler:
with dynesty.pool.Pool(16, loglike, prior_transform, logl_args=(...) ) as pool: dns = DynamicNestedSampler(pool.loglike, pool.prior_transform, ndim, pool=pool)
as this way they will not need to be pickled and unpickled every function call.
Note though that if you specify logl_args, and ptform_args when creating the Pool AND in the sampler those will be concatenated
- Attributes:
- loglike: function
ln(likelihood) function
- prior_transform: function
Function transforming from a unit cube to the parameter space of interest according to the prior
- close()
- join()
- map(F, x)
Apply the function F to the list x
- Parameters:
- F: function
- x: iterable
- property size
Return the number of processes in the pool