class Leafy::Core::EWMA
Constants
- FIFTEEN_MINUTES
- FIVE_MINUTES
- FIVE_NANOS
- INTERVAL
- M15_ALPHA
- M1_ALPHA
- M5_ALPHA
- ONE_MINUTE
- ONE_NANOS
- SECONDS_PER_MINUTE
Public Class Methods
fifteenMinuteEWMA()
click to toggle source
fiveMinuteEWMA()
click to toggle source
new(alpha)
click to toggle source
Create a new EWMA
with a specific smoothing constant.
@param alpha the smoothing constant @param interval the expected tick interval @param intervalUnit the time unit of the tick interval
# File lib/leafy/core/ewma.rb, line 58 def initialize(alpha) @alpha = alpha; @initialized = false # volatile @rate = 0.0 # volatile @uncounted = Adder.new end
Public Instance Methods
rate()
click to toggle source
Returns the rate in the given units of time.
@param rateUnit the unit of time @return the rate
# File lib/leafy/core/ewma.rb, line 90 def rate @rate * ONE_NANOS end
tick()
click to toggle source
Mark the passage of time and decay the current rate accordingly.
# File lib/leafy/core/ewma.rb, line 73 def tick count = @uncounted.sum_then_reset# @uncounted = 0 # uncounted.sumThenReset(); instantRate = count / FIVE_NANOS; if @initialized oldRate = @rate @rate = oldRate + (@alpha * (instantRate - oldRate)) else @rate = instantRate @initialized = true end self end
update(n)
click to toggle source
Update the moving average with a new value.
@param n the new value
# File lib/leafy/core/ewma.rb, line 68 def update(n) @uncounted.add(n) end