statistics/moving_average.rb
# Exponentially weighted average with bias correction.
Exponentially weighted average with bias correction.
Exponentially weighted average with bias correction .
def moving_average(numbers)
    alpha = 0.8
    average = numbers.reduce(0) do |average, number|
      average * alpha + (1 - alpha) * number
    end
    corrected = average / (1 - alpha ** numbers.length) 
    corrected.round
  end
def moving_average ( numbers ) alpha = 0.8 average = numbers . reduce ( 0 ) do | average , number | average * alpha + ( 1 - alpha ) * number end corrected = average / ( 1 - alpha ** numbers . length ) corrected . round end
Exponentially weighted average with bias correction.
Exponentially weighted average with bias correction .
# Apply bias correction.
numbers
<not_specific>