mopti 0.2.0 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c9e81da580fe5dd2be2958e34bee75fe5c82bb29240edf43bb7d01c89522f863
4
- data.tar.gz: 43648573d898ae4fdbce70ce84b6f6dbcfd5109ea95eb743e9fb51fc2101251b
3
+ metadata.gz: 00c061fd0bbe6751f39dbc139de732990c02915c650b5c25cafb1469162372b3
4
+ data.tar.gz: c8df3190b009acc36393615791e0baa1045ccc026f3c3c61444b0f96f4afe7ac
5
5
  SHA512:
6
- metadata.gz: 2de393870f138bfeba855c7d1c95d8263e85a30e0e9fb4a3a65ae6614784531865b32cafc0761ab856331dc66b9f19df4a00c8bfff3ff69eb07a9b850902c718
7
- data.tar.gz: a71eead28cac1eb28e4b3154fabd846d11468ae803f5e7cbe5e4cb04faed18d1a468793131e465b282504b71bde2ae03db114fa245f08a8b9d0be99b3f3cbfcf
6
+ metadata.gz: 5d27e97704610889a028b98541a282292cdea04313b37346af32ecc6732c5d947ee169f558679ab1048f5d4176b34c25d3f0aa7f497c9a0e212252b16863920c
7
+ data.tar.gz: 14808c545bba9ce60ee1fd0825391ef7cd280fe1a6a4d2afd7de02be101faaa45a7a457d487ff47597e9350e5cb6daef80a6c80330889678f700d14e90a85eea
@@ -6,16 +6,15 @@ jobs:
6
6
  build:
7
7
  runs-on: ubuntu-latest
8
8
  strategy:
9
+ fail-fast: false
9
10
  matrix:
10
- ruby: [ '2.6', '2.7', '3.0' ]
11
+ ruby: [ '2.7', '3.0', '3.1' ]
11
12
  steps:
12
- - uses: actions/checkout@v2
13
- - name: Set up Ruby
14
- uses: actions/setup-ruby@v1
13
+ - uses: actions/checkout@v3
14
+ - name: Set up Ruby ${{ matrix.ruby }}
15
+ uses: ruby/setup-ruby@v1
15
16
  with:
16
17
  ruby-version: ${{ matrix.ruby }}
18
+ bundler-cache: true
17
19
  - name: Build and test with Rake
18
- run: |
19
- gem install bundler
20
- bundle install --jobs 4 --retry 3
21
- bundle exec rake
20
+ run: bundle exec rake
data/.rubocop.yml CHANGED
@@ -1,13 +1,24 @@
1
1
  require:
2
2
  - rubocop-performance
3
+ - rubocop-rake
3
4
  - rubocop-rspec
4
5
 
5
6
  AllCops:
6
7
  NewCops: enable
8
+ DisplayCopNames: true
9
+ DisplayStyleGuide: true
10
+ Exclude:
11
+ - 'ext/**/*'
12
+ - 'tmp/**/*'
13
+ - 'vendor/**/*'
14
+ - 'Steepfile'
15
+
16
+ Gemspec/RequiredRubyVersion:
17
+ Enabled: false
7
18
 
8
19
  Layout/LineLength:
9
20
  Max: 145
10
- IgnoredPatterns: ['(\A|\s)#']
21
+ AllowedPatterns: ['(\A|\s)#']
11
22
 
12
23
  Metrics/ModuleLength:
13
24
  Max: 200
@@ -37,3 +48,9 @@ Metrics/ParameterLists:
37
48
 
38
49
  Naming/MethodParameterName:
39
50
  Enabled: false
51
+
52
+ Style/SlicingWithRange:
53
+ Enabled: false
54
+
55
+ RSpec/MultipleMemoizedHelpers:
56
+ Max: 12
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ # 0.2.3
2
+ - Refactor codes and configs with RuboCop.
3
+
4
+ # 0.2.2
5
+ - Remove dependent gem's type declaration file from installation files.
6
+
7
+ # 0.2.1
8
+ - Fix version specifier of runtime dependencies.
9
+
1
10
  # 0.2.0
2
11
  - Add type declaration files.
3
12
  - Refactor some codes with type check.
data/Gemfile CHANGED
@@ -1,9 +1,15 @@
1
- source "https://rubygems.org"
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in mopti.gemspec
4
6
  gemspec
5
7
 
