@@ -167,60 +167,6 @@ public void ChangePointDetectionWithSeasonality()
167167 }
168168 }
169169
170- [ LessThanNetCore30OrNotNetCoreFact ( "netcoreapp3.0 output differs from Baseline" ) ]
171- public void Forecast ( )
172- {
173- var env = new MLContext ( ) ;
174- const int ChangeHistorySize = 10 ;
175- const int SeasonalitySize = 10 ;
176- const int NumberOfSeasonsInTraining = 5 ;
177-
178- List < Data > data = new List < Data > ( ) ;
179- var dataView = env . Data . LoadFromEnumerable ( data ) ;
180-
181- var args = new SsaForecasting . Options ( )
182- {
183- ConfidenceLevel = 0.95f ,
184- Source = "Value" ,
185- Name = "Forecast" ,
186- ForecastingConfidenceIntervalMinOutputColumnName = "MinCnf" ,
187- ForecastingConfidenceIntervalMaxOutputColumnName = "MaxCnf" ,
188- WindowSize = 10 ,
189- SeriesLength = 11 ,
190- TrainSize = 22 ,
191- Horizon = 4 ,
192- IsAdaptive = true
193- } ;
194-
195- for ( int j = 0 ; j < NumberOfSeasonsInTraining ; j ++ )
196- for ( int i = 0 ; i < SeasonalitySize ; i ++ )
197- data . Add ( new Data ( i ) ) ;
198-
199- for ( int i = 0 ; i < ChangeHistorySize ; i ++ )
200- data . Add ( new Data ( i * 100 ) ) ;
201-
202- // Train
203- var detector = new SsaForecastingEstimator ( env , args ) . Fit ( dataView ) ;
204- // Transform
205- var output = detector . Transform ( dataView ) ;
206- // Get predictions
207- var enumerator = env . Data . CreateEnumerable < ForecastPrediction > ( output , true ) . GetEnumerator ( ) ;
208- ForecastPrediction row = null ;
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 ;
214-
215- for ( int localIndex = 0 ; localIndex < 4 ; localIndex ++ )
216- {
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 ) ;
220- }
221-
222- }
223-
224170 [ LessThanNetCore30OrNotNetCoreFact ( "netcoreapp3.0 output differs from Baseline" ) ]
225171 public void ChangePointDetectionWithSeasonalityPredictionEngineNoColumn ( )
226172 {
@@ -368,7 +314,61 @@ public void ChangePointDetectionWithSeasonalityPredictionEngine()
368314 }
369315
370316 [ LessThanNetCore30OrNotNetCoreFact ( "netcoreapp3.0 output differs from Baseline" ) ]
371- public void ForecastingPredictionEngine ( )
317+ public void SsaForecast ( )
318+ {
319+ var env = new MLContext ( ) ;
320+ const int ChangeHistorySize = 10 ;
321+ const int SeasonalitySize = 10 ;
322+ const int NumberOfSeasonsInTraining = 5 ;
323+
324+ List < Data > data = new List < Data > ( ) ;
325+ var dataView = env . Data . LoadFromEnumerable ( data ) ;
326+
327+ var args = new SsaForecasting . Options ( )
328+ {
329+ ConfidenceLevel = 0.95f ,
330+ Source = "Value" ,
331+ Name = "Forecast" ,
332+ ForecastingConfidenceIntervalMinOutputColumnName = "MinCnf" ,
333+ ForecastingConfidenceIntervalMaxOutputColumnName = "MaxCnf" ,
334+ WindowSize = 10 ,
335+ SeriesLength = 11 ,
336+ TrainSize = 22 ,
337+ Horizon = 4 ,
338+ IsAdaptive = true
339+ } ;
340+
341+ for ( int j = 0 ; j < NumberOfSeasonsInTraining ; j ++ )
342+ for ( int i = 0 ; i < SeasonalitySize ; i ++ )
343+ data . Add ( new Data ( i ) ) ;
344+
345+ for ( int i = 0 ; i < ChangeHistorySize ; i ++ )
346+ data . Add ( new Data ( i * 100 ) ) ;
347+
348+ // Train
349+ var detector = new SsaForecastingEstimator ( env , args ) . Fit ( dataView ) ;
350+ // Transform
351+ var output = detector . Transform ( dataView ) ;
352+ // Get predictions
353+ var enumerator = env . Data . CreateEnumerable < ForecastPrediction > ( output , true ) . GetEnumerator ( ) ;
354+ ForecastPrediction row = null ;
355+ List < float > expectedForecast = new List < float > ( ) { 0.191491723f , 2.53994083f , 5.26454258f , 7.37313938f } ;
356+ List < float > minCnf = new List < float > ( ) { - 3.9741993f , - 2.36872721f , 0.09407653f , 2.18899345f } ;
357+ List < float > maxCnf = new List < float > ( ) { 4.3571825f , 7.448609f , 10.435009f , 12.5572853f } ;
358+ enumerator . MoveNext ( ) ;
359+ row = enumerator . Current ;
360+
361+ for ( int localIndex = 0 ; localIndex < 4 ; localIndex ++ )
362+ {
363+ Assert . Equal ( expectedForecast [ localIndex ] , row . Forecast [ localIndex ] , precision : 7 ) ;
364+ Assert . Equal ( minCnf [ localIndex ] , row . MinCnf [ localIndex ] , precision : 7 ) ;
365+ Assert . Equal ( maxCnf [ localIndex ] , row . MaxCnf [ localIndex ] , precision : 7 ) ;
366+ }
367+
368+ }
369+
370+ [ LessThanNetCore30OrNotNetCoreFact ( "netcoreapp3.0 output differs from Baseline" ) ]
371+ public void SsaForecastPredictionEngine ( )
372372 {
373373 const int ChangeHistorySize = 10 ;
374374 const int SeasonalitySize = 10 ;
@@ -457,104 +457,5 @@ public void AnomalyDetectionWithSrCnn()
457457 k += 1 ;
458458 }
459459 }
460-
461- /*
462- [Fact]
463- public void Forecasting()
464- {
465- const int SeasonalitySize = 10;
466- const int NumberOfSeasonsInTraining = 5;
467-
468- List<Data> data = new List<Data>();
469-
470- var ml = new MLContext(seed: 1);
471- var dataView = ml.Data.LoadFromEnumerable<Data>(data);
472-
473- for (int j = 0; j < NumberOfSeasonsInTraining; j++)
474- for (int i = 0; i < SeasonalitySize; i++)
475- data.Add(new Data(i));
476-
477- // Create forecasting model.
478- var model = ml.Forecasting.AdaptiveSingularSpectrumSequenceModeler("Value", data.Count, SeasonalitySize + 1, SeasonalitySize,
479- 1, AdaptiveSingularSpectrumSequenceForecasting.RankSelectionMethod.Exact, null, SeasonalitySize / 2, false, false);
480-
481- // Train.
482- model.Train(dataView);
483-
484- // Forecast.
485- var forecast = model.Forecast(5);
486-
487- // Update with new observations.
488- model.Update(dataView);
489-
490- // Checkpoint.
491- ml.Model.SaveForecastingModel(model, "model.zip");
492-
493- // Load the checkpointed model from disk.
494- var modelCopy = ml.Model.LoadForecastingModel<float>("model.zip");
495-
496- // Forecast with the checkpointed model loaded from disk.
497- var forecastCopy = modelCopy.Forecast(5);
498-
499- // Forecast with the original model(that was checkpointed to disk).
500- forecast = model.Forecast(5);
501-
502- // Both the forecasted values from model loaded from disk and
503- // already in memory model should be the same.
504- Assert.Equal(forecast, forecastCopy);
505- }
506-
507- [Fact]
508- public void ForecastingWithConfidenceInterval()
509- {
510- const int SeasonalitySize = 10;
511- const int NumberOfSeasonsInTraining = 5;
512-
513- List<Data> data = new List<Data>();
514-
515- var ml = new MLContext(seed: 1);
516- var dataView = ml.Data.LoadFromEnumerable<Data>(data);
517-
518- for (int j = 0; j < NumberOfSeasonsInTraining; j++)
519- for (int i = 0; i < SeasonalitySize; i++)
520- data.Add(new Data(i));
521-
522- // Create forecasting model.
523- var model = ml.Forecasting.AdaptiveSingularSpectrumSequenceModeler("Value", data.Count, SeasonalitySize + 1, SeasonalitySize,
524- 1, AdaptiveSingularSpectrumSequenceForecasting.RankSelectionMethod.Exact, null, SeasonalitySize / 2, shouldComputeForecastIntervals: true, false);
525-
526- // Train.
527- model.Train(dataView);
528-
529- // Forecast.
530- float[] forecast;
531- float[] lowConfInterval;
532- float[] upperConfInterval;
533- model.ForecastWithConfidenceIntervals(5, out forecast, out lowConfInterval, out upperConfInterval);
534-
535- // Update with new observations.
536- model.Update(dataView);
537-
538- // Checkpoint.
539- ml.Model.SaveForecastingModel(model, "model.zip");
540-
541- // Load the checkpointed model from disk.
542- var modelCopy = ml.Model.LoadForecastingModel<float>("model.zip");
543-
544- // Forecast with the checkpointed model loaded from disk.
545- float[] forecastCopy;
546- float[] lowConfIntervalCopy;
547- float[] upperConfIntervalCopy;
548- modelCopy.ForecastWithConfidenceIntervals(5, out forecastCopy, out lowConfIntervalCopy, out upperConfIntervalCopy);
549-
550- // Forecast with the original model(that was checkpointed to disk).
551- model.ForecastWithConfidenceIntervals(5, out forecast, out lowConfInterval, out upperConfInterval);
552-
553- // Both the forecasted values from model loaded from disk and
554- // already in memory model should be the same.
555- Assert.Equal(forecast, forecastCopy);
556- Assert.Equal(lowConfInterval, lowConfIntervalCopy);
557- Assert.Equal(upperConfInterval, upperConfIntervalCopy);
558- }*/
559460 }
560461}
0 commit comments