Skip to content

Commit

Permalink
feature #177; model_decay - remove redundant params
Browse files Browse the repository at this point in the history
  • Loading branch information
capelastegui committed Aug 10, 2020
1 parent 0747bbe commit 75eaf06
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
16 changes: 7 additions & 9 deletions anticipy/forecast_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_forecast_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 75eaf06

Please sign in to comment.