epsie.proposals package
Submodules
epsie.proposals.angular module
- class epsie.proposals.angular.ATAdaptiveAngular(parameters, adaptation_duration, componentwise=False, start_step=1, target_rate=None, jump_interval=1)[source]
Bases:
epsie.proposals.normal.ATAdaptiveSupport
,epsie.proposals.angular.Angular
An angular proposal with adaptive variance, using the algorithm from Andrieu & Thoms.
See
ATAdaptiveSupport
for details on the adaptation algorithm.- Parameters
parameters ((list of) str) – The names of the parameters.
adaptation_duration (int) – The number of proposal steps over which to apply the adaptation. No more adaptation will be done once a proposal exceeds this value.
start_step (int, optional) – The proposal step index when adaptation phase begins.
target_rate (float, optional) – Target acceptance ratio. By default 0.234 and 0.48 for componentwise scaling.
jump_interval (int, optional) – The jump interval of the proposal, the proposal only gets called every jump interval-th time. After
adaptation_duration
number of proposal steps elapses the proposal will again be called on every chain iteration. By defaultjump_interval
= 1.
- name = 'at_adaptive_angular'
- symmetric = True
- class epsie.proposals.angular.AdaptiveAngular(parameters, adaptation_duration, jump_interval=1, start_step=1, **kwargs)[source]
Bases:
epsie.proposals.normal.AdaptiveSupport
,epsie.proposals.angular.Angular
An angular proposoal with adaptive variance, using the algorithm from Veitch et al.
See
AdaptiveSupport
for details on the adaptation algorithm.- Parameters
parameters ((list of) str) – The names of the parameters.
boundaries (dict) – Dictionary mapping parameters to boundaries. Boundaries must be a tuple or iterable of length two. The boundaries will be used for the prior widths in the adaptation algorithm.
adaptation_duration (int) – The number of proposal steps over which to apply the adaptation. No more adaptation will be done once a proposal exceeds this value.
jump_interval (int, optional) – The jump interval of the proposal, the proposal only gets called every jump interval-th time. After
adaptation_duration
number of proposal steps elapses the proposal will again be called on every chain iteration. By defaultjump_interval
= 1.start_step (int, optional) – The proposal step to start doing the adaptation (\(k_0+1\) in the equation below). Must be greater than zero. Default is 1.
**kwargs – All other keyword arguments are passed to
AdaptiveSupport.setup_adaptation()
. See that function for details.
- name = 'adaptive_angular'
- symmetric = True
- class epsie.proposals.angular.Angular(parameters, cov=None, jump_interval=1, jump_interval_duration=None)[source]
Bases:
epsie.proposals.normal.Normal
A propsal distribution for parameters that are cyclic over \([0, 2\pi)\).
To generate a jump proposal from a given point, a truncated normal distribution centered on the point and with bounds at \(\pm \pi\) around the point. Cyclic bounds are then applied, resulting in a proposed point that is in \([0, 2\pi)\). For example, if a the given point is at \(1.75\pi\) and the jump is \(+0.5\pi\), then proposed point will be at \(0.25\pi\). Since the same proposal distribution is used regardless of the location, this is a symmetric proposal.
This proposal can handle more than one parameter; however, parameters must all be independent of each other.
- Parameters
parameters ((list of) str) – The names of the parameters to create proposals for.
cov ((array of) float, optional) – The covariance to use for the underlying truncated normal distribution, in squared radians. May provide either a single float, a 1D array with length
ndim
, or anndim x ndim
array, wherendim
= the number of parameters given. If 2D array is given, the off-diagonal terms must be zero. Default is 1 sq. radian for all parameters.jump_interval (int, optional) – The jump interval of the proposal, the proposal only gets called every jump interval-th time. After
jump_interval_duration
number of proposal steps elapses the proposal will again be called on every chain iteration. By defaultjump_interval
= 1.jump_interval_duration (int, optional) – The number of proposals steps during which values of
jump_interval
other than 1 are used. After this elapses the proposal is called on each iteration.
- name = 'angular'
- symmetric = True
- class epsie.proposals.angular.SSAdaptiveAngular(parameters, cov=None, jump_interval=1, jump_interval_duration=None, **kwargs)[source]
Bases:
epsie.proposals.normal.SSAdaptiveSupport
,epsie.proposals.angular.Angular
An angular proposoal with adaptive variance, using the algorithm from Sivia and Skilling.
See
SSAdaptiveSupport
for details on the adaptation algorithm.- Parameters
parameters ((list of) str) – The names of the parameters.
boundaries (dict) – Dictionary mapping parameters to boundaries. Boundaries must be a tuple or iterable of length two. The boundaries will be used for the prior widths in the adaptation algorithm.
jump_interval (int, optional) – The jump interval of the proposal, the proposal only gets called every jump interval-th time. After
jump_interval_duration
number of proposal steps elapses the proposal will again be called on every chain iteration. By defaultjump_interval
= 1.jump_interval_duration (int, optional) – The number of proposals steps during which values of
jump_interval
other than 1 are used. After this elapses the proposal is called on each iteration.**kwargs – All other keyword arguments are passed to
SSAdaptiveSupport.setup_adaptation()
. See that function for details.
- name = 'ss_adaptive_angular'
- symmetric = True
epsie.proposals.base module
- class epsie.proposals.base.BaseAdaptiveSupport[source]
Bases:
abc.ABC
Abstract base class for all proposal classes.
- property adaptation_duration
The adaptation duration used.
- property start_step
The iteration that the adaption begins.
- property target_rate
Target acceptance ratio.
- class epsie.proposals.base.BaseBirth[source]
Bases:
epsie.proposals.base.BaseRandom
Abstract base class for all birth classes.
All birth distributions must inherit from this class, as it lays out all of the functions/attributes that a sampler will try to access.
In addition to the abstract methods/properties, all samplers must set a
parameters
attribute. This is a list of the names of the parameters the proposal produces jumps for.- symmetric
- state
- abstract property birth
This should provide random samples from the birth distribution.
Samples should be returned as a dictionary mapping parameters to the proposed birth.
- name = None
- class epsie.proposals.base.BaseProposal[source]
Bases:
epsie.proposals.base.BaseRandom
Abstract base class for all proposal classes.
All proposals must inherit from this class, as it lays out all of the functions/attributes that a sampler will try to access.
In addition to the abstract methods/properties, all samplers must set a
parameters
attribute. This is a list of the names of the parameters the proposal produces jumps for.- symmetric
- state
- nsteps
- jump(fromx)[source]
Depending on the current number of chain iterations and the
jump_interval
either calls the_jump
method to provide a random sample or returnsfromx
.
- property jump_interval
Returns the jump interval for a proposal.
- property jump_interval_duration
Returns the number of steps after which no more fast jumps are performed.
- logpdf(xi, givenx)[source]
Depending on the current number of chain iterations and the
jump_interval
either calls the_logpdf
method or returns 0.0 as the jump fromgivenx
toxi
was fully determinate.
- name = None
- property nsteps
Returns number of update iterations with this proposal.
While for a standard adaptive MCMC this will match the length of the chain for a transdimensional proposal it will differ.
- pdf(xi, givenx)[source]
The pdf of the proposal at the given values.
This just expoentiates
logpdf
.
- abstract property symmetric
Boolean indicating whether the proposal distribution is symmetric.
A jump proposal is symmetric if the proposal probability density has the property that \(p(x'|x) = p(x|x')\), where \(x\) is the current position, \(x'\) is the proposed position. In this, case, the Metropolis-Hastings ratio simplfies to just the ratio of posterior values at the two points.
Note that an adaptive proposal may still be symmetric. Symmetry only means that the current state of the proposal satisfies the above condition; it does not necessarily mean that transitions between states be symmetric.
- class epsie.proposals.base.BaseRandom[source]
Bases:
abc.ABC
Abstract base class for handling random number generation for proposals ans birth distributions.
All proposals must inherit from this class, as it handles random number generation.
Warning
All proposals must use the random number generator provided by this class (see the
random_generator
attribute) for creating random numbers. Do not attempt to use scipy/numpy’s random number generator. Use of any other generator may result in chains not being independent of each other when run in a parallel environment.In addition to the abstract methods/properties, all samplers must set a
parameters
attribute. This is a list of the names of the parameters the proposal produces jumps and births for.- bit_generator
- random_generator
- random_state
- parameters
- state
- property bit_generator
The random bit generator instance being used.
- name = None
- property parameters
Sorted tuple of the parameters that proposals are produced for.
- property random_generator
The random number generator.
This is an instance of
numpy.random.Generator
that is derived from the bit generator. It provides methods to create random draws from various distributions.
- property random_state
The current state of the random bit generator.
- abstract property state
Returns all information needed to produce a deterministic jump. The information returned by this property should be everything needed such that if you pass it to set_state, you will get the same proposal on the next call of jump. The information should be returned as a dictionary. At the very least, this should include the current state of the proposal’s
random_state
. For adaptive proposals, this may also include the buffer used to adjust the proposal distribution.
epsie.proposals.birth module
- class epsie.proposals.birth.LogNormalBirth(parameters, mean, std)[source]
Bases:
epsie.proposals.base.BaseBirth
Normal birth distribution object used in nested transdimensional proposals to propose birth to parameters which were previously inactive.
- Parameters
parameters ((list of) str) – The names of the parameters to produce proposals for.
mean (dict) – Dictionary mapping parameters to their means
std (dict) – Dictionary mapping parameters to their stds
Properties –
---------- –
birth (dict) – Returns random variate sample from the uniform distribution for each parameter (dictionary).
- logpdf : py:func
Evalues the logpdf of the proposal. Takes dictionary of parameters as input.
- property birth
This should provide random samples from the birth distribution.
Samples should be returned as a dictionary mapping parameters to the proposed birth.
- property mu
Dictionary of parameter -> mu.
- name = 'log_normal_birth'
- setup_mu_std(mu, std)[source]
Sets the mean and standard deviation for each parameter in
parameters
.
- property state
Returns all information needed to produce a deterministic jump. The information returned by this property should be everything needed such that if you pass it to set_state, you will get the same proposal on the next call of jump. The information should be returned as a dictionary. At the very least, this should include the current state of the proposal’s
random_state
. For adaptive proposals, this may also include the buffer used to adjust the proposal distribution.
- property std
Dictionary of parameter -> std.
- class epsie.proposals.birth.NormalBirth(parameters, mean, std)[source]
Bases:
epsie.proposals.base.BaseBirth
Normal birth distribution object used in nested transdimensional proposals to propose birth to parameters which were previously inactive.
- Parameters
parameters ((list of) str) – The names of the parameters to produce proposals for.
mean (dict) – Dictionary mapping parameters to their means
std (dict) – Dictionary mapping parameters to their stds
Properties –
---------- –
birth (dict) – Returns random variate sample from the uniform distribution for each parameter (dictionary).
- logpdf : py:func
Evalues the logpdf of the proposal. Takes dictionary of parameters as input.
- property birth
This should provide random samples from the birth distribution.
Samples should be returned as a dictionary mapping parameters to the proposed birth.
- property mu
Dictionary of parameter -> mu.
- name = 'normal_birth'
- setup_mu_std(mu, std)[source]
Sets the mean and standard deviation for each parameter in
parameters
.
- property state
Returns all information needed to produce a deterministic jump. The information returned by this property should be everything needed such that if you pass it to set_state, you will get the same proposal on the next call of jump. The information should be returned as a dictionary. At the very least, this should include the current state of the proposal’s
random_state
. For adaptive proposals, this may also include the buffer used to adjust the proposal distribution.
- property std
Dictionary of parameter -> std.
- class epsie.proposals.birth.UniformBirth(parameters, boundaries)[source]
Bases:
epsie.proposals.base.BaseBirth
Uniform birth distribution object used in nested transdimensional proposals to propose birth to parameters which were previously inactive.
- Parameters
- logpdf : py:func
Evalues the logpdf of the proposal. Takes dictionary of parameters as input.
- property birth
This should provide random samples from the birth distribution.
Samples should be returned as a dictionary mapping parameters to the proposed birth.
- property boundaries
Dictionary of parameter -> boundaries.
- name = 'uniform_birth'
- property state
Returns all information needed to produce a deterministic jump. The information returned by this property should be everything needed such that if you pass it to set_state, you will get the same proposal on the next call of jump. The information should be returned as a dictionary. At the very least, this should include the current state of the proposal’s
random_state
. For adaptive proposals, this may also include the buffer used to adjust the proposal distribution.
epsie.proposals.bounded_eigenvector module
- class epsie.proposals.bounded_eigenvector.AdaptiveBoundedEigenvector(parameters, boundaries, adaptation_duration, cov0=None, target_rate=0.234, shuffle_rate=0.33, start_step=1, jump_interval=1)[source]
Bases:
epsie.proposals.eigenvector.AdaptiveEigenvectorSupport
,epsie.proposals.bounded_eigenvector.BoundedEigenvector
Uses a bounded eigenvector jump with a adaptive scales
See
AdaptiveEigenvectorSupport
for details on the adaptation algorithm.- Parameters
parameters ((list of) str) – The names of the parameters.
boundaries (dict) – Dictionary mapping parameters to boundaries. Boundaries must be a tuple or iterable of length two.
adaptation_duration (int) – The number of steps after which adaptation of the eigenvectors ends. Post-adaptation phase the eigenvectors and eigenvalues are kept constant.
cov0 (array, optional) – The initial covariance matrix of the parameters used to calculate the initial eigenvectors. May provide either a single float, a 1D array with length
ndim
, or anndim x ndim
array, wherendim
= the number of parameters given. If a single float or a 1D array is given, will use a diagonal covariance matrix (i.e., all parameters are independent of each other). Default (None) is to use unit variance for all parameters.target_rate (float, optional) – Target acceptance ratio. By default 0.234
shuffle_rate (float, optional) – Probability of shuffling the eigenvector jump probabilities. By default 0.33.
start_step (int, optional) – The proposal step index when adaptation phase begins.
jump_interval (int, optional) – The jump interval of the proposal, the proposal only gets called every jump interval-th time. After
jump_interval_duration
number of proposal steps elapses the proposal will again be called on every chain iteration. By defaultjump_interval
= 1.
- name = 'adaptive_bounded_eigenvector'
- symmetric = False
- class epsie.proposals.bounded_eigenvector.BoundedEigenvector(parameters, boundaries, cov=None, shuffle_rate=0.33, jump_interval=1, jump_interval_duration=None)[source]
Bases:
epsie.proposals.eigenvector.Eigenvector
Uses a bounded eigenvector jump with a fixed scale.
This proposal calculates the eigenvectors from the covariance matrix and always proposes a jump along a single eigenvector from a univariate normal distribution. Uses a truncated normal distribution whose scale corresponds to the width of the boundaries surface along the specific eigenvector.
This proposal may handle one or more parameters.
- Parameters
parameters ((list of) str) – The names of the parameters to produce proposals for.
boundaries (dict) – Dictionary mapping parameters to boundaries. Boundaries must be a tuple or iterable of length two.
cov (array, optional) – The covariance matrix of the parameters. May provide either a single float, a 1D array with length
ndim
, or anndim x ndim
array, wherendim
= the number of parameters given. If a single float or a 1D array is given, will use a diagonal covariance matrix (i.e., all parameters are independent of each other). Default (None) is to use unit variance for all parameters.shuffle_rate (float (optional)) – Probability of shuffling the eigenvector jump probabilities. By default 0.33.
jump_interval (int, optional) – The jump interval of the proposal, the proposal only gets called every jump interval-th time. After
jump_interval_duration
number of proposal steps elapses the proposal will again be called on every chain iteration. By defaultjump_interval
= 1.jump_interval_duration (int, optional) – The number of proposals steps during which values of
jump_interval
other than 1 are used. After this elapses the proposal is called on each iteration.
- property boundaries
Dictionary of parameter -> boundaries.
- property hyperplanes
Returns an array of hyperplanes defining the boundaries
- name = 'bounded_eigenvector'
- symmetric = False
epsie.proposals.bounded_normal module
- class epsie.proposals.bounded_normal.ATAdaptiveBoundedNormal(parameters, boundaries, adaptation_duration, componentwise=False, start_step=1, target_rate=None, jump_interval=1)[source]
Bases:
epsie.proposals.normal.ATAdaptiveSupport
,epsie.proposals.bounded_normal.BoundedNormal
A bounded adaptive proposal, using the algorithm from Andrieu & Thoms.
See
ATAdaptiveSupport
for details on the adaptation algorithm.- Parameters
parameters ((list of) str) – The names of the parameters.
boundaries (dict) – Dictionary mapping parameters to boundaries. Boundaries must be a tuple or iterable of length two. The boundaries will be used for the prior widths in the adaptation algorithm.
adaptation_duration (int) – The number of proposal steps over which to apply the adaptation. No more adaptation will be done once a proposal exceeds this value.
componentwise (bool, optional) – Whether to include a componentwise scaling of the parameters (algorithm 6 in [1]). By default set to False (algorithm 4 in [1]). Componentwise scaling ndim times more expensive than global scaling.
start_step (int, optional) – The proposal step index when adaptation phase begins.
target_rate (float, optional) – Target acceptance ratio. By default 0.234 and 0.48 for componentwise scaling.
jump_interval (int, optional) – The jump interval of the proposal, the proposal only gets called every jump interval-th time. After
adaptation_duration
number of proposal steps elapses the proposal will again be called on every chain iteration. By defaultjump_interval
= 1.
- name = 'at_adaptive_bounded_normal'
- symmetric = False
- class epsie.proposals.bounded_normal.AdaptiveBoundedNormal(parameters, boundaries, adaptation_duration, start_step=1, jump_interval=1, **kwargs)[source]
Bases:
epsie.proposals.normal.AdaptiveSupport
,epsie.proposals.bounded_normal.BoundedNormal
A bounded normal proposoal with adaptive variance, using the algorithm from Veitch et al.
See
AdaptiveSupport
for details on the adaptation algorithm.- Parameters
parameters ((list of) str) – The names of the parameters.
boundaries (dict) – Dictionary mapping parameters to boundaries. Boundaries must be a tuple or iterable of length two. The boundaries will be used for the prior widths in the adaptation algorithm.
adaptation_duration (int) – The number of proposal steps over which to apply the adaptation. No more adaptation will be done once a proposal exceeds this value.
start_step (int, optional) – The proposal step to start doing the adaptation (\(k_0+1\) in the equation below). Must be greater than zero. Default is 1.
jump_interval (int, optional) – The jump interval of the proposal, the proposal only gets called every jump interval-th time. After
adaptation_duration
number of proposal steps elapses the proposal will again be called on every chain iteration. By defaultjump_interval
= 1.**kwargs – All other keyword arguments are passed to
AdaptiveSupport.setup_adaptation()
. See that function for details.
- name = 'adaptive_bounded_normal'
- symmetric = False
- class epsie.proposals.bounded_normal.Boundaries(args)[source]
Bases:
tuple
Support class for bounded proposals.
This is basically a length-2 tuple with an abs function. Also has lower and upper attributes to get the first and second item.
Example
>>> b = Boundaries((-1, 1)) >>> b[0], b[1] (-1, 1) >>> b.lower, b.upper (-1, 1) >>> abs(b) 2
- property lower
The lower bound.
- property upper
The upper bound.
- class epsie.proposals.bounded_normal.BoundedNormal(parameters, boundaries, cov=None, jump_interval=1, jump_interval_duration=None)[source]
Bases:
epsie.proposals.normal.Normal
Uses a normal distribution with fixed bounds on a parameter.
This uses a truncated normal distribution for jump proposals, with the truncation dependent on where a given point is with respect to the parameter’s boundaries. As a result, the proposal changes depending on where it is in the parameter space.
This proposal can handle more than one parameter; however, parameters must all be independent of each other.
- Parameters
parameters ((list of) str) – The names of the parameters to produce proposals for.
boundaries (dict) – Dictionary mapping parameters to boundaries. Boundaries must be a tuple or iterable of length two.
cov (array, optional) – The covariance matrix of the parameters. May provide either a single float, a 1D array with length
ndim
, or anndim x ndim
array, wherendim
= the number of parameters given. If 2D array is given, the off-diagonal terms must be zero. Default is 1 for all parameters.jump_interval (int, optional) – The jump interval of the proposal, the proposal only gets called every jump interval-th time. After
jump_interval_duration
number of proposal steps elapses the proposal will again be called on every chain iteration. By defaultjump_interval
= 1.jump_interval_duration (int, optional) – The number of proposals steps during which values of
jump_interval
other than 1 are used. After this elapses the proposal is called on each iteration.
- property boundaries
Dictionary of parameter -> boundaries.
- name = 'bounded_normal'
- symmetric = False
- class epsie.proposals.bounded_normal.SSAdaptiveBoundedNormal(parameters, boundaries, cov=None, jump_interval=1, jump_interval_duration=None, **kwargs)[source]
Bases:
epsie.proposals.normal.SSAdaptiveSupport
,epsie.proposals.bounded_normal.BoundedNormal
A bounded normal proposoal using the Sivia and Skilling algorithm for adjusting the variance.
By default, the maximum possible standard deviation is set to be 1.49 times largest boundary width (via the
max_cov
argument). At this value, there is a 50% chance that a jump will be larger than the boundary width. For more details on the adaptation algorithm, seeSSAdaptiveSupport
.- Parameters
parameters ((list of) str) – The names of the parameters.
boundaries (dict) – Dictionary mapping parameters to boundaries. Boundaries must be a tuple or iterable of length two. The boundaries will be used for the prior widths in the adaptation algorithm.
cov (array, optional) – The covariance matrix of the parameters. May provide either a single float, a 1D array with length
ndim
, or anndim x ndim
array, wherendim
= the number of parameters given. If 2D array is given, the off-diagonal terms must be zero. Default is 1 for all parameters.jump_interval (int, optional) – The jump interval of the proposal, the proposal only gets called every jump interval-th time. After
jump_interval_duration
number of proposal steps elapses the proposal will again be called on every chain iteration. By defaultjump_interval
= 1.jump_interval_duration (int, optional) – The number of proposals steps during which values of
jump_interval
other than 1 are used. After this elapses the proposal is called on each iteration.**kwargs – All other keyword arguments are passed to
SSAdaptiveSupport.setup_adaptation()
. See that function for details.
- name = 'ss_adaptive_bounded_normal'
- symmetric = False
epsie.proposals.discrete module
- class epsie.proposals.discrete.AdaptiveBoundedDiscrete(parameters, boundaries, adaptation_duration, successive=None, jump_interval=1, **kwargs)[source]
Bases:
epsie.proposals.normal.AdaptiveSupport
,epsie.proposals.discrete.BoundedDiscrete
A bounded discrete proposoal with adaptive variance.
See
AdaptiveSupport
for details on the adaptation algorithm.- Parameters
parameters ((list of) str) – The names of the parameters to produce proposals for.
boundaries (dict) – Dictionary mapping parameters to boundaries. Boundaries must be a tuple or iterable of length two. If floats are provided, the floor (ceil) of the lower (upper) bound will be used.
adaptation_duration (int) – The number of proposal steps over which to apply the adaptation. No more adaptation will be done once a proposal exceeds this value.
jump_interval (int, optional) – The jump interval of the proposal, the proposal only gets called every jump interval-th time. After
adaptation_duration
number of proposal steps elapses the proposal will again be called on every chain iteration. By defaultjump_interval
= 1.**kwargs – All other keyword arguments are passed to
AdaptiveSupport.setup_adaptation()
. See that function for details.
- name = 'adaptive_bounded_discrete'
- symmetric = False
- class epsie.proposals.discrete.AdaptiveNormalDiscrete(parameters, prior_widths, adaptation_duration, successive=None, jump_interval=1, **kwargs)[source]
Bases:
epsie.proposals.normal.AdaptiveSupport
,epsie.proposals.discrete.NormalDiscrete
A discrete proposoal with adaptive variance, using the algorithm from Veitch et al.
See
AdaptiveSupport
for details on the adaptation algorithm.- Parameters
parameters ((list of) str) – The names of the parameters to produce proposals for.
prior_widths (dict) – Dictionary mapping parameter names to values giving the width of each parameter’s prior. The values may be floats, or any object that has an
__abs__
method that will return a float.adaptation_duration (int) – The number of proposal steps over which to apply the adaptation. No more adaptation will be done once a proposal exceeds this value.
jump_interval (int, optional) – The jump interval of the proposal, the proposal only gets called every jump interval-th time. After
adaptation_duration
number of proposal steps elapses the proposal will again be called on every chain iteration. By defaultjump_interval
= 1.**kwargs – All other keyword arguments are passed to
AdaptiveSupport.setup_adaptation()
. See that function for details.
- name = 'adaptive_discrete'
- symmetric = True
- class epsie.proposals.discrete.BoundedDiscrete(parameters, boundaries, cov=None, successive=None, jump_interval=1, jump_interval_duration=None)[source]
Bases:
epsie.proposals.bounded_normal.BoundedNormal
A proposal for discrete parameters with bounds.
This is a discretized form of
BoundedNormal
. Jump proposals are produced in the same manner asNormalDiscrete
, except that the distribution used to draw \(\Delta x\) (before applying the floor/ceil or round) is a truncated normal. As such, this is not a symmetric distribution.The variance used for drawing \(\Delta x\) need not be an integer, and can be set. Multiple parameters are supported, however, they all must be independent of each other.
- Parameters
parameters ((list of) str) – The names of the parameters to produce proposals for.
boundaries (dict) – Dictionary mapping parameters to boundaries. Boundaries must be a tuple or iterable of length two. If floats are provided, the floor (ceil) of the lower (upper) bound will be used.
cov (array, optional) – The covariance matrix of the parameters. May provide either a single float, a 1D array with length
ndim
, or anndim x ndim
array, wherendim
= the number of parameters given. If 2D array is given, the off-diagonal terms must be zero. Default is 1 for all parameters.successive (dict, optional) – Dictionary of bools, keys must be parameters and items bools. If False then the proposal never produces the same integer on successive jumps. Default is False for all parameters
jump_interval (int, optional) – The jump interval of the proposal, the proposal only gets called every jump interval-th time. After
jump_interval_duration
number of proposal steps elapses the proposal will again be called on every chain iteration. By defaultjump_interval
= 1.jump_interval_duration (int, optional) – The number of proposals steps during which values of
jump_interval
other than 1 are used. After this elapses the proposal is called on each iteration.
- name = 'bounded_discrete'
- property successive
Dictionary of successive toggles for each parameter. If True allows two equal integers on successive jumps.
- symmetric = False
- class epsie.proposals.discrete.NormalDiscrete(parameters, cov=None, successive=None, jump_interval=1, jump_interval_duration=None)[source]
Bases:
epsie.proposals.normal.Normal
A proposal for discrete parameters.
The jump proposals produced by this are always integer values. For a given point \(x \in \mathbb{Z}\), a new point \(x' = x + \bar{\Delta x}\) is generated by using
\[\begin{split}\bar{\Delta x} = \begin{cases} \lfloor \Delta x \rfloor \textrm{ if } \Delta x < 0, \\ \lceil \Delta x \rceil \textrm{ if } \Delta x > 0, \end{cases}\end{split}\]where \(\Delta x \sim \mathcal{N}(0, \sigma)\) if successive is False. This results in a stepped probability density that is zero \(\in [0, 1)\). In other words, the proposal will never produce the same integer on successive jumps, and it will most often draw integers closest to the current point.
If successive is True, then for a given point \(x \in \mathbb{Z}\), a new point \(x' = x + \bar{\Delta x}\) is generated by using
\[\bar{\Delta x} = Round\left(\mathcal{N}(0, \sigma)\right),\]meaning that the proposal can now propose the same integer on successive jumps.
The variance used for drawing \(\Delta x\) need not be an integer, and can be set. Multiple parameters are supported, however, they all must be independent of each other.
- Parameters
parameters ((list of) str) – The names of the parameters to produce proposals for.
cov (array, optional) – The covariance matrix of the parameters. May provide either a single float, a 1D array with length
ndim
, or anndim x ndim
array, wherendim
= the number of parameters given. If 2D array is given, the off-diagonal terms must be zero. Default is 1 for all parameters.successive (dict, optional) – Dictionary of bools, keys must be parameters and items bools. If False then the proposal never produces the same integer on successive jumps. Default is False for all parameters
jump_interval (int, optional) – The jump interval of the proposal, the proposal only gets called every jump interval-th time. After
jump_interval_duration
number of proposal steps elapses the proposal will again be called on every chain iteration. By defaultjump_interval
= 1.jump_interval_duration (int, optional) – The number of proposals steps during which values of
jump_interval
other than 1 are used. After this elapses the proposal is called on each iteration.
- name = 'discrete'
- property successive
Dictionary of successive toggles for each parameter. If True allows two equal integers on successive jumps.
- symmetric = True
- class epsie.proposals.discrete.SSAdaptiveBoundedDiscrete(parameters, boundaries, cov=None, successive=None, jump_interval=1, jump_interval_duration=None, **kwargs)[source]
Bases:
epsie.proposals.normal.SSAdaptiveSupport
,epsie.proposals.discrete.BoundedDiscrete
A bounded discrete proposoal with adaptive variance, using the algorithm from Sivia and Skilling.
See
AdaptiveSupport
for details on the adaptation algorithm.- Parameters
parameters ((list of) str) – The names of the parameters to produce proposals for.
boundaries (dict) – Dictionary mapping parameters to boundaries. Boundaries must be a tuple or iterable of length two. If floats are provided, the floor (ceil) of the lower (upper) bound will be used.
cov (array, optional) – The covariance matrix of the parameters. May provide either a single float, a 1D array with length
ndim
, or anndim x ndim
array, wherendim
= the number of parameters given. If 2D array is given, the off-diagonal terms must be zero. Default is 1 for all parameters.jump_interval (int, optional) – The jump interval of the proposal, the proposal only gets called every jump interval-th time. After
jump_interval_duration
number of proposal steps elapses the proposal will again be called on every chain iteration. By defaultjump_interval
= 1.jump_interval_duration (int, optional) – The number of proposals steps during which values of
jump_interval
other than 1 are used. After this elapses the proposal is called on each iteration.**kwargs – All other keyword arguments are passed to
SSAdaptiveSupport.setup_adaptation()
. See that function for details.
- name = 'ss_adaptive_bounded_discrete'
- symmetric = False
- class epsie.proposals.discrete.SSAdaptiveNormalDiscrete(parameters, cov=None, successive=None, jump_interval=1, jump_interval_duration=None, **kwargs)[source]
Bases:
epsie.proposals.normal.SSAdaptiveSupport
,epsie.proposals.discrete.NormalDiscrete
A discrete proposoal with adaptive variance, using the algorithm from Sivia and Skilling.
See
SSAdaptiveSupport
for details on the adaptation algorithm.- Parameters
parameters ((list of) str) – The names of the parameters to produce proposals for.
cov (array, optional) – The covariance matrix of the parameters. May provide either a single float, a 1D array with length
ndim
, or anndim x ndim
array, wherendim
= the number of parameters given. If 2D array is given, the off-diagonal terms must be zero. Default is 1 for all parameters.jump_interval (int, optional) – The jump interval of the proposal, the proposal only gets called every jump interval-th time. After
jump_interval_duration
number of proposal steps elapses the proposal will again be called on every chain iteration. By defaultjump_interval
= 1.jump_interval_duration (int, optional) – The number of proposals steps during which values of
jump_interval
other than 1 are used. After this elapses the proposal is called on each iteration.**kwargs – All other keyword arguments are passed to
SSAdaptiveSupport.setup_adaptation()
. See that function for details.
- name = 'ss_adaptive_discrete'
- symmetric = True
epsie.proposals.eigenvector module
- class epsie.proposals.eigenvector.AdaptiveEigenvector(parameters, adaptation_duration, cov0=None, target_rate=0.234, shuffle_rate=0.33, start_step=1, jump_interval=1)[source]
Bases:
epsie.proposals.eigenvector.AdaptiveEigenvectorSupport
,epsie.proposals.eigenvector.Eigenvector
Uses jumps along eigenvectors with adaptive scales.
See
AdaptiveEigenvectorSupport
for details on the adaptation algorithm.- Parameters
parameters ((list of) str) – The names of the parameters.
adaptation_duration (int) – The number of steps after which adaptation of the eigenvectors ends. Post-adaptation phase the eigenvectors and eigenvalues are kept constant.
cov0 (array, optional) – The initial covariance matrix of the parameters used to calculate the initial eigenvectors. May provide either a single float, a 1D array with length
ndim
, or anndim x ndim
array, wherendim
= the number of parameters given. If a single float or a 1D array is given, will use a diagonal covariance matrix (i.e., all parameters are independent of each other). Default (None) is to use unit variance for all parameters.target_rate (float (optional)) – Target acceptance ratio. By default 0.234
shuffle_rate (float, optional) – Probability of shuffling the eigenvector jump probabilities. By default 0.33.
start_step (int, optional) – The proposal step index when adaptation phase begins.
jump_interval (int, optional) – The jump interval of the proposal, the proposal only gets called every jump interval-th time. After
adaptation_duration
number of proposal steps elapses the proposal will again be called on every chain iteration. By defaultjump_interval
= 1.
- name = 'adaptive_eigenvector'
- symmetric = True
- class epsie.proposals.eigenvector.AdaptiveEigenvectorSupport[source]
Bases:
epsie.proposals.base.BaseAdaptiveSupport
Utility class for adding AdaptiveEigenvector proposal support.
The adaptation algorithm is based on Algorithm 8 in [1].
See [1] for details.
Notes
For the vanishing decay we use
\[\gamma_{g+1} = \left(g - g_{0}\right)^{-0.6} - C,\]where \(g_{0}\) is the iteration at which adaptation starts, by default \(g_{0}=1\) and \(C\) is a positive constant ensuring that when the adaptation phase ends the vanishing decay tends to zero. By default assumes that the adaptation phase never ends (only decays with time)
References
[1] Andrieu, Christophe & Thoms, Johannes. (2008). A tutorial on adaptive MCMC. Statistics and Computing. 18. 10.1007/s11222-008-9110-y.
- recursive_covariance(chain)[source]
Recursively updates the covariance given the latest observation. Weights all sampled points uniformly.
- setup_adaptation(adaptation_duration, start_step=1, target_rate=0.234)[source]
Sets up the adaptation parameters.
- property state
- class epsie.proposals.eigenvector.Eigenvector(parameters, cov=None, shuffle_rate=0.33, jump_interval=1, jump_interval_duration=None)[source]
Bases:
epsie.proposals.base.BaseProposal
Uses a eigenvector jump with a fixed scale that is determined by the given covariance matrix.
This proposal may handle one or more parameters.
- Parameters
parameters ((list of) str) – The names of the parameters to produce proposals for.
cov (array, optional) – The covariance matrix of the parameters. May provide either a single float, a 1D array with length
ndim
, or anndim x ndim
array, wherendim
= the number of parameters given. If a single float or a 1D array is given, will use a diagonal covariance matrix (i.e., all parameters are independent of each other). Default (None) is to use unit variance for all parameters.shuffle_rate (float, optional) – Probability of shuffling the eigenvector jump probabilities. By default 0.33.
jump_interval (int, optional) – The jump interval of the proposal, the proposal only gets called every jump interval-th time. After
jump_interval_duration
number of proposal steps elapses the proposal will again be called on every chain iteration. By defaultjump_interval
= 1.jump_interval_duration (int, optional) – The number of proposals steps during which values of
jump_interval
other than 1 are used. After this elapses the proposal is called on each iteration.
- property bit_generator
The random bit generator instance being used.
- property cov
The covariance matrix used.
- property eigvals
Returns the eigenvalues
- property eigvects
Returns the eigenvectors
- name = 'eigenvector'
- property shuffle_rate
- property state
Returns all information needed to produce a deterministic jump. The information returned by this property should be everything needed such that if you pass it to set_state, you will get the same proposal on the next call of jump. The information should be returned as a dictionary. At the very least, this should include the current state of the proposal’s
random_state
. For adaptive proposals, this may also include the buffer used to adjust the proposal distribution.
- symmetric = True
epsie.proposals.joint module
- class epsie.proposals.joint.JointProposal(*proposals, bit_generator=None)[source]
Bases:
epsie.proposals.base.BaseProposal
A collection of jump proposals for multiple parameters.
- Parameters
*proposals – The arguments should provide the constituent proposals to use.
bit_generator (
epsie.BIT_GENERATOR
instance or int, optional) – The random bit generator to use, or an integer/None. If the latter, a bit generator will be created usingepsie.create_bit_generator()
.
- name = 'joint'
- property state
Returns all information needed to produce a deterministic jump. The information returned by this property should be everything needed such that if you pass it to set_state, you will get the same proposal on the next call of jump. The information should be returned as a dictionary. At the very least, this should include the current state of the proposal’s
random_state
. For adaptive proposals, this may also include the buffer used to adjust the proposal distribution.
- property symmetric
Boolean indicating whether the proposal distribution is symmetric.
A jump proposal is symmetric if the proposal probability density has the property that \(p(x'|x) = p(x|x')\), where \(x\) is the current position, \(x'\) is the proposed position. In this, case, the Metropolis-Hastings ratio simplfies to just the ratio of posterior values at the two points.
Note that an adaptive proposal may still be symmetric. Symmetry only means that the current state of the proposal satisfies the above condition; it does not necessarily mean that transitions between states be symmetric.
epsie.proposals.nested_transdimensional module
- class epsie.proposals.nested_transdimensional.NestedTransdimensional(parameters, model_proposal, proposals, birth_distributions, bit_generator=None)[source]
Bases:
epsie.proposals.base.BaseProposal
Nested transdimensional proposal.
- Parameters
parameters ((list of) str) – The names of the parameters to produce proposals for.
model_proposal (proposal) – The model hopping proposals. This must be a discrete, bounded proposal.
proposals (list of proposals) – The transdimensional proposals that are being turned on/off.
birth_distributions (list of objects) – Objects that match transdimensional proposals and are used to birth new samples and evaluate their proposal probability. Must use structure as given in the example.
bit_generator (BIT_GENERATOR or int, optional) – The random bit generator to use, or an integer/None. If the latter, a bit generator will be created using
epsie.create_bit_generator()
.
- proposals
The constituent in-model proposals.
- Type
list of proposals
- model_proposal
The model hopping proposal
- property model_proposal
- name = 'nested_transdimensional'
- property proposals
- setup_births(birth_distributions)[source]
Matches birth distributions to proposals. Note that order of parameters matters
- property state
Returns all information needed to produce a deterministic jump. The information returned by this property should be everything needed such that if you pass it to set_state, you will get the same proposal on the next call of jump. The information should be returned as a dictionary. At the very least, this should include the current state of the proposal’s
random_state
. For adaptive proposals, this may also include the buffer used to adjust the proposal distribution.
- property symmetric
Boolean indicating whether the proposal distribution is symmetric.
A jump proposal is symmetric if the proposal probability density has the property that \(p(x'|x) = p(x|x')\), where \(x\) is the current position, \(x'\) is the proposed position. In this, case, the Metropolis-Hastings ratio simplfies to just the ratio of posterior values at the two points.
Note that an adaptive proposal may still be symmetric. Symmetry only means that the current state of the proposal satisfies the above condition; it does not necessarily mean that transitions between states be symmetric.
- transdimensional = True
epsie.proposals.normal module
- class epsie.proposals.normal.ATAdaptiveNormal(parameters, adaptation_duration, diagonal=False, componentwise=False, start_step=1, target_rate=None, jump_interval=1)[source]
Bases:
epsie.proposals.normal.ATAdaptiveSupport
,epsie.proposals.normal.Normal
Uses a normal distribution with adaptive covariance for proposals.
See
ATAdaptiveSupport
for details on the adaptation algorithm.- Parameters
parameters ((list of) str) – The names of the parameters.
adaptation_duration (int) – The number of proposal steps over which to apply the adaptation. No more adaptation will be done once a proposal exceeds this value.
diagonal (bool, optional) – Whether to train off-diagonal elements of the proposal covariance. By default set to False; off-diagonal elements are being trained.
componentwise (bool, optional) – Whether to include a componentwise scaling of the parameters (algorithm 6 in [1]). By default set to False (algorithm 4 in [1]). Componentwise scaling ndim times more expensive than global scaling.
start_step (int, optional) – The proposal step index when adaptation phase begins.
target_rate (float, optional) – Target acceptance ratio. By default 0.234 and 0.48 for componentwise scaling.
jump_interval (int, optional) – The jump interval of the proposal, the proposal only gets called every jump interval-th time. After
adaptation_duration
number of proposal steps elapses the proposal will again be called on every chain iteration. By defaultjump_interval
= 1.**kwargs – All other keyword arguments are passed to
AdaptiveSupport.setup_adaptation()
. See that function for details.
- name = 'at_adaptive_normal'
- symmetric = True
- class epsie.proposals.normal.ATAdaptiveSupport[source]
Bases:
epsie.proposals.base.BaseAdaptiveSupport
Utility class for adding ATAdaptiveNormal proposal support.
The adaptation algorithm is based on Algorithm 4 and 6 in [1].
See [1] for details.
Notes
For the vanishing decay we use
\[\gamma_{g+1} = \left(g - g_{0}\right)^{-0.6} - C,\]where :math: g_{0} is the iteration at which adaptation starts, by default :math: g_{0}=1 and :math: C is a positive constant ensuring that when the adaptation phase ends the vanishing decay tends to zero.
References
[1] Andrieu, Christophe & Thoms, Johannes. (2008). A tutorial on adaptive MCMC. Statistics and Computing. 18. 10.1007/s11222-008-9110-y.
- setup_adaptation(adaptation_duration, diagonal=False, componentwise=False, start_step=1, target_rate=None)[source]
Sets up the adaptation parameters.
- Parameters
adaptation_duration (int) – The number of proposal steps over which to apply the adaptation. No more adaptation will be done once a proposal exceeds this value.
diagonal (bool, optional) – Whether to train off-diagonal elements of the proposal covariance. By default set to False; off-diagonal elements are being trained.
componentwise (bool, optional) – Whether to include a componentwise scaling of the parameters (algorithm 6 in [1]). By default set to False (algorithm 4 in [1]). Componentwise scaling ndim times more expensive than global scaling.
start_step (int, optional) – The proposal step when the adaptation phase begins.
target_rate (float, optional) – Target acceptance ratio. By default 0.234 and 0.48 for componentwise scaling.
- property state
- class epsie.proposals.normal.AdaptiveNormal(parameters, prior_widths, adaptation_duration, start_step=1, jump_interval=1, **kwargs)[source]
Bases:
epsie.proposals.normal.AdaptiveSupport
,epsie.proposals.normal.Normal
Uses a normal distribution with adaptive variance for proposals.
See
AdaptiveSupport
for details on the adaptation algorithm.- Parameters
parameters ((list of) str) – The names of the parameters.
prior_widths (dict) – Dictionary mapping parameter names to values giving the width of each parameter’s prior. The values may be floats, or any object that has an
__abs__
method that will return a float.adaptation_duration (int) – The number of proposal steps over which to apply the adaptation. No more adaptation will be done once a proposal exceeds this value.
start_step (int, optional) – The proposal step index when adaptation phase begins.
jump_interval (int, optional) – The jump interval of the proposal, the proposal only gets called every jump interval-th time. After
adaptation_duration
number of proposal steps elapses the proposal will again be called on every chain iteration. By defaultjump_interval
= 1.**kwargs – All other keyword arguments are passed to
AdaptiveSupport.setup_adaptation()
. See that function for details.
- name = 'adaptive_normal'
- symmetric = True
- class epsie.proposals.normal.AdaptiveSupport[source]
Bases:
epsie.proposals.base.BaseAdaptiveSupport
Utility class for adding adaptive variance support to a proposal.
The adaptation algorithm is based on Eqs. 35 and 36 of Veitch et al. 1. The with of the proposal at each step is based on the width of the prior and whether or not the previous proposal was accepted or not. See Notes for more details.
This is only meant to be used in conjuction with proposals that have independent parameters, each with their own standard deviation. Specifically, the propsal must have an
isdiagonal
attribute and an_std
attribute.Notes
For a given parameter, the standard deviation of the \(k^{\rm th}\) iteration is given by 1:
\[\sigma_k = \sigma_{k-1} + \alpha_{k-1} \left[\left(k - k_0\right)^{-\beta} - 0.1\right]\frac{\Delta}{10},\]where \(\alpha_{k-1} = 1 - \xi\) if the previous iteration was accpeted and \(\alpha_{k-1} = -\xi\) if the previous iteration was rejected. Here, \(\xi\) is the target acceptance rate, \(\Delta\) is the prior width, \(\beta\) is the adaptation decay, and \(k_0\) gives the iteration after which the adaptation begins. The initial standard deviation \(\sigma_0\) to use is a free parameter. The default in this function is to use \(\sigma_0 = (1-\xi)0.09\Delta\).
References
- 1(1,2)
J. Veitch et al., “Parameter estimation for compact binaries with ground-based gravitational-wave observations using the LALInference software library, ” Phys. Rev. D91 042003 (2015), arXiv:1409.7215 [gr-qc].
- property deltas
The prior widths, as a numpy array.
- property prior_widths
The width of the prior used for each parameter.
- setup_adaptation(prior_widths, adaptation_duration, adaptation_decay=None, start_step=1, target_rate=0.234, initial_std=None)[source]
Sets up the adaptation parameters.
- Parameters
prior_widths (dict) – Dictionary mapping parameter names to values giving the width of each parameter’s prior. The values may be floats, or any object that has an
__abs__
method that will return a float.adaptation_duration (int) – The number of proposal steps over which to apply the adaptation. No more adaptation will be done once a chain exceeds this value.
adaptation_decay (int, optional) – The decay rate to use for the adaptation size (\(beta\) in the equation in the notes). If not provided, will use \(1/\log_10(T)\), where \(T\) is the adaptation duration.
start_step (int, optional) – The proposal step to start doing the adaptation (\(k_0+1\) in the equation below). Must be greater than zero. Default is 1.
target_rate (float, optional) – The target acceptance rate. Default is 0.234.
initial_std (array, optional) – The initial standard deviation to use. Default is to use (1 - target_rate)*0.09*prior_widths.
- property state
- class epsie.proposals.normal.Normal(parameters, cov=None, jump_interval=1, jump_interval_duration=None)[source]
Bases:
epsie.proposals.base.BaseProposal
Uses a normal distribution with a fixed variance for proposals.
This proposal may handle one or more parameters.
- Parameters
parameters ((list of) str) – The names of the parameters to produce proposals for.
cov (array, optional) – The covariance matrix of the parameters. May provide either a single float, a 1D array with length
ndim
, or anndim x ndim
array, wherendim
= the number of parameters given. If a single float or a 1D array is given, will use a diagonal covariance matrix (i.e., all parameters are independent of each other). Default (None) is to use unit variance for all parameters.jump_interval (int, optional) – The jump interval of the proposal, the proposal only gets called every jump interval-th time. After
jump_interval_duration
number of proposal steps elapses the proposal will again be called on every chain iteration. By defaultjump_interval
= 1.jump_interval_duration (int, optional) – The number of proposals steps during which values of
jump_interval
other than 1 are used. After this elapses the proposal is called on each iteration.
- cov
The covariance matrix being used.
- Type
- property cov
The covariance matrix used.
- property isdiagonal
Whether or not the parameters are independent of each other.
If True (the parameters are independent), then a normal distribution will be used for proposals. Otherwise, a multivariate normal is used.
- name = 'normal'
- property state
Returns all information needed to produce a deterministic jump. The information returned by this property should be everything needed such that if you pass it to set_state, you will get the same proposal on the next call of jump. The information should be returned as a dictionary. At the very least, this should include the current state of the proposal’s
random_state
. For adaptive proposals, this may also include the buffer used to adjust the proposal distribution.
- property std
The standard deviation.
Raises a
ValueError
if the covariance matrix is not diagonal.
- symmetric = True
- class epsie.proposals.normal.SSAdaptiveNormal(parameters, cov=None, jump_interval=1, jump_interval_duration=None, **kwargs)[source]
Bases:
epsie.proposals.normal.SSAdaptiveSupport
,epsie.proposals.normal.Normal
Uses a normal distribution with adaptive variance for proposals.
See
SSAdaptiveSupport
for details on the adaptation algorithm.- Parameters
parameters ((list of) str) – The names of the parameters.
jump_interval (int, optional) – The jump interval of the proposal, the proposal only gets called every jump interval-th time. After
jump_interval_duration
number of proposal steps elapses the proposal will again be called on every chain iteration. By defaultjump_interval
= 1.jump_interval_duration (int, optional) – The number of proposals steps during which values of
jump_interval
other than 1 are used. After this elapses the proposal is called on each iteration.**kwargs – All other keyword arguments are passed to
SSAdaptiveSupport.setup_adaptation()
. See that function for details.
- name = 'ss_adaptive_normal'
- symmetric = True
- class epsie.proposals.normal.SSAdaptiveSupport[source]
Bases:
epsie.proposals.base.BaseAdaptiveSupport
Utility class for adding adaptive variance support to a proposal.
The adaptation algorithm is based on a method in Sivia and Skilling 2.
Notes
At each iteration \(k\), the variance is scaled by a factor \(\gamma(k)\)
\[\gamma(k) = \alpha(k) \gamma(k-1),\]where
\[\begin{split}\alpha(k) = \begin{cases} e^{1/N_a(k)} &\textrm{ if } \frac{N_a(k)}{k} > \xi,\\ e^{-1/(k-N_a(k))} &\textrm{ if } \frac{N_a(k)}{k} < \xi,\\ 1 &\textrm{ if } \frac{N_a(k)}{k} = \xi. \end{cases}\end{split}\]Here, \(N_a(k)\) is the number of iterations that have been accepted to this point (so that \(k-N_a(k)\) is the number of rejections), and \(\xi\) is the target acceptance rate. The initial \(gamma\) is set to 1.
References
- 2
Sivia D., Skilling J., “Data Analysis: A Bayesian Tutorial,” Oxford Univ. Press, Oxford (2006)
- max_std = None
- n_accepted = None
- setup_adaptation(target_rate=0.234, max_cov=None)[source]
Sets up the adaptation parameters.
- Parameters
target_rate (float, optional) – The target acceptance rate. Default is 0.234.
max_cov (float, optional) – The maximum value any element in the covariance matrix is allowed to obtain. If an adapatation step would cause any element to exceed this value, the covariance matrix will not be changed. Default (None) means that no cap will be applied.
- property state
epsie.proposals.solid_angle module
Proposals for sampling on the surface of a 2-sphere.
- class epsie.proposals.solid_angle.AdaptiveIsotropicSolidAngle(azimuthal_parameter, polar_parameter, adaptation_duration, start_step=1, target_rate=0.234, radec=False, degs=False, jump_interval=1)[source]
Bases:
epsie.proposals.solid_angle.AdaptiveIsotropicSolidAngleSupport
,epsie.proposals.solid_angle.IsotropicSolidAngle
An adaptive isotropic solid angle proposal based on the von Mises-Fisher distribution.
See
AdaptiveIsotropicSolidAngleSupport
andIsotropicSolidAngle
for more details on the adaptation algorithm and the proposal distribution.- Parameters
azimuthal_parameter (str) – The name of the azimuthal parameter.
polar_parameter (str) – The name of the polar parameter.
adaptation_duration (int) – The number of proposal steps over which to apply the adaptation. No more adaptation will be done once a proposal exceeds this value.
start_step (int, optional) – The proposal step index when adaptation phase begins.
target_rate (float, optional) – Target acceptance ratio. By default 0.234 and 0.48 for componentwise scaling.
radec (bool, optional) – Defines the polar angle convention. By default False, i.e. the polar angle range is [0, np.pi]. If
radec
= True, then the polar angle range is [-np.pi/2, np.pi/2].degs (bool, optional) – Whether the input parameters are in degrees. By default False (radians).
jump_interval (int, optional) – The jump interval of the proposal, the proposal only gets called every jump interval-th time. After
jump_interval_duration
number of proposal steps elapses the proposal will again be called on every chain iteration. By defaultjump_interval
= 1.
- name = 'adaptive_isotropic_solid_angle'
- symmetric = True
- class epsie.proposals.solid_angle.AdaptiveIsotropicSolidAngleSupport[source]
Bases:
epsie.proposals.base.BaseAdaptiveSupport
A utility class for adding adaptation support for the
IsotropicSolidAngle
proposal.The adaptation adapts the concentration parameter to achieve a specific acceptance ration.
Notes
For the vanishing decay we use
\[\gamma_{g+1} = \left(g - g_{0}\right)^{-0.6} - C,\]where :math: g_{0} is the iteration at which adaptation starts, by default :math: g_{0}=1 and :math: C is a positive constant ensuring that when the adaptation phase ends the vanishing decay tends to zero.
- setup_adaptation(adaptation_duration, start_step, target_rate)[source]
Sets up the adaptation parameters.
- Parameters
adaptation_duration (int) – The number of proposal steps over which to apply the adaptation. No more adaptation will be done once a proposal exceeds this value.
start_step (int, optional) – The proposal step when the adaptation phase begins.
target_rate (float, optional) – Target acceptance ratio. By default 0.234 and 0.48 for componentwise scaling.
- property state
- class epsie.proposals.solid_angle.IsotropicSolidAngle(azimuthal_parameter, polar_parameter, kappa=10, radec=False, degs=False, jump_interval=1, jump_interval_duration=None)[source]
Bases:
epsie.proposals.base.BaseProposal
Uses the von Mises-Fisher distribution with a fixed concentration parameter.
The von Mises-Fisher distribution is an isotropic distribution on the surface of a 2-sphere and is analogoues to the isotropic normal distribution on a plane (where the covariance matrix is proportional to unity).
- Parameters
azimuthal_parameter (str) – The name of the azimuthal parameter.
polar_parameter (str) – The name of the polar parameter.
kappa (float, optional) –
The distribution concentration parameter. The mean angular distance of a jump in degrees for several values of
kappa
is:kappa
= 1 : 69 degreeskappa
= 10 : 23 degreeskappa
= 100 : 7 degreesradec (bool, optional) – Defines the polar angle convention. By default False, i.e. the polar angle range is [0, np.pi]. If
radec
= True, then the polar angle range is [-np.pi/2, np.pi/2].degs (bool, optional) – Whether the input parameters are in degrees. By default False (radians).
jump_interval (int, optional) – The jump interval of the proposal, the proposal only gets called every jump interval-th time. After
jump_interval_duration
number of proposal steps elapses the proposal will again be called on every chain iteration. By defaultjump_interval
= 1.jump_interval_duration (int, optional) – The number of proposals steps during which values of
jump_interval
other than 1 are used. After this elapses the proposal is called on each iteration.
- property isdegs
Whether input and ouput values are in degrees.
- property isradec
Whether the polar angle assumes the right-ascension declination convention and runs in range [-np.pi/2, np.pi/2].
- property kappa
Returns the concentration parameter of the von Mises-Fisher distribution.
- name = 'isotropic_solid_angle'
- property norm
Returns the normalisation constant for the von Mises-Fisher distribution.
- property state
Returns all information needed to produce a deterministic jump. The information returned by this property should be everything needed such that if you pass it to set_state, you will get the same proposal on the next call of jump. The information should be returned as a dictionary. At the very least, this should include the current state of the proposal’s
random_state
. For adaptive proposals, this may also include the buffer used to adjust the proposal distribution.
- symmetric = True