Class: Fastout::Ranker::Point
- Inherits:
-
Object
- Object
- Fastout::Ranker::Point
- Defined in:
- lib/fastout/ranker.rb
Constant Summary collapse
- @@next_id =
0
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#bins ⇒ Object
readonly
Returns the value of attribute bins.
-
#cluster ⇒ Object
Returns the value of attribute cluster.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#score ⇒ Object
Returns the value of attribute score.
Class Method Summary collapse
Instance Method Summary collapse
- #[](index) ⇒ Object
- #clustered? ⇒ Boolean
- #in_the_neighborhood_of?(point, attribute_indexes, neighborhoods) ⇒ Boolean
-
#initialize(*attributes) ⇒ Point
constructor
A new instance of Point.
- #neighbor_of_any?(points, attribute_indexes, neighborhoods) ⇒ Boolean
- #uncluster! ⇒ Object
Constructor Details
#initialize(*attributes) ⇒ Point
23 24 25 26 27 28 29 30 31 |
# File 'lib/fastout/ranker.rb', line 23 def initialize *attributes @attributes = attributes @cluster = nil @score = 0 @bins = [] @id = @@next_id @@next_id += 1 end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
20 21 22 |
# File 'lib/fastout/ranker.rb', line 20 def attributes @attributes end |
#bins ⇒ Object (readonly)
Returns the value of attribute bins.
20 21 22 |
# File 'lib/fastout/ranker.rb', line 20 def bins @bins end |
#cluster ⇒ Object
Returns the value of attribute cluster.
21 22 23 |
# File 'lib/fastout/ranker.rb', line 21 def cluster @cluster end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
20 21 22 |
# File 'lib/fastout/ranker.rb', line 20 def id @id end |
#score ⇒ Object
Returns the value of attribute score.
21 22 23 |
# File 'lib/fastout/ranker.rb', line 21 def score @score end |
Class Method Details
.next_id=(id) ⇒ Object
16 17 18 |
# File 'lib/fastout/ranker.rb', line 16 def self.next_id= id @@next_id = id end |
Instance Method Details
#[](index) ⇒ Object
33 34 35 |
# File 'lib/fastout/ranker.rb', line 33 def [] index @attributes[index] end |
#clustered? ⇒ Boolean
37 38 39 |
# File 'lib/fastout/ranker.rb', line 37 def clustered? !! cluster end |
#in_the_neighborhood_of?(point, attribute_indexes, neighborhoods) ⇒ Boolean
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/fastout/ranker.rb', line 45 def in_the_neighborhood_of? point, attribute_indexes, neighborhoods attribute_indexes.each do |attribute_index| return false if (bins[attribute_index] - point.bins[attribute_index]).abs > 1 end attribute_indexes.each_with_index do |attribute_index, neighborhood_index| return false if (attributes[attribute_index] - point.attributes[attribute_index]) > (neighborhoods[neighborhood_index] / 2.0) end true end |
#neighbor_of_any?(points, attribute_indexes, neighborhoods) ⇒ Boolean
57 58 59 |
# File 'lib/fastout/ranker.rb', line 57 def neighbor_of_any? points, attribute_indexes, neighborhoods points.inject(false) {|found, point| found or in_the_neighborhood_of?(point, attribute_indexes, neighborhoods) } end |
#uncluster! ⇒ Object
41 42 43 |
# File 'lib/fastout/ranker.rb', line 41 def uncluster! @cluster = nil end |