Skip to content

exponential_distribution

ExponentialDistribution

Bases: BaseDistribution

This class represents an exponential distribution, a type of statistical distribution where the probability of an event decreases exponentially with time. An exponential distribution is defined by a single parameter: the mean, which represents the average time between events.

Parameters:

Name Type Description Default
mean float
  • The mean, also the scale parameter of the exponential distribution.
  • It's the 1/rate parameter.
  • This value is set during the initialization of the class instance. It can be updated using the 'update_attribute()' method.
  • The value should not be negative.
required

Raises:

Type Description
ValueError

If 'mean' argument is negative.

Example

Create an ExponentialDistribution object.

ed = ExponentialDistribution(1)

The mean attribute can be accessed and updated.

ed.mean 1 ed.mean = 2 ed.mean 2

Source code in emod_api/utils/distributions/exponential_distribution.py
class ExponentialDistribution(BaseDistribution):
    """
    This class represents an exponential distribution, a type of statistical distribution
    where the probability of an event decreases exponentially with time.
    An exponential distribution is defined by a single parameter: the mean, which represents the average time
    between events.

    Args:
        mean (float):
            - The mean, also the scale parameter of the exponential distribution.
            - It's the 1/rate parameter.
            - This value is set during the initialization of the class instance. It can be updated using the 'update_attribute()' method.
            - The value should not be negative.

    Raises:
        ValueError: If 'mean' argument is negative.

    Example:
        >>> # Create an ExponentialDistribution object.
        >>> ed = ExponentialDistribution(1)
        >>> # The mean attribute can be accessed and updated.
        >>> ed.mean
        1
        >>> ed.mean = 2
        >>> ed.mean
        2
    """
    DEMOGRAPHIC_DISTRIBUTION_FLAG = DemographicDistributionFlag.EXPONENTIAL.value

    def __init__(self, mean: float):
        super().__init__()
        if mean < 0:
            raise ValueError("The 'mean' argument should not be negative.")
        self.mean = mean

    def set_intervention_distribution(self, intervention_object: s2c.ReadOnlyDict, prefix: str):
        """
        Set the distribution parameters to the object.

        Args:
            intervention_object (s2c.ReadOnlyDict):
                - The object to set.
            prefix (str):
                - The prefix of the parameters.
        """
        self._set_parameters(intervention_object, f"{prefix}_Distribution",
                             DistributionType.EXPONENTIAL_DISTRIBUTION.value)
        self._set_parameters(intervention_object, f"{prefix}_Exponential", self.mean)

    def get_demographic_distribution_parameters(self) -> dict:
        """
        Yield the flag and relevant values necessary for setting a demographics exponential distribution

        Returns:
            a dict of the form: {'flag': X, 'value1': Y, 'value2': Z}
        """
        return {"flag": self.DEMOGRAPHIC_DISTRIBUTION_FLAG, "value1": self.mean, "value2": None}  # value2 not used

get_demographic_distribution_parameters()

Yield the flag and relevant values necessary for setting a demographics exponential distribution

Returns:

Type Description
dict

a dict of the form: {'flag': X, 'value1': Y, 'value2': Z}

Source code in emod_api/utils/distributions/exponential_distribution.py
def get_demographic_distribution_parameters(self) -> dict:
    """
    Yield the flag and relevant values necessary for setting a demographics exponential distribution

    Returns:
        a dict of the form: {'flag': X, 'value1': Y, 'value2': Z}
    """
    return {"flag": self.DEMOGRAPHIC_DISTRIBUTION_FLAG, "value1": self.mean, "value2": None}  # value2 not used

set_intervention_distribution(intervention_object, prefix)

Set the distribution parameters to the object.

Parameters:

Name Type Description Default
intervention_object ReadOnlyDict
  • The object to set.
required
prefix str
  • The prefix of the parameters.
required
Source code in emod_api/utils/distributions/exponential_distribution.py
def set_intervention_distribution(self, intervention_object: s2c.ReadOnlyDict, prefix: str):
    """
    Set the distribution parameters to the object.

    Args:
        intervention_object (s2c.ReadOnlyDict):
            - The object to set.
        prefix (str):
            - The prefix of the parameters.
    """
    self._set_parameters(intervention_object, f"{prefix}_Distribution",
                         DistributionType.EXPONENTIAL_DISTRIBUTION.value)
    self._set_parameters(intervention_object, f"{prefix}_Exponential", self.mean)