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)
- {
- var sum = 0.0;
- var queue = new Queue<double>();
- foreach (var i in data)
- {
- queue.Enqueue(i.OriginalY);
- sum += i.OriginalY;
- if (queue.Count > windowWidth)
- sum -= queue.Dequeue();
- i.AvgSmoothedY = sum / queue.Count;
- yield return i;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement