Module: Lbfgsb
- Defined in:
- lib/lbfgsb.rb,
lib/lbfgsb/version.rb,
ext/lbfgsb/lbfgsbext.c
Overview
Lbfgsb.rb is a Ruby binding for L-BFGS-B with Numo::NArray.
Constant Summary collapse
- VERSION =
The version of Lbfgsb.rb you are using.
'0.5.1'
- DBL_EPSILON =
The value of double epsilon used in the native extension.
DBL2NUM(DBL_EPSILON)
- SZ_F77_INTEGER =
The bit size of fortran integer.
INT2NUM(32)
Class Method Summary collapse
-
.minimize(fnc:, x_init:, jcb:, args: nil, bounds: nil, factr: 1e7, pgtol: 1e-5, maxcor: 10, maxiter: 15_000, verbose: nil) ⇒ Hash
Minimize a function using the L-BFGS-B algorithm.
Class Method Details
.minimize(fnc:, x_init:, jcb:, args: nil, bounds: nil, factr: 1e7, pgtol: 1e-5, maxcor: 10, maxiter: 15_000, verbose: nil) ⇒ Hash
Minimize a function using the L-BFGS-B algorithm.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/lbfgsb.rb', line 43 def minimize(fnc:, x_init:, jcb:, args: nil, bounds: nil, factr: 1e7, pgtol: 1e-5, maxcor: 10, maxiter: 15_000, verbose: nil) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity n_elements = x_init.size l = Numo::DFloat.zeros(n_elements) u = Numo::DFloat.zeros(n_elements) nbd = SZ_F77_INTEGER == 64 ? Numo::Int64.zeros(n_elements) : Numo::Int32.zeros(n_elements) unless bounds.nil? n_elements.times do |n| lower = bounds[n, 0] upper = bounds[n, 1] l[n] = lower u[n] = upper if lower.finite? && !upper.finite? nbd[n] = 1 elsif lower.finite? && upper.finite? nbd[n] = 2 elsif !lower.finite? && upper.finite? nbd[n] = 3 end end end min_l_bfgs_b(fnc, x_init, jcb, args, l, u, nbd, maxcor, factr, pgtol, maxiter, verbose) end |