Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class DES
- {
- private readonly double[] _rawDataPoints;
- private readonly double[] _smoothedDataPoints;
- private readonly double[] _trends;
- public DES(double[] dataPoints, double smoothingFactor, double trendFactor)
- {
- _rawDataPoints = dataPoints;
- _smoothedDataPoints = new double[dataPoints.Length];
- _smoothedDataPoints[0] = double.NaN;
- _trends[0] = double.NaN;
- _smoothedDataPoints[1] = dataPoints[1];
- _trends[1] = dataPoints[1] - dataPoints[0];
- for (int i = 2; i < dataPoints.Length; i++)
- {
- _smoothedDataPoints[i] = smoothingFactor * dataPoints[i] + (1 - smoothingFactor) * (_smoothedDataPoints[i - 1] + _trends[i - 1]);
- _trends[i] = trendFactor * (_smoothedDataPoints[i] - _smoothedDataPoints[i - 1]) + (1 - trendFactor) * _trends[i - 1];
- }
- }
- public double Predict(int index)
- {
- if (index < _smoothedDataPoints.Length)
- return _smoothedDataPoints[index] + _trends[index];
- return _smoothedDataPoints.Last() + (index - _smoothedDataPoints.Length) * _trends.Last();
- }
- }
Add Comment
Please, Sign In to add comment