Parent

Minimization::Unidimensional

Base class for unidimensional minimizers

Constants

EPSILON

Default value for error on f(x)

MAX_ITERATIONS

Default number of maximum iterations

Attributes

x_minimum[R]

Minimum value for x

f_minimum[R]

Minimum value for f(x)

log[R]

Log of iterations. Should be an array

log_header[R]

Name of fields of log

epsilon[RW]

Absolute error on x

expected[R]

Expected value. Fast minimum finding if set

Public Class Methods

minimize(lower,upper,expected=nil,&block) click to toggle source

Convenience method to minimize

Parameters:

  • lower: Lower possible value
  • upper: Higher possible value
  • expected: Optional expected value. Faster the search is near correct value.
  • &block: Block with function to minimize

Usage:

  minimizer=Minimization::GoldenSection.minimize(-1000, 1000) {|x|
            x**2 }
# File lib/minimization.rb, line 73
    def self.minimize(lower,upper,expected=nil,&block)
      minimizer=new(lower,upper,block)
      minimizer.expected=expected unless expected.nil?
      raise FailedIteration unless minimizer.iterate
      minimizer
    end
new(lower, upper, proc) click to toggle source

Create a new minimizer

# File lib/minimization.rb, line 43
    def initialize(lower, upper, proc)
      raise "first argument  should be lower than second" if lower>=upper
      @lower=lower
      @upper=upper
      @proc=proc
      golden = 0.3819660;
      @expected = @lower + golden * (@upper - @lower);
      @max_iteration=MAX_ITERATIONS
      @epsilon=EPSILON
      @iterations=0
      @log=[]
      @log_header=%w{I xl xh f(xl) f(xh) dx df(x)}
    end

Public Instance Methods

expected=(v) click to toggle source

Set expected value

# File lib/minimization.rb, line 57
    def expected=(v)
      @expected=v
    end
f(x) click to toggle source

(Not documented)

# File lib/minimization.rb, line 83
    def f(x)
      @proc.call(x)
    end
iterate() click to toggle source

Iterate to find the minimum

# File lib/minimization.rb, line 80
    def iterate
      raise "You should implement this"
    end
log_summary() click to toggle source

(Not documented)

# File lib/minimization.rb, line 60
    def log_summary
      @log.join("\n")
    end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.