Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- namespace yield
- {
- public static class MovingAverageTask
- {
- public static IEnumerable<DataPoint> MovingAverage(this IEnumerable<DataPoint> data, int windowWidth)
- {
- double sum = 0;
- var queue = new Queue<double>();
- foreach (var e in data)
- {
- if (queue.Count == windowWidth)
- sum -= queue.Dequeue();
- queue.Enqueue(e.OriginalY);
- sum += e.OriginalY;
- yield return new DataPoint(e.X, e.OriginalY).WithAvgSmoothedY(sum / queue.Count);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement