Class: OpenCLMinimization::GodlSectionMinimizer
- Inherits:
-
Object
- Object
- OpenCLMinimization::GodlSectionMinimizer
- Defined in:
- lib/opencl/opencl_minimization.rb
Overview
Classic GodlSectionMinimizer minimization method.
Basic minimization algorithm. Slow, but robust.
See Unidimensional for methods.
== Usage
n = 3
start_point = [1, 3, 5]
expected_point = [1.5, 3.5, 5.5]
end_point = [3, 5, 7]
f = "pow((x-2)(x-4)(x-6), 2)+1"
min = OpenCLMinimization::GodlSectionMinimizer.new(n, start_point, expected_point, end_point, f)
min.minimize
min.x_minimum
min.f_minimum
Direct Known Subclasses
Instance Attribute Summary collapse
-
#epsilon ⇒ Object
writeonly
Sets the attribute epsilon.
-
#f_minimum ⇒ Object
readonly
Returns the value of attribute f_minimum.
-
#golden ⇒ Object
writeonly
Sets the attribute golden.
-
#max_iterations ⇒ Object
writeonly
Sets the attribute max_iterations.
-
#x_minimum ⇒ Object
readonly
Returns the value of attribute x_minimum.
Instance Method Summary collapse
-
#initialize(n, start_point, expected_point, end_point, f) ⇒ GodlSectionMinimizer
constructor
== Parameters: * n: Number of Jobs * start_point: Lower possible value * expected_point: Initial point * end_point: Higher possible value * f: Original function string.
- #minimize ⇒ Object
Constructor Details
#initialize(n, start_point, expected_point, end_point, f) ⇒ GodlSectionMinimizer
== Parameters:
- n: Number of Jobs
- start_point: Lower possible value
- expected_point: Initial point
- end_point: Higher possible value
- f: Original function string
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/opencl/opencl_minimization.rb', line 46 def initialize(n, start_point, expected_point, end_point, f) @n = n @start_point = start_point @expected_point = expected_point @end_point = end_point @f = f @max_iterations = MAX_ITERATIONS_DEFAULT @epsilon = EPSILON_DEFAULT @golden = GOLDEN_DEFAULT @sqrt_epsilon = SQRT_EPSILON_DEFAULT end |
Instance Attribute Details
#epsilon=(value) ⇒ Object (writeonly)
Sets the attribute epsilon
36 37 38 |
# File 'lib/opencl/opencl_minimization.rb', line 36 def epsilon=(value) @epsilon = value end |
#f_minimum ⇒ Object (readonly)
Returns the value of attribute f_minimum.
33 34 35 |
# File 'lib/opencl/opencl_minimization.rb', line 33 def f_minimum @f_minimum end |
#golden=(value) ⇒ Object (writeonly)
Sets the attribute golden
37 38 39 |
# File 'lib/opencl/opencl_minimization.rb', line 37 def golden=(value) @golden = value end |
#max_iterations=(value) ⇒ Object (writeonly)
Sets the attribute max_iterations
35 36 37 |
# File 'lib/opencl/opencl_minimization.rb', line 35 def max_iterations=(value) @max_iterations = value end |
#x_minimum ⇒ Object (readonly)
Returns the value of attribute x_minimum.
32 33 34 |
# File 'lib/opencl/opencl_minimization.rb', line 32 def x_minimum @x_minimum end |
Instance Method Details
#minimize ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/opencl/opencl_minimization.rb', line 58 def minimize # create Buffers for inputs and outputs start_buffer = FFI::Buffer.alloc_inout(:pointer, @n) expected_buffer = FFI::Buffer.alloc_inout(:pointer, @n) end_buffer = FFI::Buffer.alloc_inout(:pointer, @n) x_buffer = FFI::Buffer.alloc_inout(:pointer, @n) f_buffer = FFI::Buffer.alloc_inout(:pointer, @n) # set inputs start_buffer.write_array_of_float(@start_point) expected_buffer.write_array_of_float(@expected_point) end_buffer.write_array_of_float(@end_point) # call minimizer OpenCLMinimization::opencl_minimize(@n, start_buffer, expected_buffer, end_buffer, 0, @f, "", "", x_buffer, f_buffer, 0, @max_iterations, @epsilon, @golden, @sqrt_epsilon, PATH_TO_KERNEL) @x_minimum = Array.new(@n) @f_minimum = Array.new(@n) # read results @x_minimum = x_buffer.read_array_of_float(@n) @f_minimum = f_buffer.read_array_of_float(@n) end |