rb-libsvm 1.3.1 → 1.4.0

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: c04b43e9bcd03b81b5e928566c8449f91650bfc4
4
- data.tar.gz: 1338454d938aeffdb2bfcc371f994177982bd984
3
+ metadata.gz: b45728dc2dd8a43e475299b21ca321ac440ec240
4
+ data.tar.gz: bb1e9e59c680fa2bff83e37b636f8354327e63fe
5
5
  SHA512:
6
- metadata.gz: f4dbead862bfa6284ed286759cd6215764fe3f4124162bcd3e7f5a441ac540ba41eab7ada12a4a2c221220ff322b443421f4e663189eb65bc7d939eb8dfa9236
7
- data.tar.gz: 5512309213d09e792e2e12b2c753a12b800020f7696f6b46dd04fe5e67e5041af9b61e199465ac87c58f18ab9c4bc4f78cfa6edf51270d769a65ff7fbd0ea979
6
+ metadata.gz: 04f4b3a390f705f41e78e1f6531af1117bfb944a1901fc17cee3e12a668d0ff58761ee6cbb69c59c474a66fc9549fdb1f9e1339b663e73b7d2e535232b8998ec
7
+ data.tar.gz: 27d948de88f60491aa3ff226f074411dd168d821193e9f1b43db5a1f78f5aa75b1ffa01c6021e846f34fa3022199fd369bb9a8f397920250537f51125e138838
@@ -5,3 +5,4 @@ rvm:
5
5
  - 2.1.5
6
6
  - 2.2.0
7
7
  - ruby-head
8
+ sudo: false
@@ -2,6 +2,13 @@
2
2
  All notable changes to this project will be documented in this file.
3
3
  This project adheres to [Semantic Versioning](http://semver.org/).
4
4
 
5
+ ## [1.4.0] - 2015-09-18
6
+ ### Changed
7
+ - Complete transition to `expect` specs.
8
+ - Raise exception in `Libsvm::Model.load` if model can't be loaded (fixes #21).
9
+ ### Fixed
10
+ - Fix a bug in `Libsvm::Node#==` when comparing with `nil`.
11
+
5
12
  ## [1.3.1] - 2015-03-21
6
13
  ### Fixed
7
14
  - Spelling and punctuation in documentation comments
data/README.md CHANGED
@@ -22,7 +22,7 @@ LIBSVM includes a number of command line tools for preprocessing
22
22
  training data and finding parameters. These tools are not included in
23
23
  this gem. You should install the original package if you need them.
24
24
 
25
- It is helpful to consult the [README][] of the LIBSVM package for
25
+ It is helpful to consult the [README of the LIBSVM][README] package for
26
26
  reference when configuring the training parameters.
27
27
 
28
28
  Currently this package includes libsvm version 3.20.
@@ -490,6 +490,8 @@ static VALUE cModel_support_vectors_count(VALUE obj)
490
490
  * internal file representation of the model.
491
491
  *
492
492
  * @param filename [String] name of the model file
493
+ * @raise [IOError] if the model can't be loaded,
494
+ * e.g. because the model path doesn't point to a model
493
495
  * @return [Libsvm::Model] the model
494
496
  */
495
497
  static VALUE cModel_class_load(VALUE cls, VALUE filename)
@@ -498,6 +500,9 @@ static VALUE cModel_class_load(VALUE cls, VALUE filename)
498
500
  char *path;
499
501
  path = StringValueCStr(filename);
500
502
  model = svm_load_model(path);
503
+ if(model == NULL) {
504
+ rb_raise(rb_eIOError, "unable to load model from file: \"%s\"", path);
505
+ }
501
506
  return Data_Wrap_Struct(cModel, 0, model_free, model);
502
507
  }
503
508
 
@@ -90,13 +90,15 @@ module Libsvm
90
90
  self.value = value
91
91
  end
92
92
 
93
- # Compare features for equality.
93
+ # Compare feature node for equality.
94
94
  #
95
95
  # Nodes with equal index and value are equal.
96
96
  #
97
97
  # @return [Boolean]
98
- def ==(other)
99
- index == other.index && value == other.value
98
+ def == (other)
99
+ other.class == self.class &&
100
+ index == other.index &&
101
+ value == other.value
100
102
  end
101
103
 
102
104
  def inspect
@@ -1,3 +1,3 @@
1
1
  module Libsvm
2
- VERSION = "1.3.1"
2
+ VERSION = "1.4.0"
3
3
  end
