DirichletPriorDict¶
- class DirichletPriorDict(n_dim=None, label='dirichlet_')[source]¶
Bases:
ConditionalPriorDict- __init__(n_dim=None, label='dirichlet_')[source]¶
- Parameters:
- dictionary: dict
See parent class
- filename: str
See parent class
- __call__(*args, **kwargs)¶
Call self as a function.
Methods
__init__([n_dim, label])cdf(*args[, xp])Evaluate the cumulative distribution function at the provided points
check_ln_prob(sample, ln_prob[, normalized, xp])check_prob(sample, prob, *[, normalized, xp])Convert all float parameters to delta functions
copy(**kwargs)We have to overwrite the copy method as it fails due to the presence of defaults.
default_conversion_function(sample)Placeholder parameter conversion function.
evaluate_constraints(*args[, xp])fill_priors([likelihood, default_priors_file])Any floats in prior will be converted to delta function prior.
from_dictionary(dictionary)from_file(filename)Reads in a prior from a file specification
from_json(filename)Reads in a prior from a json file
fromkeys(iterable[, value])Create a new dictionary with keys from iterable and values set to value.
Returns the required variables to sample a given conditional key.
ln_prob(sample, *[, axis, normalized, xp])normalize_constraint_factor(keys[, ...])prob(sample, *[, normalized, xp])rescale(keys, theta)Rescale samples from unit cube to prior
sample([size, random_state])Draw samples from the prior set
sample_subset([keys, size, random_state])Draw samples from the prior set for parameters which are not a DeltaFunction
sample_subset_constrained([keys, size, ...])Sample a subset of priors while ensuring constraints are satisfied.
sample_subset_constrained_as_array([keys, ...])Return an array of samples
Test whether there are redundant keys in self.
test_redundancy(key[, disable_logging])Empty redundancy test, should be overwritten in subclasses
to_file(outdir, label)Write the prior distribution to file.
to_json(outdir, label)Attributes
conditional_keysconstraint_keysfixed_keysnon_fixed_keyssorted_keyssorted_keys_without_fixed_parametersunconditional_keys- cdf(*args, xp=None, **kwargs)[source]¶
Evaluate the cumulative distribution function at the provided points
- Parameters:
- sample: dict, pandas.DataFrame
Dictionary of the samples of which to calculate the CDF
- Returns:
- dict, pandas.DataFrame: Dictionary containing the CDF values
- copy(**kwargs)[source]¶
We have to overwrite the copy method as it fails due to the presence of defaults.
- default_conversion_function(sample)[source]¶
Placeholder parameter conversion function.
- Parameters:
- sample: dict
Dictionary to convert
- Returns:
- sample: dict
Same as input
- fill_priors(likelihood=None, default_priors_file=None)[source]¶
Any floats in prior will be converted to delta function prior.
- Parameters:
- likelihood: bilby.likelihood.GravitationalWaveTransient instance
Used to infer the set of parameters to fill the prior with
- default_priors_file: str, optional
If given, a file containing the default priors.
- Returns:
- prior: dict
The filled prior dictionary
- from_file(filename)[source]¶
Reads in a prior from a file specification
- Parameters:
- filename: str
Name of the file to be read in
Notes
Lines beginning with ‘#’ or empty lines will be ignored. Priors can be loaded from:
bilby.core.prior as, e.g.,
foo = Uniform(minimum=0, maximum=1)floats, e.g.,
foo = 1bilby.gw.prior as, e.g.,
foo = bilby.gw.prior.AlignedSpin()other external modules, e.g.,
foo = my.module.CustomPrior(...)
- classmethod from_json(filename)[source]¶
Reads in a prior from a json file
- Parameters:
- filename: str
Name of the file to be read in
- classmethod fromkeys(iterable, value=None, /)¶
Create a new dictionary with keys from iterable and values set to value.
- get_required_variables(key)[source]¶
Returns the required variables to sample a given conditional key.
- Parameters:
- keystr
Name of the key that we want to know the required variables for
- Returns:
- dict: key/value pairs of the required variables
- ln_prob(sample, *, axis=None, normalized=True, xp=None)[source]¶
- Parameters:
- sample: dict
Dictionary of the samples of which we want to have the log probability of
- axis: Union[None, int]
Axis along which the summation is performed
- normalized: bool
When False, disables calculation of constraint normalization factor during prior probability computation. Default value is True.
- Returns:
- float: Joint log probability of all the individual sample probabilities
- prob(sample, *, normalized=True, xp=None, **kwargs)[source]¶
- Parameters:
- sample: dict
Dictionary of the samples of which we want to have the probability of
- kwargs:
The keyword arguments are passed directly to np.prod
- Returns:
- float: Joint probability of all individual sample probabilities
- rescale(keys, theta)[source]¶
Rescale samples from unit cube to prior
- Parameters:
- keys: list
List of prior keys to be rescaled
- theta: list
List of randomly drawn values on a unit cube associated with the prior keys
- Returns:
- list: List of floats containing the rescaled sample
- sample(size=None, *, random_state=None)[source]¶
Draw samples from the prior set
- Parameters:
- size: int or tuple of ints, optional
See numpy.random.uniform docs
- Returns:
- dict: Dictionary of the samples
- sample_subset(keys=<list_iterator object>, size=None, *, random_state=None)[source]¶
Draw samples from the prior set for parameters which are not a DeltaFunction
- Parameters:
- keys: list
List of prior keys to draw samples from
- size: int or tuple of ints, optional
See numpy.random.uniform docs
- Returns:
- dict: Dictionary of the drawn samples
- sample_subset_constrained(keys=<list_iterator object>, size=None, *, random_state=None)[source]¶
Sample a subset of priors while ensuring constraints are satisfied.
- Parameters:
- keys: list
List of prior keys to sample from.
- size: int
The number of samples to draw.
- Returns:
- dict: Dictionary of valid samples.
- sample_subset_constrained_as_array(keys=<list_iterator object>, size=None, *, random_state=None)[source]¶
Return an array of samples
- Parameters:
- keys: list
A list of keys to sample in
- size: int
The number of samples to draw
- Returns:
- array: array_like
An array of shape (len(key), size) of the samples (ordered by keys)
- test_has_redundant_keys()[source]¶
Test whether there are redundant keys in self.
- Returns:
- bool: Whether there are redundancies or not