bilby.core.prior.conditional.DirichletElement
- class bilby.core.prior.conditional.DirichletElement(order, n_dimensions, label)[source]
Bases:
ConditionalBetaSingle element in a dirichlet distribution. The probability defined as,
\[\begin{split}p(x_n\mid S_n) := \begin{cases} 1 & N = 1 \\ \displaystyle\frac{(N - n - 1)(1 - S_n - x_n)^{N - n - 2}}{(1-S_n)^{N-n-1}} & n < N - 1 \\ \displaystyle\delta(1-S_{N-1}-x_{N-1}) & n = N - 1 \end{cases}, \qquad 0 \leq x_n \leq 1 - S_n\end{split}\]where, \(\delta\) is the Dirac delta function, \(N\) is the total number of dimensions and \(S_n\) is the sum of all previous dimensions,
\[S_n := \sum_{i=0}^{n-1}x_i \qquad n < N\]- Parameters:
- order: int
Order of this element of the dirichlet distribution. Equivalent to \(n\).
- n_dimensions: int
Total number of elements of the dirichlet distribution. Equivalent to \(N\).
- label: str
Label for the dirichlet distribution. This should be the same for all elements.
Examples
n_dimensions= \(N = 1\):\[p(x_0) = 1 ; 0 \leq x_0 \leq 1\]n_dimensions= \(N = 2\):\[p(x_0) = 1 ; \qquad 0 \leq x_0 \leq 1\]\[p(x_1\mid x_0) = \delta(1-x_0-x_1); \qquad 0 \leq x_1 \leq 1 - x_0\]- __call__()[source]
Overrides the __call__ special method. Calls the sample method.
- Returns:
- float: The return value of the sample method.
Methods
__init__(order, n_dimensions, label)cdf(*args[, xp])dirichlet_condition(reference_parms, **kwargs)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(*args[, xp])prob(*args[, xp])Return the prior probability of val, this should be overwritten
rescale(*args[, xp])'Rescale' a sample from the unit line element to the prior.
Reset the object attributes to match the original reference parameters
sample([size, random_state])Draw a sample from the prior
to_json()update_conditions(**required_variables)This method updates the conditional parameters (depending on the parent class this could be e.g. minimum, maximum, mu, sigma, etc.) of this prior class depending on the required variables it depends on.
Attributes
boundarycondition_funcReturns 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
maximumminimumInitial values for attributes such as minimum, maximum.
The required variables to pass into the condition function.
unitwidth- 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
- prob(*args, xp=None, **kwargs)[source]
Return the prior probability of val, this should be overwritten
- Parameters:
- val: Union[float, int, array_like]
- Returns:
- np.nan
- property reference_params
Initial values for attributes such as minimum, maximum. This depends on the prior_class, for example for the Gaussian prior this is mu and sigma. This is read-only.
- property required_variables
The required variables to pass into the condition function.
- rescale(*args, xp=None, **kwargs)[source]
‘Rescale’ a sample from the unit line element to the prior.
This should be overwritten by each subclass.
- Parameters:
- val: Union[float, int, array_like]
A random number between 0 and 1
- Returns:
- None
- reset_to_reference_parameters()[source]
Reset the object attributes to match the original reference parameters
- sample(size=None, *, random_state=None, **required_variables)[source]
Draw a sample from the prior
- Parameters:
- size: int or tuple of ints, optional
See superclass
- required_variables:
Any required variables that this prior depends on
- Returns:
- float: See superclass
- update_conditions(**required_variables)[source]
This method updates the conditional parameters (depending on the parent class this could be e.g. minimum, maximum, mu, sigma, etc.) of this prior class depending on the required variables it depends on.
If no variables are given, the most recently used conditional parameters are kept
- Parameters:
- required_variables:
Any required variables that this prior depends on. If none are given, self.reference_params will be used.