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 CHANGED
@@ -1,3 +1,10 @@
1
+ == 0.1.1 2008-02-04
2
+
3
+ * 1 minor enhancement:
4
+ * add method for returning flattened list of points in a cluster
5
+ * 1 bugfix:
6
+ * correct intermittent failure of Clusterer spec
7
+
1
8
  == 0.1.0 2008-02-01
2
9
 
3
10
  * 1 major enhancement:
@@ -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)
@@ -18,6 +18,11 @@ module Hierclust
18
18
  1
19
19
  end
20
20
 
21
+ # Simplifies code by letting us treat Clusters and Points interchangeably
22
+ def points #:nodoc:
23
+ self
24
+ end
25
+
21
26
  # Returns a legible representation of this Point.
22
27
  def to_s
23
28
  "(#{x}, #{y})"
@@ -2,7 +2,7 @@ module Hierclust #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 0
5
+ TINY = 1
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -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, " with no data" do
5
- before do
6
- @c = Clusterer.new([])
7
- end
8
-
9
- it "should return no clusters" do
10
- @c.clusters.should == []
11
- end
12
- end
13
-
14
- describe Clusterer, " with one point" do
15
- before do
16
- @x = 1
17
- @y = 2
18
- @p = Point.new(@x, @y)
19
- @c = Clusterer.new([@p])
20
- end
21
-
22
- it "should return the point" do
23
- @c.clusters.should == [@p]
24
- end
25
- end
26
-
27
- describe Clusterer, " with two points" do
28
- before do
29
- @x_1, @x_2 = 1, 5
30
- @y_1, @y_2 = 2, 8
31
- @p_1 = Point.new(@x_1, @y_1)
32
- @p_2 = Point.new(@x_2, @y_2)
33
- @c = Clusterer.new([@p_1, @p_2])
34
- end
35
-
36
- it "should return one cluster" do
37
- @c.clusters.size.should == 1
38
- end
39
-
40
- it "should have two points in the cluster" do
41
- @c.clusters.first.size.should == 2
42
- end
43
-
44
- it "should have the first point in the cluster" do
45
- @c.clusters.first.should include(@p_1)
46
- end
47
-
48
- it "should have the second point in the cluster" do
49
- @c.clusters.first.should include(@p_2)
50
- end
51
- end
52
-
53
- describe Clusterer, " with three points" do
54
- before do
55
- @x_1, @x_2, @x_3 = 1, 5, 2
56
- @y_1, @y_2, @y_3 = 2, 6, 3
57
- @p_1 = Point.new(@x_1, @y_1)
58
- @p_2 = Point.new(@x_2, @y_2)
59
- @p_3 = Point.new(@x_3, @y_3)
60
- @c = Clusterer.new([@p_1, @p_2, @p_3])
61
- @cluster = @c.clusters.first
62
- @clusters = @cluster.items.sort_by{|c|c.size}
63
- end
64
-
65
- it "should return one cluster" do
66
- @c.clusters.size.should == 1
67
- end
68
-
69
- it "containing two items" do
70
- @cluster.items.size.should == 2
71
- end
72
-
73
- it "should have one Cluster" do
74
- @clusters[1].class.should == Cluster
75
- end
76
-
77
- it "and one Point" do
78
- @clusters[0].class.should == Point
79
- end
80
-
81
- it "should have the first and third points in the bigger cluster" do
82
- @clusters[1].should include(@p_1, @p_3)
83
- end
84
-
85
- it "should have the second point in the smaller cluster" do
86
- @clusters[0].should == @p_2
87
- end
88
- end
89
-
90
- FOUR_P = [
91
- Point.new(0, 1),
92
- Point.new(1, 0),
93
- Point.new(3, 4),
94
- Point.new(4, 3),
95
- ]
96
-
97
- describe Clusterer, " with four points and no separation" do
98
- before do
99
- @c = Clusterer.new(FOUR_P)
100
- end
101
-
102
- it "should return one cluster" do
103
- @c.clusters.size.should == 1
104
- end
105
- end
106
-
107
- describe Clusterer, " with four points and separation 1" do
108
- before do
109
- @c = Clusterer.new(FOUR_P, 1)
110
- end
111
-
112
- it "should return all four individual points" do
113
- @c.clusters.size.should == 4
114
- end
115
- end
116
-
117
- describe Clusterer, " with four points and separation 2" do
118
- before do
119
- @c = Clusterer.new(FOUR_P, 2)
120
- end
121
-
122
- it "should return two clusters" do
123
- @c.clusters.size.should == 2
124
- end
125
- end
126
-
127
- EIGHT_P = [
128
- Point.new(0, 1),
129
- Point.new(1, 0),
130
- Point.new(3, 4),
131
- Point.new(4, 3),
132
- Point.new(7, 8),
133
- Point.new(8, 7),
134
- Point.new(8, 9),
135
- Point.new(9, 8),
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
- describe Clusterer, " with eight points and no separation" do
139
- before do
140
- @c = Clusterer.new(EIGHT_P)
141
- end
142
-
143
- it "should return one cluster when no minimum separation is given" do
144
- @c.clusters.size.should == 1
145
- end
146
- end
147
-
148
- describe Clusterer, " with eight points and separation 1" do
149
- before do
150
- @c = Clusterer.new(EIGHT_P, 1)
151
- end
152
-
153
- it "should return all eight individual points" do
154
- @c.clusters.size.should == 8
155
- end
156
- end
157
-
158
- describe Clusterer, " with eight points and separation 2" do
159
- before do
160
- @c = Clusterer.new(EIGHT_P, 2)
161
- end
162
-
163
- it "should return three clusters" do
164
- @c.clusters.size.should == 3
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
- begin
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
- exit(0)
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/*_spec.rb']
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.0</a>
36
+ <a href="http://rubyforge.org/projects/hierclust" class="numbers">0.1.1</a>
37
37
  </div>
38
38
  <h1>&#x2192; &#8216;hierclust&#8217;</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>How to submit patches</h2>
125
+ <h2>Source code</h2>
120
126
 
121
127
 
122
- <p>Read the <a href="http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/">8 steps for fixing other people&#8217;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>
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>The trunk repository is <code>svn://rubyforge.org/var/svn/hierclust/trunk</code> for anonymous access.</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&#8217;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:FIXME"><span class="caps">FIXME</span> full name</a> email via the <a href="http://groups.google.com/group/hierclust">forum</a></p>
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="FIXME email">FIXME full name</a>, 2nd February 2008<br>
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 "FIXME full name":mailto:FIXME email via the "forum":http://groups.google.com/group/hierclust
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
 
@@ -37,7 +37,7 @@
37
37
  </div>
38
38
  <%= body %>
39
39
  <p class="coda">
40
- <a href="FIXME email">FIXME full name</a>, <%= modified.pretty %><br>
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.0
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-02 00:00:00 -05:00
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.9.5
86
+ rubygems_version: 1.0.1
87
87
  signing_key:
88
88
  specification_version: 2
89
89
  summary: performs hierarchical clustering on geometric points