Skip to content

Commit c303c41

Browse files
Make EnsembleDistribtuion.distribution_map public
1 parent 69db0c6 commit c303c41

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

CHANGELOG.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
**2.2.2 - 12/30/25**
2+
3+
- Make EnsembleDistribution.distribution_map a public attribute
4+
15
**2.2.1 - 11/20/25**
26

37
- Improve 'make build-env': better handle args and make the env name optional

src/risk_distributions/risk_distributions.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ def target_function(guess, m, s):
535535
class EnsembleDistribution:
536536
"""Represents an arbitrary distribution as a weighted sum of several concrete distribution types."""
537537

538-
_distribution_map = {
538+
distribution_map = {
539539
"betasr": Beta,
540540
"exp": Exponential,
541541
"gamma": Gamma,
@@ -567,13 +567,13 @@ def get_parameters(
567567
mean: Parameter = None,
568568
sd: Parameter = None,
569569
) -> tuple[pd.DataFrame, dict[str, pd.DataFrame]]:
570-
expected_columns = list(cls._distribution_map.keys())
570+
expected_columns = list(cls.distribution_map.keys())
571571

572572
weights = cls.fill_missing_weights(weights, expected_columns)
573573
weights = format_data(weights, expected_columns, "weights")
574574

575575
params = {}
576-
for name, dist in cls._distribution_map.items():
576+
for name, dist in cls.distribution_map.items():
577577
try:
578578
param = parameters[name] if parameters else None
579579
params[name] = dist.get_parameters(param, mean, sd)
@@ -631,9 +631,7 @@ def pdf(self, x: pd.Series | np.ndarray | float | int) -> pd.Series | np.ndarray
631631
for name, parameters in self.parameters.items():
632632
w = weights.loc[computable, name]
633633
params = parameters.loc[computable] if len(parameters) > 1 else parameters
634-
p += w * self._distribution_map[name](parameters=params).pdf(
635-
x.loc[computable]
636-
)
634+
p += w * self.distribution_map[name](parameters=params).pdf(x.loc[computable])
637635

638636
if single_val:
639637
p = p.iloc[0]
@@ -682,7 +680,7 @@ def ppf(
682680
if len(parameters) > 1
683681
else parameters
684682
)
685-
x[idx] = self._distribution_map[name](parameters=params).ppf(q[idx])
683+
x[idx] = self.distribution_map[name](parameters=params).ppf(q[idx])
686684

687685
if single_val:
688686
x = x.iloc[0]
@@ -706,9 +704,7 @@ def cdf(self, x: pd.Series | np.ndarray | float | int) -> pd.Series | np.ndarray
706704
for name, parameters in self.parameters.items():
707705
w = weights.loc[computable, name]
708706
params = parameters.loc[computable] if len(parameters) > 1 else parameters
709-
c += w * self._distribution_map[name](parameters=params).cdf(
710-
x.loc[computable]
711-
)
707+
c += w * self.distribution_map[name](parameters=params).cdf(x.loc[computable])
712708

713709
if single_val:
714710
c = c.iloc[0]

0 commit comments

Comments
 (0)