From 75eaf065386cc2dbff2596ea491b0f66a4536c3d Mon Sep 17 00:00:00 2001 From: capelastegui Date: Thu, 30 Jul 2020 18:36:51 +0100 Subject: [PATCH] feature #177; model_decay - remove redundant params --- anticipy/forecast_models.py | 16 +++++++--------- tests/test_forecast_model.py | 2 +- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/anticipy/forecast_models.py b/anticipy/forecast_models.py index 368dc4c..be491f5 100644 --- a/anticipy/forecast_models.py +++ b/anticipy/forecast_models.py @@ -742,29 +742,27 @@ def _f_model_exp(a_x, a_date, params, is_mult=False, **kwargs): # - Exponential decay model: math:: Y = A * e^(B*(x-C)) + D def _f_model_decay(a_x, a_date, params, is_mult=False, **kwargs): - (A, B, C, D) = params - y = A * np.exp(B * (a_x + C)) + D + (A, B, D) = params + y = A * np.exp(B * (a_x)) + D return y def f_init_params_decay(a_x=None, a_y=None, a_date=None, is_mult=False): if a_y is None: - return np.array([0, 0, 0, 0]) + return np.array([0, 0, 0]) A = a_y[0] - a_y[-1] B = np.log(np.min(a_y) / np.max(a_y)) / (len(a_y) - 1) if B > 0 or B == -np.inf: B = -0.5 - C = 0. - D = a_y[-1] - return np.array([A, B, C, D]) + C = a_y[-1] + return np.array([A, B, C]) def f_bounds_decay(a_x=None, a_y=None, a_date=None): - # B should be between 0 and inf - return [-np.inf, -np.inf, 0, -np.inf], [np.inf, 0, np.inf, np.inf] + return [-np.inf, -np.inf, -np.inf], [np.inf, 0, np.inf] -model_decay = ForecastModel('decay', 4, _f_model_decay, +model_decay = ForecastModel('decay', 3, _f_model_decay, f_init_params=f_init_params_decay, f_bounds=f_bounds_decay) diff --git a/tests/test_forecast_model.py b/tests/test_forecast_model.py index 14cfff2..b425fe4 100644 --- a/tests/test_forecast_model.py +++ b/tests/test_forecast_model.py @@ -195,7 +195,7 @@ def test_model( test_model('spike', model_spike, [10., 4., 6.], np.array(4 * [1.] + 2 * [10.] + 4 * [1.]), [True]) - test_model('decay', model_decay, [10., -1000., 0., 0.], + test_model('decay', model_decay, [10., -1000., 0.], np.array([10.] + 9 * [0.])) test_model(