Skip to content

Commit

Permalink
feature #188; get_fixed_model() - do nothing if 0 params
Browse files Browse the repository at this point in the history
  • Loading branch information
capelastegui committed Aug 10, 2020
1 parent 874f90f commit 0747bbe
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions anticipy/forecast_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1192,6 +1192,8 @@ def _f_init_bounds_fourier_yearly(a_x=None, a_y=None, a_date=None):

def get_fixed_model(forecast_model, params_fixed, is_mult=False):
# Generate model with some fixed parameters
if forecast_model.n_params == 0: # Nothing to do
return forecast_model
if len(params_fixed) != forecast_model.n_params:
err = 'Wrong number of fixed parameters'
raise ValueError(err)
Expand Down
7 changes: 6 additions & 1 deletion tests/test_forecast_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,8 @@ def test_get_model_outliers_withgap(self):
# - get list of steps
# - if a step is in a filled gap, move to next sample

def test_fixed_model_creation(self):
def test_get_fixed_model(self):
logger.info('Test 1 - default settings')
a_x = np.arange(0, 10)
a_date = pd.date_range('2014-01-01', periods=10, freq='D')

Expand All @@ -809,6 +810,10 @@ def test_fixed_model_creation(self):
a2 = model_constant_fixed(a_x, a_date, None)
self.assert_array_equal(a1, a2)

logger.info('Test 2 - 0-param model')
model_out = get_fixed_model(model_naive, [])
self.assertEqual(model_out.name, 'naive')

def test_fix_params_fmodel(self):
a_x = np.arange(0, 10)
a_date = pd.date_range('2014-01-01', periods=10, freq='D')
Expand Down

0 comments on commit 0747bbe

Please sign in to comment.