Skip to content

geometric

Geometric

Bases: Distribution

A Geometric distribution.

Source code in hfppl/distributions/geometric.py
class Geometric(Distribution):
    """A Geometric distribution.
    """

    def __init__(self, p):
        """Create a Geometric distribution.

        Args:
            p: the rate of the Geometric distribution.
        """
        self.p = p

    async def sample(self):
        n = np.random.geometric(self.p)
        return n, await self.log_prob(n)

    async def log_prob(self, value):
        return np.log(self.p) + np.log(1 - self.p)*(value - 1)

    async def argmax(self, idx):
        return idx - 1 # Most likely outcome is 0, then 1, etc.

__init__(p)

Create a Geometric distribution.

Parameters:

Name Type Description Default
p

the rate of the Geometric distribution.

required
Source code in hfppl/distributions/geometric.py
def __init__(self, p):
    """Create a Geometric distribution.

    Args:
        p: the rate of the Geometric distribution.
    """
    self.p = p