bilby.core.prior.slabspike.SlabSpikePrior
- class bilby.core.prior.slabspike.SlabSpikePrior(slab, spike_location=None, spike_height=0)[source]
Bases:
Prior
- __init__(slab, spike_location=None, spike_height=0)[source]
‘Slab-and-spike’ prior, see e.g. https://arxiv.org/abs/1812.07259 This prior is composed of a slab, i.e. any common prior distribution, and a Dirac spike at a fixed location. This can effectively be used to emulate sampling in the number of dimensions (similar to reversible- jump MCMC).
SymmetricLogUniform and FermiDirac are currently not supported.
- Parameters:
- slab: Prior
Any instance of a bilby prior class. All general prior attributes from the slab are copied into the SlabSpikePrior. Note that this hasn’t been tested for conditional priors.
- spike_location: float, optional
Location of the Dirac spike. Must be between minimum and maximum of the slab. Defaults to the minimum of the slab
- spike_height: float, optional
Relative weight of the spike compared to the slab. Must be between 0 and 1. Defaults to 0, i.e. the prior is just the slab.
- __call__()[source]
Overrides the __call__ special method. Calls the sample method.
- Returns:
- float: The return value of the sample method.
Methods
__init__
(slab[, spike_location, spike_height])'Slab-and-spike' prior, see e.g. https://arxiv.org/abs/1812.07259 This prior is composed of a slab, i.e. any common prior distribution, and a Dirac spike at a fixed location.
cdf
(val)Return the CDF of the prior.
from_json
(dct)from_repr
(string)Generate the prior from its __repr__
get_instantiation_dict
()is_in_prior_range
(val)Returns True if val is in the prior boundaries, zero otherwise
ln_prob
(val)Return the Log prior probability of val.
prob
(val)Return the prior probability of val.
rescale
(val)'Rescale' a sample from the unit line element to the prior.
sample
([size])Draw a sample from the prior
to_json
()Attributes
boundary
Returns True if the prior is fixed and should not be used in the sampler.
Latex label that can be used for plots.
If a unit is specified, returns a string of the latex label and unit
maximum
minimum
Relative prior weight of the slab.
spike_height
spike_location
unit
width
- cdf(val)[source]
Return the CDF of the prior. This calls to the slab CDF and adds a discrete step at the spike location.
- Parameters:
- val: Union[float, int, array_like]
- Returns:
- array_like: CDF value of val
- property is_fixed
Returns True if the prior is fixed and should not be used in the sampler. Does this by checking if this instance is an instance of DeltaFunction.
- Returns:
- bool: Whether it’s fixed or not!
- is_in_prior_range(val)[source]
Returns True if val is in the prior boundaries, zero otherwise
- Parameters:
- val: Union[float, int, array_like]
- Returns:
- np.nan
- property latex_label
Latex label that can be used for plots.
Draws from a set of default labels if no label is given
- Returns:
- str: A latex representation for this prior
- property latex_label_with_unit
If a unit is specified, returns a string of the latex label and unit
- ln_prob(val)[source]
Return the Log prior probability of val. Returns np.inf for the spike location
- Parameters:
- val: Union[float, int, array_like]
- Returns:
- array_like: Prior probability of val
- prob(val)[source]
Return the prior probability of val. Returns np.inf for the spike location
- Parameters:
- val: Union[float, int, array_like]
- Returns:
- array_like: Prior probability of val
- rescale(val)[source]
‘Rescale’ a sample from the unit line element to the prior.
- Parameters:
- val: Union[float, int, array_like]
A random number between 0 and 1
- Returns:
- array_like: Associated prior value with input value.
- sample(size=None)[source]
Draw a sample from the prior
- Parameters:
- size: int or tuple of ints, optional
See numpy.random.uniform docs
- Returns:
- float: A random number between 0 and 1, rescaled to match the distribution of this Prior
- property slab_fraction
Relative prior weight of the slab.