Akka.Cluster.EWMA.CalculateAlpha C# (CSharp) Method

CalculateAlpha() public static method

Calculate the alpha (decay factor) used in EWMA from specified half-life and interval between observations. Half-life is the interval over which the weights decrease by a factor of two. The relevance of each data sample is halved for every passing half-life duration, i.e. after 4 times the half-life, a data sample's relevance is reduced to 6% of its original relevance. The initial relevance of a data sample is given by 1 – 0.5 ^ (collect-interval / half-life).
public static CalculateAlpha ( System.TimeSpan halfLife, System.TimeSpan collectInterval ) : double
halfLife System.TimeSpan
collectInterval System.TimeSpan
return double
        public static double CalculateAlpha(TimeSpan halfLife, TimeSpan collectInterval)
        {
            var halfLifeMillis = halfLife.TotalMilliseconds;
            if (halfLifeMillis < 0) throw new ArgumentOutOfRangeException("halfLife", "halfLife must be > 0s");
            var decayRate = LogOf2 / halfLifeMillis;
            return 1 - Math.Exp(-decayRate * collectInterval.TotalMilliseconds);
        }

Usage Example

 private PerformanceCounterMetricsCollector(Cluster cluster) : this(cluster.SelfAddress,
                                                                    EWMA.CalculateAlpha(cluster.Settings.MetricsMovingAverageHalfLife, cluster.Settings.MetricsInterval))
 {
 }