Class: OpenCLMinimization::BisectionMinimizer

Inherits:
GodlSectionMinimizer show all
Defined in:
lib/opencl/opencl_minimization.rb

Overview

= Bisection Minimizer. 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::BisectionMinimizer.new(n, start_point, expected_point, end_point, f) min.minimize min.x_minimum min.f_minimum

Instance Attribute Summary

Attributes inherited from GodlSectionMinimizer

#epsilon, #f_minimum, #golden, #max_iterations, #x_minimum

Instance Method Summary collapse

Methods inherited from GodlSectionMinimizer

#initialize

Constructor Details

This class inherits a constructor from OpenCLMinimization::GodlSectionMinimizer

Instance Method Details

#minimizeObject



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/opencl/opencl_minimization.rb', line 160

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, 2, @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