tomz-libsvm-ruby-swig 0.2.5 → 0.3.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.
- data/History.txt +2 -1
- data/Manifest.txt +2 -2
- data/{README.txt → README.rdoc} +7 -10
- data/Rakefile +6 -6
- data/ext/{svmc_wrap.cxx → libsvm_wrap.cxx} +51 -51
- data/lib/svm.rb +26 -2
- metadata +6 -7
data/History.txt
CHANGED
data/Manifest.txt
CHANGED
data/{README.txt → README.rdoc}
RENAMED
@@ -8,16 +8,13 @@
|
|
8
8
|
This is the Ruby port of the LIBSVM Python SWIG (Simplified Wrapper and
|
9
9
|
Interface Generator) interface.
|
10
10
|
|
11
|
-
A modified version of LIBSVM 2.
|
12
|
-
|
13
|
-
|
14
|
-
to expose additional data/parameters in the model object. You don't need your
|
15
|
-
own copy of SWIG to use this library - all needed files are generated using
|
16
|
-
SWIG already.
|
11
|
+
A slightly modified version of LIBSVM 2.89 is included, it allows turrning on/off
|
12
|
+
the debug log. You don't need your own copy of SWIG to use this library - all
|
13
|
+
needed files are generated using SWIG already.
|
17
14
|
|
18
15
|
Look for the README file in the ruby subdirectory for instructions.
|
19
16
|
The binaries included were built under Ubuntu Linux 2.6.24-23-generic,
|
20
|
-
you should run make under the libsvm-2.
|
17
|
+
you should run make under the libsvm-2.89 and libsvm-2.89/ruby
|
21
18
|
directories to regenerate the executables for your environment.
|
22
19
|
|
23
20
|
== INSTALL:
|
@@ -52,7 +49,7 @@ Segaran's "Programming Collective Intelligence" book):
|
|
52
49
|
== AUTHOR:
|
53
50
|
|
54
51
|
Tom Zeng
|
55
|
-
http://www.tomzconsulting.com
|
56
|
-
http://www.linkedin.com/in/tomzeng
|
57
|
-
tom.z.zeng _at_ gmail _dot_ com
|
52
|
+
- http://www.tomzconsulting.com
|
53
|
+
- http://www.linkedin.com/in/tomzeng
|
54
|
+
- tom.z.zeng _at_ gmail _dot_ com
|
58
55
|
|
data/Rakefile
CHANGED
@@ -5,7 +5,7 @@ task :default => ["sync_files","make_gem"]
|
|
5
5
|
|
6
6
|
EXT = "ext/svm?.#{Hoe::DLEXT}"
|
7
7
|
|
8
|
-
Hoe.new('libsvm-ruby-swig', '0.
|
8
|
+
Hoe.new('libsvm-ruby-swig', '0.3.1') do |p|
|
9
9
|
p.author = 'Tom Zeng'
|
10
10
|
p.email = 'tom.z.zeng@gmail.com'
|
11
11
|
p.url = 'http://www.tomzconsulting.com'
|
@@ -18,7 +18,7 @@ end
|
|
18
18
|
|
19
19
|
task :make_gem => EXT
|
20
20
|
|
21
|
-
file EXT => ["ext/extconf.rb", "ext/
|
21
|
+
file EXT => ["ext/extconf.rb", "ext/libsvm_wrap.cxx", "ext/svm.cpp", "ext/svm.h"] do
|
22
22
|
Dir.chdir "ext" do
|
23
23
|
ruby "extconf.rb"
|
24
24
|
sh "make"
|
@@ -26,10 +26,10 @@ file EXT => ["ext/extconf.rb", "ext/svmc_wrap.cxx", "ext/svm.cpp", "ext/svm.h"]
|
|
26
26
|
end
|
27
27
|
|
28
28
|
task :sync_files do
|
29
|
-
cp "libsvm-2.
|
30
|
-
cp "libsvm-2.
|
31
|
-
cp "libsvm-2.
|
32
|
-
cp "libsvm-2.
|
29
|
+
cp "libsvm-2.89/svm.h","ext/"
|
30
|
+
cp "libsvm-2.89/svm.cpp","ext/"
|
31
|
+
cp "libsvm-2.89/ruby/libsvm_wrap.cxx","ext/"
|
32
|
+
cp "libsvm-2.89/ruby/svm.rb","lib/"
|
33
33
|
end
|
34
34
|
|
35
35
|
task :test do
|
@@ -1816,10 +1816,10 @@ static swig_module_info swig_module = {swig_types, 8, 0, 0, 0, 0};
|
|
1816
1816
|
|
1817
1817
|
/* -------- TYPES TABLE (END) -------- */
|
1818
1818
|
|
1819
|
-
#define SWIG_init
|
1820
|
-
#define SWIG_name "
|
1819
|
+
#define SWIG_init Init_libsvm
|
1820
|
+
#define SWIG_name "Libsvm"
|
1821
1821
|
|
1822
|
-
static VALUE
|
1822
|
+
static VALUE mLibsvm;
|
1823
1823
|
|
1824
1824
|
#define SWIG_RUBY_THREAD_BEGIN_BLOCK
|
1825
1825
|
#define SWIG_RUBY_THREAD_END_BLOCK
|
@@ -4439,7 +4439,7 @@ SWIGEXPORT void Init_libsvm(void) {
|
|
4439
4439
|
size_t i;
|
4440
4440
|
|
4441
4441
|
SWIG_InitRuntime();
|
4442
|
-
|
4442
|
+
mLibsvm = rb_define_module("Libsvm");
|
4443
4443
|
|
4444
4444
|
SWIG_InitializeModule(0);
|
4445
4445
|
for (i = 0; i < swig_module.size; i++) {
|
@@ -4447,18 +4447,18 @@ SWIGEXPORT void Init_libsvm(void) {
|
|
4447
4447
|
}
|
4448
4448
|
|
4449
4449
|
SWIG_RubyInitializeTrackings();
|
4450
|
-
rb_define_const(
|
4451
|
-
rb_define_const(
|
4452
|
-
rb_define_const(
|
4453
|
-
rb_define_const(
|
4454
|
-
rb_define_const(
|
4455
|
-
rb_define_const(
|
4456
|
-
rb_define_const(
|
4457
|
-
rb_define_const(
|
4458
|
-
rb_define_const(
|
4459
|
-
rb_define_const(
|
4450
|
+
rb_define_const(mLibsvm, "C_SVC", SWIG_From_int(static_cast< int >(C_SVC)));
|
4451
|
+
rb_define_const(mLibsvm, "NU_SVC", SWIG_From_int(static_cast< int >(NU_SVC)));
|
4452
|
+
rb_define_const(mLibsvm, "ONE_CLASS", SWIG_From_int(static_cast< int >(ONE_CLASS)));
|
4453
|
+
rb_define_const(mLibsvm, "EPSILON_SVR", SWIG_From_int(static_cast< int >(EPSILON_SVR)));
|
4454
|
+
rb_define_const(mLibsvm, "NU_SVR", SWIG_From_int(static_cast< int >(NU_SVR)));
|
4455
|
+
rb_define_const(mLibsvm, "LINEAR", SWIG_From_int(static_cast< int >(LINEAR)));
|
4456
|
+
rb_define_const(mLibsvm, "POLY", SWIG_From_int(static_cast< int >(POLY)));
|
4457
|
+
rb_define_const(mLibsvm, "RBF", SWIG_From_int(static_cast< int >(RBF)));
|
4458
|
+
rb_define_const(mLibsvm, "SIGMOID", SWIG_From_int(static_cast< int >(SIGMOID)));
|
4459
|
+
rb_define_const(mLibsvm, "PRECOMPUTED", SWIG_From_int(static_cast< int >(PRECOMPUTED)));
|
4460
4460
|
|
4461
|
-
cSvm_parameter.klass = rb_define_class_under(
|
4461
|
+
cSvm_parameter.klass = rb_define_class_under(mLibsvm, "Svm_parameter", rb_cObject);
|
4462
4462
|
SWIG_TypeClientData(SWIGTYPE_p_svm_parameter, (void *) &cSvm_parameter);
|
4463
4463
|
rb_define_alloc_func(cSvm_parameter.klass, _wrap_svm_parameter_allocate);
|
4464
4464
|
rb_define_method(cSvm_parameter.klass, "initialize", VALUEFUNC(_wrap_new_svm_parameter), -1);
|
@@ -4496,7 +4496,7 @@ SWIGEXPORT void Init_libsvm(void) {
|
|
4496
4496
|
cSvm_parameter.destroy = (void (*)(void *)) free_svm_parameter;
|
4497
4497
|
cSvm_parameter.trackObjects = 0;
|
4498
4498
|
|
4499
|
-
cSvm_problem.klass = rb_define_class_under(
|
4499
|
+
cSvm_problem.klass = rb_define_class_under(mLibsvm, "Svm_problem", rb_cObject);
|
4500
4500
|
SWIG_TypeClientData(SWIGTYPE_p_svm_problem, (void *) &cSvm_problem);
|
4501
4501
|
rb_define_alloc_func(cSvm_problem.klass, _wrap_svm_problem_allocate);
|
4502
4502
|
rb_define_method(cSvm_problem.klass, "initialize", VALUEFUNC(_wrap_new_svm_problem), -1);
|
@@ -4509,40 +4509,40 @@ SWIGEXPORT void Init_libsvm(void) {
|
|
4509
4509
|
cSvm_problem.mark = 0;
|
4510
4510
|
cSvm_problem.destroy = (void (*)(void *)) free_svm_problem;
|
4511
4511
|
cSvm_problem.trackObjects = 0;
|
4512
|
-
rb_define_module_function(
|
4513
|
-
rb_define_module_function(
|
4514
|
-
rb_define_module_function(
|
4515
|
-
rb_define_module_function(
|
4516
|
-
rb_define_module_function(
|
4517
|
-
rb_define_module_function(
|
4518
|
-
rb_define_module_function(
|
4519
|
-
rb_define_module_function(
|
4520
|
-
rb_define_module_function(
|
4521
|
-
rb_define_module_function(
|
4522
|
-
rb_define_module_function(
|
4523
|
-
rb_define_module_function(
|
4524
|
-
rb_define_module_function(
|
4525
|
-
rb_define_module_function(
|
4526
|
-
rb_define_module_function(
|
4527
|
-
rb_define_module_function(
|
4528
|
-
rb_define_module_function(
|
4529
|
-
rb_define_module_function(
|
4530
|
-
rb_define_module_function(
|
4531
|
-
rb_define_module_function(
|
4532
|
-
rb_define_module_function(
|
4533
|
-
rb_define_module_function(
|
4534
|
-
rb_define_module_function(
|
4535
|
-
rb_define_module_function(
|
4536
|
-
rb_define_module_function(
|
4537
|
-
rb_define_module_function(
|
4538
|
-
rb_define_module_function(
|
4539
|
-
rb_define_singleton_method(
|
4540
|
-
rb_define_singleton_method(
|
4541
|
-
rb_define_module_function(
|
4542
|
-
rb_define_module_function(
|
4543
|
-
rb_define_module_function(
|
4544
|
-
rb_define_module_function(
|
4545
|
-
rb_define_module_function(
|
4546
|
-
rb_define_module_function(
|
4512
|
+
rb_define_module_function(mLibsvm, "svm_train", VALUEFUNC(_wrap_svm_train), -1);
|
4513
|
+
rb_define_module_function(mLibsvm, "svm_cross_validation", VALUEFUNC(_wrap_svm_cross_validation), -1);
|
4514
|
+
rb_define_module_function(mLibsvm, "svm_save_model", VALUEFUNC(_wrap_svm_save_model), -1);
|
4515
|
+
rb_define_module_function(mLibsvm, "svm_load_model", VALUEFUNC(_wrap_svm_load_model), -1);
|
4516
|
+
rb_define_module_function(mLibsvm, "svm_get_obj", VALUEFUNC(_wrap_svm_get_obj), -1);
|
4517
|
+
rb_define_module_function(mLibsvm, "svm_get_svm_type", VALUEFUNC(_wrap_svm_get_svm_type), -1);
|
4518
|
+
rb_define_module_function(mLibsvm, "svm_get_nr_class", VALUEFUNC(_wrap_svm_get_nr_class), -1);
|
4519
|
+
rb_define_module_function(mLibsvm, "svm_get_labels", VALUEFUNC(_wrap_svm_get_labels), -1);
|
4520
|
+
rb_define_module_function(mLibsvm, "svm_get_svr_probability", VALUEFUNC(_wrap_svm_get_svr_probability), -1);
|
4521
|
+
rb_define_module_function(mLibsvm, "svm_predict_values", VALUEFUNC(_wrap_svm_predict_values), -1);
|
4522
|
+
rb_define_module_function(mLibsvm, "svm_predict", VALUEFUNC(_wrap_svm_predict), -1);
|
4523
|
+
rb_define_module_function(mLibsvm, "svm_predict_probability", VALUEFUNC(_wrap_svm_predict_probability), -1);
|
4524
|
+
rb_define_module_function(mLibsvm, "svm_destroy_model", VALUEFUNC(_wrap_svm_destroy_model), -1);
|
4525
|
+
rb_define_module_function(mLibsvm, "svm_check_parameter", VALUEFUNC(_wrap_svm_check_parameter), -1);
|
4526
|
+
rb_define_module_function(mLibsvm, "svm_check_probability_model", VALUEFUNC(_wrap_svm_check_probability_model), -1);
|
4527
|
+
rb_define_module_function(mLibsvm, "svm_get_model_rho", VALUEFUNC(_wrap_svm_get_model_rho), -1);
|
4528
|
+
rb_define_module_function(mLibsvm, "svm_get_model_num_coefs", VALUEFUNC(_wrap_svm_get_model_num_coefs), -1);
|
4529
|
+
rb_define_module_function(mLibsvm, "svm_get_model_coefs", VALUEFUNC(_wrap_svm_get_model_coefs), -1);
|
4530
|
+
rb_define_module_function(mLibsvm, "svm_get_model_perm", VALUEFUNC(_wrap_svm_get_model_perm), -1);
|
4531
|
+
rb_define_module_function(mLibsvm, "new_int", VALUEFUNC(_wrap_new_int), -1);
|
4532
|
+
rb_define_module_function(mLibsvm, "delete_int", VALUEFUNC(_wrap_delete_int), -1);
|
4533
|
+
rb_define_module_function(mLibsvm, "int_getitem", VALUEFUNC(_wrap_int_getitem), -1);
|
4534
|
+
rb_define_module_function(mLibsvm, "int_setitem", VALUEFUNC(_wrap_int_setitem), -1);
|
4535
|
+
rb_define_module_function(mLibsvm, "new_double", VALUEFUNC(_wrap_new_double), -1);
|
4536
|
+
rb_define_module_function(mLibsvm, "delete_double", VALUEFUNC(_wrap_delete_double), -1);
|
4537
|
+
rb_define_module_function(mLibsvm, "double_getitem", VALUEFUNC(_wrap_double_getitem), -1);
|
4538
|
+
rb_define_module_function(mLibsvm, "double_setitem", VALUEFUNC(_wrap_double_setitem), -1);
|
4539
|
+
rb_define_singleton_method(mLibsvm, "info_on", VALUEFUNC(_wrap_info_on_get), 0);
|
4540
|
+
rb_define_singleton_method(mLibsvm, "info_on=", VALUEFUNC(_wrap_info_on_set), 1);
|
4541
|
+
rb_define_module_function(mLibsvm, "svm_node_array", VALUEFUNC(_wrap_svm_node_array), -1);
|
4542
|
+
rb_define_module_function(mLibsvm, "svm_node_array_set", VALUEFUNC(_wrap_svm_node_array_set), -1);
|
4543
|
+
rb_define_module_function(mLibsvm, "svm_node_array_destroy", VALUEFUNC(_wrap_svm_node_array_destroy), -1);
|
4544
|
+
rb_define_module_function(mLibsvm, "svm_node_matrix", VALUEFUNC(_wrap_svm_node_matrix), -1);
|
4545
|
+
rb_define_module_function(mLibsvm, "svm_node_matrix_set", VALUEFUNC(_wrap_svm_node_matrix_set), -1);
|
4546
|
+
rb_define_module_function(mLibsvm, "svm_node_matrix_destroy", VALUEFUNC(_wrap_svm_node_matrix_destroy), -1);
|
4547
4547
|
}
|
4548
4548
|
|
data/lib/svm.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require 'libsvm
|
2
|
-
include
|
1
|
+
require 'libsvm'
|
2
|
+
include Libsvm
|
3
3
|
|
4
4
|
def _int_array(seq)
|
5
5
|
size = seq.size
|
@@ -335,3 +335,27 @@ def cross_validation(prob, param, fold)
|
|
335
335
|
delete_double(dblarr)
|
336
336
|
return ret
|
337
337
|
end
|
338
|
+
|
339
|
+
def read_file filename
|
340
|
+
labels = []
|
341
|
+
samples = []
|
342
|
+
max_index = 0
|
343
|
+
|
344
|
+
f = File.open(filename)
|
345
|
+
f.each do |line|
|
346
|
+
elems = line.split
|
347
|
+
sample = {}
|
348
|
+
for e in elems[1..-1]
|
349
|
+
points = e.split(":")
|
350
|
+
sample[points[0].to_i] = points[1].to_f
|
351
|
+
if points[0].to_i < max_index
|
352
|
+
max_index = points[0].to_i
|
353
|
+
end
|
354
|
+
end
|
355
|
+
labels << elems[0].to_i
|
356
|
+
samples << sample
|
357
|
+
end
|
358
|
+
puts "#{filename}: #{samples.size} samples loaded."
|
359
|
+
return labels,samples
|
360
|
+
end
|
361
|
+
|
metadata
CHANGED
@@ -1,16 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tomz-libsvm-ruby-swig
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Zeng
|
8
|
-
- FeedbackMine
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
11
|
|
13
|
-
date: 2009-
|
12
|
+
date: 2009-05-14 00:00:00 -07:00
|
14
13
|
default_executable:
|
15
14
|
dependencies:
|
16
15
|
- !ruby/object:Gem::Dependency
|
@@ -32,16 +31,16 @@ extensions:
|
|
32
31
|
extra_rdoc_files:
|
33
32
|
- History.txt
|
34
33
|
- Manifest.txt
|
35
|
-
- README.
|
34
|
+
- README.rdoc
|
36
35
|
files:
|
37
36
|
- History.txt
|
38
37
|
- COPYING
|
39
38
|
- AUTHORS
|
40
39
|
- Manifest.txt
|
41
|
-
- README.
|
40
|
+
- README.rdoc
|
42
41
|
- Rakefile
|
43
42
|
- lib/svm.rb
|
44
|
-
- ext/
|
43
|
+
- ext/libsvm_wrap.cxx
|
45
44
|
- ext/svm.cpp
|
46
45
|
- ext/svm.h
|
47
46
|
- ext/extconf.rb
|
@@ -50,7 +49,7 @@ homepage: http://www.tomzconsulting.com
|
|
50
49
|
post_install_message:
|
51
50
|
rdoc_options:
|
52
51
|
- --main
|
53
|
-
- README.
|
52
|
+
- README.rdoc
|
54
53
|
require_paths:
|
55
54
|
- lib
|
56
55
|
- ext
|