class Prognosium::Adaptive::Holt

Constants

PARAMS

Attributes

alpha[RW]
beta[RW]
period[RW]
smoothed[RW]
trend[RW]

Public Class Methods

new(options) click to toggle source
Calls superclass method Prognosium::Adaptive::Base::new
# File lib/prognosium/adaptive/holt.rb, line 8
def initialize(options)
  @alpha = options[:alpha] || PARAMS[:alpha]
  @beta = options[:beta] || PARAMS[:beta]
  @period = options[:period] || PARAMS[:period]
  super(options)
end

Private Instance Methods

calc_forecast() click to toggle source
# File lib/prognosium/adaptive/holt.rb, line 17
def calc_forecast
  calc_trend_smoothed
  forecast_data = []
  (data.size - 1).times.each do |index|
    forecast_data << smoothed[index] + trend[index]
  end
  forecast_data + calc_predicted
end
calc_predicted() click to toggle source
# File lib/prognosium/adaptive/holt.rb, line 46
def calc_predicted
  calc_trend_smoothed
  super do |index|
    predicted_formula(index)
  end
end
calc_smoothed(data_value, prev_smoothed, prev_trend) click to toggle source
# File lib/prognosium/adaptive/holt.rb, line 38
def calc_smoothed(data_value, prev_smoothed, prev_trend)
  alpha * data_value + (1 - alpha) * (prev_smoothed + prev_trend)
end
calc_trend(smoothed_value, prev_smoothed, prev_trend) click to toggle source
# File lib/prognosium/adaptive/holt.rb, line 42
def calc_trend(smoothed_value, prev_smoothed, prev_trend)
  beta * (smoothed_value - prev_smoothed) + (1 - beta) * prev_trend
end
calc_trend_smoothed() click to toggle source
# File lib/prognosium/adaptive/holt.rb, line 26
def calc_trend_smoothed
  self.trend = [0]
  self.smoothed = [data[0]]
  data.size.times do |index|
    next if index.zero?
    prev_smoothed = smoothed[index - 1]
    prev_trend = trend[index - 1]
    smoothed << calc_smoothed(data[index], prev_smoothed, prev_trend)
    trend << calc_trend(smoothed[index], prev_smoothed, prev_trend)
  end
end
predicted_formula(index) click to toggle source
# File lib/prognosium/adaptive/holt.rb, line 53
def predicted_formula(index)
  smoothed.last + trend.last * index
end