Package org.apache.pinot.common.utils
Class ExponentialMovingAverage
- java.lang.Object
-
- org.apache.pinot.common.utils.ExponentialMovingAverage
-
@ThreadSafe public class ExponentialMovingAverage extends Object
TheExponentialMovingAverageis the implementation of the utility Exponential Weighted Moving Average which is a statistical measure used to model time series data. Refer https://en.wikipedia.org/wiki/Moving_average for more details.
-
-
Constructor Summary
Constructors Constructor Description ExponentialMovingAverage(double alpha, long autoDecayWindowMs, long warmUpDurationMs, double avgInitializationVal, ScheduledExecutorService periodicTaskExecutor)Constructor
-
Method Summary
Modifier and Type Method Description doublecompute(double value)Adds a value to the exponentially weighted moving average.doublegetAverage()Returns the exponentially weighted moving average.
-
-
-
Constructor Detail
-
ExponentialMovingAverage
public ExponentialMovingAverage(double alpha, long autoDecayWindowMs, long warmUpDurationMs, double avgInitializationVal, @Nullable ScheduledExecutorService periodicTaskExecutor)Constructor- Parameters:
alpha- Determines how much weightage should be given to the new value. Can only take a value between 0 and 1.autoDecayWindowMs- Time interval to periodically decay the average if no updates are received. For example if autoDecayWindowMs = 30s, if average is not updated for a period of 30 seconds, we automatically update the average to 0.0 with a weightage of alpha.warmUpDurationMs- The initial duration after initialization during which new incoming values are ignored in the average calculation.avgInitializationVal- The default value to initialize for average.periodicTaskExecutor- Executor to schedule periodic tasks like autoDecay.
-
-
Method Detail
-
getAverage
public double getAverage()
Returns the exponentially weighted moving average.
-
compute
public double compute(double value)
Adds a value to the exponentially weighted moving average. If warmUpDurationMs is not reached yet, this value is ignored.- Parameters:
value- incoming value- Returns:
- the updated exponentially weighted moving average.
-
-