numo-liblinear 1.1.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +14 -0
  3. data/LICENSE.txt +1 -1
  4. data/README.md +1 -6
  5. data/ext/numo/liblinear/extconf.rb +8 -14
  6. data/ext/numo/liblinear/liblinearext.cpp +215 -0
  7. data/ext/numo/liblinear/liblinearext.hpp +636 -0
  8. data/ext/numo/liblinear/src/COPYRIGHT +31 -0
  9. data/ext/numo/liblinear/{liblinear → src}/blas/blas.h +0 -0
  10. data/ext/numo/liblinear/{liblinear → src}/blas/blasp.h +0 -0
  11. data/ext/numo/liblinear/{liblinear → src}/blas/daxpy.c +0 -0
  12. data/ext/numo/liblinear/{liblinear → src}/blas/ddot.c +0 -0
  13. data/ext/numo/liblinear/{liblinear → src}/blas/dnrm2.c +0 -0
  14. data/ext/numo/liblinear/{liblinear → src}/blas/dscal.c +0 -0
  15. data/ext/numo/liblinear/{liblinear → src}/linear.cpp +0 -0
  16. data/ext/numo/liblinear/{liblinear → src}/linear.h +0 -0
  17. data/ext/numo/liblinear/{liblinear → src}/newton.cpp +0 -0
  18. data/ext/numo/liblinear/{liblinear → src}/newton.h +0 -0
  19. data/lib/numo/liblinear/version.rb +1 -1
  20. data/sig/numo/liblinear.rbs +52 -0
  21. metadata +19 -91
  22. data/.github/workflows/build.yml +0 -27
  23. data/.gitignore +0 -20
  24. data/.gitmodules +0 -3
  25. data/.rspec +0 -3
  26. data/CODE_OF_CONDUCT.md +0 -74
  27. data/Gemfile +0 -4
  28. data/Rakefile +0 -15
  29. data/ext/numo/liblinear/converter.c +0 -133
  30. data/ext/numo/liblinear/converter.h +0 -18
  31. data/ext/numo/liblinear/liblinearext.c +0 -576
  32. data/ext/numo/liblinear/liblinearext.h +0 -17
  33. data/ext/numo/liblinear/model.c +0 -48
  34. data/ext/numo/liblinear/model.h +0 -15
  35. data/ext/numo/liblinear/parameter.c +0 -105
  36. data/ext/numo/liblinear/parameter.h +0 -15
  37. data/ext/numo/liblinear/problem.c +0 -92
  38. data/ext/numo/liblinear/problem.h +0 -12
  39. data/ext/numo/liblinear/solver_type.c +0 -36
  40. data/ext/numo/liblinear/solver_type.h +0 -9
  41. data/numo-liblinear.gemspec +0 -54
@@ -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.2
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - yoshoku
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-23 00:00:00.000000000 Z
11
+ date: 2022-01-09 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,42 +35,26 @@ extensions:
91
35
  - ext/numo/liblinear/extconf.rb
92
36
  extra_rdoc_files: []
93
37
  files:
94
- - ".github/workflows/build.yml"
95
- - ".gitignore"
96
- - ".gitmodules"
97
- - ".rspec"
98
38
  - CHANGELOG.md
99
- - CODE_OF_CONDUCT.md
100
- - Gemfile
101
39
  - LICENSE.txt
102
40
  - README.md
103
- - Rakefile
104
- - ext/numo/liblinear/converter.c
105
- - ext/numo/liblinear/converter.h
106
41
  - ext/numo/liblinear/extconf.rb