6
- gem "rake", "~> 12.0"
7
- gem "rspec", "~> 3.0"
8
- gem "rbs", "~> 1.2"
9
- gem "steep", "~> 0.44"
8
+ gem 'rake', '~> 12.0'
9
+ gem 'rbs', '~> 1.2'
10
+ gem 'rspec', '~> 3.0'
11
+ gem 'rubocop', '~> 1.33'
12
+ gem 'rubocop-performance', '~> 1.14'
13
+ gem 'rubocop-rake', '~> 0.6.0'
14
+ gem 'rubocop-rspec', '~> 2.12'
15
+ gem 'steep', '~> 0.44'
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2020-2021 Atsushi Tatsuma
1
+ Copyright (c) 2020-2022 Atsushi Tatsuma
2
2
  All rights reserved.
3
3
 
4
4
  Redistribution and use in source and binary forms, with or without
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  ![Ruby](https://github.com/yoshoku/mopti/workflows/Ruby/badge.svg)
4
4
  [![Gem Version](https://badge.fury.io/rb/mopti.svg)](https://badge.fury.io/rb/mopti)
5
5
  [![BSD 3-Clause License](https://img.shields.io/badge/License-BSD%203--Clause-orange.svg)](https://github.com/yoshoku/mopti/blob/main/LICENSE.txt)
6
- [![Documentation](http://img.shields.io/badge/api-reference-blue.svg)](https://yoshoku.github.io/mopti/doc/)
6
+ [![Documentation](https://img.shields.io/badge/api-reference-blue.svg)](https://yoshoku.github.io/mopti/doc/)
7
7
 
8
8
  Mopti is a multivariate optimization library in Ruby.
9
9
  Mopti supports Nelder-Mead simplex method and Scaled Conjugate Gradient.
data/Rakefile CHANGED
@@ -1,6 +1,12 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
3
5
 
4
6
  RSpec::Core::RakeTask.new(:spec)
5
7
 
6
- task :default => :spec
8
+ require 'rubocop/rake_task'
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[rubocop spec]
data/Steepfile CHANGED
@@ -1,5 +1,5 @@
1
1
  target :lib do
2
- signature "sig"
2
+ signature "sig", "sig-deps"
3
3
 
4
4
  check "lib" # Directory name
5
5
  # check "Gemfile" # File name
@@ -61,7 +61,7 @@ module Mopti
61
61
 
62
62
  x = @x_init.dup
63
63
  n = x.size
64
- max_iter = @max_iter || 200 * n
64
+ max_iter = @max_iter || (200 * n)
65
65
 
66
66
  alpha = 1.0
67
67
  beta = n > 1 ? 1 + 2.fdiv(n) : 2.0
@@ -90,13 +90,13 @@ module Mopti
90
90
  break if ((sim[1..-1, true] - sim[0, true]).abs.flatten.max <= @xtol) && ((fsim[0] - fsim[1..-1]).abs.max <= @ftol)
91
91
 
92
92
  xbar = sim[0...-1, true].sum(0) / n
93
- xr = xbar + alpha * (xbar - sim[-1, true])
93
+ xr = xbar + (alpha * (xbar - sim[-1, true]))
94
94
  fr = func(xr, @args)
95
95
  n_fev += 1
96
96
 
97
97
  shrink = true
98
98
  if fr < fsim[0]
99
- xe = xbar + beta * (xr - xbar)
99
+ xe = xbar + (beta * (xr - xbar))
100
100
  fe = func(xe, @args)
101
101
  n_fev += 1
102
102
  shrink = false
@@ -112,7 +112,7 @@ module Mopti
112
112
  sim[-1, true] = xr
113
113
  fsim[-1] = fr
114
114
  elsif fr < fsim[-1]
115
- xoc = xbar + gamma * (xr - xbar)
115
+ xoc = xbar + (gamma * (xr - xbar))
116
116
  foc = func(xoc, @args)
117
117
  n_fev += 1
118
118
  if foc <= fr
@@ -121,7 +121,7 @@ module Mopti
121
121
  fsim[-1] = foc
122
122
  end
123
123
  else
124
- xic = xbar - gamma * (xr - xbar)
124
+ xic = xbar - (gamma * (xr - xbar))
125
125
  fic = func(xic, @args)
126
126
  n_fev += 1
127
127
  if fic < fsim[-1]
@@ -133,7 +133,7 @@ module Mopti
133
133
 
134
134
  if shrink
135
135
  (1..n).to_a.each do |j|
136
- sim[j, true] = sim[0, true] + delta * (sim[j, true] - sim[0, true])
136
+ sim[j, true] = sim[0, true] + (delta * (sim[j, true] - sim[0, true]))
137
137
  fsim[j] = func(sim[j, true], @args)
138
138
  n_fev += 1
139
139
  end
@@ -108,13 +108,13 @@ module Mopti
108
108
  break if kappa < 1e-16
109
109
 
110
110
  sigma = SIGMA_INIT / Math.sqrt(kappa)
111
- x_plus = x + sigma * d
111
+ x_plus = x + (sigma * d)
112
112
  j_plus = jacb(x_plus, @args)
113
113
  n_jev += 1
114
114
  theta = d.dot(j_plus - j_next) / sigma
115
115
  end
116
116
 
117
- delta = theta + beta * kappa
117
+ delta = theta + (beta * kappa)
118
118
  if delta <= 0
119
119
  delta = beta * kappa
120
120
  # TODO: Investigate the cause of the type error.
@@ -124,7 +124,7 @@ module Mopti
124
124
  end
125
125
  alpha = -mu / delta
126
126
 
127
- x_next = x + alpha * d
127
+ x_next = x + (alpha * d)
128
128
  f_next = func(x_next, @args)
129
129
  n_fev += 1
130
130
 
@@ -165,7 +165,7 @@ module Mopti
165
165
  n_successes = 0
166
166
  elsif success
167
167
  gamma = (j_prev - j_next).dot(j_next) / mu
168
- d = -j_next + gamma * d
168
+ d = -j_next + (gamma * d)
169
169
  end
170
170
  end
171
171
  end
data/lib/mopti/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Mopti
4
4
  # The version of Mopti you are using.
5
- VERSION = '0.2.0'
5
+ VERSION = '0.2.3'
6
6
  end
data/mopti.gemspec CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'lib/mopti/version'
2
4
 
3
5
  Gem::Specification.new do |spec|
@@ -18,15 +20,16 @@ Gem::Specification.new do |spec|
18
20
  spec.metadata['source_code_uri'] = 'https://github.com/yoshoku/mopti'
19
21
  spec.metadata['changelog_uri'] = 'https://github.com/yoshoku/mopti/blob/master/CHANGELOG.md'
20
22
  spec.metadata['documentation_url'] = 'https://yoshoku.github.io/mopti/doc/'
23
+ spec.metadata['rubygems_mfa_required'] = 'true'
21
24
 
22
25
  # Specify which files should be added to the gem when it is released.
23
26
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
27
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
25
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
28
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|sig-deps)/}) }
26
29
  end
27
30
  spec.bindir = 'exe'
28
31
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
32
  spec.require_paths = ['lib']
30
33
 
31
- spec.add_runtime_dependency 'numo-narray', '~> 0.9.1'
34
+ spec.add_runtime_dependency 'numo-narray', '>= 0.9.1'
32
35
  end
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mopti
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - yoshoku
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-06-25 00:00:00.000000000 Z
11
+ date: 2022-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: numo-narray
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 0.9.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.9.1
27
27
  description: |
@@ -52,7 +52,6 @@ files:
52
52
  - sig/mopti.rbs
53
53
  - sig/mopti/nelder_mead.rbs
54
54
  - sig/mopti/scaled_conjugate_gradient.rbs
55
- - sig/patch.rbs
56
55
  homepage: https://github.com/yoshoku/mopti
57
56
  licenses:
58
57
  - BSD-3-Clause
@@ -61,7 +60,8 @@ metadata:
61
60
  source_code_uri: https://github.com/yoshoku/mopti
62
61
  changelog_uri: https://github.com/yoshoku/mopti/blob/master/CHANGELOG.md
63
62
  documentation_url: https://yoshoku.github.io/mopti/doc/
64
- post_install_message:
63
+ rubygems_mfa_required: 'true'
64
+ post_install_message:
65
65
  rdoc_options: []
66
66
  require_paths:
67
67
  - lib
@@ -76,8 +76,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
78
  requirements: []
79
- rubygems_version: 3.1.6
80
- signing_key:
79
+ rubygems_version: 3.2.33
80
+ signing_key:
81
81
  specification_version: 4
82
82
  summary: Multivariate Optimization Library in Ruby.
83
83
  test_files: []
data/sig/patch.rbs DELETED
@@ -1,20 +0,0 @@
1
- module Numo
2
- class NArray
3
- def self.zeros: (*untyped) -> untyped
4
- def dot: (untyped b) -> untyped
5
- def empty?: () -> bool
6
- def ndim: () -> Integer
7
- def shape: () -> Array[Integer]
8
- def swapaxes: (Integer, Integer) -> untyped
9
- end
10
-
11
- class DFloat < NArray
12
- def -@: () -> untyped
13
- def +: (untyped) -> untyped
14
- def -: (untyped) -> untyped
15
- def *: (untyped) -> untyped
16
- def /: (untyped) -> untyped
17
- def []: (*untyped) -> untyped
18
- def []=: (*untyped) -> untyped
19
- end
20
- end