-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* #315 clamp smoothed values at 0 * cast smoothed data back to lists (from numpy arrays) for consistency * command line args now restricted to available smoothing and emergence * added simple test for holt-winters to confirm -ve values not handled
- Loading branch information
1 parent
5e45e88
commit f7edcbc
Showing
3 changed files
with
77 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import unittest | ||
|
||
import numpy.testing as np_test | ||
|
||
from scripts.algorithms.holtwinters_predictor import HoltWintersPredictor | ||
|
||
|
||
class HoltWintersTests(unittest.TestCase): | ||
|
||
def test_negatives_in_sequence(self): | ||
time_series = [1, 1, -1, 1, 1] | ||
num_predicted_periods = 3 | ||
|
||
try: | ||
HoltWintersPredictor(time_series, num_predicted_periods) | ||
self.fail('Expected to throw due to negative values') | ||
|
||
except NotImplementedError as nie: | ||
self.assertEqual(nie.args[0], 'Unable to correct for negative or zero values') | ||
|
||
except ValueError as ve: | ||
self.assertEqual(ve.args[0], | ||
'endog must be strictly positive when using multiplicative trend or seasonal components.') | ||
|
||
def test_zeros_in_sequence(self): | ||
time_series = [1, 1, 0, 1, 1] | ||
num_predicted_periods = 3 | ||
expected_prediction = [0.8] * num_predicted_periods | ||
hw = HoltWintersPredictor(time_series, num_predicted_periods) | ||
|
||
actual_prediction = hw.predict_counts() | ||
|
||
np_test.assert_almost_equal(actual_prediction, expected_prediction, decimal=4) | ||
|
||
def test_static_sequence(self): | ||
time_series = [1.0, 1.0, 1.0, 1.0, 1.0] | ||
num_predicted_periods = 3 | ||
expected_prediction = [1] * num_predicted_periods | ||
hw = HoltWintersPredictor(time_series, num_predicted_periods) | ||
|
||
actual_prediction = hw.predict_counts() | ||
|
||
np_test.assert_almost_equal(actual_prediction, expected_prediction, decimal=4) |