@@ -1,15 +1,15 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe "Create examples" do
4
- describe "from a hash" do
4
+ it "from a hash" do
5
5
  example = { 11 => 0.11, 21 => 0.21, 101 => 0.99 }.to_example.sort_by(&:index)
6
- example.should == Node.features({11 => 0.11, 21 => 0.21, 101 => 0.99 }).sort_by(&:index)
6
+ expect(example).to eq(Node.features({11 => 0.11, 21 => 0.21, 101 => 0.99 }).sort_by(&:index))
7
7
  end
8
8
 
9
9
  describe "from an array of tuples" do
10
10
  it "can create example from array of pairs" do
11
11
  example = [ [11, 0.11], [21, 0.21], [101, 0.99] ].to_example
12
- example.should == Node.features({11 => 0.11, 21 => 0.21, 101 => 0.99 }).sort_by(&:index)
12
+ expect(example).to eq(Node.features({11 => 0.11, 21 => 0.21, 101 => 0.99 }).sort_by(&:index))
13
13
  end
14
14
  end
15
15
  end
@@ -70,6 +70,10 @@ describe "A saved model" do
70
70
  expect(Model.load(@filename)).to be_an_instance_of(Model)
71
71
  end
72
72
 
73
+ it "missing model raises exception" do
74
+ expect{Model.load("missing.model")}.to raise_error(IOError, /unable to load model from file: "missing.model"/)
75
+ end
76
+
73
77
  after(:each) do
74
78
  File.delete(@filename) rescue nil
75
79
  end
@@ -28,43 +28,50 @@ describe "A Node" do
28
28
  end
29
29
 
30
30
  it "can be created" do
31
- @node.should_not be_nil
31
+ expect(@node).not_to be_nil
32
32
  end
33
33
 
34
- it "does not segfault on setting properties" do
34
+ it "has in :index property" do
35
35
  @node.index = 99
36
- @node.index.should == 99
36
+ expect(@node.index).to eq(99)
37
+ end
38
+
39
+ it "has a :value porperty" do
37
40
  @node.value = 3.141
38
- @node.value.should be_within(0.00001).of(3.141)
41
+ expect(@node.value).to be_within(0.00001).of(3.141)
39
42
  end
40
43
 
41
44
  it "has inited properties" do
42
- @node.index.should == 0
43
- @node.value.should be_within(0.00001).of(0)
45
+ expect(@node.index).to eq(0)
46
+ expect(@node.value).to be_within(0.00001).of(0)
44
47
  end
45
48
 
46
49
  it "class can create nodes from an array" do
47
50
  ary = Node.features([0.1, 0.2, 0.3, 0.4, 0.5])
48
- ary.map {|n| n.class.should == Node}
49
- ary.map {|n| n.value }.should == [0.1, 0.2, 0.3, 0.4, 0.5]
50
- ary.map {|n| n.index }.should == [0, 1, 2, 3, 4]
51
+ expect(ary).to all(be_a(Node))
52
+ expect(ary.map(&:value).sort).to eq([0.1, 0.2, 0.3, 0.4, 0.5])
53
+ expect(ary.map(&:index).sort).to eq([0, 1, 2, 3, 4])
51
54
  end
52
55
 
53
56
  it "class can create nodes from variable parameters" do
54
57
  ary = Node.features(0.1, 0.2, 0.3, 0.4, 0.5)
55
- ary.map {|n| Node.should === n }
56
- ary.map {|n| n.value }.should == [0.1, 0.2, 0.3, 0.4, 0.5]
57
- ary.map {|n| n.index }.should == [0, 1, 2, 3, 4]
58
+ expect(ary).to all(be_a(Node))
59
+ expect(ary.map(&:value).sort).to eq([0.1, 0.2, 0.3, 0.4, 0.5])
60
+ expect(ary.map(&:index).sort).to eq([0, 1, 2, 3, 4])
58
61
  end
59
62
 
60
63
  it "class can create nodes from hash" do
61
64
  ary = Node.features(3=>0.3, 5=>0.5, 6=>0.6, 10=>1.0)
62
- ary.map {|n| n.class.should == Node}
63
- ary.map {|n| n.value }.sort.should == [0.3, 0.5, 0.6, 1.0]
64
- ary.map {|n| n.index }.sort.should == [3, 5, 6, 10]
65
+ expect(ary).to all(be_a(Node))
66
+ expect(ary.map(&:value).sort).to eq([0.3, 0.5, 0.6, 1.0])
67
+ expect(ary.map(&:index).sort).to eq([3, 5, 6, 10])
68
+ end
69
+
70
+ it "compares with nil" do
71
+ expect(Node.new(1,2)).to_not eq(nil)
65
72
  end
66
73
 
67
- it "implements a value-like equality, not identity-notion" do
68
- Node[1, 0.1].should == Node[1, 0.1]
74
+ it "implements value equality" do
75
+ expect(Node[1, 0.1]).to eq(Node[1, 0.1])
69
76
  end
70
77
  end
@@ -5,72 +5,71 @@ describe "A Parameter has accessors for" do
5
5
  @p = Libsvm::SvmParameter.new
6
6
  end
7
7
  it "int svm_type" do
8
- SvmType::C_SVC.should == 0
8
+ expect(SvmType::C_SVC).to eq(0)
9
9
  @p.svm_type = SvmType::C_SVC
10
- @p.svm_type.should == SvmType::C_SVC
10
+ expect(@p.svm_type).to eq(SvmType::C_SVC)
11
11
  end
12
12
 
13
13
  it "int kernel_type" do
14
- KernelType::RBF.should == 2
14
+ expect(KernelType::RBF).to eq(2)
15
15
  @p.kernel_type = KernelType::RBF
16
- @p.kernel_type.should == KernelType::RBF
16
+ expect(@p.kernel_type).to eq(KernelType::RBF)
17
17
  end
18
18
 
19
19
  it "int degree" do
20
20
  @p.degree = 99
21
- @p.degree.should == 99
21
+ expect(@p.degree).to eq(99)
22
22
  end
23
23
 
24
24
  it "double gamma" do
25
25
  @p.gamma = 0.33
26
- @p.gamma.should == 0.33
26
+ expect(@p.gamma).to eq(0.33)
27
27
  end
28
28
 
29
29
  it "double coef0" do
30
30
  @p.coef0 = 0.99
31
- @p.coef0.should == 0.99
31
+ expect(@p.coef0).to eq(0.99)
32
32
  end
33
33
 
34
34
  it "double cache_size" do
35
35
  @p.cache_size = 0.77
36
- @p.cache_size.should == 0.77
36
+ expect(@p.cache_size).to eq(0.77)
37
37
  end
38
38
 
39
39
  it "double eps" do
40
40
  @p.eps = 0.111
41
- @p.eps.should == 0.111
41
+ expect(@p.eps).to eq(0.111)
42
42
  @p.eps = 0.112
43
- @p.eps.should == 0.112
43
+ expect(@p.eps).to eq(0.112)
44
44
  end
45
45
 
46
46
  it "double C" do
47
47
  @p.c = 3.141
48
- @p.c.should == 3.141
48
+ expect(@p.c).to eq(3.141)
49
49
  end
50
50
 
51
51
  it "can set and read weights (weight, weight_label, nr_weight members from struct)" do
52
- @p.label_weights = {1=> 1.2, 3=>0.2, 5=>0.888}
53
- @p.label_weights.should == {1=> 1.2, 3=>0.2, 5=>0.888}
52
+ @p.label_weights = {1 => 1.2, 3 => 0.2, 5 => 0.888}
53
+ expect(@p.label_weights).to eq({1 => 1.2, 3 => 0.2, 5 => 0.888})
54
54
  end
55
55
 
56
-
57
56
  it "double nu" do
58
57
  @p.nu = 1.1
59
- @p.nu.should == 1.1
58
+ expect(@p.nu).to eq(1.1)
60
59
  end
61
60
 
62
61
  it "double p" do
63
62
  @p.p = 0.123
64
- @p.p.should == 0.123
63
+ expect(@p.p).to eq(0.123)
65
64
  end
66
65
 
67
- it "int shrinking" do
66
+ it "boolean-as-int shrinking" do
68
67
  @p.shrinking = 22
69
- @p.shrinking.should == 22
68
+ expect(@p.shrinking).to eq(22)
70
69
  end
71
70
 
72
- it "int probability" do
71
+ it "boolean-as-int probability" do
73
72
  @p.probability = 35
74
- @p.probability.should == 35
73
+ expect(@p.probability).to eq(35)
75
74
  end
76
75
  end
@@ -12,26 +12,30 @@ describe "A Problem" do
12
12
  it "examples get stored and retrieved" do
13
13
  @problem.set_examples([1,2,1,2], @features)
14
14
  labels, examples = @problem.examples
