Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Initial guess outside of bounds #173

Open
capelastegui opened this issue Apr 30, 2020 · 2 comments
Open

Error: Initial guess outside of bounds #173

capelastegui opened this issue Apr 30, 2020 · 2 comments

Comments

@capelastegui
Copy link
Contributor

capelastegui commented Apr 30, 2020

We are using the following custom model:

model_step_lockdown = forecast_models.get_model_step_date('2020-03-16')
forecast_models.model_linear+model_step_lockdown

On the initial value check, we get an out of bounds errors:

AssertionError: Initial guess outside of bounds: 
(((decay+step_lockdown)+(season_wday+season_month))+calendar_uk) 
- [-0.00114933         nan  0.          0.00120371  0.00236946  0.66702322
  0.01967633  0.02398207  0.24821339  0.95640447  0.59944057  0.8343352
 -0.07392551 -0.84970678  0.95439321  0.05401732 -0.03123115 -0.39606425
  0.60877698  0.06738449  0.35155036  0.58593382  0.          0.        ], 
[[-inf -inf   0. -inf -inf -inf -inf -inf -inf -inf -inf -inf -inf -inf
  -inf -inf -inf -inf -inf -inf -inf -inf -inf -inf]
 [ inf   0.  inf  inf  inf  inf  inf  inf  inf  inf  inf  inf  inf  inf
   inf  inf  inf  inf  inf  inf  inf  inf  inf  inf]]

Most likely the error is due to the second guessed parameter of the model being NA for some reason. The first 4 parameters are from model_decay, so let's focus on those:

Estimate:
[-0.00114933         nan  0.          0.00120371 ]

Bounds:
[[-inf -inf   0. -inf], [ inf   0.  inf  inf ]]

Relevant code for model_decay:

# - 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
    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])
    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])
@capelastegui
Copy link
Contributor Author

capelastegui commented Apr 30, 2020

We can reproduce the problematic set of guessed parameters with an input array containing negative values:

forecast_models.f_init_params_decay(a_y=[1, -1, 0])

# Out: array([ 1., nan,  0.,  0.])

@capelastegui
Copy link
Contributor Author

Solution: We need to check for non-negative input data when validating input for a model_decay

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant