class Prognosium::Adaptive::Base

Attributes

data[R]
deviation_errors[R]
error_percent[R]
forecast[R]
forecast_dates[R]
predicted[R]

Public Class Methods

new(options) click to toggle source
# File lib/prognosium/adaptive/base.rb, line 7
def initialize(options)
  @data = options[:data]
  @forecast = calc_forecast.unshift(nil)
  @deviation_errors = calc_errors
  @error_percent = calc_mape
end

Private Instance Methods

calc_average(array_data) click to toggle source
# File lib/prognosium/adaptive/base.rb, line 44
def calc_average(array_data)
  array_data.inject(0, :+) / array_data.size
end
calc_errors() click to toggle source
# File lib/prognosium/adaptive/base.rb, line 29
def calc_errors
  (0...data.size).to_a.map do |index|
    next unless forecast[index]
    (data[index] - forecast[index]).abs
  end
end
calc_forecast() click to toggle source
# File lib/prognosium/adaptive/base.rb, line 25
def calc_forecast
  raise 'Need redefined'
end
calc_mape() click to toggle source
# File lib/prognosium/adaptive/base.rb, line 36
def calc_mape
  errors = deviation_errors.each_with_index.map do |error, index|
    next if error.nil? || forecast[index].nil?
    error / forecast[index]
  end
  ((errors.compact.inject(0, :+) / forecast.size) * 100).round(3)
end
calc_predicted() { |index| ... } click to toggle source
# File lib/prognosium/adaptive/base.rb, line 48
def calc_predicted
  (1..period).to_a.map do |index|
    yield(index)
  end
end