Numo::Optimize
Numo::Optimize (numo-optimize) provides functions for minimizing objective functions. This gem is based on Lbfgsb.rb and mopti by the same author.
Please note that numo-optimize depends on numo-narray-alt, not Numo::NArray.
Installation
Install the gem and add to the application's Gemfile by executing:
bundle add numo-optimize
If bundler is not being used to manage dependencies, install the gem by executing:
gem install numo-optimize
Usage
example.rb:
require 'numo/narray'
require 'numo/optimize'
# Define the objective function.
obj_func = proc do |x|
(x - 3)**2 + 2
end
# Define the gradient (Jacobian) of the objective function.
gradient_func = proc do |x|
2 * (x - 3)
end
# Initial guess
x_init = Numo::DFloat[0.0]
# Perform optimization
result = Numo::Optimize.minimize(x_init: x_init, fnc: obj_func, jcb: gradient_func)
# Output the result
puts "Optimized parameters: #{result[:x][0]}"
$ ruby example.rb
Optimized parameters: 3.0
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/yoshoku/numo-optimize. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
License
The gem is available as open source under the terms of the BSD-3-Clause License. In addition, L-BFGS-B carries the following condition for use:
This software is freely available, but we expect that all publications describing work using this software , or all commercial products using it, quote at least one of the references given below. This software is released under the "New BSD License" (aka "Modified BSD License" or "3-clause license").
Code of Conduct
Everyone interacting in the Numo::Optimize project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.