107
- - ext/numo/liblinear/liblinear/blas/blas.h
108
- - ext/numo/liblinear/liblinear/blas/blasp.h
109
- - ext/numo/liblinear/liblinear/blas/daxpy.c
110
- - ext/numo/liblinear/liblinear/blas/ddot.c
111
- - ext/numo/liblinear/liblinear/blas/dnrm2.c
112
- - ext/numo/liblinear/liblinear/blas/dscal.c
113
- - ext/numo/liblinear/liblinear/linear.cpp
114
- - ext/numo/liblinear/liblinear/linear.h
115
- - ext/numo/liblinear/liblinear/newton.cpp
116
- - ext/numo/liblinear/liblinear/newton.h
117
- - ext/numo/liblinear/liblinearext.c
118
- - ext/numo/liblinear/liblinearext.h
119
- - ext/numo/liblinear/model.c
120
- - ext/numo/liblinear/model.h
121
- - ext/numo/liblinear/parameter.c
122
- - ext/numo/liblinear/parameter.h
123
- - ext/numo/liblinear/problem.c
124
- - ext/numo/liblinear/problem.h
125
- - ext/numo/liblinear/solver_type.c
126
- - ext/numo/liblinear/solver_type.h
42
+ - ext/numo/liblinear/liblinearext.cpp
43
+ - ext/numo/liblinear/liblinearext.hpp
44
+ - ext/numo/liblinear/src/COPYRIGHT
45
+ - ext/numo/liblinear/src/blas/blas.h
46
+ - ext/numo/liblinear/src/blas/blasp.h
47
+ - ext/numo/liblinear/src/blas/daxpy.c
48
+ - ext/numo/liblinear/src/blas/ddot.c
49
+ - ext/numo/liblinear/src/blas/dnrm2.c
50
+ - ext/numo/liblinear/src/blas/dscal.c
51
+ - ext/numo/liblinear/src/linear.cpp
52
+ - ext/numo/liblinear/src/linear.h
53
+ - ext/numo/liblinear/src/newton.cpp
54
+ - ext/numo/liblinear/src/newton.h
127
55
  - lib/numo/liblinear.rb
128
56
  - lib/numo/liblinear/version.rb
129
- - numo-liblinear.gemspec
57
+ - sig/numo/liblinear.rbs
130
58
  homepage: https://github.com/yoshoku/numo-liblinear
131
59
  licenses:
132
60
  - BSD-3-Clause
@@ -149,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
77
  - !ruby/object:Gem::Version
150
78
  version: '0'
151
79
  requirements: []
152
- rubygems_version: 3.2.3
80
+ rubygems_version: 3.3.3
153
81
  signing_key:
154
82
  specification_version: 4
155
83
  summary: Numo::Liblinear is a Ruby gem binding to the LIBLINEAR library. Numo::Liblinear
