@@ -26,11 +26,11 @@ private sealed class ForecastPrediction
2626 {
2727#pragma warning disable CS0649
2828 [ VectorType ( 4 ) ]
29- public float [ ] Change ;
29+ public float [ ] Forecast ;
3030 [ VectorType ( 4 ) ]
31- public float [ ] Min ;
31+ public float [ ] MinCnf ;
3232 [ VectorType ( 4 ) ]
33- public float [ ] Max ;
33+ public float [ ] MaxCnf ;
3434#pragma warning restore CS0649
3535 }
3636
@@ -182,13 +182,14 @@ public void Forecast()
182182 {
183183 ConfidenceLevel = 0.95f ,
184184 Source = "Value" ,
185- Name = "Change " ,
186- ForecastingConfidenceIntervalMinOutputColumnName = "Min " ,
187- ForecastingConfidenceIntervalMaxOutputColumnName = "Max " ,
185+ Name = "Forecast " ,
186+ ForecastingConfidenceIntervalMinOutputColumnName = "MinCnf " ,
187+ ForecastingConfidenceIntervalMaxOutputColumnName = "MaxCnf " ,
188188 WindowSize = 10 ,
189189 SeriesLength = 11 ,
190190 TrainSize = 22 ,
191- Horizon = 4
191+ Horizon = 4 ,
192+ IsAdaptive = true
192193 } ;
193194
194195 for ( int j = 0 ; j < NumberOfSeasonsInTraining ; j ++ )
@@ -205,18 +206,19 @@ public void Forecast()
205206 // Get predictions
206207 var enumerator = env . Data . CreateEnumerable < ForecastPrediction > ( output , true ) . GetEnumerator ( ) ;
207208 ForecastPrediction row = null ;
208- List < double > expectedValues = new List < double > ( ) { 0 , - 3.31410598754883 , 0.5 , 5.12000000000001E-08 , 0 , 1.5700820684432983 , 5.2001145245395008E-07 ,
209- 0.012414560443710681 , 0 , 1.2854313254356384 , 0.28810801662678009 , 0.02038940454467935 , 0 , - 1.0950627326965332 , 0.36663890634019225 , 0.026956459625565483 } ;
209+ List < float > expectedForecast = new List < float > ( ) { 0.191491723f , 2.53994083f , 5.26454258f , 7.37313938f } ;
210+ List < float > minCnf = new List < float > ( ) { - 3.9741993f , - 2.36872721f , 0.09407653f , 2.18899345f } ;
211+ List < float > maxCnf = new List < float > ( ) { 4.3571825f , 7.448609f , 10.435009f , 12.5572853f } ;
212+ enumerator . MoveNext ( ) ;
213+ row = enumerator . Current ;
210214
211- int index = 0 ;
212- while ( enumerator . MoveNext ( ) && index < expectedValues . Count )
215+ for ( int localIndex = 0 ; localIndex < 4 ; localIndex ++ )
213216 {
214- row = enumerator . Current ;
215- /*Assert.Equal(expectedValues[index++], row.Change[0], precision: 7); // Alert
216- Assert.Equal(expectedValues[index++], row.Change[1], precision: 7); // Raw score
217- Assert.Equal(expectedValues[index++], row.Change[2], precision: 7); // P-Value score
218- Assert.Equal(expectedValues[index++], row.Change[3], precision: 7); // Martingale score*/
217+ Assert . Equal ( expectedForecast [ localIndex ] , row . Forecast [ localIndex ] , precision : 7 ) ;
218+ Assert . Equal ( minCnf [ localIndex ] , row . MinCnf [ localIndex ] , precision : 7 ) ;
219+ Assert . Equal ( maxCnf [ localIndex ] , row . MaxCnf [ localIndex ] , precision : 7 ) ;
219220 }
221+
220222 }
221223
222224 [ LessThanNetCore30OrNotNetCoreFact ( "netcoreapp3.0 output differs from Baseline" ) ]
@@ -385,7 +387,7 @@ public void ForecastingPredictionEngine()
385387 WindowSize = 10 ,
386388 SeriesLength = 11 ,
387389 TrainSize = 22 ,
388- Horizon = 4
390+ Horizon = 4 ,
389391 } ;
390392
391393 for ( int j = 0 ; j < NumberOfSeasonsInTraining ; j ++ )
@@ -403,37 +405,16 @@ public void ForecastingPredictionEngine()
403405 engine . Update ( new Data ( 1 ) ) ;
404406 engine . Update ( new Data ( 2 ) ) ;
405407 var forecast = engine . Forecast ( horizon : 5 ) ;
406- var prediction = ml . Data . CreateEnumerable < ForecastResult > ( forecast , reuseRowObject : false ) ;
407-
408-
409- /*Assert.Equal(0, prediction.Change[0], precision: 7); // Alert
410- Assert.Equal(1.1661833524703979, prediction.Change[1], precision: 5); // Raw score
411- Assert.Equal(0.5, prediction.Change[2], precision: 7); // P-Value score
412- Assert.Equal(5.1200000000000114E-08, prediction.Change[3], precision: 7); // Martingale score
413-
414- //Model 1: Checkpoint.
415- var modelPath = "temp.zip";
416- engine.CheckPoint(ml, modelPath);
417-
418- //Model 1: Prediction #2
419- prediction = engine.Predict(new Data(1));
420- Assert.Equal(0, prediction.Change[0], precision: 7); // Alert
421- Assert.Equal(0.12216401100158691, prediction.Change[1], precision: 5); // Raw score
422- Assert.Equal(0.14823824685192111, prediction.Change[2], precision: 5); // P-Value score
423- Assert.Equal(1.5292508189989167E-07, prediction.Change[3], precision: 7); // Martingale score
408+ var prediction = ml . Data . CreateEnumerable < ForecastResult > ( forecast , reuseRowObject : false ) . GetEnumerator ( ) ;
424409
425- // Load Model 1.
426- ITransformer model2 = null;
427- using (var file = File.OpenRead(modelPath))
428- model2 = ml.Model.Load(file, out var schema);
410+ int index = 0 ;
411+ List < float > expectedForecast = new List < float > ( ) { 3.9516573f , 6.212672f , 7.732854f , 8.125769f , 7.22453928f } ;
412+ while ( prediction . MoveNext ( ) )
413+ {
414+ Assert . Equal ( prediction . Current . Forecast , expectedForecast [ index ++ ] ) ;
415+ }
429416
430- //Predict and expect the same result after checkpointing(Prediction #2).
431- engine = model2.CreateTimeSeriesPredictionFunction<Data, Prediction>(ml);
432- prediction = engine.Predict(new Data(1));
433- Assert.Equal(0, prediction.Change[0], precision: 7); // Alert
434- Assert.Equal(0.12216401100158691, prediction.Change[1], precision: 5); // Raw score
435- Assert.Equal(0.14823824685192111, prediction.Change[2], precision: 5); // P-Value score
436- Assert.Equal(1.5292508189989167E-07, prediction.Change[3], precision: 5); // Martingale score*/
417+ Assert . Equal ( 5 , index ) ;
437418 }
438419
439420 [ Fact ]
0 commit comments