Skip to content

raplan.distributions

RaPlan distributions module.

Distribution

Bases: ABC

Abstract base class for distributions.

cdf

cdf(x: int | float = 1.0) -> float

Cumulative probability density function of this distribution.

Source code in src/raplan/distributions.py
def cdf(self, x: int | float = 1.0) -> float:
    """Cumulative probability density function of this distribution."""
    if x < 0:
        return 0.0
    return self._cdf(x)

sample abstractmethod

sample() -> float

Take a sample of this distribution.

Source code in src/raplan/distributions.py
@abstractmethod
def sample(self) -> float:
    """Take a sample of this distribution."""

Exponential dataclass

Exponential(lambd: int | float = 1.0)

Bases: Distribution

Exponential distribution.

Parameters:

Name Type Description Default
lambd int | float

Occasion rate or 1 divided by the desired mean. In scheduling, it should be greater than zero.

1.0

LogNormal dataclass

LogNormal(mu: int | float = 1.0, sigma: int | float = 1.0)

Bases: Distribution

Log-normal distribution.

Parameters:

Name Type Description Default
mu int | float

Mean of the underlying normal distribution. Any value.

1.0
sigma int | float

Standard deviation of the underlying normal distribution. Must be >0.

1.0

Pareto dataclass

Pareto(min_x: int | float = 1.0, alpha: int | float = 1.0)

Bases: Distribution

Pareto distribution.

Parameters:

Name Type Description Default
min_x int | float

Minimum x value.

1.0

Triangular dataclass

Triangular(
    low: int | float = 0.0,
    high: int | float = 1.0,
    mode: int
    | float
    | None = field(default=None, skip_if_default=True),
)

Bases: Distribution

Triangular distribution.

Samples are in the range [low, high] and with the specified mode between those bounds. The mode defaults to the midpoint between the two bounds.

Parameters:

Name Type Description Default
low int | float

Lower bound of the sample range.

0.0
high int | float

Upper bound of the sample range.

1.0
mode int | float | None

The mode between those two bounds.

field(default=None, skip_if_default=True)

Uniform dataclass

Uniform(a: int | float = 0.0, b: int | float = 1.0)

Bases: Distribution

A uniform distribution.

Weibull dataclass

Weibull(alpha: int | float = 2.0, mtbf: int | float = 10.0)

Bases: Distribution

Weibull distribution (2-parameter).

Parameters:

Name Type Description Default
alpha int | float

Shape parameter.

2.0
mtbf int | float

Mean time between failure.

10.0

beta property

beta: float

Weibull scale parameter.

compound_probability

compound_probability(
    probabilities: Iterable[float],
) -> float

Compound CDF value of multiple contributions.

Source code in src/raplan/distributions.py
def compound_probability(probabilities: Iterable[float]) -> float:
    """Compound CDF value of multiple contributions."""
    return max(0.0, 1.0 - math.prod(1 - p for p in probabilities))