Guest User

Untitled

a guest
Jun 25th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. public class DES
  2. {
  3. private readonly double[] _rawDataPoints;
  4. private readonly double[] _smoothedDataPoints;
  5. private readonly double[] _trends;
  6.  
  7. public DES(double[] dataPoints, double smoothingFactor, double trendFactor)
  8. {
  9. _rawDataPoints = dataPoints;
  10. _smoothedDataPoints = new double[dataPoints.Length];
  11.  
  12. _smoothedDataPoints[0] = double.NaN;
  13. _trends[0] = double.NaN;
  14. _smoothedDataPoints[1] = dataPoints[1];
  15. _trends[1] = dataPoints[1] - dataPoints[0];
  16.  
  17. for (int i = 2; i < dataPoints.Length; i++)
  18. {
  19. _smoothedDataPoints[i] = smoothingFactor * dataPoints[i] + (1 - smoothingFactor) * (_smoothedDataPoints[i - 1] + _trends[i - 1]);
  20. _trends[i] = trendFactor * (_smoothedDataPoints[i] - _smoothedDataPoints[i - 1]) + (1 - trendFactor) * _trends[i - 1];
  21. }
  22.  
  23. }
  24.  
  25. public double Predict(int index)
  26. {
  27. if (index < _smoothedDataPoints.Length)
  28. return _smoothedDataPoints[index] + _trends[index];
  29. return _smoothedDataPoints.Last() + (index - _smoothedDataPoints.Length) * _trends.Last();
  30. }
  31. }
Add Comment
Please, Sign In to add comment