def initial_trend_values_test(self): hwm = HoltWintersMethod(seasonLength=4) data = [[0, 362.0], [1,385.0], [2, 432.0], [3, 341.0], [4, 382.0], [5, 425.0]] tsSrc = TimeSeries.from_twodim_list(data) trend = hwm.initialTrendSmoothingFactors(tsSrc) assert trend == 7.5, "Initial Trend should be 7.5 but is %f" % trend
def smoothing_test(self): """ Test if the smoothing works correctly""" data = [ 362.0, 385.0, 432.0, 341.0, 382.0, 409.0, 498.0, 387.0, 473.0, 513.0, 582.0, 474.0, 544.0, 582.0, 681.0, 557.0, 628.0, 707.0, 773.0, 592.0, 627.0, 725.0, 854.0, 661.0 ] tsSrc = TimeSeries.from_twodim_list(zip(range(len(data)), data)) expected = [[0.0, 362.0], [1.0, 379.93673257607463], [2.0, 376.86173719924875], [3.0, 376.0203652542205], [4.0, 408.21988583215574], [5.0, 407.16235446485433], [6.0, 430.0950666716297], [7.0, 429.89797609228435], [8.0, 489.4888959723074], [9.0, 507.8407281475308], [10.0, 506.3556647249702], [11.0, 523.9422448655133], [12.0, 556.0311543025242], [13.0, 573.6520991970604], [14.0, 590.2149136780341], [15.0, 611.8813425659495], [16.0, 637.0393967524727], [17.0, 684.6600411792656], [18.0, 675.9589298142507], [19.0, 659.0266828674846], [20.0, 644.0903317144154], [21.0, 690.4507762388047], [22.0, 735.3219292023371], [23.0, 737.9752345691215]] hwm = HoltWintersMethod(.7556, 0.0000001, .9837, 4, valuesToForecast=0) initialA_2 = hwm.computeA(2, tsSrc) assert initialA_2 == 510.5, "Third initial A_2 should be 510.5, but it %d" % initialA_2 initialTrend = hwm.initialTrendSmoothingFactors(tsSrc) assert initialTrend == 9.75, "Initial Trend should be 9.75 but is %d" % initialTrend #correctness is not proven, but will be enough for regression testing resTS = tsSrc.apply(hwm) expectedTS = TimeSeries.from_twodim_list(expected) assert len(resTS) == len(expectedTS) assert resTS == expectedTS, "Smoothing result not correct."
def initial_trend_values_test(self): hwm = HoltWintersMethod(seasonLength=4) data = [[0, 362.0], [1, 385.0], [2, 432.0], [3, 341.0], [4, 382.0], [5, 425.0]] tsSrc = TimeSeries.from_twodim_list(data) trend = hwm.initialTrendSmoothingFactors(tsSrc) assert trend == 7.5, "Initial Trend should be 7.5 but is %f" % trend
def smoothing_test(self): """ Test if the smoothing works correctly""" data = [362.0, 385.0, 432.0, 341.0, 382.0, 409.0, 498.0, 387.0, 473.0, 513.0, 582.0, 474.0, 544.0, 582.0, 681.0, 557.0, 628.0, 707.0, 773.0, 592.0, 627.0, 725.0, 854.0, 661.0] tsSrc = TimeSeries.from_twodim_list(zip(range(len(data)),data)) expected = [[0.0, 362.0],[1.0, 379.93673257607463],[2.0, 376.86173719924875],[3.0, 376.0203652542205],[4.0, 408.21988583215574],[5.0, 407.16235446485433],[6.0, 430.0950666716297],[7.0, 429.89797609228435],[8.0, 489.4888959723074],[9.0, 507.8407281475308],[10.0, 506.3556647249702],[11.0, 523.9422448655133],[12.0, 556.0311543025242],[13.0, 573.6520991970604],[14.0, 590.2149136780341],[15.0, 611.8813425659495],[16.0, 637.0393967524727],[17.0, 684.6600411792656],[18.0, 675.9589298142507],[19.0, 659.0266828674846],[20.0, 644.0903317144154],[21.0, 690.4507762388047],[22.0, 735.3219292023371],[23.0, 737.9752345691215]] hwm = HoltWintersMethod(.7556, 0.0000001, .9837, 4, valuesToForecast=0) initialA_2 = hwm.computeA(2, tsSrc) assert initialA_2 == 510.5, "Third initial A_2 should be 510.5, but it %d" % initialA_2 initialTrend = hwm.initialTrendSmoothingFactors(tsSrc) assert initialTrend == 9.75, "Initial Trend should be 9.75 but is %d" % initialTrend #correctness is not proven, but will be enough for regression testing resTS = tsSrc.apply(hwm) expectedTS = TimeSeries.from_twodim_list(expected) assert len(resTS) == len(expectedTS) assert resTS == expectedTS, "Smoothing result not correct."