def one_forecast(self, trainingdata, testdata, start_forecast, end_forecast, period_errors): #electrical_forecast = DayTypeForecast(BaseEnvironment(start_forecast, False, False), trainingdata, samples_per_hour=1) #forecast = [electrical_forecast.get_forecast_at(timestamp) for timestamp in range(start_forecast,end_forecast,3600)] forecast_nodaysplit, (alpha, beta, gamma, delta,autocorr), insample = double_seasonal(trainingdata,24,24*7,len(testdata) ,optimization_type="RMSE") for day, length in enumerate(range(24,14*24,24)): period_errors[day][0] += self.rmse(forecast_nodaysplit[:length], testdata[:length]) period_errors[day][1] += StatisticalForecast.MASE(trainingdata,forecast_nodaysplit[:length], testdata[:length])
def test_performance(self): input_length = 24 * 7 * 8 forecast = 24 * 7 * 4 t = time.time() for i in range(100): double_seasonal(self.dataset[:-input_length], 24, 24 * 7, forecast, alpha=0.5, beta=0.0, gamma=0.5, delta=0, autocorrelation=0.2) py_timing = time.time() - t t2 = time.time() for i in range(100): Cdouble_seasonal( self.dataset[:-input_length], 24, 24 * 7, forecast, alpha=0.5, beta=0.0, gamma=0.5, delta=0, autocorrelation=0.2) cy_timing = time.time() - t2 # print py_timing, cy_timing self.assertTrue( cy_timing < py_timing, "cython version is slower than python. WTF?")
def test_doubleseasonal(self): input_length = 24 * 7 * 8 forecast = 24 * 7 * 4 for a in [0.0, 0.5, 1.0]: for b in [0.0, 0.5, 1.0]: py_forecast, p, insample = double_seasonal( self.dataset[:-input_length], 24, 24 * 7, forecast, alpha=a, beta=0.0, gamma=a, delta=a, autocorrelation=b) cy_forecast, p, insample = Cdouble_seasonal( self.dataset[:-input_length], 24, 24 * 7, forecast, alpha=a, beta=0.0, gamma=a, delta=a, autocorrelation=b) # exclude very high values from testing, as these will have # floating point accuracy issues if abs(numpy.mean(py_forecast)) < 10 ** 9: self.assertTrue(self.rmse(py_forecast, cy_forecast) < 0.5, "python and cython dshw-forecasts differ significantly.")
def one_forecast(self, trainingdata, testdata, start_forecast, end_forecast, period_errors): #electrical_forecast = DayTypeForecast(BaseEnvironment(start_forecast, False, False), trainingdata, samples_per_hour=1) #forecast = [electrical_forecast.get_forecast_at(timestamp) for timestamp in range(start_forecast,end_forecast,3600)] forecast_nodaysplit, (alpha, beta, gamma, delta, autocorr), insample = double_seasonal( trainingdata, 24, 24 * 7, len(testdata), optimization_type="RMSE") for day, length in enumerate(range(24, 14 * 24, 24)): period_errors[day][0] += self.rmse(forecast_nodaysplit[:length], testdata[:length]) period_errors[day][1] += StatisticalForecast.MASE( trainingdata, forecast_nodaysplit[:length], testdata[:length])