public void Train(double[] values, ref double[][] results) { if (results == null) { results = new double[values.Length][]; for (int i = 0; i < results.Length; ++i) { results[i] = new double[_outputLengthArray[(int)_detectMode]]; } } else if (results.Length > values.Length) { Array.Resize <double[]>(ref results, values.Length); } _minimumOriginValue = Double.MaxValue; _maximumOriginValue = Double.MinValue; Array.Resize(ref _seriesToDetect, values.Length); for (int i = 0; i < values.Length; ++i) { _seriesToDetect[i] = values[i]; _minimumOriginValue = Math.Min(_minimumOriginValue, values[i]); _maximumOriginValue = Math.Max(_maximumOriginValue, values[i]); } if (_period > 0) { _deseasonalityFunction.Deseasonality(ref values, _period, ref _seriesToDetect); } SpectralResidual(_seriesToDetect, results, _threshold); //Optional Steps if (_detectMode == SrCnnDetectMode.AnomalyAndMargin) { if (_period > 0) { GetMarginPeriod(values, results, _seriesToDetect, _sensitivity); } else { GetMargin(values, results, _sensitivity); } } else if (_detectMode == SrCnnDetectMode.AnomalyAndExpectedValue) { if (_period > 0) { GetExpectedValuePeriod(values, results, _seriesToDetect); } else { GetExpectedValue(values, results); } } }
public void Deseasonality(ref double[] values, int period, ref double[] results) { bool success = _stl.Decomposition(values, period); if (success) { for (int i = 0; i < _stl.Residual.Count; ++i) { results[i] = _stl.Residual[i]; } } // invoke the back up deseasonality method if stl decompose fails. else { _backupFunc.Deseasonality(ref values, period, ref results); } }