Skip to content

Commit 61c88cd

Browse files
committed
Trigger feasibility error by default
1 parent 4cc1c9f commit 61c88cd

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

epochutils/stats/distributions.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ def backward(self, y):
136136
x = 1 / z
137137
return x
138138

139+
class FeasibilityError(Exception):
140+
pass
139141

140142
class Metalog(rv_continuous):
141143
"""
@@ -146,7 +148,7 @@ class Metalog(rv_continuous):
146148

147149
# TODO Add inline references to sections, equations...
148150

149-
def __init__(self, quantiles, n_terms=None):
151+
def __init__(self, quantiles, n_terms=None, skip_validity_check=False):
150152
self.raw_quantiles = quantiles.copy()
151153
self.quantiles = quantiles.copy()
152154

@@ -172,6 +174,9 @@ def __init__(self, quantiles, n_terms=None):
172174
if self.metalog_a is None:
173175
raise ValueError('Failed to fit metalog. The Y^T Y matrix is not invertible.')
174176

177+
if not skip_validity_check:
178+
self._check_feasibility(self.metalog_a, self.raw_quantiles)
179+
175180
def _compute_transforms(self, lower_bound, upper_bound):
176181
if (lower_bound is not None) and (upper_bound is not None):
177182
# TODO: Handle y = 0 and y = 1 cases
@@ -207,7 +212,7 @@ def _check_feasibility(self, a, raw_quantiles):
207212
warnings.warn('Warning: Feasibility check not implemented for more than 3 quantiles')
208213

209214
if not feasible:
210-
raise ValueError(f'Failed feasibility check for quantiles {raw_quantiles}')
215+
raise FeasibilityError(f'Failed feasibility check for quantiles {raw_quantiles}')
211216

212217
# Equations 7 and 8
213218
def _fit_metalog(self, quantiles, n_terms, transform):

0 commit comments

Comments
 (0)