Class: Minimization::ConjugateDirectionMinimizer
- Inherits:
-
Object
- Object
- Minimization::ConjugateDirectionMinimizer
- Defined in:
- lib/multidim/powell.rb
Direct Known Subclasses
Constant Summary collapse
- Max_Iterations_Default =
default maximum Powell's iteration value
100- MAX_BRENT_ITERATION_DEFAULT =
default Brent iteration value
10
Instance Attribute Summary collapse
-
#f_minimum ⇒ Object
Returns the value of attribute f_minimum.
-
#max_brent_iterations ⇒ Object
Returns the value of attribute max_brent_iterations.
-
#max_iterations ⇒ Object
Returns the value of attribute max_iterations.
-
#x_minimum ⇒ Object
Returns the value of attribute x_minimum.
Instance Method Summary collapse
-
#brent_search(point, direction) ⇒ Object
line minimization using Brent's minimization == Parameters: * point: Starting point * direction: Search direction.
-
#check_parameters ⇒ Object
validate input parameters.
-
#converging? ⇒ Boolean
return the convergence of the search.
-
#f(x) ⇒ Object
set minimization function.
-
#initialize(f, initial_guess, lower_bound, upper_bound) ⇒ ConjugateDirectionMinimizer
constructor
give a suitable value.
Constructor Details
#initialize(f, initial_guess, lower_bound, upper_bound) ⇒ ConjugateDirectionMinimizer
give a suitable value
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/multidim/powell.rb', line 40 def initialize(f, initial_guess, lower_bound, upper_bound) @iterations = 0 @max_iterations = Max_Iterations_Default @evaluations = 0 @max_brent_iterations = MAX_BRENT_ITERATION_DEFAULT @converging = true # set minimizing function @f = f @start = initial_guess @lower_bound = lower_bound @upper_bound = upper_bound # set maximum and minimum coordinate value a point can have # while minimization process @min_coordinate_val = lower_bound.min @max_coordinate_val = upper_bound.max # validate input parameters check_parameters end |
Instance Attribute Details
#f_minimum ⇒ Object
Returns the value of attribute f_minimum.
33 34 35 |
# File 'lib/multidim/powell.rb', line 33 def f_minimum @f_minimum end |
#max_brent_iterations ⇒ Object
Returns the value of attribute max_brent_iterations.
31 32 33 |
# File 'lib/multidim/powell.rb', line 31 def max_brent_iterations @max_brent_iterations end |
#max_iterations ⇒ Object
Returns the value of attribute max_iterations.
30 31 32 |
# File 'lib/multidim/powell.rb', line 30 def max_iterations @max_iterations end |
#x_minimum ⇒ Object
Returns the value of attribute x_minimum.
32 33 34 |
# File 'lib/multidim/powell.rb', line 32 def x_minimum @x_minimum end |
Instance Method Details
#brent_search(point, direction) ⇒ Object
line minimization using Brent's minimization
Parameters:
- point: Starting point
- direction: Search direction
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/multidim/powell.rb', line 117 def brent_search(point, direction) n = point.length # Create a proc to minimize using brent search # Function value varies with alpha value and represent a point # of the minimizing function which is on the given plane func = proc{ |alpha| x = Array.new(n) 0.upto(n - 1) do |i| # create a point according to the given alpha value x[i] = point[i] + alpha * direction[i] end # return the function value of the obtained point f(x) } # create Brent minimizer line_minimizer = Minimization::Brent.new(@min_coordinate_val, @max_coordinate_val, func) # iterate Brent minimizer for given number of iteration value 0.upto(@max_brent_iterations) do line_minimizer.iterate end # return the minimum point return {:alpha_min => line_minimizer.x_minimum, :f_val => line_minimizer.f_minimum} end |
#check_parameters ⇒ Object
validate input parameters
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/multidim/powell.rb', line 73 def check_parameters if (!@start.nil?) dim = @start.length if (!@lower_bound.nil?) # check for dimension mismatches raise "dimension mismatching #{@lower_bound.length} and #{dim}" if @lower_bound.length != dim # check whether start point exeeds the lower bound 0.upto(dim - 1) do |i| v = @start[i] lo = @lower_bound[i] raise "start point is lower than lower bound" if v < lo end end if (!@upper_bound.nil?) # check for dimension mismatches raise "dimension mismatching #{@upper_bound.length} and #{dim}" if @upper_bound.length != dim # check whether strating point exceeds the upper bound 0.upto(dim - 1) do |i| v = @start[i] hi = @upper_bound[i] raise "start point is higher than the upper bound" if v > hi end end if (@lower_bound.nil?) @lower_bound = Array.new(dim) 0.upto(dim - 1) do |i| @lower_bound[i] = Float::INFINITY # eventually this will occur an error end end if (@upper_bound.nil?) @upper_bound = Array.new(dim) 0.upto(dim - 1) do |i| @upper_bound[i] = -Float::INFINITY # eventually this will occur an error end end end end |
#converging? ⇒ Boolean
return the convergence of the search
63 64 65 |
# File 'lib/multidim/powell.rb', line 63 def converging? return @converging end |
#f(x) ⇒ Object
set minimization function
68 69 70 |
# File 'lib/multidim/powell.rb', line 68 def f(x) @f.call(x) end |