Skip to content

parameterspace.priors.beta

Beta (BasePrior)

Beta prior for variables in the interval [0,1].

Source code in parameterspace/priors/beta.py
class Beta(BasePrior):
    """Beta prior for variables in the interval [0,1]."""

    @store_init_arguments
    def __init__(self, a: float, b: float):
        """
        Args:
            a: Positive parameter of the Beta distribution.
            b: Positive parameter of the Beta distribution.
        """
        super().__init__((0, 1))
        self.a, self.b = a, b
        self.sps_beta_dist = sps.beta(a, b)

    def pdf(self, value):
        return self.sps_beta_dist.pdf(value)

    def loglikelihood(self, value):
        return self.sps_beta_dist.logpdf(value)

    def sample(self, num_samples=None, random_state=np.random):
        return self.sps_beta_dist.rvs(size=num_samples, random_state=random_state)

    def __repr__(self):
        return f"Beta distribution with parameters a={self.a}, b={self.b}"

    def __eq__(self, other):
        return super().__eq__(other) and np.allclose(
            [self.a, self.b], [other.a, other.b]
        )

loglikelihood(self, value)

Compute the log PDF (up to an additive constant) of a given value.

Note

Values for the priors are always after the transformation!

Parameters:

Name Type Description Default
value

[description]

required

Returns:

Type Description

[descriptions]

Source code in parameterspace/priors/beta.py
def loglikelihood(self, value):
    return self.sps_beta_dist.logpdf(value)

pdf(self, value)

Computes the PDF of a given value.

Note

Values for the priors are always after the transformation!

Parameters:

Name Type Description Default
value

[description]

required

Returns:

Type Description

[descriptions]

Source code in parameterspace/priors/beta.py
def pdf(self, value):
    return self.sps_beta_dist.pdf(value)

sample(self, num_samples=None, random_state=<module 'numpy.random' from '/home/runner/.cache/pypoetry/virtualenvs/parameterspace-9AYrJA9h-py3.8/lib/python3.8/site-packages/numpy/random/__init__.py'>)

Draw random samples from the prior.

Parameters:

Name Type Description Default
num_samples

[description]

None

Returns:

Type Description

[descriptions]

Source code in parameterspace/priors/beta.py
def sample(self, num_samples=None, random_state=np.random):
    return self.sps_beta_dist.rvs(size=num_samples, random_state=random_state)