numo-libsvm 1.0.0 → 1.1.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
- SHA1:
3
- metadata.gz: c0a730ce303204c97607bd8c5ce7bf6440fe3526
4
- data.tar.gz: 5370997eadf0f407239763a6fc31241538f06758
2
+ SHA256:
3
+ metadata.gz: f321e889c3d7a6a617f6700885d5c39f00272a4cd2aad82e2efadb6818fe78aa
4
+ data.tar.gz: bc8062c42b4f20cc1b6cfe11a2cebff4fc2881be180c92ca287e5f3c85b74a76
5
5
  SHA512:
6
- metadata.gz: 5ba7e42f36ec3f7fff0d42c900f79500a61695efe03f4b0cd74a6f2758e92ecc80172006f3186e4567feb322572943b31332f1147263aef5f257ea960379936c
7
- data.tar.gz: da34b077e7d299c0c7a760ecbf02b395f95606e4f87deb9e060de3330ad5ae507f81fe3d1b7dbbadfd4b54c3161af049a27302a5554249f7f7b17766a204f1aa
6
+ metadata.gz: faa13722b019804975e539f4f10a64bb602a3052529d885e168e343801a61a074af186efa6f0c8e124f03ed8b95cfc7067a7c06eda334d89a9c41f4775d18c2c
7
+ data.tar.gz: 28b0830bd53f280c6511013ca838bf29ed510cf8062b7f47425d15aa287418452c14ea7f98567ee459518be9aa946cee40d3401a9011169e3f51d64f64f96ca8
@@ -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.1.2
2
+ - Remove dependent gem's type declaration file from installation files.
3
+
4
+ # 1.1.1
5
+ - Fix version specifier of runtime dependencies.
6
+
7
+ # 1.1.0
8
+ - Add type declaration file: sig/numo/libsvm.rbs
9
+
10
+ # 1.0.2
11
+ - Add GC guard to model saving and loading methods.
12
+ - Fix size specification to memcpy function.
13
+
14
+ # 1.0.1
15
+ - Add GC guard codes.
16
+ - Fix some configuration files.
17
+
1
18
  # 1.0.0
2
19
  ## Breaking change
3
20
  - For easy installation, Numo::LIBSVM bundles LIBSVM codes.
data/Gemfile CHANGED
@@ -2,3 +2,10 @@ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in numo-libsvm.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 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,9 +1,9 @@
1
1
  # Numo::Libsvm
2
2
 