@@ -1,27 +0,0 @@
1
- name: build
2
-
3
- on: [push, pull_request]
4
-
5
- jobs:
6
- build:
7
- runs-on: ubuntu-latest
8
- strategy:
9
- matrix:
10
- ruby: [ '2.5', '2.6', '2.7' ]
11
- steps:
12
- - uses: actions/checkout@v2
13
- - name: Checkout submodule
14
- shell: bash
15
- run: |
16
- auth_header="$(git config --local --get http.https://github.com/.extraheader)"
17
- git submodule sync --recursive
18
- git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive --depth=1
19
- - name: Set up Ruby ${{ matrix.ruby }}
20
- uses: actions/setup-ruby@v1
21
- with:
22
- ruby-version: ${{ matrix.ruby }}
23
- - name: Build and test with Rake
24
- run: |
25
- gem install bundler
26
- bundle install --jobs 4 --retry 3
27
- bundle exec rake
data/.gitignore DELETED
@@ -1,20 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
10
- /bin/
11
-
12
- # rspec failure tracking
13
- .rspec_status
14
-
15
- *.swp
16
- *.bundle
17
- mkmf.log
18
- tags
19
- .DS_Store
20
- .ruby-version
data/.gitmodules DELETED
@@ -1,3 +0,0 @@
1
- [submodule "ext/numo/liblinear/liblinear"]
2
- path = ext/numo/liblinear/liblinear
3
- url = https://github.com/cjlin1/liblinear
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --format documentation
2
- --color
3
- --require spec_helper
data/CODE_OF_CONDUCT.md DELETED
@@ -1,74 +0,0 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- In the interest of fostering an open and welcoming environment, we as
6
- contributors and maintainers pledge to making participation in our project and
7
- our community a harassment-free experience for everyone, regardless of age, body
8
- size, disability, ethnicity, gender identity and expression, level of experience,
9
- nationality, personal appearance, race, religion, or sexual identity and
10
- orientation.
11
-
12
- ## Our Standards
13
-
14
- Examples of behavior that contributes to creating a positive environment
15
- include:
16
-
17
- * Using welcoming and inclusive language
18
- * Being respectful of differing viewpoints and experiences
19
- * Gracefully accepting constructive criticism
20
- * Focusing on what is best for the community
21
- * Showing empathy towards other community members
22
-
23
- Examples of unacceptable behavior by participants include:
24
-
25
- * The use of sexualized language or imagery and unwelcome sexual attention or
26
- advances
27
- * Trolling, insulting/derogatory comments, and personal or political attacks
28
- * Public or private harassment
29
- * Publishing others' private information, such as a physical or electronic
30
- address, without explicit permission
31
- * Other conduct which could reasonably be considered inappropriate in a
32
- professional setting
33
-
34
- ## Our Responsibilities
35
-
36
- Project maintainers are responsible for clarifying the standards of acceptable
37
- behavior and are expected to take appropriate and fair corrective action in
38
- response to any instances of unacceptable behavior.
39
-
40
- Project maintainers have the right and responsibility to remove, edit, or
41
- reject comments, commits, code, wiki edits, issues, and other contributions
42
- that are not aligned to this Code of Conduct, or to ban temporarily or
43
- permanently any contributor for other behaviors that they deem inappropriate,
44
- threatening, offensive, or harmful.
45
-
46
- ## Scope
47
-
48
- This Code of Conduct applies both within project spaces and in public spaces
49
- when an individual is representing the project or its community. Examples of
50
- representing a project or community include using an official project e-mail
51
- address, posting via an official social media account, or acting as an appointed
52
- representative at an online or offline event. Representation of a project may be
53
- further defined and clarified by project maintainers.
54
-
55
- ## Enforcement
56
-
57
- Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
- reported by contacting the project team at yoshoku@outlook.com. All
59
- complaints will be reviewed and investigated and will result in a response that
60
- is deemed necessary and appropriate to the circumstances. The project team is
61
- obligated to maintain confidentiality with regard to the reporter of an incident.
62
- Further details of specific enforcement policies may be posted separately.
63
-
64
- Project maintainers who do not follow or enforce the Code of Conduct in good
65
- faith may face temporary or permanent repercussions as determined by other
66
- members of the project's leadership.
67
-
68
- ## Attribution
69
-
70
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
- available at [http://contributor-covenant.org/version/1/4][version]
72
-
73
- [homepage]: http://contributor-covenant.org
74
- [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- # Specify your gem's dependencies in numo-liblinear.gemspec
4
- gemspec
data/Rakefile DELETED
@@ -1,15 +0,0 @@
1
- require 'bundler/gem_tasks'
2
- require 'rspec/core/rake_task'
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- require 'rake/extensiontask'
7
-
8
- task :build => :compile
9
-
10
- Rake::ExtensionTask.new('liblinearext') do |ext|
11
- ext.ext_dir = 'ext/numo/liblinear'
12
- ext.lib_dir = 'lib/numo/liblinear'
13
- end
14
-
15
- task :default => [:clobber, :compile, :spec]
@@ -1,133 +0,0 @@
1
- #include "converter.h"
2
-
3
- VALUE int_vec_to_nary(int* const arr, int const size)
4
- {
5
- int i;
6
- size_t shape[1] = { size };
7
- VALUE v = rb_narray_new(numo_cInt32, 1, shape);
8
- int32_t* vp = (int32_t*)na_get_pointer_for_write(v);
9
- for (i = 0; i < size; i++) { vp[i] = (int32_t)arr[i]; }
10
- return v;
11
- }
12
-
13
- int* nary_to_int_vec(VALUE vec_val)
14
- {
15
- int i;
16
- int n_elements;
17
- narray_t* vec_nary;
18
- int32_t* vec_pt;
19
- int* vec;
20
-
21
- if (vec_val == Qnil) return NULL;
22
-
23
- GetNArray(vec_val, vec_nary);
24
- n_elements = (int)NA_SHAPE(vec_nary)[0];
25
-
26
- vec = ALLOC_N(int, n_elements);
27
- vec_pt = (int32_t*)na_get_pointer_for_read(vec_val);
28
- for (i = 0; i < n_elements; i++) { vec[i] = (int)vec_pt[i]; }
29
-
30
- RB_GC_GUARD(vec_val);
31
-
32
- return vec;
33
- }
34
-
35
- VALUE dbl_vec_to_nary(double* const arr, int const size)
36
- {
37
- int i;
38
- size_t shape[1] = { size };
39
- VALUE v = rb_narray_new(numo_cDFloat, 1, shape);
40
- double* vp = (double*)na_get_pointer_for_write(v);
41
- for (i = 0; i < size; i++) { vp[i] = arr[i]; }
42
- return v;
43
- }
44
-
45
- double* nary_to_dbl_vec(VALUE vec_val)
46
- {
47
- int n_elements;
48
- narray_t* vec_nary;
49
- double* vec_pt;
50
- double* vec;
51
-
52
- if (vec_val == Qnil) return NULL;
53
-
54
- GetNArray(vec_val, vec_nary);
55
- n_elements = (int)NA_SHAPE(vec_nary)[0];
56
-
57
- vec = ALLOC_N(double, n_elements);
58
- vec_pt = (double*)na_get_pointer_for_read(vec_val);
59
- memcpy(vec, vec_pt, n_elements * sizeof(double));
60
-
61
- RB_GC_GUARD(vec_val);
62
-
63
- return vec;
64
- }
65
-
66
- VALUE dbl_mat_to_nary(double** const mat, int const n_rows, int const n_cols)
67
- {
68
- int i, j;
69
- size_t shape[2] = { n_rows, n_cols };
70
- VALUE v = rb_narray_new(numo_cDFloat, 2, shape);
71
- double* vp = (double*)na_get_pointer_for_write(v);
72
-
73
- for (i = 0; i < n_rows; i++) {
74
- for (j = 0; j < n_cols; j++) {
75
- vp[i * n_cols + j] = mat[i][j];
76
- }
77
- }
78
-
79
- return v;
80
- }
81
-
82
- double** nary_to_dbl_mat(VALUE mat_val)
83
- {
84
- int i, j;
85
- int n_rows, n_cols;
86
- narray_t* mat_nary;
87
- double* mat_pt;
88
- double** mat;
89
-
90
- if (mat_val == Qnil) return NULL;
91
-
92
- GetNArray(mat_val, mat_nary);
93
- n_rows = (int)NA_SHAPE(mat_nary)[0];
94
- n_cols = (int)NA_SHAPE(mat_nary)[1];
95
-
96
- mat_pt = (double*)na_get_pointer_for_read(mat_val);
97
- mat = ALLOC_N(double*, n_rows);
98
- for (i = 0; i < n_rows; i++) {
99
- mat[i] = ALLOC_N(double, n_cols);
100
- for (j = 0; j < n_cols; j++) {
101
- mat[i][j] = mat_pt[i * n_cols + j];
102
- }
103
- }
104
-
105
- RB_GC_GUARD(mat_val);
106
-
107
- return mat;
108
- }
109
-
110
- struct feature_node* dbl_vec_to_node(double* const arr, int const size)
111
- {
112
- int i, j;
113
- int n_nonzero_elements;
114
- struct feature_node* node;
115
-
116
- n_nonzero_elements = 0;
117
- for (i = 0; i < size; i++) {
118
- if (arr[i] != 0.0) n_nonzero_elements++;
119
- }
120
-
121
- node = ALLOC_N(struct feature_node, n_nonzero_elements + 1);
122
- for (i = 0, j = 0; i < size; i++) {
123
- if (arr[i] != 0.0) {
124
- node[j].index = i + 1;
125
- node[j].value = arr[i];
126
- j++;
127
- }
128
- }
129
- node[n_nonzero_elements].index = -1;
130
- node[n_nonzero_elements].value = 0.0;
131
-
132
- return node;
133
- }
@@ -1,18 +0,0 @@
1
- #ifndef NUMO_LIBLINEAR_CONVERTER_H
2
- #define NUMO_LIBLINEAR_CONVERTER_H 1
3
-
4
- #include <string.h>
5
- #include <ruby.h>
6
- #include <linear.h>
7
- #include <numo/narray.h>
8
- #include <numo/template.h>
9
-
10
- VALUE int_vec_to_nary(int* const arr, int const size);
11
- int* nary_to_int_vec(VALUE vec_val);
12
- VALUE dbl_vec_to_nary(double* const arr, int const size);
13
- double* nary_to_dbl_vec(VALUE vec_val);
14
- VALUE dbl_mat_to_nary(double** const mat, int const n_rows, int const n_cols);
15
- double** nary_to_dbl_mat(VALUE mat_val);
16
- struct feature_node* dbl_vec_to_node(double* const arr, int const size);
17
-
18
- #endif /* NUMO_LIBLINEAR_CONVERTER_H */