lbfgsb 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +1 -0
- data/ext/lbfgsb/lbfgsbext.c +9 -2
- data/lbfgsb.gemspec +2 -1
- data/lib/lbfgsb.rb +13 -3
- data/lib/lbfgsb/version.rb +1 -1
- metadata +9 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 272abcfabc883d993bd0b9eae08b4e0d590524b4a5aea38bc7b1f8c92fb0a5b5
|
4
|
+
data.tar.gz: 315ffe16183e0a08d236a9563cc6daa29db0931310b8d0cd2ccbd10810b2353e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73b05d103b55055894fec49d587c78a798b94d7cc3333324a5e1331e1dd8ce30bb0ee0280f190e111cc04e3d31c3c16e06fce51c91fe004a7f59bcc05aa8f1c5
|
7
|
+
data.tar.gz: 0ebcc71411a6fd7b9339d7c9a335277ba69eb74cb83f301de3c651bc243d1daef396b84e9904a680511d7f5f07ac1ff4af469d344f68b2ad2b41ff003b2c5534
|
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
[![Build Status](https://github.com/yoshoku/lbfgsb.rb/workflows/build/badge.svg)](https://github.com/yoshoku/lbfgsb.rb/actions?query=workflow%3Abuild)
|
4
4
|
[![Gem Version](https://badge.fury.io/rb/lbfgsb.svg)](https://badge.fury.io/rb/lbfgsb)
|
5
5
|
[![BSD 3-Clause License](https://img.shields.io/badge/License-BSD%203--Clause-orange.svg)](https://github.com/yoshoku/suika/blob/master/LICENSE.txt)
|
6
|
+
[![Documentation](http://img.shields.io/badge/api-reference-blue.svg)](https://yoshoku.github.io/lbfgsb.rb/doc/)
|
6
7
|
|
7
8
|
Lbfgsb.rb is a Ruby binding for [L-BFGS-B](http://users.iems.northwestern.edu/~nocedal/lbfgsb.html)
|
8
9
|
that is a limited-memory algorithm for solving large nonlinear optimization problems
|
data/ext/lbfgsb/lbfgsbext.c
CHANGED
@@ -37,6 +37,7 @@ VALUE lbfgsb_min_l_bfgs_b(VALUE self,
|
|
37
37
|
double dsave[29];
|
38
38
|
double* g_ptr;
|
39
39
|
VALUE g_val;
|
40
|
+
VALUE fg_arr;
|
40
41
|
VALUE ret;
|
41
42
|
|
42
43
|
GetNArray(x_val, x_nary);
|
@@ -120,8 +121,14 @@ VALUE lbfgsb_min_l_bfgs_b(VALUE self,
|
|
120
121
|
task, &iprint, csave, lsave, isave, dsave
|
121
122
|
);
|
122
123
|
if (strncmp(task, "FG", 2) == 0) {
|
123
|
-
|
124
|
-
|
124
|
+
if (RB_TYPE_P(jcb, T_TRUE)) {
|
125
|
+
fg_arr = rb_funcall(self, rb_intern("fnc"), 3, fnc, x_val, args);
|
126
|
+
f = NUM2DBL(rb_ary_entry(fg_arr, 0));
|
127
|
+
g_val = rb_ary_entry(fg_arr, 1);
|
128
|
+
} else {
|
129
|
+
f = NUM2DBL(rb_funcall(self, rb_intern("fnc"), 3, fnc, x_val, args));
|
130
|
+
g_val = rb_funcall(self, rb_intern("jcb"), 3, jcb, x_val, args);
|
131
|
+
}
|
125
132
|
n_fev += 1;
|
126
133
|
n_jev += 1;
|
127
134
|
if (CLASS_OF(g_val) != numo_cDFloat) g_val = rb_funcall(numo_cDFloat, rb_intern("cast"), 1, g_val);
|
data/lbfgsb.gemspec
CHANGED
@@ -13,7 +13,8 @@ Gem::Specification.new do |spec|
|
|
13
13
|
|
14
14
|
spec.metadata['homepage_uri'] = spec.homepage
|
15
15
|
spec.metadata['source_code_uri'] = 'https://github.com/yoshoku/lbfgsb.rb'
|
16
|
-
spec.metadata['changelog_uri'] = 'https://github.com/yoshoku/lbfgsb.rb/CHANGELOG.md'
|
16
|
+
spec.metadata['changelog_uri'] = 'https://github.com/yoshoku/lbfgsb.rb/blob/main/CHANGELOG.md'
|
17
|
+
spec.metadata['documentation_uri'] = 'https://yoshoku.github.io/lbfgsb.rb/doc/'
|
17
18
|
|
18
19
|
# Specify which files should be added to the gem when it is released.
|
19
20
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
data/lib/lbfgsb.rb
CHANGED
@@ -12,23 +12,33 @@ module Lbfgsb
|
|
12
12
|
#
|
13
13
|
# @param fnc [Method/Proc] Method for calculating the function to be minimized.
|
14
14
|
# @param x_init [Numo::DFloat] (shape: [n_elements]) Initial point.
|
15
|
-
# @param jcb [Method/Proc] Method for calculating the gradient vector.
|
15
|
+
# @param jcb [Method/Proc/Boolean] Method for calculating the gradient vector.
|
16
|
+
# If true is given, fnc is assumed to return the function value and gardient vector as [f, g] array.
|
16
17
|
# @param args [Object] Arguments pass to the 'fnc' and 'jcb'.
|
17
18
|
# @param bounds [Numo::DFloat/Nil] (shape: [n_elements, 2])
|
18
19
|
# \[lower, upper\] bounds for each element x. If nil is given, x is unbounded.
|
19
20
|
# @param factr [Float] The iteration will be stop when
|
20
21
|
#
|
21
|
-
#
|
22
|
+
# (f^k - f^\{k+1\})/max{|f^k|,|f^\{k+1\}|,1} <= factr * Lbfgsb::DBL_EPSILON
|
22
23
|
#
|
23
24
|
# Typical values for factr: 1e12 for low accuracy; 1e7 for moderate accuracy; 1e1 for extremely high accuracy.
|
24
25
|
# @param pgtol [Float] The iteration will be stop when
|
25
26
|
#
|
26
|
-
#
|
27
|
+
# max{|pg_i| i = 1, ..., n} <= pgtol
|
27
28
|
#
|
28
29
|
# where pg_i is the ith component of the projected gradient.
|
29
30
|
# @param maxcor [Integer] The maximum number of variable metric corrections used to define the limited memory matrix.
|
30
31
|
# @param maxiter [Integer] The maximum number of iterations.
|
31
32
|
# @param verbose [Integer/Nil] If negative value or nil is given, no display output is generated.
|
33
|
+
# @return [Hash] Optimization results; { x:, n_fev:, n_jev:, n_iter:, fnc:, jcb:, task:, success: }
|
34
|
+
# - x [Numo::DFloat] Updated vector by optimization.
|
35
|
+
# - n_fev [Interger] Number of calls of the objective function.
|
36
|
+
# - n_jev [Integer] Number of calls of the jacobian.
|
37
|
+
# - n_iter [Integer] Number of iterations.
|
38
|
+
# - fnc [Float] Value of the objective function.
|
39
|
+
# - jcb [Numo::Narray] Values of the jacobian
|
40
|
+
# - task [String] Description of the cause of the termination.
|
41
|
+
# - success [Boolean] Whether or not the optimization exited successfully.
|
32
42
|
def minimize(fnc:, x_init:, jcb:, args: nil, bounds: nil, factr: 1e7, pgtol: 1e-5, maxcor: 10, maxiter: 15_000, verbose: nil)
|
33
43
|
n_elements = x_init.size
|
34
44
|
l = Numo::DFloat.zeros(n_elements)
|
data/lib/lbfgsb/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lbfgsb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- yoshoku
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-11-
|
11
|
+
date: 2020-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: numo-narray
|
@@ -36,6 +36,7 @@ files:
|
|
36
36
|
- ".gitignore"
|
37
37
|
- ".rspec"
|
38
38
|
- ".yardopts"
|
39
|
+
- CHANGELOG.md
|
39
40
|
- Gemfile
|
40
41
|
- LICENSE.txt
|
41
42
|
- README.md
|
@@ -59,8 +60,9 @@ licenses:
|
|
59
60
|
metadata:
|
60
61
|
homepage_uri: https://github.com/yoshoku/lbfgsb.rb
|
61
62
|
source_code_uri: https://github.com/yoshoku/lbfgsb.rb
|
62
|
-
changelog_uri: https://github.com/yoshoku/lbfgsb.rb/CHANGELOG.md
|
63
|
-
|
63
|
+
changelog_uri: https://github.com/yoshoku/lbfgsb.rb/blob/main/CHANGELOG.md
|
64
|
+
documentation_uri: https://yoshoku.github.io/lbfgsb.rb/doc/
|
65
|
+
post_install_message:
|
64
66
|
rdoc_options: []
|
65
67
|
require_paths:
|
66
68
|
- lib
|
@@ -75,8 +77,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
77
|
- !ruby/object:Gem::Version
|
76
78
|
version: '0'
|
77
79
|
requirements: []
|
78
|
-
rubygems_version: 3.1.
|
79
|
-
signing_key:
|
80
|
+
rubygems_version: 3.1.2
|
81
|
+
signing_key:
|
80
82
|
specification_version: 4
|
81
83
|
summary: Lbfgsb.rb is a Ruby binding for L-BFGS-B
|
82
84
|
test_files: []
|