-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExpSmoothingTask.cs
More file actions
28 lines (25 loc) · 965 Bytes
/
ExpSmoothingTask.cs
File metadata and controls
28 lines (25 loc) · 965 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using System.Collections.Generic;
namespace yield
{
public static class ExpSmoothingTask
{
public static IEnumerable<DataPoint> SmoothExponentially(this IEnumerable<DataPoint> data, double alpha)
{
var counter = 0;
var lastDataPoint = new DataPoint(0, 0);
foreach (var dataPoint in data)
{
lastDataPoint = counter == 0
? dataPoint.WithExpSmoothedY(dataPoint.OriginalY)
: GetExpSmoothing(dataPoint, alpha, lastDataPoint);
yield return lastDataPoint;
counter++;
}
}
private static DataPoint GetExpSmoothing(DataPoint dataPoint, double alpha, DataPoint lastDataPoint)
{
return dataPoint.WithExpSmoothedY(lastDataPoint.ExpSmoothedY +
alpha * (dataPoint.OriginalY - lastDataPoint.ExpSmoothedY));
}
}
}