3
- [![Build Status](https://travis-ci.org/yoshoku/numo-libsvm.svg?branch=master)](https://travis-ci.org/yoshoku/numo-libsvm)
3
+ [![Build Status](https://github.com/yoshoku/numo-libsvm/workflows/build/badge.svg)](https://github.com/yoshoku/numo-libsvm/actions?query=workflow%3Abuild)
4
4
  [![Gem Version](https://badge.fury.io/rb/numo-libsvm.svg)](https://badge.fury.io/rb/numo-libsvm)
5
- [![BSD 3-Clause License](https://img.shields.io/badge/License-BSD%203--Clause-orange.svg)](https://github.com/yoshoku/numo-libsvm/blob/master/LICENSE.txt)
6
- [![Documentation](http://img.shields.io/badge/docs-rdoc.info-blue.svg)](https://www.rubydoc.info/gems/numo-libsvm/0.4.0)
5
+ [![BSD 3-Clause License](https://img.shields.io/badge/License-BSD%203--Clause-orange.svg)](https://github.com/yoshoku/numo-libsvm/blob/main/LICENSE.txt)
6
+ [![Documentation](https://img.shields.io/badge/api-reference-blue.svg)](https://yoshoku.github.io/numo-libsvm/doc/)
7
7
 
8
8
  Numo::Libsvm is a Ruby gem binding to the [LIBSVM](https://github.com/cjlin1/libsvm) library.
9
9
  LIBSVM is one of the famous libraries that implemented Support Vector Machines,
@@ -197,4 +197,4 @@ The gem is available as open source under the terms of the [BSD-3-Clause License
197
197
 
198
198
  ## Code of Conduct
199
199
 
200
- Everyone interacting in the Numo::Libsvm project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/yoshoku/numo-libsvm/blob/master/CODE_OF_CONDUCT.md).
200
+ Everyone interacting in the Numo::Libsvm project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/yoshoku/numo-libsvm/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
@@ -28,6 +28,8 @@ int* nary_to_int_vec(VALUE vec_val)
28
28
  vec_pt = (int32_t*)na_get_pointer_for_read(vec_val);
29
29
  for (i = 0; i < n_elements; i++) { vec[i] = (int)vec_pt[i]; }
30
30
 
31
+ RB_GC_GUARD(vec_val);
32
+
31
33
  return vec;
32
34
  }
33
35
 
@@ -57,6 +59,8 @@ double* nary_to_dbl_vec(VALUE vec_val)
57
59
  vec_pt = (double*)na_get_pointer_for_read(vec_val);
58
60
  memcpy(vec, vec_pt, n_elements * sizeof(double));
59
61
 
62
+ RB_GC_GUARD(vec_val);
63
+
60
64
  return vec;
61
65
  }
62
66
 
@@ -99,6 +103,8 @@ double** nary_to_dbl_mat(VALUE mat_val)
99
103
  }
100
104
  }
101
105
 
106
+ RB_GC_GUARD(mat_val);
107
+
102
108
  return mat;
103
109
  }
104
110
 
@@ -167,6 +173,8 @@ struct svm_node** nary_to_svm_nodes(VALUE nary_val)
167
173
  support_vecs[i][n_nonzero_cols].value = 0.0;
168
174
  }
169
175
 
176
+ RB_GC_GUARD(nary_val);
177
+
170
178
  return support_vecs;
171
179
  }
172
180
 
@@ -114,6 +114,9 @@ VALUE train(VALUE self, VALUE x_val, VALUE y_val, VALUE param_hash)
114
114
  xfree_svm_problem(problem);
115
115
  xfree_svm_parameter(param);
116
116
 
117
+ RB_GC_GUARD(x_val);
118
+ RB_GC_GUARD(y_val);
119
+
117
120
  return model_hash;
118
121
  }
119
122
 
@@ -229,6 +232,9 @@ VALUE cross_validation(VALUE self, VALUE x_val, VALUE y_val, VALUE param_hash, V
229
232
  xfree_svm_problem(problem);
230
233
  xfree_svm_parameter(param);
231
234
 
235
+ RB_GC_GUARD(x_val);
236
+ RB_GC_GUARD(y_val);
237
+
232
238
  return t_val;
233
239
  }
234
240
 
@@ -295,6 +301,8 @@ VALUE predict(VALUE self, VALUE x_val, VALUE param_hash, VALUE model_hash)
295
301
  xfree_svm_model(model);
296
302
  xfree_svm_parameter(param);
297
303
 
304
+ RB_GC_GUARD(x_val);
305
+
298
306
  return y_val;
299
307
  }
300
308
 
@@ -385,6 +393,8 @@ VALUE decision_function(VALUE self, VALUE x_val, VALUE param_hash, VALUE model_h
385
393
  xfree_svm_model(model);
386
394
  xfree_svm_parameter(param);
387
395
 
396
+ RB_GC_GUARD(x_val);
397
+
388
398
  return y_val;
389
399
  }
390
400
 
@@ -460,6 +470,8 @@ VALUE predict_proba(VALUE self, VALUE x_val, VALUE param_hash, VALUE model_hash)
460
470
  xfree_svm_model(model);
461
471
  xfree_svm_parameter(param);
462
472
 
473
+ RB_GC_GUARD(x_val);
474
+
463
475
  return y_val;
464
476
  }
465
477
 
@@ -493,6 +505,8 @@ VALUE load_svm_model(VALUE self, VALUE filename)
493
505
  rb_ary_store(res, 0, param_hash);
494
506
  rb_ary_store(res, 1, model_hash);
495
507
 
508
+ RB_GC_GUARD(filename);
509
+
496
510
  return res;
497
511
  }
498
512
 
@@ -527,6 +541,8 @@ VALUE save_svm_model(VALUE self, VALUE filename, VALUE param_hash, VALUE model_h
527
541
  return Qfalse;
528
542
  }
529
543
 
544
+ RB_GC_GUARD(filename);
545
+
530
546
  return Qtrue;
531
547
  }
532
548
 
@@ -35,13 +35,13 @@ struct svm_parameter* rb_hash_to_svm_parameter(VALUE param_hash)
35
35
  param->weight_label = NULL;
36
36
  if (!NIL_P(el)) {
37
37
  param->weight_label = ALLOC_N(int, param->nr_weight);
38
- memcpy(param->weight_label, (int32_t*)na_get_pointer_for_read(el), param->nr_weight);
38
+ memcpy(param->weight_label, (int32_t*)na_get_pointer_for_read(el), param->nr_weight * sizeof(int32_t));
39
39
  }
40
40
  el = rb_hash_aref(param_hash, ID2SYM(rb_intern("weight")));
41
41
  param->weight = NULL;
42
42
  if (!NIL_P(el)) {
43
43
  param->weight = ALLOC_N(double, param->nr_weight);
44
- memcpy(param->weight, (double*)na_get_pointer_for_read(el), param->nr_weight);
44
+ memcpy(param->weight, (double*)na_get_pointer_for_read(el), param->nr_weight * sizeof(double));
45
45
  }
46
46
  return param;
47
47
  }
@@ -83,5 +83,8 @@ struct svm_problem* dataset_to_svm_problem(VALUE x_val, VALUE y_val)
83
83
  problem->y[i] = y_pt[i];
84
84
  }
85
85
 
86
+ RB_GC_GUARD(x_val);
87
+ RB_GC_GUARD(y_val);
88
+
86
89
  return problem;
87
90
  }
