HoltWintersSimpleTrainingModel { public void observeAndTrain(double y, HoltWintersPointForecasterParams params, HoltWintersOnlineComponents components) { checkNulls(params, components); checkTrainingMethod(params); checkStillInInitialTraining(params); int frequency = params.getFrequency(); if (isBetween(n, 0, frequency - 1)) { firstCycle[n] = y; } else { secondCycle[n - frequency] = y; } if (n == params.calculateInitTrainingPeriod() - 1) { setLevel(components); setSeasonals(y, params, components); setBase(params, components); updateComponentsAndForecast(params, components); } n++; } HoltWintersSimpleTrainingModel(HoltWintersPointForecasterParams params); void observeAndTrain(double y, HoltWintersPointForecasterParams params, HoltWintersOnlineComponents components); boolean isTrainingComplete(HoltWintersPointForecasterParams params);  }
@Test public void testObserveAndTrain() { checkObserveAndTrain(HoltWintersSeasonalityType.MULTIPLICATIVE, HoltWintersAustouristsTestHelper.MULT_LEVEL, HoltWintersAustouristsTestHelper.MULT_BASE, HoltWintersAustouristsTestHelper.MULT_SEASONAL); checkObserveAndTrain(HoltWintersSeasonalityType.ADDITIVE, HoltWintersAustouristsTestHelper.ADD_LEVEL, HoltWintersAustouristsTestHelper.ADD_BASE, HoltWintersAustouristsTestHelper.ADD_SEASONAL); }
@Test public void testNullParamFails() { expectedEx.expect(IllegalArgumentException.class); expectedEx.expectMessage("params can't be null"); HoltWintersSimpleTrainingModel subject = new HoltWintersSimpleTrainingModel(HoltWintersAustouristsTestHelper.buildAustouristsParams(HoltWintersSeasonalityType.MULTIPLICATIVE)); subject.observeAndTrain(0, null, null); }
@Test public void testNullComponentsFails() { expectedEx.expect(IllegalArgumentException.class); expectedEx.expectMessage("components can't be null"); HoltWintersPointForecasterParams params = HoltWintersAustouristsTestHelper.buildAustouristsParams(HoltWintersSeasonalityType.MULTIPLICATIVE); HoltWintersSimpleTrainingModel subject = new HoltWintersSimpleTrainingModel(params); subject.observeAndTrain(0, params, null); }
@Test public void testInvalidTrainingMethod() { expectedEx.expect(IllegalArgumentException.class); expectedEx.expectMessage(String.format("Expected training method to be %s but was %s", HoltWintersTrainingMethod.SIMPLE, HoltWintersTrainingMethod.NONE)); HoltWintersPointForecasterParams params = HoltWintersAustouristsTestHelper.buildAustouristsParams(HoltWintersSeasonalityType.MULTIPLICATIVE); HoltWintersOnlineComponents components = new HoltWintersOnlineComponents(params); HoltWintersSimpleTrainingModel subject = new HoltWintersSimpleTrainingModel(params); subject.observeAndTrain(0, params, components); }
@Test public void testExcessTrainingFails() { expectedEx.expect(IllegalArgumentException.class); expectedEx.expectMessage(String.format( "Training invoked %d times which is greater than the training window of frequency * 2 (%d * 2 = %d) observations.", (HoltWintersAustouristsTestHelper.AUSTOURISTS_FREQUENCY * 2) + 1, HoltWintersAustouristsTestHelper.AUSTOURISTS_FREQUENCY, HoltWintersAustouristsTestHelper.AUSTOURISTS_FREQUENCY * 2)); HoltWintersPointForecasterParams params = HoltWintersAustouristsTestHelper.buildAustouristsParams(HoltWintersSeasonalityType.MULTIPLICATIVE) .setInitTrainingMethod(HoltWintersTrainingMethod.SIMPLE); HoltWintersOnlineComponents components = new HoltWintersOnlineComponents(params); HoltWintersSimpleTrainingModel subject = new HoltWintersSimpleTrainingModel(params); for (int i = 0; i < 9; i++) { subject.observeAndTrain(i, params, components); } }