Skip to content

Commit

Permalink
docstrings for UniformCDF
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelBrand1 committed Feb 12, 2025
1 parent ef77270 commit fad6539
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion forecasttools/sbc_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,46 @@ def hist(ary, color, ax):


class UniformCDF:
"""
A class to represent the cumulative distribution function (CDF) of a
uniform distribution.
"""

def __init__(self, upper_bound):
"""
Constructs all the necessary attributes for the UniformCDF object.
Parameters
----------
upper_bound : float
The upper bound of the uniform distribution. Must be positive.
Raises
------
ValueError
If upper_bound is not positive.
"""
if upper_bound <= 0:
raise ValueError(f"Upper bound must be positive; got {upper_bound}.")
raise ValueError(
f"Upper bound must be positive; got {upper_bound}."
)
self.upper_bound = upper_bound

def __call__(self, x):
"""
Evaluates the CDF at a given value x.
Parameters
----------
x : array-like
The value(s) at which to evaluate the CDF.
Returns
-------
array-like
The CDF evaluated at x. Returns 0 if x < 0, 1 if x > upper_bound,
and x / upper_bound otherwise.
"""
return np.where(
x < 0, 0, np.where(x > self.upper_bound, 1, x / self.upper_bound)
)

0 comments on commit fad6539

Please sign in to comment.