hierclust 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +7 -0
- data/lib/hierclust/cluster.rb +6 -0
- data/lib/hierclust/point.rb +5 -0
- data/lib/hierclust/version.rb +1 -1
- data/spec/hierclust/cluster_spec.rb +9 -0
- data/spec/hierclust/clusterer_spec.rb +176 -160
- data/tasks/rspec.rake +10 -9
- data/website/index.html +18 -6
- data/website/index.txt +11 -3
- data/website/template.rhtml +1 -1
- metadata +4 -4
data/History.txt
CHANGED
data/lib/hierclust/cluster.rb
CHANGED
@@ -29,6 +29,12 @@ module Hierclust
|
|
29
29
|
@items.size
|
30
30
|
end
|
31
31
|
|
32
|
+
# Returns a flat list of all the points contained in either this cluster
|
33
|
+
# or any of the clusters it contains.
|
34
|
+
def points
|
35
|
+
@items.map {|item| item.points}.flatten
|
36
|
+
end
|
37
|
+
|
32
38
|
# Returns +true+ if this Cluster includes the given +item+, otherwise
|
33
39
|
# returns +false+.
|
34
40
|
def include?(item)
|
data/lib/hierclust/point.rb
CHANGED
data/lib/hierclust/version.rb
CHANGED
@@ -39,6 +39,7 @@ module Hierclust
|
|
39
39
|
@p_1 = Point.new(@x_1, @y_1)
|
40
40
|
@p_2 = Point.new(@x_2, @y_2)
|
41
41
|
@c = Cluster.new([@p_1, @p_2])
|
42
|
+
@points = @c.points
|
42
43
|
end
|
43
44
|
|
44
45
|
it "should have x-coordinate at average of point's x-coordinates" do
|
@@ -48,5 +49,13 @@ module Hierclust
|
|
48
49
|
it "should have y-coordinate at average of point's y-coordinates" do
|
49
50
|
@c.y.should == 6
|
50
51
|
end
|
52
|
+
|
53
|
+
it "should have two points" do
|
54
|
+
@points.size.should == 2
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should include both points" do
|
58
|
+
@points.should include(@p_1, @p_2)
|
59
|
+
end
|
51
60
|
end
|
52
61
|
end
|
@@ -1,167 +1,183 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb')
|
2
2
|
|
3
3
|
module Hierclust
|
4
|
-
describe Clusterer
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
4
|
+
describe Clusterer do
|
5
|
+
describe "with no data" do
|
6
|
+
before do
|
7
|
+
@c = Clusterer.new([])
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should return no clusters" do
|
11
|
+
@c.clusters.should == []
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "with one point" do
|
16
|
+
before do
|
17
|
+
@x = 1
|
18
|
+
@y = 2
|
19
|
+
@p = Point.new(@x, @y)
|
20
|
+
@c = Clusterer.new([@p])
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should return the point" do
|
24
|
+
@c.clusters.should == [@p]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "with two points" do
|
29
|
+
before do
|
30
|
+
@x_1, @x_2 = 1, 5
|
31
|
+
@y_1, @y_2 = 2, 8
|
32
|
+
@p_1 = Point.new(@x_1, @y_1)
|
33
|
+
@p_2 = Point.new(@x_2, @y_2)
|
34
|
+
@c = Clusterer.new([@p_1, @p_2])
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should return one cluster" do
|
38
|
+
@c.clusters.size.should == 1
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should have two points in the cluster" do
|
42
|
+
@c.clusters.first.size.should == 2
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should have the first point in the cluster" do
|
46
|
+
@c.clusters.first.should include(@p_1)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should have the second point in the cluster" do
|
50
|
+
@c.clusters.first.should include(@p_2)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "with three points" do
|
55
|
+
before do
|
56
|
+
@x_1, @x_2, @x_3 = 1, 5, 2
|
57
|
+
@y_1, @y_2, @y_3 = 2, 6, 3
|
58
|
+
@p_1 = Point.new(@x_1, @y_1)
|
59
|
+
@p_2 = Point.new(@x_2, @y_2)
|
60
|
+
@p_3 = Point.new(@x_3, @y_3)
|
61
|
+
@c = Clusterer.new([@p_1, @p_2, @p_3])
|
62
|
+
@cluster = @c.clusters.first
|
63
|
+
@clusters = @cluster.items.sort_by{|c|c.size}
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should return one cluster" do
|
67
|
+
@c.clusters.size.should == 1
|
68
|
+
end
|
69
|
+
|
70
|
+
it "containing two items" do
|
71
|
+
@cluster.items.size.should == 2
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should have one Cluster" do
|
75
|
+
@clusters[1].class.should == Cluster
|
76
|
+
end
|
77
|
+
|
78
|
+
it "and one Point" do
|
79
|
+
@clusters[0].class.should == Point
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should have the first and third points in the bigger cluster" do
|
83
|
+
@clusters[1].should include(@p_1, @p_3)
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should have the second point in the smaller cluster" do
|
87
|
+
@clusters[0].should == @p_2
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe "with four points" do
|
92
|
+
before do
|
93
|
+
@points = [
|
94
|
+
Point.new(0, 1),
|
95
|
+
Point.new(1, 0),
|
96
|
+
Point.new(3, 4),
|
97
|
+
Point.new(4, 3),
|
98
|
+
]
|
99
|
+
end
|
100
|
+
|
101
|
+
describe "and no separation" do
|
102
|
+
before do
|
103
|
+
@c = Clusterer.new(@points)
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should return one cluster" do
|
107
|
+
@c.clusters.size.should == 1
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
describe "and separation 1" do
|
112
|
+
before do
|
113
|
+
@c = Clusterer.new(@points, 1)
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should return all four individual points" do
|
117
|
+
@c.clusters.size.should == 4
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
describe "and separation 2" do
|
122
|
+
before do
|
123
|
+
@c = Clusterer.new(@points, 2)
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should return two clusters" do
|
127
|
+
@c.clusters.size.should == 2
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
describe "with eight points" do
|
133
|
+
before do
|
134
|
+
@points = [
|
135
|
+
Point.new(0, 1),
|
136
|
+
Point.new(1, 0),
|
137
|
+
Point.new(3, 4),
|
138
|
+
Point.new(4, 3),
|
139
|
+
Point.new(7, 8),
|
140
|
+
Point.new(8, 7),
|
141
|
+
Point.new(8, 9),
|
142
|
+
Point.new(9, 8),
|
143
|
+
]
|
144
|
+
end
|
137
145
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
146
|
+
describe "and no separation" do
|
147
|
+
before do
|
148
|
+
@clusters = Clusterer.new(@points).clusters.sort
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should return one cluster when no minimum separation is given" do
|
152
|
+
@clusters.size.should == 1
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
describe "and separation 1" do
|
157
|
+
before do
|
158
|
+
@clusters = Clusterer.new(@points, 1).clusters.sort
|
159
|
+
end
|
160
|
+
|
161
|
+
it "should have all eight points in individual clusters" do
|
162
|
+
@clusters.size.should == 8
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
describe "and separation 3" do
|
167
|
+
before do
|
168
|
+
@clusters = Clusterer.new(@points, 3).clusters.sort
|
169
|
+
end
|
170
|
+
|
171
|
+
it "should have three clusters" do
|
172
|
+
@clusters.size.should == 3
|
173
|
+
end
|
174
|
+
|
175
|
+
it "should have clusters size 2, 2, and 4 " do
|
176
|
+
@clusters[0].points.size.should == 2
|
177
|
+
@clusters[1].points.size.should == 2
|
178
|
+
@clusters[2].points.size.should == 4
|
179
|
+
end
|
180
|
+
end
|
165
181
|
end
|
166
182
|
end
|
167
183
|
end
|
data/tasks/rspec.rake
CHANGED
@@ -1,20 +1,21 @@
|
|
1
|
+
begin
|
2
|
+
require 'spec'
|
3
|
+
rescue LoadError
|
4
|
+
require 'rubygems'
|
5
|
+
require 'spec'
|
6
|
+
end
|
1
7
|
begin
|
2
8
|
require 'spec/rake/spectask'
|
3
9
|
rescue LoadError
|
4
|
-
|
5
|
-
require 'rubygems'
|
6
|
-
require 'spec/rake/spectask'
|
7
|
-
rescue LoadError
|
8
|
-
puts <<-EOS
|
10
|
+
puts <<-EOS
|
9
11
|
To use rspec for testing you must install rspec gem:
|
10
12
|
gem install rspec
|
11
13
|
EOS
|
12
|
-
|
13
|
-
end
|
14
|
+
exit(0)
|
14
15
|
end
|
15
16
|
|
16
|
-
desc "Run the specs under spec/"
|
17
|
+
desc "Run the specs under spec/models"
|
17
18
|
Spec::Rake::SpecTask.new do |t|
|
18
19
|
t.spec_opts = ['--options', "spec/spec.opts"]
|
19
|
-
t.spec_files = FileList['spec
|
20
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
20
21
|
end
|
data/website/index.html
CHANGED
@@ -33,7 +33,7 @@
|
|
33
33
|
<h1>Simple Hierarchical Clustering</h1>
|
34
34
|
<div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/hierclust"; return false'>
|
35
35
|
<p>Get Version</p>
|
36
|
-
<a href="http://rubyforge.org/projects/hierclust" class="numbers">0.1.
|
36
|
+
<a href="http://rubyforge.org/projects/hierclust" class="numbers">0.1.1</a>
|
37
37
|
</div>
|
38
38
|
<h1>→ ‘hierclust’</h1>
|
39
39
|
|
@@ -110,19 +110,31 @@ to your data:</p>
|
|
110
110
|
<span class="keyword">end</span></pre></p>
|
111
111
|
|
112
112
|
|
113
|
+
<h2>Documentaion</h2>
|
114
|
+
|
115
|
+
|
116
|
+
<p><span class="caps">API</span> documentation: <a href="rdoc/">RDoc</a></p>
|
117
|
+
|
118
|
+
|
113
119
|
<h2>Forum</h2>
|
114
120
|
|
115
121
|
|
116
122
|
<p><a href="http://groups.google.com/group/hierclust">http://groups.google.com/group/hierclust</a></p>
|
117
123
|
|
118
124
|
|
119
|
-
<h2>
|
125
|
+
<h2>Source code</h2>
|
120
126
|
|
121
127
|
|
122
|
-
<p>
|
128
|
+
<p>The trunk repository is <code>svn://rubyforge.org/var/svn/hierclust/trunk</code> for anonymous access.</p>
|
123
129
|
|
124
130
|
|
125
|
-
<p>
|
131
|
+
<p>You can also browse the source online at <a href="http://hierclust.rubyforge.org/svn/trunk/">http://hierclust.rubyforge.org/svn/trunk/</a></p>
|
132
|
+
|
133
|
+
|
134
|
+
<h2>How to submit patches</h2>
|
135
|
+
|
136
|
+
|
137
|
+
<p>Read the <a href="http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/">8 steps for fixing other people’s code</a> and for section <a href="http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/#8b-google-groups">8b: Submit patch to Google Groups</a>, use the Google Group above.</p>
|
126
138
|
|
127
139
|
|
128
140
|
<h2>License</h2>
|
@@ -134,9 +146,9 @@ to your data:</p>
|
|
134
146
|
<h2>Contact</h2>
|
135
147
|
|
136
148
|
|
137
|
-
<p>Comments are welcome. Send an email to <a href="mailto:
|
149
|
+
<p>Comments are welcome. Send an email to <a href="mailto:brandt@kurowski.net">Brandt Kurowski</a> email via the <a href="http://groups.google.com/group/hierclust">forum</a></p>
|
138
150
|
<p class="coda">
|
139
|
-
<a href="
|
151
|
+
<a href="http://brandt.kurowski.net/">Brandt Kurowski</a>, 4th February 2008<br>
|
140
152
|
Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
|
141
153
|
</p>
|
142
154
|
</div>
|
data/website/index.txt
CHANGED
@@ -56,21 +56,29 @@ clusters.each do |cluster|
|
|
56
56
|
)
|
57
57
|
end</pre>
|
58
58
|
|
59
|
+
h2. Documentaion
|
60
|
+
|
61
|
+
API documentation: "RDoc":rdoc/
|
62
|
+
|
59
63
|
h2. Forum
|
60
64
|
|
61
65
|
"http://groups.google.com/group/hierclust":http://groups.google.com/group/hierclust
|
62
66
|
|
67
|
+
h2. Source code
|
68
|
+
|
69
|
+
The trunk repository is <code>svn://rubyforge.org/var/svn/hierclust/trunk</code> for anonymous access.
|
70
|
+
|
71
|
+
You can also browse the source online at "http://hierclust.rubyforge.org/svn/trunk/":http://hierclust.rubyforge.org/svn/trunk/
|
72
|
+
|
63
73
|
h2. How to submit patches
|
64
74
|
|
65
75
|
Read the "8 steps for fixing other people's code":http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/ and for section "8b: Submit patch to Google Groups":http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/#8b-google-groups, use the Google Group above.
|
66
76
|
|
67
|
-
The trunk repository is <code>svn://rubyforge.org/var/svn/hierclust/trunk</code> for anonymous access.
|
68
|
-
|
69
77
|
h2. License
|
70
78
|
|
71
79
|
This code is free to use under the terms of the MIT license.
|
72
80
|
|
73
81
|
h2. Contact
|
74
82
|
|
75
|
-
Comments are welcome. Send an email to "
|
83
|
+
Comments are welcome. Send an email to "Brandt Kurowski":mailto:brandt@kurowski.net email via the "forum":http://groups.google.com/group/hierclust
|
76
84
|
|
data/website/template.rhtml
CHANGED
@@ -37,7 +37,7 @@
|
|
37
37
|
</div>
|
38
38
|
<%= body %>
|
39
39
|
<p class="coda">
|
40
|
-
<a href="
|
40
|
+
<a href="http://brandt.kurowski.net/">Brandt Kurowski</a>, <%= modified.pretty %><br>
|
41
41
|
Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
|
42
42
|
</p>
|
43
43
|
</div>
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hierclust
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
5
|
-
platform:
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandt Kurowski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-02-
|
12
|
+
date: 2008-02-04 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -83,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
83
|
requirements: []
|
84
84
|
|
85
85
|
rubyforge_project: hierclust
|
86
|
-
rubygems_version: 0.
|
86
|
+
rubygems_version: 1.0.1
|
87
87
|
signing_key:
|
88
88
|
specification_version: 2
|
89
89
|
summary: performs hierarchical clustering on geometric points
|