Files

Class Index [+]

Quicksearch

GridSearch

Public Instance Methods

argmax(&block) click to toggle source

Finds the argument which maximizes the function given in the block trhu grid-search maximization.

  [-1,0,1,2].argmax {|x| x**2 } #=> 2
   # File lib/grid_search.rb, line 6
6:   def argmax(&block)
7:     argbest(:>, &block)
8:   end
argmin(&block) click to toggle source

Finds the argument which minimizes the function given in the block trhu grid-search minimization.

  [-1,0,1,2].argmin {|x| x**2 } #=> 0
    # File lib/grid_search.rb, line 13
13:   def argmin(&block)
14:     argbest(:<, &block)
15:   end

Private Instance Methods

argbest(cmp) click to toggle source
    # File lib/grid_search.rb, line 19
19:   def argbest(cmp)
20:     best_arg, best_val = nil, nil
21:     self.each do |*curr_arg|
22:       curr_val = yield(*curr_arg)
23:       if best_val.nil? || curr_val.send(cmp, best_val)
24:         best_val = curr_val
25:         best_arg = curr_arg
26:       end
27:     end
28:     best_arg
29:   end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.