Class: PrettyGSL::Minimizer
- Inherits:
-
Object
- Object
- PrettyGSL::Minimizer
- Includes:
- GSL, GSL::MultiMin
- Defined in:
- lib/pretty_gsl/minimizer.rb
Instance Attribute Summary collapse
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Instance Method Summary collapse
-
#initialize(function, constants, options = {}) ⇒ Minimizer
constructor
A new instance of Minimizer.
- #minimize(*guess) ⇒ Object
Constructor Details
#initialize(function, constants, options = {}) ⇒ Minimizer
Returns a new instance of Minimizer.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/pretty_gsl/minimizer.rb', line 8 def initialize(function, constants, = {}) @function = function @constants = constants @params = { max_iterations: 100, # the maximum number of iterations to carry out the minimization step_size: 0.01, # initial guess of the length scale of the minimiztion steps direction_tolerance: 1e-4, # the tolerance for errors in the direction of line minimization absolute_gradient_tolerance: 1e-3, # halt if the magnetude of the gradient falls below this value logger: nil, # logger target }.merge() @result = nil @logger = Logger.new(@params[:logger]) self end |
Instance Attribute Details
#result ⇒ Object (readonly)
Returns the value of attribute result.
6 7 8 |
# File 'lib/pretty_gsl/minimizer.rb', line 6 def result @result end |
Instance Method Details
#minimize(*guess) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/pretty_gsl/minimizer.rb', line 23 def minimize(*guess) minimizer = get_gsl_minimizer(guess) @params[:max_iterations].times do |iter| status = minimizer.iterate status = test_gsl_convergence(minimizer) @logger.info minimizer.x.to_a.inspect if status != CONTINUE @result = { success: status == SUCCESS, minimum_x: minimizer.x.to_a, iterations: iter }.merge(get_gsl_result(minimizer)) break end end @result end |