class TeaLeaves::SingleExponentialSmoothingForecast
Public Class Methods
new(time_series, alpha)
click to toggle source
# File lib/tealeaves/single_exponential_smoothing_forecast.rb, line 5 def initialize(time_series, alpha) @time_series = time_series @alpha = alpha @one_step_ahead_forecasts = [nil] ([@time_series.first] + @time_series).inject do |a,b| value = (1 - @alpha) * a + @alpha * b @one_step_ahead_forecasts << value value end @prediction = @one_step_ahead_forecasts.pop end
Public Instance Methods
predict(n=nil)
click to toggle source
# File lib/tealeaves/single_exponential_smoothing_forecast.rb, line 20 def predict(n=nil) if n.nil? @prediction else [@prediction] * n end end