rb-libsvm 1.0.8 → 1.0.9

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -2,22 +2,29 @@
2
2
 
3
3
  Spec Status: [![Build Status](https://secure.travis-ci.org/febeling/rb-libsvm.png)](http://travis-ci.org/febeling/rb-libsvm)
4
4
 
5
- This package provides a Ruby bindings to the LIBSVM [1] library. SVM
5
+ This package provides a Ruby bindings to the [LIBSVM][] library. SVM
6
6
  is a machine learning and classification algorithm, and LIBSVM is a
7
7
  popular free implementation of it, written by Chih-Chung Chang and
8
- Chih-Jen Lin, of National Taiwan University, Taipei. See "Programming
9
- Collective Intelligence," [2] among others, for a usage example.
8
+ Chih-Jen Lin, of National Taiwan University, Taipei. See the book ["Programming
9
+ Collective Intelligence,"](http://books.google.com/books?id=fEsZ3Ey-Hq4C) among others, for a usage example.
10
10
 
11
11
  Note: There exist two other Ruby bindings for LIBSVM. One is named
12
- Ruby SVM, written by Rudi Cilibrasi. It is hard to find now. The
13
- other, more actively developed one is libsvm-ruby-swig by Tom Zeng
14
- [3], which is built using SWIG.
12
+ "Ruby SVM," and is written by Rudi Cilibrasi. It is hard to find
13
+ nowadays. The other, more actively developed one is
14
+ [libsvm-ruby-swig][svmrubyswig] by Tom Zeng, which is built using
15
+ SWIG.
15
16
 
16
17
  ## Dependencies
17
18
 
18
- None. Libsvm is bundled with the project. Just install and go!
19
+ None. LIBSVM is bundled with the project. Just install and go!
19
20
 
20
- Currently includes libsvm version 3.12.
21
+ Currently this package includes libsvm version 3.13.
22
+
23
+ LIBSVM includes a number of command line tools for preprocessing
24
+ training data and finding parameters. These tools are not included in
25
+ this gem. You should install the original package if you need these.
26
+ It is also helpful to consult the Readme of the LIBSVM package for
27
+ reference when configuring the training parameters.
21
28
 
22
29
  ## Installation
23
30
 
@@ -48,13 +55,9 @@ pred = model.predict(Libsvm::Node.features(1, 1, 1))
48
55
  puts "Example [1, 1, 1] - Predicted #{pred}"
49
56
  ```
50
57
 
51
- ## Author, License
52
-
53
- Written by C. Florian Ebeling. This software can be freely used under
54
- the terms of the MIT license, see file MIT-LICENSE.
58
+ ## Author
55
59
 
56
- This package includes the source of LIBSVM, which is free to use under
57
- the license in the file LIBSVM-LICENSE.
60
+ Written by C. Florian Ebeling.
58
61
 
59
62
  ## Contributors
60
63
 
@@ -62,16 +65,20 @@ the license in the file LIBSVM-LICENSE.
62
65
 
63
66
  [Aleksander Pohl](https://github.com/apohllo)
64
67
 
65
- ### Posts about SVMs and Ruby
68
+ ## License
66
69
 
67
- [http://neovintage.blogspot.com/2011/11/text-classification-using-support.html](http://neovintage.blogspot.com/2011/11/text-classification-using-support.html)
70
+ This software can be freely used under the terms of the MIT license,
71
+ see file MIT-LICENSE.
68
72
 
69
- [http://www.igvita.com/2008/01/07/support-vector-machines-svm-in-ruby/](http://www.igvita.com/2008/01/07/support-vector-machines-svm-in-ruby/)
73
+ This package includes the source of LIBSVM, which is free to use under
74
+ the license in the file LIBSVM-LICENSE.
70
75
 
76
+ ### Posts about using SVMs with Ruby
71
77
 
78
+ http://neovintage.blogspot.com/2011/11/text-classification-using-support.html
72
79
 
73
- [1]: [http://www.csie.ntu.edu.tw/~cjlin/libsvm/](http://www.csie.ntu.edu.tw/~cjlin/libsvm/)
80
+ http://www.igvita.com/2008/01/07/support-vector-machines-svm-in-ruby/
74
81
 
75
- [2]: [http://books.google.com/books?id=fEsZ3Ey-Hq4C](http://books.google.com/books?id=fEsZ3Ey-Hq4C)
82
+ [libsvm]: http://www.csie.ntu.edu.tw/~cjlin/libsvm/
76
83
 
77
- [3]: http://github.com/tomz/libsvm-ruby-swig/tree/master
84
+ [svmrubyswig]: http://github.com/tomz/libsvm-ruby-swig/tree/master
data/ext/libsvm/svm.cpp CHANGED
@@ -737,7 +737,7 @@ void Solver::Solve(int l, const QMatrix& Q, const double *p_, const schar *y_,
737
737
  active_size = l;
738
738
  info("*");
739
739
  }
740
- info("\nWARNING: reaching max number of iterations");
740
+ fprintf(stderr,"\nWARNING: reaching max number of iterations\n");
741
741
  }
742
742
 
743
743
  // calculate rho
@@ -1006,7 +1006,7 @@ double Solver::calculate_rho()
1006
1006
  //
1007
1007
  // additional constraint: e^T \alpha = constant
1008
1008
  //
1009
- class Solver_NU : public Solver
1009
+ class Solver_NU: public Solver
1010
1010
  {
1011
1011
  public:
1012
1012
  Solver_NU() {}
@@ -2107,12 +2107,14 @@ svm_model *svm_train(const svm_problem *prob, const svm_parameter *param)
2107
2107
  model->l = nSV;
2108
2108
  model->SV = Malloc(svm_node *,nSV);
2109
2109
  model->sv_coef[0] = Malloc(double,nSV);
2110
+ model->sv_indices = Malloc(int,nSV);
2110
2111
  int j = 0;
2111
2112
  for(i=0;i<prob->l;i++)
2112
2113
  if(fabs(f.alpha[i]) > 0)
2113
2114
  {
2114
2115
  model->SV[j] = prob->x[i];
2115
2116
  model->sv_coef[0][j] = f.alpha[i];
2117
+ model->sv_indices[j] = i+1;
2116
2118
  ++j;
2117
2119
  }
2118
2120
 
@@ -2254,9 +2256,14 @@ svm_model *svm_train(const svm_problem *prob, const svm_parameter *param)
2254
2256
 
2255
2257
  model->l = total_sv;
2256
2258
  model->SV = Malloc(svm_node *,total_sv);
2259
+ model->sv_indices = Malloc(int,total_sv);
2257
2260
  p = 0;
2258
2261
  for(i=0;i<l;i++)
2259
- if(nonzero[i]) model->SV[p++] = x[i];
2262
+ if(nonzero[i])
2263
+ {
2264
+ model->SV[p] = x[i];
2265
+ model->sv_indices[p++] = perm[i] + 1;
2266
+ }
2260
2267
 
2261
2268
  int *nz_start = Malloc(int,nr_class);
2262
2269
  nz_start[0] = 0;
@@ -2444,6 +2451,18 @@ void svm_get_labels(const svm_model *model, int* label)
2444
2451
  label[i] = model->label[i];
2445
2452
  }
2446
2453
 
2454
+ void svm_get_sv_indices(const svm_model *model, int* indices)
2455
+ {
2456
+ if (model->sv_indices != NULL)
2457
+ for(int i=0;i<model->l;i++)
2458
+ indices[i] = model->sv_indices[i];
2459
+ }
2460
+
2461
+ int svm_get_nr_sv(const svm_model *model)
2462
+ {
2463
+ return model->l;
2464
+ }
2465
+
2447
2466
  double svm_get_svr_probability(const svm_model *model)
2448
2467
  {
2449
2468
  if ((model->param.svm_type == EPSILON_SVR || model->param.svm_type == NU_SVR) &&
data/ext/libsvm/svm.h CHANGED
@@ -1,7 +1,7 @@
1
1
  #ifndef _LIBSVM_H
2
2
  #define _LIBSVM_H
3
3
 
4
- #define LIBSVM_VERSION 312
4
+ #define LIBSVM_VERSION 313
5
5
 
6
6
  #ifdef __cplusplus
7
7
  extern "C" {
@@ -59,6 +59,7 @@ struct svm_model
59
59
  double *rho; /* constants in decision functions (rho[k*(k-1)/2]) */
60
60
  double *probA; /* pariwise probability information */
61
61
  double *probB;
62
+ int *sv_indices; /* sv_indices[0,...,nSV-1] are values in [1,...,num_traning_data] to indicate SVs in the training set */
62
63
 
63
64
  /* for classification only */
64
65
 
@@ -79,6 +80,8 @@ struct svm_model *svm_load_model(const char *model_file_name);
79
80
  int svm_get_svm_type(const struct svm_model *model);
80
81
  int svm_get_nr_class(const struct svm_model *model);
81
82
  void svm_get_labels(const struct svm_model *model, int *label);
83
+ void svm_get_sv_indices(const struct svm_model *model, int *sv_indices);
84
+ int svm_get_nr_sv(const struct svm_model *model);
82
85
  double svm_get_svr_probability(const struct svm_model *model);
83
86
 
84
87
  double svm_predict_values(const struct svm_model *model, const struct svm_node *x, double* dec_values);
@@ -1,3 +1,3 @@
1
1
  module Libsvm
2
- VERSION = "1.0.8"
2
+ VERSION = "1.0.9"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rb-libsvm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.8
4
+ version: 1.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-07-02 00:00:00.000000000Z
13
+ date: 2012-11-11 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake-compiler
17
- requirement: &70133955492220 !ruby/object:Gem::Requirement
17
+ requirement: &70287494349840 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '0'
23
23
  type: :development
24
24
  prerelease: false
25
- version_requirements: *70133955492220
25
+ version_requirements: *70287494349840
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: rspec
28
- requirement: &70133955490320 !ruby/object:Gem::Requirement
28
+ requirement: &70287494349340 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,7 +33,7 @@ dependencies:
33
33
  version: 2.7.0
34
34
  type: :development
35
35
  prerelease: false
36
- version_requirements: *70133955490320
36
+ version_requirements: *70287494349340
37
37
  description: libsvm and ruby without using swig
38
38
  email:
39
39
  - florian.ebeling@gmail.com
@@ -82,7 +82,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
82
82
  version: '0'
83
83
  segments:
84
84
  - 0
85
- hash: 1508460701576130505
85
+ hash: -1009595894930293011
86
86
  required_rubygems_version: !ruby/object:Gem::Requirement
87
87
  none: false
88
88
  requirements:
@@ -91,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
91
  version: '0'
92
92
  segments:
93
93
  - 0
94
- hash: 1508460701576130505
94
+ hash: -1009595894930293011
95
95
  requirements: []
96
96
  rubyforge_project: rb-libsvm
97
97
  rubygems_version: 1.8.10