Class: Fastout::Ranker::Point

Inherits:
Object
  • Object
show all
Defined in:
lib/fastout/ranker.rb

Constant Summary collapse

@@next_id =
0

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#attributesObject (readonly)

Returns the value of attribute attributes.



20
21
22
# File 'lib/fastout/ranker.rb', line 20

def attributes
  @attributes
end

#binsObject (readonly)

Returns the value of attribute bins.



20
21
22
# File 'lib/fastout/ranker.rb', line 20

def bins
  @bins
end

#clusterObject

Returns the value of attribute cluster.



21
22
23
# File 'lib/fastout/ranker.rb', line 21

def cluster
  @cluster
end

#idObject (readonly)

Returns the value of attribute id.



20
21
22
# File 'lib/fastout/ranker.rb', line 20

def id
  @id
end

#scoreObject

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