Class: TeaLeaves::BruteForceOptimization

Inherits:
Object
  • Object
show all
Defined in:
lib/tealeaves/brute_force_optimization.rb

Constant Summary collapse

INITIAL_PARAMETER_VALUES =
[0.0, 0.2, 0.4, 0.6, 0.8, 1.0].freeze

Instance Method Summary collapse

Constructor Details

#initialize(time_series, period, opts = {}) ⇒ BruteForceOptimization

Returns a new instance of BruteForceOptimization.



5
6
7
8
9
# File 'lib/tealeaves/brute_force_optimization.rb', line 5

def initialize(time_series, period, opts={})
  @time_series = time_series
  @period = period
  @opts = opts
end

Instance Method Details

#initial_test_parameters(opts = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/tealeaves/brute_force_optimization.rb', line 18

def initial_test_parameters(opts={})
  parameters = []
  INITIAL_PARAMETER_VALUES.each do |alpha|
    parameters << {:alpha => alpha, :seasonality => :none, :trend => :none}
    
    unless opts[:seasonality] == :none && opts[:trend] == :none
      INITIAL_PARAMETER_VALUES.each do |b|
        parameters << {:alpha => alpha, :beta => b, :seasonality => :none, :trend => :additive}
        parameters << {:alpha => alpha, :beta => b, :seasonality => :none, :trend => :multiplicative}
        parameters << {:alpha => alpha, :gamma => b, :trend => :none, :seasonality => :additive}
        parameters << {:alpha => alpha, :gamma => b, :trend => :none, :seasonality => :multiplicative}
        
        INITIAL_PARAMETER_VALUES.each do |gamma|
          [:additive, :multiplicative].each do |trend|
            [:additive, :multiplicative].each do |seasonality|
              parameters << {
                :alpha => alpha,
                :beta => b,
                :gamma => gamma,
                :trend => trend,
                :seasonality => seasonality
              }
            end
          end
        end
      end
    end
  end

  parameters
end

#optimizeObject



12
13
14
15
16
# File 'lib/tealeaves/brute_force_optimization.rb', line 12

def optimize
  [0.1, 0.5, 0.25, 0.125, 0.0625, 0.03125, 0.015625].inject(optimum(initial_models)) do |model, change|
    improve_model(model, change)
  end
end