numo-liblinear 1.1.0 → 1.2.2

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: 4e69ca89df0a86fdc4be7d1a3074a4722ead3997a6f7ba2fff84b48c6d1c36ea
4
- data.tar.gz: 992d8f8606dbf272ac18c1f6502e923d69ce3242d6cb35a460b3856cace29671
3
+ metadata.gz: e01c76e5ada65d064a521c29a11e1ad18644ca60a5f79119b552ad6732fc6ab2
4
+ data.tar.gz: d73b0a4e48ca51053ba162783c6dc128ef20b49ef3ecb7f06654ed9eba4c8a55
5
5
  SHA512:
6
- metadata.gz: 46f453f5b9ee23640a7131d92d3f666806e182265654cec321ebae22c97ae6af06a5b35726e4ab0cfde96407d0fb828391a2c5578c3e27644c487df66432cce8
7
- data.tar.gz: d1e0fc15d4227491823fe4ed8f631c491e6cd4c8fb9c078ccf230785e2881fa12134dbfca9e84069bd8d995c140523bfc0572cbaa38761b114d162015dea5be1
6
+ metadata.gz: 27188ec56a5956df8acebf89384d901aab38b24f6f98cf5b877b4f70be8172b107e05021f9d637761cdf23e3578daf1c1a50f009129e2f556b6d963cd30ebe28
7
+ data.tar.gz: 3bf342d11db29b36a05cd0f345ae98376547a25e3920d7937f1974ed625fa8c4dfbe23be8e7910207090084f2c23cd2b65cf5f999e162d6f1ae35c5d18667df7
@@ -0,0 +1,29 @@
1
+ name: build
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ strategy:
9
+ fail-fast: false
10
+ matrix:
11
+ ruby: [ '2.6', '2.7', '3.0' ]
12
+ steps:
13
+ - uses: actions/checkout@v2
14
+ - name: Checkout submodule
15
+ shell: bash
16
+ run: |
17
+ auth_header="$(git config --local --get http.https://github.com/.extraheader)"
18
+ git submodule sync --recursive
19
+ git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive --depth=1
20
+ - name: Set up Ruby ${{ matrix.ruby }}
21
+ uses: ruby/setup-ruby@v1
22
+ with:
23
+ ruby-version: ${{ matrix.ruby }}
24
+ bundler-cache: true
25
+ - name: Build and test with Rake
26
+ run: |
27
+ gem install --no-document bundler
28
+ bundle install --jobs 4 --retry 3
29
+ bundle exec rake
data/CHANGELOG.md CHANGED
@@ -1,3 +1,20 @@
1
+ # 1.2.2
2
+ - Remove dependent gem's type declaration file from installation files.
3
+
4
+ # 1.2.1
5
+ - Fix version specifier of runtime dependencies.
6
+
7
+ # 1.2.0
8
+ - Add type declaration file: sig/numo/liblinear.rbs
9
+
10
+ # 1.1.2
11
+ - Add GC guard to model saving and loading methods.
12
+ - Fix size specification to memcpy function.
13
+
14
+ # 1.1.1
15
+ - Add GC guard codes.
16
+ - Fix some configuration files.
17
+
1
18
  # 1.1.0
2
19
  - Update bundled LIBLINEAR version to 2.4.1.
3
20
  - Support one-class SVM implemented on LIBLINEAR ver. 2.4.0.
data/Gemfile CHANGED
@@ -2,3 +2,10 @@ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in numo-liblinear.gemspec
4
4
  gemspec
5
+
6
+ gem 'bundler', '~> 2.0'
7
+ gem 'rake', '~> 13.0'
8
+ gem 'rake-compiler', '~> 1.0'
9
+ gem 'rspec', '~> 3.0'
10
+ gem 'rbs', '~> 1.2'
11
+ gem 'steep', '~> 0.44'
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2019-2020 Atsushi Tatsuma
1
+ Copyright (c) 2019-2021 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
@@ -1,8 +1,8 @@
1
1
  # Numo::Liblinear
2
2
 