15
- labels.size.should == 4
16
- examples.size.should == 4
17
- examples.map {|x|x.size}.should == [4,4,4,4]
18
- examples.first.map {|node| node.index}.should == [0,1,2,3]
19
- examples.first.map {|node| node.value}.should == [0.2,0.3,0.4,0.4]
15
+ expect(labels.size).to eq(4)
16
+ expect(examples.size).to eq(4)
17
+ expect(examples.map {|x|x.size}).to eq([4,4,4,4])
18
+ expect(examples.first.map {|node| node.index}).to eq([0,1,2,3])
19
+ expect(examples.first.map {|node| node.value}).to eq([0.2,0.3,0.4,0.4])
20
20
  end
21
21
 
22
22
  it "can be populated" do
23
- examples = [Node.features(0.2,0.3,0.4,0.4),
24
- Node.features(0.1,0.5,0.1,0.9),
25
- Node.features(0.2,0.2,0.6,0.5),
26
- Node.features(0.3,0.1,0.5,0.9)]
27
- @problem.set_examples([1,2,1,2], examples)
23
+ examples = [ Node.features(0.2,0.3,0.4,0.4),
24
+ Node.features(0.1,0.5,0.1,0.9),
25
+ Node.features(0.2,0.2,0.6,0.5),
26
+ Node.features(0.3,0.1,0.5,0.9) ]
27
+ expect {
28
+ @problem.set_examples([1,2,1,2], examples)
29
+ }.to_not raise_error
28
30
  end
29
31
 
30
- it "can be set twice over" do
31
- features = [Node.features(0.2, 0.3, 0.4, 0.4), Node.features(0.3,0.1,0.5,0.9)]
32
- @problem.set_examples([1,2], features)
33
- features = [Node.features(0.2, 0.3, 0.4, 0.4), Node.features(0.3,0.1,0.5,0.9)]
34
- @problem.set_examples([8,2], features)
32
+ it "can be set twice" do
33
+ expect {
34
+ features = [Node.features(0.2, 0.3, 0.4, 0.4), Node.features(0.3,0.1,0.5,0.9)]
35
+ @problem.set_examples([1,2], features)
36
+ features = [Node.features(0.2, 0.3, 0.4, 0.4), Node.features(0.3,0.1,0.5,0.9)]
37
+ @problem.set_examples([8,2], features)
38
+ }.to_not raise_error
35
39
  end
36
40
 
37
41
  end
@@ -15,7 +15,7 @@ describe "Basic usage" do
15
15
 
16
16
  it "has a nice API" do
17
17
  example = {11 => 0.11, 21 => 0.21, 101 => 0.99 }.to_example
18
- example.should == Node.features({11 => 0.11, 21 => 0.21, 101 => 0.99 })
18
+ expect(example).to eq(Node.features({11 => 0.11, 21 => 0.21, 101 => 0.99 }))
19
19
  end
20
20
 
21
21
  it "is as in [PCI,217]" do
@@ -26,13 +26,13 @@ describe "Basic usage" do
26
26
  model = Model.train(@problem, @parameter)
27
27
 
28
28
  pred = model.predict(Node.features(1, 1, 1))
29
- pred.should == 1.0
29
+ expect(pred).to eq(1.0)
30
30
 
31
31
  pred = model.predict(Node.features(-1, 1, -1))
32
- pred.should == -1.0
32
+ expect(pred).to eq(-1.0)
33
33
 
34
34
  pred = model.predict(Node.features(-1, 55, -1))
35
- pred.should == -1.0
35
+ expect(pred).to eq(-1.0)
36
36
  end
37
37
 
38
38
  it "kernel parameter use" do
@@ -42,6 +42,6 @@ describe "Basic usage" do
42
42
 
43
43
  model = Model.train(@problem, @parameter)
44
44
 
45
- model.predict(Node.features(1, 2, 3)).should == 2
45
+ expect(model.predict(Node.features(1, 2, 3))).to eq(2)
46
46
  end
47
47
  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.3.1
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - C. Florian Ebeling
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-03-21 00:00:00.000000000 Z
12
+ date: 2015-09-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake-compiler
@@ -100,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
100
  version: '0'
101
101
  requirements: []
102
102
  rubyforge_project: rb-libsvm
103
- rubygems_version: 2.2.2
103
+ rubygems_version: 2.4.5
104
104
  signing_key:
105
105
  specification_version: 4
106
106
  summary: Ruby bindings for LIBSVM
@@ -112,4 +112,3 @@ test_files:
112
112
  - spec/problem_spec.rb
113
113
  - spec/spec_helper.rb
114
114
  - spec/usage_spec.rb
115
- has_rdoc: