liblinear-ruby 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5a7efbbe95e53288a0a4be6ae55411f693a16b65
4
- data.tar.gz: c7882e4f98923ff2193b9eb797f918bf7a83295d
3
+ metadata.gz: e70466e2b89a0daa504f9dd8a655d759beb40260
4
+ data.tar.gz: e414010bb3853f7d2609e9e5a2fe34474d86e784
5
5
  SHA512:
6
- metadata.gz: 333b9b43537b0b903761a7141b25dce9ef9af61cc04a9b985ad6988c63a9d53c46caa07ff8ed123a295a759ab7bd4dcfcbbf69ccabdaf7529d41f250eea37712
7
- data.tar.gz: d94f42793a1b98e6bdf3f33fddded2934806be5e8a9e0913fb8c44a041b59a6c4d7afa4f3d84aa0985ac3b5f5811b61f48d2a01b65e066bb13d0e1c49e2b85b7
6
+ metadata.gz: 208a81ca1d8ebe5aaf221797417fbb3501a88f3a3d40310c65691980e3808463f5dc67c04cdea3ecf676b46b824d6506d9bfe0fb0f0d123094f39ae391454ec3
7
+ data.tar.gz: 848111ae60b0ae8422550f719fdf60d2ad701ee07a723da1c9e4c58e50dbce73f977a52eb1dc5ef8b981102d65d606e6333a15fa84fe1e5759f8852a35066ff9
@@ -48,22 +48,35 @@ module Liblinear
48
48
  # @param example [Array, Hash]
49
49
  # @return [Hash]
50
50
  def predict_probability(example)
51
- feature_nodes = convert_to_feature_node_array(example, @model.nr_feature, @model.bias)
52
- c_double_array = new_double_array(nr_class)
53
- Liblinearswig.predict_probability(@model, feature_nodes, c_double_array)
54
- probabilities = double_array_c_to_ruby(c_double_array, nr_class)
55
- delete_double(c_double_array)
56
- feature_node_array_destroy(feature_nodes)
57
- probability_list = {}
58
- labels.size.times do |i|
59
- probability_list[labels[i]] = probabilities[i]
60
- end
61
- probability_list
51
+ predict_prob_val(example, :predict_probability)
52
+ end
53
+
54
+ # @param example [Array, Hash]
55
+ # @return [Hash]
56
+ def predict_values(example)
57
+ predict_prob_val(example, :predict_values)
62
58
  end
63
59
 
64
60
  # @param filename [String]
65
61
  def save(filename)
66
62
  save_model(filename, @model)
67
63
  end
64
+
65
+ private
66
+ # @param example [Array, Hash]
67
+ # @return [Hash]
68
+ def predict_prob_val(example, liblinear_func)
69
+ feature_nodes = convert_to_feature_node_array(example, @model.nr_feature, @model.bias)
70
+ c_double_array = Liblinearswig.new_double(nr_class)
71
+ Liblinearswig.send(liblinear_func, @model, feature_nodes, c_double_array)
72
+ values = double_array_c_to_ruby(c_double_array, nr_class)
73
+ delete_double(c_double_array)
74
+ feature_node_array_destroy(feature_nodes)
75
+ value_list = {}
76
+ labels.size.times do |i|
77
+ value_list[labels[i]] = values[i]
78
+ end
79
+ value_list
80
+ end
68
81
  end
69
82
  end
@@ -1,3 +1,3 @@
1
1
  module Liblinear
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
@@ -53,4 +53,10 @@ describe Liblinear::Model do
53
53
  expect(@model.predict_probability([1]).class).to eq(Hash)
54
54
  end
55
55
  end
56
+
57
+ describe '#predict_values' do
58
+ it 'return predict_values' do
59
+ expect(@model.predict_values([1]).class).to eq(Hash)
60
+ end
61
+ end
56
62
  end
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.3
4
+ version: 0.0.4
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-02-17 00:00:00.000000000 Z
11
+ date: 2014-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -134,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
134
  version: '0'
135
135
  requirements: []
136
136
  rubyforge_project:
137
- rubygems_version: 2.0.2
137
+ rubygems_version: 2.0.14
138
138
  signing_key:
139
139
  specification_version: 4
140
140
  summary: Ruby wrapper of LIBLINEAR using SWIG
@@ -143,4 +143,3 @@ test_files:
143
143
  - spec/liblinear/parameter_spec.rb
144
144
  - spec/liblinear/problem_spec.rb
145
145
  - spec/liblinear_spec.rb
146
- has_rdoc: