knnball 0.0.6 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
1
  require 'rake/testtask'
2
2
 
3
- Rake::TestTask.new do |tt|
4
- tt.test_files = FileList['test/specs/*_spec.rb', 'test/units/*_test.rb']
3
+ Rake::TestTask.new(:test) do |tt|
4
+ tt.test_files = FileList['test/spec/*_spec.rb', 'test/units/*_test.rb']
5
5
  tt.verbose = true
6
6
  end
7
+
8
+ task :default => :test
data/knnball.gemspec CHANGED
@@ -4,8 +4,8 @@ Gem::Specification.new do |s|
4
4
  s.rubygems_version = '1.3.5'
5
5
 
6
6
  s.name = 'knnball'
7
- s.version = '0.0.6'
8
- s.date = '2011-09-09'
7
+ s.version = '0.1.0'
8
+ s.date = '2012-05-28'
9
9
  s.rubyforge_project = 'knnball'
10
10
 
11
11
  s.summary = "Multi-dimensional nearest neighbor search"
@@ -31,15 +31,15 @@ lib/knnball/ball.rb
31
31
  lib/knnball/stat.rb
32
32
  lib/knnball/kdtree.rb
33
33
  lib/knnball/result_set.rb
34
- test/specs/ball_spec.rb
35
- test/specs/data.json
36
- test/specs/kdtree_spec.rb
37
- test/specs/knnball_spec.rb
38
- test/specs/result_set_spec.rb
39
- test/specs/spec_helpers.rb
34
+ test/spec/ball_spec.rb
35
+ test/spec/data.json
36
+ test/spec/kdtree_spec.rb
37
+ test/spec/knnball_spec.rb
38
+ test/spec/result_set_spec.rb
39
+ test/spec/spec_helpers.rb
40
40
  test/units/stat_test.rb
41
41
  ]
42
42
  # = MANIFEST =
43
43
 
44
- s.test_files = s.files.select { |path| path =~ /^test\/units\/\.*_test\.rb|test\/specs\/\.*_spec\.rb/ }
44
+ s.test_files = s.files.select { |path| path =~ /^test\/units\/\.*_test\.rb|test\/spec\/\.*_spec\.rb/ }
45
45
  end
data/lib/knnball.rb CHANGED
@@ -5,8 +5,6 @@
5
5
  # knnball is freely distributable under the terms of an MIT license.
6
6
  # See LICENSE or http://www.opensource.org/licenses/mit-license.php.
7
7
 
8
-
9
-
10
8
  # This module is used as namespace for every elements of
11
9
  # the knnball library.
12
10
  module KnnBall
@@ -58,7 +56,7 @@ module KnnBall
58
56
  actual_dimension = (max_dimension == actual_dimension ? 1 : actual_dimension)
59
57
 
60
58
  ball.left = generate(data[0..(median_idx-1)], max_dimension, actual_dimension) if median_idx > 0
61
- ball.right = generate(data[(median_idx+1)..-1], max_dimension, actual_dimension) if median_idx < (data.count)
59
+ ball.right = generate(data[(median_idx+1)..-1], max_dimension, actual_dimension) if median_idx < (data.count - 1)
62
60
  return ball
63
61
  end
64
62
 
data/lib/knnball/stat.rb CHANGED
@@ -53,8 +53,13 @@ module KnnBall
53
53
  return left
54
54
  end
55
55
 
56
+ # Retrieve the median index of an array.
57
+ # array.count == 0 -> 0
58
+ # array.count == 1 -> 0
59
+ # array.count == 2 -> 1
60
+ # array.count == 3 -> 1
56
61
  def self.median_index(data)
57
- (data.size % 2 == 0) ? (data.size - 1)/ 2 : data.size / 2
62
+ (data.size % 2 == 0) ? (data.size / 2) : (data.size - 1) / 2
58
63
  end
59
64
  end
60
65
  end
@@ -5,12 +5,9 @@
5
5
  # knnball is freely distributable under the terms of an MIT license.
6
6
  # See LICENSE or http://www.opensource.org/licenses/mit-license.php.
7
7
 
8
-
9
-
10
8
  require 'minitest/autorun'
11
9
  require 'knnball'
12
10
 
13
-
14
11
  module KnnBall
15
12
 
16
13
  describe Ball do
File without changes
File without changes
@@ -49,7 +49,7 @@ describe KnnBall do
49
49
  {:id => 6, :point => [13]},
50
50
  {:id => 7, :point => [21]},
51
51
  {:id => 8, :point => [34]}
52
- ]).root.value.must_equal({:id => 4, :point => [5]})
52
+ ]).root.value.must_equal({:id => 5, :point => [8]})
53
53
  end
54
54
  end
55
55
 
@@ -92,7 +92,7 @@ describe KnnBall do
92
92
  msgs << "For #{p}, #{nn_result} retrieved amongs those 2 first results #{tree.nearest(p[:point], :limit => 2)}"
93
93
  end
94
94
  end
95
- must_be_empty msgs
95
+ msgs.must_be_empty
96
96
  end
97
97
 
98
98
  it "is more efficient than the brute force approach" do
@@ -166,7 +166,7 @@ describe KnnBall do
166
166
  nn_result = @index.nearest(p[:point], :limit => 10)
167
167
  (nn_result.map{|r| r[:point]}).must_equal(brute_force_result.map{|r| r[:point]})
168
168
  end
169
- must_be_empty(msgs)
169
+ msgs.must_be_empty
170
170
  end
171
171
  end
172
172
  end
@@ -150,8 +150,8 @@ module KnnBall
150
150
  end
151
151
 
152
152
  it "accept smaller value" do
153
- assert @rs.eligible? -2
154
- assert @rs.eligible? 4
153
+ @rs.eligible?(-2).must_equal true
154
+ @rs.eligible?(4).must_equal true
155
155
  end
156
156
  end
157
157
  end
File without changes
@@ -5,16 +5,17 @@
5
5
  # knnball is freely distributable under the terms of an MIT license.
6
6
  # See LICENSE or http://www.opensource.org/licenses/mit-license.php.
7
7
 
8
-
9
-
10
- require 'minitest/autorun'
8
+ require 'test/unit'
11
9
  require 'knnball'
12
10
 
13
11
  module KnnBall
14
- class StatTest < MiniTest::Unit::TestCase
12
+ class StatTest < Test::Unit::TestCase
15
13
  def test_median_index
14
+ assert_equal(0, Stat.median_index([]))
15
+ assert_equal(0, Stat.median_index([1]))
16
+ assert_equal(1, Stat.median_index([1] * 2))
16
17
  assert_equal(1, Stat.median_index([1] * 3))
17
- assert_equal(1, Stat.median_index([1] * 4))
18
+ assert_equal(2, Stat.median_index([1] * 4))
18
19
  end
19
20
 
20
21
  def test_pivot
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knnball
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-09 00:00:00.000000000 +02:00
13
- default_executable:
12
+ date: 2012-05-28 00:00:00.000000000 Z
14
13
  dependencies: []
15
14
  description: Implements K-Nearest Neighbor algorithm using a KDTree in Ruby. Usefull
16
15
  for sorting geolocation or any other multi-dimensional data.
@@ -30,14 +29,13 @@ files:
30
29
  - lib/knnball/stat.rb
31
30
  - lib/knnball/kdtree.rb
32
31
  - lib/knnball/result_set.rb
33
- - test/specs/ball_spec.rb
34
- - test/specs/data.json
35
- - test/specs/kdtree_spec.rb
36
- - test/specs/knnball_spec.rb
37
- - test/specs/result_set_spec.rb
38
- - test/specs/spec_helpers.rb
32
+ - test/spec/ball_spec.rb
33
+ - test/spec/data.json
34
+ - test/spec/kdtree_spec.rb
35
+ - test/spec/knnball_spec.rb
36
+ - test/spec/result_set_spec.rb
37
+ - test/spec/spec_helpers.rb
39
38
  - test/units/stat_test.rb
40
- has_rdoc: true
41
39
  homepage: http://github.com/oliamb/knnball
42
40
  licenses: []
43
41
  post_install_message:
@@ -59,7 +57,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
57
  version: '0'
60
58
  requirements: []
61
59
  rubyforge_project: knnball
62
- rubygems_version: 1.6.2
60
+ rubygems_version: 1.8.24
63
61
  signing_key:
64
62
  specification_version: 1
65
63
  summary: Multi-dimensional nearest neighbor search