numo-libsvm 1.1.1 → 2.0.1
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 +4 -4
- data/CHANGELOG.md +12 -0
- data/LICENSE.txt +1 -1
- data/README.md +1 -5
- data/ext/numo/libsvm/extconf.rb +6 -16
- data/ext/numo/libsvm/libsvmext.cpp +220 -0
- data/ext/numo/libsvm/libsvmext.hpp +715 -0
- data/ext/numo/libsvm/src/COPYRIGHT +31 -0
- data/ext/numo/libsvm/{libsvm → src}/svm.cpp +0 -0
- data/ext/numo/libsvm/{libsvm → src}/svm.h +0 -0
- data/lib/numo/libsvm/version.rb +1 -1
- metadata +12 -32
- data/.github/workflows/build.yml +0 -28
- data/.gitignore +0 -20
- data/.gitmodules +0 -3
- data/.rspec +0 -3
- data/CODE_OF_CONDUCT.md +0 -74
- data/Gemfile +0 -11
- data/Rakefile +0 -15
- data/Steepfile +0 -20
- data/ext/numo/libsvm/converter.c +0 -204
- data/ext/numo/libsvm/converter.h +0 -20
- data/ext/numo/libsvm/kernel_type.c +0 -22
- data/ext/numo/libsvm/kernel_type.h +0 -9
- data/ext/numo/libsvm/libsvmext.c +0 -578
- data/ext/numo/libsvm/libsvmext.h +0 -18
- data/ext/numo/libsvm/svm_model.c +0 -89
- data/ext/numo/libsvm/svm_model.h +0 -15
- data/ext/numo/libsvm/svm_parameter.c +0 -88
- data/ext/numo/libsvm/svm_parameter.h +0 -15
- data/ext/numo/libsvm/svm_problem.c +0 -90
- data/ext/numo/libsvm/svm_problem.h +0 -12
- data/ext/numo/libsvm/svm_type.c +0 -22
- data/ext/numo/libsvm/svm_type.h +0 -9
- data/numo-libsvm.gemspec +0 -50
- data/sig/patch.rbs +0 -8
@@ -0,0 +1,31 @@
|
|
1
|
+
|
2
|
+
Copyright (c) 2000-2019 Chih-Chung Chang and Chih-Jen Lin
|
3
|
+
All rights reserved.
|
4
|
+
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
6
|
+
modification, are permitted provided that the following conditions
|
7
|
+
are met:
|
8
|
+
|
9
|
+
1. Redistributions of source code must retain the above copyright
|
10
|
+
notice, this list of conditions and the following disclaimer.
|
11
|
+
|
12
|
+
2. Redistributions in binary form must reproduce the above copyright
|
13
|
+
notice, this list of conditions and the following disclaimer in the
|
14
|
+
documentation and/or other materials provided with the distribution.
|
15
|
+
|
16
|
+
3. Neither name of copyright holders nor the names of its contributors
|
17
|
+
may be used to endorse or promote products derived from this software
|
18
|
+
without specific prior written permission.
|
19
|
+
|
20
|
+
|
21
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
22
|
+
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
23
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
24
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
|
25
|
+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
26
|
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
27
|
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
28
|
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
29
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
30
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
31
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
File without changes
|
File without changes
|
data/lib/numo/libsvm/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: numo-libsvm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- yoshoku
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: numo-narray
|
@@ -36,39 +36,18 @@ extensions:
|
|
36
36
|
- ext/numo/libsvm/extconf.rb
|
37
37
|
extra_rdoc_files: []
|
38
38
|
files:
|
39
|
-
- ".github/workflows/build.yml"
|
40
|
-
- ".gitignore"
|
41
|
-
- ".gitmodules"
|
42
|
-
- ".rspec"
|
43
39
|
- CHANGELOG.md
|
44
|
-
- CODE_OF_CONDUCT.md
|
45
|
-
- Gemfile
|
46
40
|
- LICENSE.txt
|
47
41
|
- README.md
|
48
|
-
- Rakefile
|
49
|
-
- Steepfile
|
50
|
-
- ext/numo/libsvm/converter.c
|
51
|
-
- ext/numo/libsvm/converter.h
|
52
42
|
- ext/numo/libsvm/extconf.rb
|
53
|
-
- ext/numo/libsvm/
|
54
|
-
- ext/numo/libsvm/
|
55
|
-
- ext/numo/libsvm/
|
56
|
-
- ext/numo/libsvm/
|
57
|
-
- ext/numo/libsvm/
|
58
|
-
- ext/numo/libsvm/libsvmext.h
|
59
|
-
- ext/numo/libsvm/svm_model.c
|
60
|
-
- ext/numo/libsvm/svm_model.h
|
61
|
-
- ext/numo/libsvm/svm_parameter.c
|
62
|
-
- ext/numo/libsvm/svm_parameter.h
|
63
|
-
- ext/numo/libsvm/svm_problem.c
|
64
|
-
- ext/numo/libsvm/svm_problem.h
|
65
|
-
- ext/numo/libsvm/svm_type.c
|
66
|
-
- ext/numo/libsvm/svm_type.h
|
43
|
+
- ext/numo/libsvm/libsvmext.cpp
|
44
|
+
- ext/numo/libsvm/libsvmext.hpp
|
45
|
+
- ext/numo/libsvm/src/COPYRIGHT
|
46
|
+
- ext/numo/libsvm/src/svm.cpp
|
47
|
+
- ext/numo/libsvm/src/svm.h
|
67
48
|
- lib/numo/libsvm.rb
|
68
49
|
- lib/numo/libsvm/version.rb
|
69
|
-
- numo-libsvm.gemspec
|
70
50
|
- sig/numo/libsvm.rbs
|
71
|
-
- sig/patch.rbs
|
72
51
|
homepage: https://github.com/yoshoku/numo-libsvm
|
73
52
|
licenses:
|
74
53
|
- BSD-3-Clause
|
@@ -76,7 +55,8 @@ metadata:
|
|
76
55
|
homepage_uri: https://github.com/yoshoku/numo-libsvm
|
77
56
|
source_code_uri: https://github.com/yoshoku/numo-libsvm
|
78
57
|
documentation_uri: https://yoshoku.github.io/numo-libsvm/doc/
|
79
|
-
|
58
|
+
rubygems_mfa_required: 'true'
|
59
|
+
post_install_message:
|
80
60
|
rdoc_options: []
|
81
61
|
require_paths:
|
82
62
|
- lib
|
@@ -91,8 +71,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
71
|
- !ruby/object:Gem::Version
|
92
72
|
version: '0'
|
93
73
|
requirements: []
|
94
|
-
rubygems_version: 3.2.
|
95
|
-
signing_key:
|
74
|
+
rubygems_version: 3.2.33
|
75
|
+
signing_key:
|
96
76
|
specification_version: 4
|
97
77
|
summary: Numo::Libsvm is a Ruby gem binding to the LIBSVM library. Numo::Libsvm makes
|
98
78
|
to use the LIBSVM functions with dataset represented by Numo::NArray.
|
data/.github/workflows/build.yml
DELETED
@@ -1,28 +0,0 @@
|
|
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: actions/setup-ruby@v1
|
22
|
-
with:
|
23
|
-
ruby-version: ${{ matrix.ruby }}
|
24
|
-
- name: Build and test with Rake
|
25
|
-
run: |
|
26
|
-
gem install --no-document bundler
|
27
|
-
bundle install --jobs 4 --retry 3
|
28
|
-
bundle exec rake
|
data/.gitignore
DELETED
data/.gitmodules
DELETED
data/.rspec
DELETED
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
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('libsvmext') do |ext|
|
11
|
-
ext.ext_dir = 'ext/numo/libsvm'
|
12
|
-
ext.lib_dir = 'lib/numo/libsvm'
|
13
|
-
end
|
14
|
-
|
15
|
-
task :default => [:clobber, :compile, :spec]
|
data/Steepfile
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
target :lib do
|
2
|
-
signature "sig"
|
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
|
data/ext/numo/libsvm/converter.c
DELETED
@@ -1,204 +0,0 @@
|
|
1
|
-
|
2
|
-
#include "converter.h"
|
3
|
-
|
4
|
-
VALUE int_vec_to_nary(int* const arr, int const size)
|
5
|
-
{
|
6
|
-
int i;
|
7
|
-
size_t shape[1] = { size };
|
8
|
-
VALUE v = rb_narray_new(numo_cInt32, 1, shape);
|
9
|
-
int32_t* vp = (int32_t*)na_get_pointer_for_write(v);
|
10
|
-
for (i = 0; i < size; i++) { vp[i] = (int32_t)arr[i]; }
|
11
|
-
return v;
|
12
|
-
}
|
13
|
-
|
14
|
-
int* nary_to_int_vec(VALUE vec_val)
|
15
|
-
{
|
16
|
-
int i;
|
17
|
-
int n_elements;
|
18
|
-
narray_t* vec_nary;
|
19
|
-
int32_t* vec_pt;
|
20
|
-
int* vec;
|
21
|
-
|
22
|
-
if (vec_val == Qnil) return NULL;
|
23
|
-
|
24
|
-
GetNArray(vec_val, vec_nary);
|
25
|
-
n_elements = (int)NA_SHAPE(vec_nary)[0];
|
26
|
-
|
27
|
-
vec = ALLOC_N(int, n_elements);
|
28
|
-
vec_pt = (int32_t*)na_get_pointer_for_read(vec_val);
|
29
|
-
for (i = 0; i < n_elements; i++) { vec[i] = (int)vec_pt[i]; }
|
30
|
-
|
31
|
-
RB_GC_GUARD(vec_val);
|
32
|
-
|
33
|
-
return vec;
|
34
|
-
}
|
35
|
-
|
36
|
-
VALUE dbl_vec_to_nary(double* const arr, int const size)
|
37
|
-
{
|
38
|
-
int i;
|
39
|
-
size_t shape[1] = { size };
|
40
|
-
VALUE v = rb_narray_new(numo_cDFloat, 1, shape);
|
41
|
-
double* vp = (double*)na_get_pointer_for_write(v);
|
42
|
-
for (i = 0; i < size; i++) { vp[i] = arr[i]; }
|
43
|
-
return v;
|
44
|
-
}
|
45
|
-
|
46
|
-
double* nary_to_dbl_vec(VALUE vec_val)
|
47
|
-
{
|
48
|
-
int n_elements;
|
49
|
-
narray_t* vec_nary;
|
50
|
-
double* vec_pt;
|
51
|
-
double* vec;
|
52
|
-
|
53
|
-
if (vec_val == Qnil) return NULL;
|
54
|
-
|
55
|
-
GetNArray(vec_val, vec_nary);
|
56
|
-
n_elements = (int)NA_SHAPE(vec_nary)[0];
|
57
|
-
|
58
|
-
vec = ALLOC_N(double, n_elements);
|
59
|
-
vec_pt = (double*)na_get_pointer_for_read(vec_val);
|
60
|
-
memcpy(vec, vec_pt, n_elements * sizeof(double));
|
61
|
-
|
62
|
-
RB_GC_GUARD(vec_val);
|
63
|
-
|
64
|
-
return vec;
|
65
|
-
}
|
66
|
-
|
67
|
-
VALUE dbl_mat_to_nary(double** const mat, int const n_rows, int const n_cols)
|
68
|
-
{
|
69
|
-
int i, j;
|
70
|
-
size_t shape[2] = { n_rows, n_cols };
|
71
|
-
VALUE v = rb_narray_new(numo_cDFloat, 2, shape);
|
72
|
-
double* vp = (double*)na_get_pointer_for_write(v);
|
73
|
-
|
74
|
-
for (i = 0; i < n_rows; i++) {
|
75
|
-
for (j = 0; j < n_cols; j++) {
|
76
|
-
vp[i * n_cols + j] = mat[i][j];
|
77
|
-
}
|
78
|
-
}
|
79
|
-
|
80
|
-
return v;
|
81
|
-
}
|
82
|
-
|
83
|
-
double** nary_to_dbl_mat(VALUE mat_val)
|
84
|
-
{
|
85
|
-
int i, j;
|
86
|
-
int n_rows, n_cols;
|
87
|
-
narray_t* mat_nary;
|
88
|
-
double* mat_pt;
|
89
|
-
double** mat;
|
90
|
-
|
91
|
-
if (mat_val == Qnil) return NULL;
|
92
|
-
|
93
|
-
GetNArray(mat_val, mat_nary);
|
94
|
-
n_rows = (int)NA_SHAPE(mat_nary)[0];
|
95
|
-
n_cols = (int)NA_SHAPE(mat_nary)[1];
|
96
|
-
|
97
|
-
mat_pt = (double*)na_get_pointer_for_read(mat_val);
|
98
|
-
mat = ALLOC_N(double*, n_rows);
|
99
|
-
for (i = 0; i < n_rows; i++) {
|
100
|
-
mat[i] = ALLOC_N(double, n_cols);
|
101
|
-
for (j = 0; j < n_cols; j++) {
|
102
|
-
mat[i][j] = mat_pt[i * n_cols + j];
|
103
|
-
}
|
104
|
-
}
|
105
|
-
|
106
|
-
RB_GC_GUARD(mat_val);
|
107
|
-
|
108
|
-
return mat;
|
109
|
-
}
|
110
|
-
|
111
|
-
VALUE svm_nodes_to_nary(struct svm_node** const support_vecs, const int n_support_vecs)
|
112
|
-
{
|
113
|
-
int i, j;
|
114
|
-
int n_dimensions = 0;
|
115
|
-
size_t shape[2] = { n_support_vecs, 1 };
|
116
|
-
VALUE v;
|
117
|
-
double* vp;
|
118
|
-
|
119
|
-
for (i = 0; i < n_support_vecs; i++) {
|
120
|
-
for (j = 0; support_vecs[i][j].index != -1; j++) {
|
121
|
-
if (n_dimensions < support_vecs[i][j].index) {
|
122
|
-
n_dimensions = support_vecs[i][j].index;
|
123
|
-
}
|
124
|
-
}
|
125
|
-
}
|
126
|
-
|
127
|
-
shape[1] = n_dimensions;
|
128
|
-
v = rb_narray_new(numo_cDFloat, 2, shape);
|
129
|
-
vp = (double*)na_get_pointer_for_write(v);
|
130
|
-
memset(vp, 0, n_support_vecs * n_dimensions * sizeof(double));
|
131
|
-
|
132
|
-
for (i = 0; i < n_support_vecs; i++) {
|
133
|
-
for (j = 0; support_vecs[i][j].index != -1; j++) {
|
134
|
-
vp[i * n_dimensions + support_vecs[i][j].index - 1] = support_vecs[i][j].value;
|
135
|
-
}
|
136
|
-
}
|
137
|
-
|
138
|
-
return v;
|
139
|
-
}
|
140
|
-
|
141
|
-
struct svm_node** nary_to_svm_nodes(VALUE nary_val)
|
142
|
-
{
|
143
|
-
int i, j, k;
|
144
|
-
int n_rows, n_cols, n_nonzero_cols;
|
145
|
-
narray_t* nary;
|
146
|
-
double* nary_pt;
|
147
|
-
struct svm_node** support_vecs;
|
148
|
-
|
149
|
-
if (nary_val == Qnil) return NULL;
|
150
|
-
|
151
|
-
GetNArray(nary_val, nary);
|
152
|
-
n_rows = (int)NA_SHAPE(nary)[0];
|
153
|
-
n_cols = (int)NA_SHAPE(nary)[1];
|
154
|
-
|
155
|
-
nary_pt = (double*)na_get_pointer_for_read(nary_val);
|
156
|
-
support_vecs = ALLOC_N(struct svm_node*, n_rows);
|
157
|
-
for (i = 0; i < n_rows; i++) {
|
158
|
-
n_nonzero_cols = 0;
|
159
|
-
for (j = 0; j < n_cols; j++) {
|
160
|
-
if (nary_pt[i * n_cols + j] != 0) {
|
161
|
-
n_nonzero_cols++;
|
162
|
-
}
|
163
|
-
}
|
164
|
-
support_vecs[i] = ALLOC_N(struct svm_node, n_nonzero_cols + 1);
|
165
|
-
for (j = 0, k = 0; j < n_cols; j++) {
|
166
|
-
if (nary_pt[i * n_cols + j] != 0) {
|
167
|
-
support_vecs[i][k].index = j + 1;
|
168
|
-
support_vecs[i][k].value = nary_pt[i * n_cols + j];
|
169
|
-
k++;
|
170
|
-
}
|
171
|
-
}
|
172
|
-
support_vecs[i][n_nonzero_cols].index = -1;
|
173
|
-
support_vecs[i][n_nonzero_cols].value = 0.0;
|
174
|
-
}
|
175
|
-
|
176
|
-
RB_GC_GUARD(nary_val);
|
177
|
-
|
178
|
-
return support_vecs;
|
179
|
-
}
|
180
|
-
|
181
|
-
struct svm_node* dbl_vec_to_svm_node(double* const arr, int const size)
|
182
|
-
{
|
183
|
-
int i, j;
|
184
|
-
int n_nonzero_elements;
|
185
|
-
struct svm_node* node;
|
186
|
-
|
187
|
-
n_nonzero_elements = 0;
|
188
|
-
for (i = 0; i < size; i++) {
|
189
|
-
if (arr[i] != 0.0) n_nonzero_elements++;
|
190
|
-
}
|
191
|
-
|
192
|
-
node = ALLOC_N(struct svm_node, n_nonzero_elements + 1);
|
193
|
-
for (i = 0, j = 0; i < size; i++) {
|
194
|
-
if (arr[i] != 0.0) {
|
195
|
-
node[j].index = i + 1;
|
196
|
-
node[j].value = arr[i];
|
197
|
-
j++;
|
198
|
-
}
|
199
|
-
}
|
200
|
-
node[n_nonzero_elements].index = -1;
|
201
|
-
node[n_nonzero_elements].value = 0.0;
|
202
|
-
|
203
|
-
return node;
|
204
|
-
}
|
data/ext/numo/libsvm/converter.h
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
#ifndef NUMO_LIBSVM_CONVERTER_H
|
2
|
-
#define NUMO_LIBSVM_CONVERTER_H 1
|
3
|
-
|
4
|
-
#include <string.h>
|
5
|
-
#include <svm.h>
|
6
|
-
#include <ruby.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
|
-
VALUE svm_nodes_to_nary(struct svm_node** const support_vecs, const int n_support_vecs);
|
17
|
-
struct svm_node** nary_to_svm_nodes(VALUE nary_val);
|
18
|
-
struct svm_node* dbl_vec_to_svm_node(double* const arr, int const size);
|
19
|
-
|
20
|
-
#endif /* NUMO_LIBSVM_CONVERTER_H */
|
@@ -1,22 +0,0 @@
|
|
1
|
-
#include "kernel_type.h"
|
2
|
-
|
3
|
-
RUBY_EXTERN VALUE mLibsvm;
|
4
|
-
|
5
|
-
void rb_init_kernel_type_module()
|
6
|
-
{
|
7
|
-
/**
|
8
|
-
* Document-module: Numo::Libsvm::KernelType
|
9
|
-
* The module consisting of constants for kernel type that used for parameter of LIBSVM.
|
10
|
-
*/
|
11
|
-
VALUE mKernelType = rb_define_module_under(mLibsvm, "KernelType");
|
12
|
-
/* Linear kernel; u' * v */
|
13
|
-
rb_define_const(mKernelType, "LINEAR", INT2NUM(LINEAR));
|
14
|
-
/* Polynomial kernel; (gamma * u' * v + coef0)^degree */
|
15
|
-
rb_define_const(mKernelType, "POLY", INT2NUM(POLY));
|
16
|
-
/* RBF kernel; exp(-gamma * ||u - v||^2) */
|
17
|
-
rb_define_const(mKernelType, "RBF", INT2NUM(RBF));
|
18
|
-
/* Sigmoid kernel; tanh(gamma * u' * v + coef0) */
|
19
|
-
rb_define_const(mKernelType, "SIGMOID", INT2NUM(SIGMOID));
|
20
|
-
/* Precomputed kernel */
|
21
|
-
rb_define_const(mKernelType, "PRECOMPUTED", INT2NUM(PRECOMPUTED));
|
22
|
-
}
|