liblinear-ruby 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/ext/blasp.h +8 -0
  3. data/ext/daxpy.c +8 -0
  4. data/ext/ddot.c +8 -0
  5. data/ext/dnrm2.c +8 -0
  6. data/ext/dscal.c +8 -0
  7. data/ext/liblinear_wrap.cxx +128 -3
  8. data/ext/linear.cpp +344 -175
  9. data/ext/linear.h +2 -0
  10. data/ext/tron.cpp +14 -8
  11. data/ext/tron.h +2 -1
  12. data/lib/liblinear/version.rb +1 -1
  13. data/{liblinear-1.95 → liblinear-2.1}/COPYRIGHT +1 -1
  14. data/{liblinear-1.95 → liblinear-2.1}/Makefile +1 -1
  15. data/{liblinear-1.95 → liblinear-2.1}/Makefile.win +3 -9
  16. data/{liblinear-1.95 → liblinear-2.1}/README +45 -7
  17. data/{liblinear-1.95 → liblinear-2.1}/blas/Makefile +0 -0
  18. data/{liblinear-1.95 → liblinear-2.1}/blas/blas.h +0 -0
  19. data/{liblinear-1.95 → liblinear-2.1}/blas/blasp.h +0 -0
  20. data/{liblinear-1.95 → liblinear-2.1}/blas/daxpy.c +0 -0
  21. data/{liblinear-1.95 → liblinear-2.1}/blas/ddot.c +0 -0
  22. data/{liblinear-1.95 → liblinear-2.1}/blas/dnrm2.c +0 -0
  23. data/{liblinear-1.95 → liblinear-2.1}/blas/dscal.c +0 -0
  24. data/{liblinear-1.95 → liblinear-2.1}/heart_scale +0 -0
  25. data/{liblinear-1.95 → liblinear-2.1}/linear.cpp +344 -175
  26. data/{liblinear-1.95 → liblinear-2.1}/linear.def +1 -0
  27. data/{liblinear-1.95 → liblinear-2.1}/linear.h +2 -0
  28. data/{liblinear-1.95 → liblinear-2.1}/matlab/Makefile +0 -0
  29. data/{liblinear-1.95 → liblinear-2.1}/matlab/README +12 -2
  30. data/{liblinear-1.95 → liblinear-2.1}/matlab/libsvmread.c +0 -0
  31. data/{liblinear-1.95 → liblinear-2.1}/matlab/libsvmwrite.c +1 -1
  32. data/{liblinear-1.95 → liblinear-2.1}/matlab/linear_model_matlab.c +1 -1
  33. data/{liblinear-1.95 → liblinear-2.1}/matlab/linear_model_matlab.h +0 -0
  34. data/liblinear-2.1/matlab/make.m +22 -0
  35. data/{liblinear-1.95 → liblinear-2.1}/matlab/predict.c +1 -1
  36. data/{liblinear-1.95 → liblinear-2.1}/matlab/train.c +65 -10
  37. data/{liblinear-1.95 → liblinear-2.1}/predict.c +0 -0
  38. data/{liblinear-1.95 → liblinear-2.1}/python/Makefile +0 -0
  39. data/{liblinear-1.95 → liblinear-2.1}/python/README +7 -0
  40. data/{liblinear-1.95 → liblinear-2.1}/python/liblinear.py +27 -8
  41. data/{liblinear-1.95 → liblinear-2.1}/python/liblinearutil.py +16 -2
  42. data/{liblinear-1.95 → liblinear-2.1}/train.c +51 -1
  43. data/{liblinear-1.95 → liblinear-2.1}/tron.cpp +14 -8
  44. data/{liblinear-1.95 → liblinear-2.1}/tron.h +2 -1
  45. data/liblinear-2.1/windows/liblinear.dll +0 -0
  46. data/{liblinear-1.95 → liblinear-2.1}/windows/libsvmread.mexw64 +0 -0
  47. data/{liblinear-1.95 → liblinear-2.1}/windows/libsvmwrite.mexw64 +0 -0
  48. data/liblinear-2.1/windows/predict.exe +0 -0
  49. data/{liblinear-1.95 → liblinear-2.1}/windows/predict.mexw64 +0 -0
  50. data/liblinear-2.1/windows/train.exe +0 -0
  51. data/liblinear-2.1/windows/train.mexw64 +0 -0
  52. data/liblinear-ruby.gemspec +9 -10
  53. metadata +49 -50
  54. data/liblinear-1.95/matlab/make.m +0 -21
  55. data/liblinear-1.95/windows/liblinear.dll +0 -0
  56. data/liblinear-1.95/windows/predict.exe +0 -0
  57. data/liblinear-1.95/windows/train.exe +0 -0
  58. data/liblinear-1.95/windows/train.mexw64 +0 -0
