{"record":{"id":"1e186838ad101654","repo":"dotnet/machinelearning","slug":"not-finite-unit-value","errorCode":null,"errorMessage":"Not finite unit value","messagePattern":"Not finite unit value","errorType":"exception","errorClass":"ArithmeticException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.ML.TimeSeries/SrCnnEntireAnomalyDetector.cs","lineNumber":1016,"sourceCode":"                }\n                else\n                {\n                    trendFraction = 1.0;\n                }\n\n                Array.Resize(ref _units, _trends.Length);\n                for (int i = 0; i < _units.Length; ++i)\n                {\n                    if (closeToZero)\n                    {\n                        _units[i] = _unitForZero;\n                    }\n                    else\n                    {\n                        _units[i] = averageTrendPart + Math.Abs(_trends[i]) * trendFraction;\n                        if (double.IsInfinity(_units[i]))\n                        {\n                            throw new ArithmeticException(\"Not finite unit value\");\n                        }\n                    }\n                }\n            }\n\n            private void MedianFilter(double[] data, int window, bool needTwoEnd = false)\n            {\n                int wLen = window / 2 * 2 + 1;\n                int tLen = data.Length;\n                Array.Resize(ref _val, tLen);\n                Array.Copy(data, _val, tLen);\n                Array.Resize(ref _trends, tLen);\n                Array.Copy(data, _trends, tLen);\n                Array.Resize(ref _curWindow, wLen);\n\n                if (tLen < wLen)\n                    return;\n","sourceCodeStart":998,"sourceCodeEnd":1034,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.ML.TimeSeries/SrCnnEntireAnomalyDetector.cs#L998-L1034","documentation":"During SrCnnEntireAnomalyDetector training, the per-unit sensitivity bound is computed as averageTrendPart + |trend| * trendFraction; if the result overflows to positive infinity, an ArithmeticException('Not finite unit value') is thrown. This guards the detector against numerically degenerate inputs where trend magnitudes explode.","triggerScenarios":"Fitting SrCnnEntireAnomalyDetector (SrCnnEntireModeler) on series whose computed trend values are huge — e.g. data containing extreme outliers or non-NaN-but-enormous magnitudes — causing _units[i] = averageTrendPart + Math.Abs(_trends[i]) * trendFraction to be double.PositiveInfinity.","commonSituations":"Training on raw data containing sentinel values like 1e308 or sensor glitches; forgetting to clean/scale extreme outliers before anomaly detection; very small datasets where trend estimation amplifies noise.","solutions":["Sanitize the input series: remove or cap extreme outliers and sentinel magnitudes before training.","Normalize/rescale the time series (e.g. z-score or min-max) so trend values stay within finite ranges.","Verify data quality: check for double.MaxValue/Infinity-adjacent values with a quick pre-scan of the column.","If this occurs on legitimately large-but-valid data, reduce the sensitivity/trendFraction or open an issue with a repro for a scale-aware fix."],"exampleFix":"// before\nvar pipeline = mlContext.Transforms.Conversion...\n    .Append(mlContext.AnomalyDetection.Trainers.SrCnnEntireAnomalyDetector(...));\n// after: cap outliers first\nfor (int i = 0; i < values.Length; i++)\n    values[i] = Math.Min(values[i], 1e6); // or drop/interpolate outliers","handlingStrategy":"validation","validationCode":"bool finite = data.All(v => !double.IsNaN(v) && !double.IsInfinity(v) && Math.Abs(v) < 1e300);","typeGuard":null,"tryCatchPattern":"try { model = pipeline.Fit(trainData); }\ncatch (ArithmeticException ex) when (ex.Message == \"Not finite unit value\")\n{ /* sanitize/rescale inputs and retry */ }","preventionTips":["Scan and clean training columns for extreme/sentinel magnitudes before fitting.","Normalize or z-score the series before anomaly detection.","Validate data quality (min/max/finite checks) as a pipeline pre-step."],"tags":["dotnet","ml-net","anomaly-detection","numerical-overflow"],"backgroundTag":"value-out-of-range","analyzedSha":"7b76e69cf964daeca3f1377af6bc5543284d56c6","analyzedAt":"2026-09-11T12:35:38.930Z","contentChangedAt":"2026-09-11T12:35:38.930Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}