class Aitk::NelderMeadOptimizer

Overview

Tries to find optimal parameters that result into maximum result of function. If you want to understand better how it works check this PDF.

Example: find a peak of the given pyaramid function.

optimizer = Aitk::NelderMeadOptimizer.new(2) do |params|
  x,y = params
  xc, yc = 30.0, -15.0
  # pyramid function, with highest peak z=1, in x=30 and y=-15
  1 - ((x-xc) + (y-yc)).abs - ((y-yc) - (x-xc)).abs
end

# Perform 100 iterations
optimizer.optimize(iterations: 100) # => [30.0, -15]

# Interrupt optimization using the callback, that is being called every 10 iterations:
optimizer.optimize(period: 10) do |optimizer|
  # Stop, when best score is higher than 0.99
  optimizer.score > 0.99
end
# => [29.999, -15.0022]

Interrupt, if 10 iterations, did not change score more than 0.01 :
optimizer.optimize(period: 10, min_change: 0.01) # => # [29.9999, -15.0002]

By default it tries to initialize solutions, that form simplex based a given range. For size=2, it would look like the following triangle (points represent the solutions):

^ y
|
* b
|
|
|
|
|
* - - - - - * - -> x
c           a

a = [range.end, range.begin]
b = [range.begin, range.end]
c = [range.begin, range.begin]

Defined in:

aitk/optimization/nelder_mead_optimizer.cr

Constructors

Instance Method Summary

Instance methods inherited from class Aitk::AbstractOptimizer

iterate iterate, iterations : Int32 iterations, optimize(iterations = nil, period = 1, min_change = nil)
optimize(iterations : Nil | Int = nil, period = 1, min_change : Nil | Number = nil, &) : Array(Float64)
optimize
, score score, solution solution

Constructor methods inherited from class Aitk::AbstractOptimizer

new(type, size, &fitness_function : Array(Float64) -> Float64) new

Constructor Detail

def self.new(type, size, range = -100.0..100.0, &fitness_function : Array(Float64) -> Float64) #

[View source]

Instance Method Detail

def iterate #

[View source]
def iterations : Int32 #

[View source]
def score : Float64 #

Get current best score.


[View source]
def scores #

[View source]
def solution : Array(Float64) #

Get current best solution.


[View source]
def vectors : Array(Aitk::Vector) #

[View source]