@@ -41,10 +41,11 @@ void TRON::info(const char *fmt,...)
41
41
  (*tron_print_string)(buf);
42
42
  }
43
43
 
44
- TRON::TRON(const function *fun_obj, double eps, int max_iter)
44
+ TRON::TRON(const function *fun_obj, double eps, double eps_cg, int max_iter)
45
45
  {
46
46
  this->fun_obj=const_cast<function *>(fun_obj);
47
47
  this->eps=eps;
48
+ this->eps_cg=eps_cg;
48
49
  this->max_iter=max_iter;
49
50
  tron_print_string = default_print;
50
51
  }
@@ -68,23 +69,28 @@ void TRON::tron(double *w)
68
69
  int search = 1, iter = 1, inc = 1;
69
70
  double *s = new double[n];
70
71
  double *r = new double[n];
71
- double *w_new = new double[n];
72
72
  double *g = new double[n];
73
73
 
74
+ // calculate gradient norm at w=0 for stopping condition.
75
+ double *w0 = new double[n];
74
76
  for (i=0; i<n; i++)
75
- w[i] = 0;
77
+ w0[i] = 0;
78
+ fun_obj->fun(w0);
79
+ fun_obj->grad(w0, g);
80
+ double gnorm0 = dnrm2_(&n, g, &inc);
81
+ delete [] w0;
76
82
 
77
83
  f = fun_obj->fun(w);
78
84
  fun_obj->grad(w, g);
79
85
  delta = dnrm2_(&n, g, &inc);
80
- double gnorm1 = delta;
81
- double gnorm = gnorm1;
86
+ double gnorm = delta;
82
87
 
83
- if (gnorm <= eps*gnorm1)
88
+ if (gnorm <= eps*gnorm0)
84
89
  search = 0;
85
90
 
86
91
  iter = 1;
87
92
 
93
+ double *w_new = new double[n];
88
94
  while (iter <= max_iter && search)
89
95
  {
90
96
  cg_iter = trcg(delta, g, s, r);
@@ -130,7 +136,7 @@ void TRON::tron(double *w)
130
136
  fun_obj->grad(w, g);
131
137
 
132
138
  gnorm = dnrm2_(&n, g, &inc);
133
- if (gnorm <= eps*gnorm1)
139
+ if (gnorm <= eps*gnorm0)
134
140
  break;
135
141
  }
136
142
  if (f < -1.0e+32)
@@ -172,7 +178,7 @@ int TRON::trcg(double delta, double *g, double *s, double *r)
172
178
  r[i] = -g[i];
173
179
  d[i] = r[i];
174
180
  }
175
- cgtol = 0.1*dnrm2_(&n, g, &inc);
181
+ cgtol = eps_cg*dnrm2_(&n, g, &inc);
176
182
 
177
183
  int cg_iter = 0;
178
184
  rTr = ddot_(&n, r, &inc, r, &inc);
@@ -15,7 +15,7 @@ public:
15
15
  class TRON
