dotnet / dotnet/machinelearning

Fitting ForecastBySsa model: 'Function does not accept floating point Not-a-Number values.'

Open
#6,411 1 comment 0 reactions 0 assignees View on GitHub
area-TimeSeries
Dominant language
C#
Stars
9.4k
Forks
2k
Avg merge
2d 20h
Merged PRs (30d)
11

Description

**System Information (please complete the following information):**
- OS & Version: Windows 11
- ML.NET Version: 1.7.1 and 2.0.0-preview.22313.1
- .NET Version: .NET 6.0

**Describe the bug**
When fitting the ForecastBySsa model with certain data sets a `System.ArithmeticException` is thrown with the message 'Function does not accept floating point Not-a-Number values.'. The call stack is:

```
at System.Math.Sign(Double value)
at Microsoft.ML.Transforms.TimeSeries.TrajectoryMatrix.FftMultiplyTranspose(Single[] vector, Single[] result, Boolean add, Int32 srcIndex, Int32 dstIndex)
at Microsoft.ML.Transforms.TimeSeries.AdaptiveSingularSpectrumSequenceModelerInternal.ComputeNoiseMoments(Single[] series, Single[] signal, Single[] alpha, Single& observationNoiseVariance, Single& autoregressionNoiseVariance, Single& observationNoiseMean, Single& autoregressionNoiseMean, Int32 startIndex)
at Microsoft.ML.Transforms.TimeSeries.AdaptiveSingularSpectrumSequenceModelerInternal.TrainCore(Single[] dataArray, Int32 originalSeriesLength)
at Microsoft.ML.Transforms.TimeSeries.AdaptiveSingularSpectrumSequenceModelerInternal.Train(RoleMappedData data)
at Microsoft.ML.Transforms.TimeSeries.SsaForecastingEstimator.Fit(IDataView input)
at TestProject.ValuePredictor.Predict(IList`1 window, DataPointStats stats)
```

**To Reproduce**
Run this code to reproduce the error:

``` csharp
using Microsoft.ML;
using Microsoft.ML.Transforms.TimeSeries;

using System.Collections.Generic;
using System.Linq;

record TrainingData(float Value);
record OutputData(float Value, float Value_LB, float Value_UB);
var data = new[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,11 };

var context = new MLContext(seed: 0);
var trainingData = context.Data.LoadFromEnumerable(data.Select(x => new TrainingData(x)));

var pipeline = context.Forecasting.ForecastBySsa(
windowSize: 28,
seriesLength: data.Length * 2,
trainSize: data.Length,
horizon: 1,
outputColumnName: nameof(OutputData.Value),
inputColumnName: nameof(TrainingData.Value),
confidenceLowerBoundColumn: nameof(OutputData.Value_LB),
confidenceUpperBoundColumn: nameof(OutputData.Value_UB));

var model = pipeline.Fit(trainingData);
```

**Expected behavior**
No error should occur when fitting the data.

**Screenshots, Code, Sample Projects**
This is a .NET interactive notebook with the repro code set up and ready to run: [Fitting ForecastBySsa ArithmeticException repro.zip](https://github.com/dotnet/machinelearning/files/9867480/Fitting.ForecastBySsa.ArithmeticException.repro.zip)

**Additional context**
-

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.