@@ -3,6 +3,6 @@
3
3
  module Numo
4
4
  module Libsvm
5
5
  # The version of Numo::Libsvm you are using.
6
- VERSION = '1.0.0'
6
+ VERSION = '1.1.2'
7
7
  end
8
8
  end
data/numo-libsvm.gemspec CHANGED
@@ -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/libsvm/version'
@@ -26,12 +24,11 @@ Gem::Specification.new do |spec|
26
24
  # Specify which files should be added to the gem when it is released.
27
25
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
28
26
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
29
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
27
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|sig-deps)/}) }
30
28
  end
31
29
 
32
- gem_dir = File.expand_path(__dir__) + '/'
33
- submodule_path = `git submodule --quiet foreach pwd`.split($OUTPUT_RECORD_SEPARATOR).first
34
- submodule_relative_path = submodule_path.sub gem_dir, ''
30
+ submodule_path = `git submodule --quiet foreach pwd`.split($INPUT_RECORD_SEPARATOR).first
31
+ submodule_relative_path = submodule_path.sub("#{File.expand_path(__dir__)}/", '')
35
32
  spec.files << "#{submodule_relative_path}/svm.cpp"
36
33
  spec.files << "#{submodule_relative_path}/svm.h"
37
34
 
@@ -46,10 +43,5 @@ Gem::Specification.new do |spec|
46
43
  'documentation_uri' => 'https://yoshoku.github.io/numo-libsvm/doc/'
47
44
  }
48
45
 
49
- spec.add_runtime_dependency 'numo-narray', '~> 0.9.1'
50
-
51
- spec.add_development_dependency 'bundler', '~> 2.0'
52
- spec.add_development_dependency 'rake', '~> 10.0'
53
- spec.add_development_dependency 'rake-compiler', '~> 1.0'
54
- spec.add_development_dependency 'rspec', '~> 3.0'
46
+ spec.add_runtime_dependency 'numo-narray', '>= 0.9.1'
55
47
  end