16
16
  {
17
17
  public:
18
- TRON(const function *fun_obj, double eps = 0.1, int max_iter = 1000);
18
+ TRON(const function *fun_obj, double eps = 0.1, double eps_cg = 0.1, int max_iter = 1000);
19
19
  ~TRON();
20
20
 
21
21
  void tron(double *w);
@@ -26,6 +26,7 @@ private:
26
26
  double norm_inf(int n, double *x);
27
27
 
28
28
  double eps;
29
+ double eps_cg;
29
30
  int max_iter;
30
31
  function *fun_obj;
31
32
  void info(const char *fmt,...);
@@ -1,24 +1,23 @@
1
- # coding: utf-8
2
1
  lib = File.expand_path('../lib', __FILE__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'liblinear/version'
3
+ require 'liblinear'
5
4
 
6
5
  Gem::Specification.new do |spec|
7
- spec.name = "liblinear-ruby"
6
+ spec.name = 'liblinear-ruby'
8
7
  spec.version = Liblinear::VERSION
9
- spec.authors = ["Kei Tsuchiya"]
10
- spec.email = ["kei.tsuchiya86@gmail.com"]
8
+ spec.authors = ['Kei Tsuchiya']
9
+ spec.email = ['kei.tsuchiya86@gmail.com']
11
10
  spec.description = %q{Ruby wrapper of LIBLINEAR using SWIG}
12
11
  spec.summary = %q{Ruby wrapper of LIBLINEAR using SWIG}
13
- spec.homepage = "https://github.com/kei500/liblinear-ruby"
14
- spec.license = "MIT"
12
+ spec.homepage = 'https://github.com/kei500/liblinear-ruby'
13
+ spec.license = 'MIT'
15
14
 
16
15
  spec.files = `git ls-files`.split($/)
17
16
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
18
+ spec.require_paths = ['lib']
20
19
 
21
- spec.add_development_dependency "bundler", "~> 1.3"
22
- spec.add_development_dependency "rake"
20
+ spec.add_development_dependency 'bundler', '~> 1.3'
21
+ spec.add_development_dependency 'rake'
23
22
  spec.extensions << 'ext/extconf.rb'
24
23
  end
metadata CHANGED
@@ -1,41 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: liblinear-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kei Tsuchiya
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-16 00:00:00.000000000 Z
11
+ date: 2015-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.3'
20
20
  type: :development
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: '1.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  description: Ruby wrapper of LIBLINEAR using SWIG
@@ -46,7 +46,7 @@ extensions:
46
46
  - ext/extconf.rb
47
47
  extra_rdoc_files: []
48
48
  files:
49
- - .gitignore
49
+ - ".gitignore"
50
50
  - Gemfile
51
51
  - LICENSE.txt
52
52
  - README.md
@@ -71,45 +71,45 @@ files:
71
71
  - lib/liblinear/parameter.rb
72
72
  - lib/liblinear/problem.rb
73
73
  - lib/liblinear/version.rb
74
- - liblinear-1.95/COPYRIGHT
75
- - liblinear-1.95/Makefile
76
- - liblinear-1.95/Makefile.win
77
- - liblinear-1.95/README
78
- - liblinear-1.95/blas/Makefile
79
- - liblinear-1.95/blas/blas.h
80
- - liblinear-1.95/blas/blasp.h
81
- - liblinear-1.95/blas/daxpy.c
82
- - liblinear-1.95/blas/ddot.c
83
- - liblinear-1.95/blas/dnrm2.c
84
- - liblinear-1.95/blas/dscal.c
85
- - liblinear-1.95/heart_scale
86
- - liblinear-1.95/linear.cpp
87
- - liblinear-1.95/linear.def
88
- - liblinear-1.95/linear.h
89
- - liblinear-1.95/matlab/Makefile
90
- - liblinear-1.95/matlab/README
91
- - liblinear-1.95/matlab/libsvmread.c
92
- - liblinear-1.95/matlab/libsvmwrite.c
93
- - liblinear-1.95/matlab/linear_model_matlab.c
94
- - liblinear-1.95/matlab/linear_model_matlab.h
95
- - liblinear-1.95/matlab/make.m
96
- - liblinear-1.95/matlab/predict.c
97
- - liblinear-1.95/matlab/train.c
98
- - liblinear-1.95/predict.c
99
- - liblinear-1.95/python/Makefile
100
- - liblinear-1.95/python/README
101
- - liblinear-1.95/python/liblinear.py
102
- - liblinear-1.95/python/liblinearutil.py
103
- - liblinear-1.95/train.c
104
- - liblinear-1.95/tron.cpp
105
- - liblinear-1.95/tron.h
106
- - liblinear-1.95/windows/liblinear.dll
107
- - liblinear-1.95/windows/libsvmread.mexw64
108
- - liblinear-1.95/windows/libsvmwrite.mexw64
109
- - liblinear-1.95/windows/predict.exe
110
- - liblinear-1.95/windows/predict.mexw64
111
- - liblinear-1.95/windows/train.exe
112
- - liblinear-1.95/windows/train.mexw64
74
+ - liblinear-2.1/COPYRIGHT
75
+ - liblinear-2.1/Makefile
76
+ - liblinear-2.1/Makefile.win
77
+ - liblinear-2.1/README
78
+ - liblinear-2.1/blas/Makefile
79
+ - liblinear-2.1/blas/blas.h
80
+ - liblinear-2.1/blas/blasp.h
81
+ - liblinear-2.1/blas/daxpy.c
82
+ - liblinear-2.1/blas/ddot.c
83
+ - liblinear-2.1/blas/dnrm2.c
84
+ - liblinear-2.1/blas/dscal.c
85
+ - liblinear-2.1/heart_scale
86
+ - liblinear-2.1/linear.cpp
87
+ - liblinear-2.1/linear.def
88
+ - liblinear-2.1/linear.h
89
+ - liblinear-2.1/matlab/Makefile
90
+ - liblinear-2.1/matlab/README
91
+ - liblinear-2.1/matlab/libsvmread.c
92
+ - liblinear-2.1/matlab/libsvmwrite.c
93
+ - liblinear-2.1/matlab/linear_model_matlab.c
94
+ - liblinear-2.1/matlab/linear_model_matlab.h
95
+ - liblinear-2.1/matlab/make.m
96
+ - liblinear-2.1/matlab/predict.c
97
+ - liblinear-2.1/matlab/train.c
98
+ - liblinear-2.1/predict.c
99
+ - liblinear-2.1/python/Makefile
100
+ - liblinear-2.1/python/README
101
+ - liblinear-2.1/python/liblinear.py
102
+ - liblinear-2.1/python/liblinearutil.py
103
+ - liblinear-2.1/train.c
104
+ - liblinear-2.1/tron.cpp
105
+ - liblinear-2.1/tron.h
106
+ - liblinear-2.1/windows/liblinear.dll
107
+ - liblinear-2.1/windows/libsvmread.mexw64
108
+ - liblinear-2.1/windows/libsvmwrite.mexw64
109
+ - liblinear-2.1/windows/predict.exe
110
+ - liblinear-2.1/windows/predict.mexw64
111
+ - liblinear-2.1/windows/train.exe
112
+ - liblinear-2.1/windows/train.mexw64
113
113
  - liblinear-ruby.gemspec
114
114
  - spec/liblinear/cross_validator_spec.rb
115
115
  - spec/liblinear/model_spec.rb
@@ -126,17 +126,17 @@ require_paths:
126
126
  - lib
127
127
  required_ruby_version: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - '>='
129
+ - - ">="
130
130
  - !ruby/object:Gem::Version
131
131
  version: '0'
132
132
  required_rubygems_version: !ruby/object:Gem::Requirement
133
133
  requirements:
134
- - - '>='
134
+ - - ">="
135
135
  - !ruby/object:Gem::Version
136
136
  version: '0'
137
137
  requirements: []
138
138
  rubyforge_project:
139
- rubygems_version: 2.0.2
139
+ rubygems_version: 2.4.5
140
140
  signing_key:
141
141
  specification_version: 4
142
142
  summary: Ruby wrapper of LIBLINEAR using SWIG
@@ -146,4 +146,3 @@ test_files:
146
146
  - spec/liblinear/parameter_spec.rb
147
147
  - spec/liblinear/problem_spec.rb
148
148
  - spec/liblinear_spec.rb
149
- has_rdoc:
@@ -1,21 +0,0 @@
1
- % This make.m is for MATLAB and OCTAVE under Windows, Mac, and Unix
2
-
3
- try
4
- Type = ver;
5
- % This part is for OCTAVE
6
- if(strcmp(Type(1).Name, 'Octave') == 1)
7
- mex libsvmread.c
8
- mex libsvmwrite.c
9
- mex train.c linear_model_matlab.c ../linear.cpp ../tron.cpp ../blas/daxpy.c ../blas/ddot.c ../blas/dnrm2.c ../blas/dscal.c
10
- mex predict.c linear_model_matlab.c ../linear.cpp ../tron.cpp ../blas/daxpy.c ../blas/ddot.c ../blas/dnrm2.c ../blas/dscal.c
11
- % This part is for MATLAB
12
- % Add -largeArrayDims on 64-bit machines of MATLAB
13
- else
14
- mex CFLAGS="\$CFLAGS -std=c99" -largeArrayDims libsvmread.c
15
- mex CFLAGS="\$CFLAGS -std=c99" -largeArrayDims libsvmwrite.c
16
- mex CFLAGS="\$CFLAGS -std=c99" -largeArrayDims train.c linear_model_matlab.c ../linear.cpp ../tron.cpp ../blas/daxpy.c ../blas/ddot.c ../blas/dnrm2.c ../blas/dscal.c
17
- mex CFLAGS="\$CFLAGS -std=c99" -largeArrayDims predict.c linear_model_matlab.c ../linear.cpp ../tron.cpp ../blas/daxpy.c ../blas/ddot.c ../blas/dnrm2.c ../blas/dscal.c
18
- end
19
- catch
20
- fprintf('If make.m fails, please check README about detailed instructions.\n');
21
- end