Informar intervalos PIM no estimables
This commit is contained in:
@@ -81,7 +81,11 @@ def test_predictions_match_the_current_models(name):
|
||||
for ours, theirs in [("probability", "probabilidad"), ("ci_low", "ic_bajo"),
|
||||
("ci_high", "ic_alto")]: # fmt: skip
|
||||
if theirs in both:
|
||||
np.testing.assert_allclose(both[ours], both[theirs], rtol=RTOL, atol=0)
|
||||
# Older reference intervals include non-estimable covariance estimates. Preserve
|
||||
# parity for point estimates and for intervals that remain estimable.
|
||||
comparable = both[ours].notna() if ours != "probability" else np.ones(len(both), bool)
|
||||
np.testing.assert_allclose(both.loc[comparable, ours], both.loc[comparable, theirs],
|
||||
rtol=RTOL, atol=0)
|
||||
if spec.method != "logistic regression":
|
||||
assert (pd.to_datetime(both["index_date"]) == pd.to_datetime(both["fecha_indice"])).all()
|
||||
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
|
||||
from models.cacu.pim import Fit, ISpline, Mixture
|
||||
|
||||
|
||||
def test_unestimable_covariances_never_produce_zero_width_intervals():
|
||||
baseline = ISpline((0.0, 1.0, 2.0), 2)
|
||||
params = np.zeros(1 + baseline.n_params)
|
||||
X, Z = np.ones((1, 1)), np.empty((1, 0))
|
||||
good = Fit(1, 0, baseline, params, np.eye(len(params)), 0, True)
|
||||
assert np.isfinite(good.risk_with_variance(X, Z, [0, 1])[1]).all()
|
||||
for covariance in (np.full((len(params), len(params)), np.nan),
|
||||
-np.eye(len(params)), np.zeros((len(params), len(params)))):
|
||||
broken = Fit(1, 0, baseline, params, covariance, 0, True)
|
||||
assert np.isnan(broken.risk_with_variance(X, Z, [0, 1])[1]).all()
|
||||
|
||||
|
||||
def test_frozen_parameter_only_invalidates_horizons_it_affects():
|
||||
baseline = ISpline((0.0, 1.0, 2.0), 2)
|
||||
params = np.zeros(1 + baseline.n_params)
|
||||
covariance = np.eye(len(params))
|
||||
covariance[1, :] = np.nan
|
||||
covariance[:, 1] = np.nan
|
||||
fitted = Fit(1, 0, baseline, params, covariance, 0, True)
|
||||
variance = fitted.risk_with_variance(np.ones((1, 1)), np.empty((1, 0)), [0, 1])[1]
|
||||
assert np.isfinite(variance[0, 0])
|
||||
assert np.isnan(variance[0, 1])
|
||||
|
||||
|
||||
def test_diagnostics_count_rows_without_intervals():
|
||||
baseline = ISpline((0.0, 1.0, 2.0), 2)
|
||||
params = np.zeros(1 + baseline.n_params)
|
||||
model = Mixture((0, 1), (), (), {})
|
||||
model.fits_ = {(): Fit(1, 0, baseline, params, -np.eye(len(params)), 0, True)}
|
||||
model.seen_ = {(): {}}
|
||||
report = model.variance_diagnostics(pd.DataFrame(index=range(2)))
|
||||
assert report['strata'][0]['rows_without_interval'] == 2
|
||||
assert report['strata'][0]['negative_variances']
|
||||
assert report['strata'][0]['status'] == 'not_estimable'
|
||||
Reference in New Issue
Block a user