liblinear-ruby 0.0.7 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: liblinear-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kei Tsuchiya
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-27 00:00:00.000000000 Z
11
+ date: 2016-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -65,8 +65,13 @@ files:
65
65
  - ext/tron.cpp
66
66
  - ext/tron.h
67
67
  - lib/liblinear.rb
68
- - lib/liblinear/cross_validator.rb
68
+ - lib/liblinear/array.rb
69
+ - lib/liblinear/array/double.rb
70
+ - lib/liblinear/array/integer.rb
69
71
  - lib/liblinear/error.rb
72
+ - lib/liblinear/example.rb
73
+ - lib/liblinear/feature_node.rb
74
+ - lib/liblinear/feature_node_matrix.rb
70
75
  - lib/liblinear/model.rb
71
76
  - lib/liblinear/parameter.rb
72
77
  - lib/liblinear/problem.rb
@@ -111,7 +116,11 @@ files:
111
116
  - liblinear-2.1/windows/train.exe
112
117
  - liblinear-2.1/windows/train.mexw64
113
118
  - liblinear-ruby.gemspec
119
+ - spec/liblinear/array/double_spec.rb
114
120
  - spec/liblinear/cross_validator_spec.rb
121
+ - spec/liblinear/example_spec.rb
122
+ - spec/liblinear/feature_node_matrix_spec.rb
123
+ - spec/liblinear/feature_node_spec.rb
115
124
  - spec/liblinear/model_spec.rb
116
125
  - spec/liblinear/parameter_spec.rb
117
126
  - spec/liblinear/problem_spec.rb
@@ -141,7 +150,11 @@ signing_key:
141
150
  specification_version: 4
142
151
  summary: Ruby wrapper of LIBLINEAR using SWIG
143
152
  test_files:
153
+ - spec/liblinear/array/double_spec.rb
144
154
  - spec/liblinear/cross_validator_spec.rb
155
+ - spec/liblinear/example_spec.rb
156
+ - spec/liblinear/feature_node_matrix_spec.rb
157
+ - spec/liblinear/feature_node_spec.rb
145
158
  - spec/liblinear/model_spec.rb
146
159
  - spec/liblinear/parameter_spec.rb
147
160
  - spec/liblinear/problem_spec.rb
@@ -1,58 +0,0 @@
1
- module Liblinear
2
- class CrossValidator
3
- include Liblinear
4
- include Liblinearswig
5
-
6
- # @param prob [LibLinear::Problem]
7
- # @param param [Liblinear::Parameter]
8
- # @param fold [Integer]
9
- def initialize(prob, param, fold)
10
- @prob = prob
11
- @param = param
12
- @fold = fold
13
- end
14
-
15
- # @return [Array <Integer, Double>]
16
- def execute
17
- target = new_double_array(@prob.labels.size.times.map { 0.0 })
18
- cross_validation(@prob.prob, @param.param, @fold, target)
19
- @predictions = double_array_c_to_ruby(target, @prob.labels.size)
20
- end
21
-
22
- # @return [Double]
23
- def accuracy
24
- total_correct = 0
25
- @prob.labels.size.times do |i|
26
- total_correct += 1 if @predictions[i] == @prob.labels[i].to_f
27
- end
28
- total_correct.to_f / @prob.labels.size.to_f
29
- end
30
-
31
- # @return [Double]
32
- def mean_squared_error
33
- total_error = 0.0
34
- @prob.labels.size.times do |i|
35
- total_error += (@prob.labels[i].to_f - @predictions[i].to_f) ** 2
36
- end
37
- total_error / @prob.labels.size.to_f
38
- end
39
-
40
- # @return [Double]
41
- def squared_correlation_coefficient
42
- sum_x = 0.0
43
- sum_y = 0.0
44
- sum_xx = 0.0
45
- sum_yy = 0.0
46
- sum_xy = 0.0
47
- @prob.labels.size.times do |i|
48
- sum_x += @predictions[i].to_f
49
- sum_y += @prob.labels[i].to_f
50
- sum_xx += @predictions[i].to_f ** 2
51
- sum_yy += @prob.labels[i].to_f ** 2
52
- sum_xy += @predictions[i].to_f * @prob.labels[i].to_f
53
- end
54
- ((@prob.labels.size * sum_xy - sum_x * sum_y) ** 2) /
55
- ((@prob.labels.size * sum_xx - sum_x ** 2) * (@prob.labels.size * sum_yy - sum_y ** 2))
56
- end
57
- end
58
- end