lbfgsb 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 10f6e681a7b2d60d8915837bc7001a79d9ea796237d9907651481eeb96618213
4
- data.tar.gz: d95ab1a0f2ac0e5d3f040de8309e4c3a9e3b3babe057c02fe553a3702dd3e75c
3
+ metadata.gz: 272abcfabc883d993bd0b9eae08b4e0d590524b4a5aea38bc7b1f8c92fb0a5b5
4
+ data.tar.gz: 315ffe16183e0a08d236a9563cc6daa29db0931310b8d0cd2ccbd10810b2353e
5
5
  SHA512:
6
- metadata.gz: 7eae04f38bb591a1a2b13b18c2be747cfccd28551c5ff3cdc5095442f00044d6489407abc1b6db33425cedd5368cff0efc88202b76c5ca27ba3a9a98094ed60d
7
- data.tar.gz: e75187c9e10cd4e9670c5f3c3a795509d35307515dbe98c951eb8059fde47eec4e7dc4190fdf80dbbf45104b2d0a4306caee050a3e0b485b30c8451bfc50ad3f
6
+ metadata.gz: 73b05d103b55055894fec49d587c78a798b94d7cc3333324a5e1331e1dd8ce30bb0ee0280f190e111cc04e3d31c3c16e06fce51c91fe004a7f59bcc05aa8f1c5
7
+ data.tar.gz: 0ebcc71411a6fd7b9339d7c9a335277ba69eb74cb83f301de3c651bc243d1daef396b84e9904a680511d7f5f07ac1ff4af469d344f68b2ad2b41ff003b2c5534
@@ -0,0 +1,6 @@
1
+ ## 0.2.0
2
+ - Add an option to minimize method for calculating both function value and gradient vector using fnc.
3
+ If true is given to jcb, fnc is assumed to return the function value and gardient vector as [f, g] array.
4
+
5
+ ## 0.1.0
6
+ - First release.
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
@@ -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
- f = NUM2DBL(rb_funcall(self, rb_intern("fnc"), 3, fnc, x_val, args));
124
- g_val = rb_funcall(self, rb_intern("jcb"), 3, jcb, x_val, args);
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);
@@ -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.
@@ -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
- # `(f^k - f^\{k+1\})/max{|f^k|,|f^\{k+1\}|,1} <= factr * Lbfgsb::DBL_EPSILON`
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
- # `max{|pg_i| i = 1, ..., n} <= pgtol`
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)
@@ -3,5 +3,5 @@
3
3
  # Lbfgsb.rb is a Ruby binding for L-BFGS-B with Numo::NArray.
4
4
  module Lbfgsb
5
5
  # The version of Lbfgsb.rb you are using.
6
- VERSION = '0.1.0'
6
+ VERSION = '0.2.0'
7
7
  end
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.1.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-07 00:00:00.000000000 Z
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
- post_install_message:
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.4
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: []