public void DataStream_must_calculate_sane_alpha_from_short_halflife() { var alpha = EWMA.CalculateAlpha(TimeSpan.FromMilliseconds(1), TimeSpan.FromSeconds(3)); Assert.True(alpha <= 1.0d); Assert.True(alpha >= 0.0d); Assert.True(alpha >= 1.0d - 0.001 && alpha <= 1.0d + 0.001); }
public void DataStream_must_calculate_alpha_from_halflife_and_collect_interval() { // according to http://en.wikipedia.org/wiki/Moving_average#Exponential_moving_average var expectedAlpha = 0.1; // alpha = 2.0 / (1 + N) var n = 19; var halfLife = n / 2.8854; var collectInterval = TimeSpan.FromSeconds(1); var halfLifeDuration = TimeSpan.FromMilliseconds(halfLife * 1000); var alpha = EWMA.CalculateAlpha(halfLifeDuration, collectInterval); Assert.True(alpha >= expectedAlpha - 0.001 && alpha <= expectedAlpha + 0.001); }