Aitk::NelderMeadOptimizer
Inherits Aitk::AbstractOptimizer / Reference / Object
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]
Constructors
new(type, size, range = -100.0..100.0, &fitness_function : Array(Float64) -> Float64)
SourceInstance methods
iterate
Sourceiterations
Sourcescores
Sourcevectors
Source