aspartik.b3.priors
class Bound:
dataclass(slots=True) class Bound(Prior): """Puts limits on the value of a parameter This prior serves the same purpose as the `lower` and `upper` attributes on BEAST parameters. It will return `1` if all dimensions of the parameter lie within `[lower, upper)` or cancel the proposal by returning negative infinity otherwise. Due to how the internals of `b3` work, these priors should be first in the `priors` list in `run`, to avoid calculating other priors and likelihood if the bounds aren't satisfied. """ param: Comparable """The parameter to be constrained.""" lower: float = 0 """Minimum possible value of the parameter, inclusive.""" upper: float = inf """Maximum value of the parameter, exclusive (strictly compared).""" def probability(self) -> float: if not (self.lower <= self.param < self.upper): return -inf else: return 0#
Puts limits on the value of a parameter
This prior serves the same purpose as the lower and upper attributes on
BEAST parameters. It will return 1 if all dimensions of the parameter
lie within [lower, upper) or cancel the proposal by returning negative
infinity otherwise.
Due to how the internals of b3 work, these priors should be first in the
priors list in run, to avoid calculating other priors and likelihood if
the bounds aren't satisfied.
param: aspartik.utils.typing.Comparable
#The parameter to be constrained.
lower: float
#Minimum possible value of the parameter, inclusive.
upper: float
#Maximum value of the parameter, exclusive (strictly compared).
def probability(self) -> float
def probability(self) -> float: if not (self.lower <= self.param < self.upper): return -inf else: return 0#
Calculates the log prior probability of the model state
The return value must be a natural logarithm of the probability.
MCMC will short-circuit and abort the move if probability returns a
negative infinity. This can be used to avoid expensive likelihood
calculations for obviously invalid moves, like going out of variable
bounds.
class Distribution:
dataclass(slots=True) class Distribution(Prior): """ Calculates prior probability of a single-dimensional parameter according to a distribution. """ param: SupportsFloat distribution: Continuous """Distribution against which the parameter prior is calculated.""" def probability(self) -> float: return self.distribution.ln_pdf(float(self.param))#
Calculates prior probability of a single-dimensional parameter according to a distribution.
param: typing.SupportsFloat
#distribution: aspartik.stats.distributions.Continuous
#Distribution against which the parameter prior is calculated.
def probability(self) -> float
def probability(self) -> float: return self.distribution.ln_pdf(float(self.param))#
Calculates the log prior probability of the model state
The return value must be a natural logarithm of the probability.
MCMC will short-circuit and abort the move if probability returns a
negative infinity. This can be used to avoid expensive likelihood
calculations for obviously invalid moves, like going out of variable
bounds.