3
- [![Build Status](https://travis-ci.org/yoshoku/numo-liblinear.svg?branch=master)](https://travis-ci.org/yoshoku/numo-liblinear)
3
+ [![Build Status](https://github.com/yoshoku/numo-liblinear/workflows/build/badge.svg)](https://github.com/yoshoku/numo-liblinear/actions?query=workflow%3Abuild)
4
4
  [![Gem Version](https://badge.fury.io/rb/numo-liblinear.svg)](https://badge.fury.io/rb/numo-liblinear)
5
- [![BSD 3-Clause License](https://img.shields.io/badge/License-BSD%203--Clause-orange.svg)](https://github.com/yoshoku/numo-liblinear/blob/master/LICENSE.txt)
5
+ [![BSD 3-Clause License](https://img.shields.io/badge/License-BSD%203--Clause-orange.svg)](https://github.com/yoshoku/numo-liblinear/blob/main/LICENSE.txt)
6
6
  [![Documentation](http://img.shields.io/badge/docs-rdoc.info-blue.svg)](https://yoshoku.github.io/numo-liblinear/doc/)
7
7
 
8
8
  Numo::Liblinear is a Ruby gem binding to the [LIBLINEAR](https://www.csie.ntu.edu.tw/~cjlin/liblinear/) library.
@@ -162,17 +162,12 @@ param = {
162
162
  weight: # [Numo::DFloat] Weight values
163
163
  Numo::DFloat[0.4, 0.4, 0.2],
164
164
  p: 0.1, # [Float] Sensitiveness of loss of support vector regression
165
+ nu: 0.5, # [Float] one-class SVM approximates the fraction of data as outliers
165
166
  verbose: false, # [Boolean] Whether to output learning process message
166
167
  random_seed: 1 # [Integer/Nil] Random seed
167
168
  }
168
169
  ```
169
170
 
170
- ## Development
171
-
172
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
173
-
174
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
175
-
176
171
  ## Contributing
177
172
 
178
173
  Bug reports and pull requests are welcome on GitHub at https://github.com/yoshoku/numo-liblinear.
@@ -181,4 +176,4 @@ This project is intended to be a safe, welcoming space for collaboration, and co
181
176
  ## Code of Conduct
182
177
 
183
178
  Everyone interacting in the Numo::Liblinear project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow
184
- the [code of conduct](https://github.com/yoshoku/numo-liblinear/blob/master/CODE_OF_CONDUCT.md).
179
+ the [code of conduct](https://github.com/yoshoku/numo-liblinear/blob/main/CODE_OF_CONDUCT.md).
data/Steepfile ADDED
@@ -0,0 +1,20 @@
1
+ target :lib do
2
+ signature "sig", "sig-deps"
3
+ #
4
+ check "lib" # Directory name
5
+ # check "Gemfile" # File name
6
+ # check "app/models/**/*.rb" # Glob
7
+ # # ignore "lib/templates/*.rb"
8
+ #
9
+ # # library "pathname", "set" # Standard libraries
10
+ # library "numo-narray" # Gems
11
+ end
12
+
13
+ # target :spec do
14
+ # signature "sig", "sig-private"
15
+ #
16
+ # check "spec"
17
+ #
18
+ # # library "pathname", "set" # Standard libraries
19
+ # # library "rspec"
20
+ # end
@@ -27,6 +27,8 @@ int* nary_to_int_vec(VALUE vec_val)
27
27
  vec_pt = (int32_t*)na_get_pointer_for_read(vec_val);
28
28
  for (i = 0; i < n_elements; i++) { vec[i] = (int)vec_pt[i]; }
29
29
 
30
+ RB_GC_GUARD(vec_val);
31
+
30
32
  return vec;
31
33
  }
32
34
 
@@ -56,6 +58,8 @@ double* nary_to_dbl_vec(VALUE vec_val)
56
58
  vec_pt = (double*)na_get_pointer_for_read(vec_val);
57
59
  memcpy(vec, vec_pt, n_elements * sizeof(double));
58
60
 
61
+ RB_GC_GUARD(vec_val);
62
+
59
63
  return vec;
60
64
  }
61
65
 
@@ -98,6 +102,8 @@ double** nary_to_dbl_mat(VALUE mat_val)
98
102
  }
99
103
  }
100
104
 
105
+ RB_GC_GUARD(mat_val);
106
+
101
107
  return mat;
102
108
  }
103
109
 
@@ -112,6 +112,9 @@ VALUE numo_liblinear_train(VALUE self, VALUE x_val, VALUE y_val, VALUE param_has
112
112
  xfree_problem(problem);
113
113
  xfree_parameter(param);
114
114
 
115
+ RB_GC_GUARD(x_val);
116
+ RB_GC_GUARD(y_val);
117
+
115
118
  return model_hash;
116
119
  }
117
120
 
@@ -225,6 +228,9 @@ VALUE numo_liblinear_cross_validation(VALUE self, VALUE x_val, VALUE y_val, VALU
225
228
  xfree_problem(problem);
226
229
  xfree_parameter(param);
227
230
 
231
+ RB_GC_GUARD(x_val);
232
+ RB_GC_GUARD(y_val);
233
+
228
234
  return t_val;
229
235
  }
230
236
 
@@ -291,6 +297,8 @@ VALUE numo_liblinear_predict(VALUE self, VALUE x_val, VALUE param_hash, VALUE mo
291
297
  xfree_model(model);
292
298
  xfree_parameter(param);
293
299
 
300
+ RB_GC_GUARD(x_val);
301
+
294
302
  return y_val;
295
303
  }
296
304
 
@@ -381,6 +389,8 @@ VALUE numo_liblinear_decision_function(VALUE self, VALUE x_val, VALUE param_hash
381
389
  xfree_model(model);
382
390
  xfree_parameter(param);
383
391
 
392
+ RB_GC_GUARD(x_val);
393
+
384
394
  return y_val;
385
395
  }
386
396
 
@@ -457,6 +467,8 @@ VALUE numo_liblinear_predict_proba(VALUE self, VALUE x_val, VALUE param_hash, VA
457
467
  xfree_model(model);
458
468
  xfree_parameter(param);
459
469
 
470
+ RB_GC_GUARD(x_val);
471
+
460
472
  return y_val;
461
473
  }
462
474
 
@@ -492,6 +504,8 @@ VALUE numo_liblinear_load_model(VALUE self, VALUE filename)
492
504
  rb_ary_store(res, 0, param_hash);
493
505
  rb_ary_store(res, 1, model_hash);
494
506
 
507
+ RB_GC_GUARD(filename);
508
+
495
509
  return res;
496
510
  }
497
511
 
@@ -526,6 +540,8 @@ VALUE numo_liblinear_save_model(VALUE self, VALUE filename, VALUE param_hash, VA
526
540
  return Qfalse;
527
541
  }
528
542
 
543
+ RB_GC_GUARD(filename);
544
+
529
545
  return Qtrue;
530
546
  }
531
547
 
@@ -46,13 +46,13 @@ struct parameter* rb_hash_to_parameter(VALUE param_hash)
46
46
  param->weight_label = NULL;
47
47
  if (!NIL_P(el)) {
48
48
  param->weight_label = ALLOC_N(int, param->nr_weight);
49
- memcpy(param->weight_label, (int32_t*)na_get_pointer_for_read(el), param->nr_weight);
49
+ memcpy(param->weight_label, (int32_t*)na_get_pointer_for_read(el), param->nr_weight * sizeof(int32_t));
50
50
  }
51
51
  el = rb_hash_aref(param_hash, ID2SYM(rb_intern("weight")));
52
52
  param->weight = NULL;
53
53
  if (!NIL_P(el)) {
54
54
  param->weight = ALLOC_N(double, param->nr_weight);
55
- memcpy(param->weight, (double*)na_get_pointer_for_read(el), param->nr_weight);
55
+ memcpy(param->weight, (double*)na_get_pointer_for_read(el), param->nr_weight * sizeof(double));
56
56
  }
57
57
  el = rb_hash_aref(param_hash, ID2SYM(rb_intern("p")));
58
58
  param->p = !NIL_P(el) ? NUM2DBL(el) : 0.1;
@@ -85,5 +85,8 @@ struct problem* dataset_to_problem(VALUE x_val, VALUE y_val)
85
85
  problem->y[i] = y_pt[i];
86
86
  }
87
87
 
88
+ RB_GC_GUARD(x_val);
89
+ RB_GC_GUARD(y_val);
90
+
88
91
  return problem;
89
92
  }
@@ -3,6 +3,6 @@
3
3
  module Numo
4
4
  module Liblinear
5
5
  # The version of Numo::Liblienar you are using.
6
- VERSION = '1.1.0'
6
+ VERSION = '1.2.2'
7
7
  end
8
8
  end
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  lib = File.expand_path('lib', __dir__)
4
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
3
  require 'numo/liblinear/version'
@@ -25,13 +23,13 @@ Gem::Specification.new do |spec|
25
23
  # Specify which files should be added to the gem when it is released.
26
24
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
27
25
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
28
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|sig-deps)/}) }
29
27
  end
30
28
 
31
- gem_dir = File.expand_path(__dir__) + '/'
32
- submodule_path = `git submodule --quiet foreach pwd`.split($OUTPUT_RECORD_SEPARATOR).first
33
- submodule_relative_path = submodule_path.sub gem_dir, ''
34
- liblinear_files = %w[linear.cpp linear.h newton.cpp newton.h blas/blas.h blas/blasp.h blas/daxpy.c blas/ddot.c blas/dnrm2.c blas/dscal.c]
29
+ submodule_path = `git submodule --quiet foreach pwd`.split($INPUT_RECORD_SEPARATOR).first
30
+ submodule_relative_path = submodule_path.sub("#{File.expand_path(__dir__)}/", '')
31
+ liblinear_files = %w[linear.cpp linear.h newton.cpp newton.h
32
+ blas/blas.h blas/blasp.h blas/daxpy.c blas/ddot.c blas/dnrm2.c blas/dscal.c]
35
33
  liblinear_files.each { |liblinf| spec.files << "#{submodule_relative_path}/#{liblinf}" }
36
34
 
37
35
  spec.bindir = 'exe'
@@ -45,10 +43,5 @@ Gem::Specification.new do |spec|
45
43
  'documentation_uri' => 'https://yoshoku.github.io/numo-liblinear/doc/'
46
44
  }
47
45
 
48
- spec.add_runtime_dependency 'numo-narray', '~> 0.9.1'
49
-
50
- spec.add_development_dependency 'bundler', '~> 2.0'
51
- spec.add_development_dependency 'rake', '~> 12.0'
52
- spec.add_development_dependency 'rake-compiler', '~> 1.0'
53
- spec.add_development_dependency 'rspec', '~> 3.0'
46
+ spec.add_runtime_dependency 'numo-narray', '>= 0.9.1'
54
47
  end
@@ -0,0 +1,52 @@
1
+ module Numo
2
+ module Liblinear
3
+ module SolverType
4
+ L2R_LR: Integer
5
+ L2R_L2LOSS_SVC_DUAL: Integer
6
+ L2R_L2LOSS_SVC: Integer
7
+ L2R_L1LOSS_SVC_DUAL: Integer
8
+ MCSVM_CS: Integer
9
+ L1R_L2LOSS_SVC: Integer
10
+ L1R_LR: Integer
11
+ L2R_LR_DUAL: Integer
12
+ L2R_L2LOSS_SVR: Integer
13
+ L2R_L2LOSS_SVR_DUAL: Integer
14
+ L2R_L1LOSS_SVR_DUAL: Integer
15
+ ONECLASS_SVM: Integer
16
+ end
17
+
18
+ LIBLINEAR_VERSION: Integer
19
+ VERSION: String
20
+
21
+ type model = {
22
+ nr_class: Integer,
23
+ nr_feature: Integer,
24
+ w: Numo::DFloat,
25
+ label: Numo::Int32,
26
+ bias: Float,
27
+ rho: Float
28
+ }
29
+
30
+ type param = {
31
+ solver_type: Integer?,
32
+ eps: Float?,
33
+ C: Float?,
34
+ nr_weight: Integer?,
35
+ weight_label: Numo::Int32?,
36
+ weight: Numo::DFloat?,
37
+ p: Float?,
38
+ nu: Float?,
39
+ verbose: bool?,
40
+ random_seed: Integer?
41
+ }
42
+
43
+ def self?.cv: (Numo::DFloat x, Numo::DFloat y, param, Integer n_folds) -> Numo::DFloat
44
+ def self?.train: (Numo::DFloat x, Numo::DFloat y, param) -> model
45
+ def self?.predict: (Numo::DFloat x, param, model) -> Numo::DFloat
46
+ def self?.predict_proba: (Numo::DFloat x, param, model) -> Numo::DFloat
47
+ def self?.decision_function: (Numo::DFloat x, param, model) -> Numo::DFloat
48
+ def self?.save_model: (String filename, param, model) -> bool
49
+ def self?.load_model: (String filename) -> [param, model]
50
+ end
51
+ end
52
+
metadata CHANGED
@@ -1,85 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: numo-liblinear
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.2
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-08-14 00:00:00.000000000 Z
11
+ date: 2021-07-10 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
- - !ruby/object:Gem::Dependency
28
- name: bundler
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '2.0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '2.0'
41
- - !ruby/object:Gem::Dependency
42
- name: rake
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '12.0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '12.0'
55
- - !ruby/object:Gem::Dependency
56
- name: rake-compiler
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '1.0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '1.0'
69
- - !ruby/object:Gem::Dependency
70
- name: rspec
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '3.0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '3.0'
83
27
  description: |
84
28
  Numo::Liblinear is a Ruby gem binding to the LIBLINEAR library.
85
29
  LIBLINEAR is one of the famous libraries for large-scale regularized linear classification and regression.
@@ -91,16 +35,17 @@ extensions:
91
35
  - ext/numo/liblinear/extconf.rb
92
36
  extra_rdoc_files: []
93
37
  files:
38
+ - ".github/workflows/build.yml"
94
39
  - ".gitignore"
95
40
  - ".gitmodules"
96
41
  - ".rspec"
97
- - ".travis.yml"
98
42
  - CHANGELOG.md
99
43
  - CODE_OF_CONDUCT.md
100
44
  - Gemfile
101
45
  - LICENSE.txt
102
46
  - README.md
103
47
  - Rakefile
48
+ - Steepfile
104
49
  - ext/numo/liblinear/converter.c
105
50
  - ext/numo/liblinear/converter.h
106
51
  - ext/numo/liblinear/extconf.rb
@@ -127,6 +72,7 @@ files:
127
72
  - lib/numo/liblinear.rb
128
73
  - lib/numo/liblinear/version.rb
129
74
  - numo-liblinear.gemspec
75
+ - sig/numo/liblinear.rbs
130
76
  homepage: https://github.com/yoshoku/numo-liblinear
131
77
  licenses:
132
78
  - BSD-3-Clause
@@ -134,7 +80,7 @@ metadata:
134
80
  homepage_uri: https://github.com/yoshoku/numo-liblinear
135
81
  source_code_uri: https://github.com/yoshoku/numo-liblinear
136
82
  documentation_uri: https://yoshoku.github.io/numo-liblinear/doc/
137
- post_install_message:
83
+ post_install_message:
138
84
  rdoc_options: []
139
85
  require_paths:
140
86
  - lib
@@ -149,8 +95,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
95
  - !ruby/object:Gem::Version
150
96
  version: '0'
151
97
  requirements: []
152
- rubygems_version: 3.1.2
153
- signing_key:
98
+ rubygems_version: 3.2.21
99
+ signing_key:
154
100
  specification_version: 4
155
101
  summary: Numo::Liblinear is a Ruby gem binding to the LIBLINEAR library. Numo::Liblinear
156
102
  makes to use the LIBLINEAR functions with dataset represented by Numo::NArray.
data/.travis.yml DELETED
@@ -1,14 +0,0 @@
1
- ---
2
- sudo: true
3
- os: linux
4
- dist: bionic
5
- language: ruby
6
- cache: bundler
7
- rvm:
8
- - '2.4'
9
- - '2.5'
10
- - '2.6'
11
- - '2.7'
12
-
13
- before_install:
14
- - gem install bundler -v 2.0.2