@@ -0,0 +1,65 @@
1
+ module Numo
2
+ module Libsvm
3
+ module SvmType
4
+ C_SVC: Integer
5
+ NU_SVC: Integer
6
+ ONE_CLASS: Integer
7
+ EPSILON_SVR: Integer
8
+ NU_SVR: Integer
9
+ end
10
+
11
+ module KenelType
12
+ LINEAR: Integer
13
+ POLY: Integer
14
+ RBF: Integer
15
+ SIGMOID: Integer
16
+ PRECOMPUTED: Integer
17
+ end
18
+
19
+ LIBSVM_VERSION: Integer
20
+ VERSION: String
21
+
22
+ type model = {
23
+ nr_class: Integer,
24
+ l: Integer,
25
+ SV: Numo::DFloat,
26
+ sv_coef: Numo::DFloat,
27
+ rho: Numo::DFloat,
28
+ probA: Numo::DFloat,
29
+ probB: Numo::DFloat,
30
+ sv_indices: Numo::Int32,
31
+ label: Numo::Int32,
32
+ nSV: Numo::Int32,
33
+ free_sv: Integer
34
+ }
35
+
36
+ type param = {
37
+ svm_type: Integer?,
38
+ kernel_type: Integer?,
39
+ degree: Integer?,
40
+ gamma: Float?,
41
+ coef0: Float?,
42
+ cache_size: Float?,
43
+ eps: Float?,
44
+ C: Float?,
45
+ nr_weight: Integer?,
46
+ weight_label: Numo::Int32?,
47
+ weight: Numo::DFloat?,
48
+ nu: Float?,
49
+ p: Float?,
50
+ shrinking: bool?,
51
+ probability: bool?,
52
+ verbose: bool?,
53
+ random_seed: Integer?
54
+ }
55
+
56
+ def self?.cv: (Numo::DFloat x, Numo::DFloat y, param, Integer n_folds) -> Numo::DFloat
57
+ def self?.train: (Numo::DFloat x, Numo::DFloat y, param) -> model
58
+ def self?.predict: (Numo::DFloat x, param, model) -> Numo::DFloat
59
+ def self?.predict_proba: (Numo::DFloat x, param, model) -> Numo::DFloat
60
+ def self?.decision_function: (Numo::DFloat x, param, model) -> Numo::DFloat
61
+ def self?.save_svm_model: (String filename, param, model) -> bool
62
+ def self?.load_svm_model: (String filename) -> [param, model]
63
+ end
64
+ end
65
+
metadata CHANGED
@@ -1,85 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: numo-libsvm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - yoshoku
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-12 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: '10.0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '10.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::Libsvm is a Ruby gem binding to the LIBSVM library.
85
29
  LIBSVM is one of the famous libraries that implemented Support Vector Machines,
@@ -92,16 +36,17 @@ extensions:
92
36
  - ext/numo/libsvm/extconf.rb
93
37
  extra_rdoc_files: []
94
38
  files:
39
+ - ".github/workflows/build.yml"
95
40
  - ".gitignore"
96
41
  - ".gitmodules"
97
42
  - ".rspec"
98
- - ".travis.yml"
99
43
  - CHANGELOG.md
100
44
  - CODE_OF_CONDUCT.md
101
45
  - Gemfile
102
46
  - LICENSE.txt
103
47
  - README.md
104
48
  - Rakefile
49
+ - Steepfile
105
50
  - ext/numo/libsvm/converter.c
106
51
  - ext/numo/libsvm/converter.h
107
52
  - ext/numo/libsvm/extconf.rb
@@ -122,6 +67,7 @@ files:
122
67
  - lib/numo/libsvm.rb
123
68
  - lib/numo/libsvm/version.rb
124
69
  - numo-libsvm.gemspec
70
+ - sig/numo/libsvm.rbs
125
71
  homepage: https://github.com/yoshoku/numo-libsvm
126
72
  licenses:
127
73
  - BSD-3-Clause
@@ -144,8 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
90
  - !ruby/object:Gem::Version
145
91
  version: '0'
146
92
  requirements: []
147
- rubyforge_project:
148
- rubygems_version: 2.6.14.4
93
+ rubygems_version: 3.2.21
149
94
  signing_key:
150
95
  specification_version: 4
151
96
  summary: Numo::Libsvm is a Ruby gem binding to the LIBSVM library. Numo::Libsvm makes
data/.travis.yml DELETED
@@ -1,13 +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
-
12
- before_install:
13
- - gem install bundler -v 2.0.2