public static IEnumerable <DataPoint> MovingAverage(this IEnumerable <DataPoint> data, int windowWidth) { var windowValues = new WindowValues <double>(windowWidth); var windowsSum = 0.0; foreach (var dataPoint in data) { var tailY = windowValues.Length == windowWidth ? windowValues.Tail.Value : 0; windowValues.Append(dataPoint.OriginalY); windowsSum -= tailY; windowsSum += dataPoint.OriginalY; yield return(CreateDataPoint(dataPoint, windowsSum / windowValues.Length)); } }
public WindowElementEnumerator(WindowValues <T> window) { this.window = window; currentElement = null; }