Class: Histogram
Defined Under Namespace
Classes: EquivalenceClass
Instance Method Summary
collapse
Constructor Details
#initialize(enum = nil) ⇒ Histogram
Here the enumearation is something which respond to each.
49
50
51
52
|
# File 'lib/histogram.rb', line 49
def initialize ( enum=nil )
@hist = []
enum.each { |x| self << x } unless enum.nil?
end
|
Instance Method Details
#<<(anObject) ⇒ Object
88
89
90
91
92
93
94
95
96
|
# File 'lib/histogram.rb', line 88
def << ( anObject )
anEquivalenceClass = equivalence_class_of anObject
if anEquivalenceClass.nil?
@hist << EquivalenceClass.new(@hist.size, anObject)
else
anEquivalenceClass << anObject
end
self
end
|
#[](anObject) ⇒ Object
99
100
101
102
|
# File 'lib/histogram.rb', line 99
def [] ( anObject )
anEquivalenceClass = equivalence_class_of(anObject)
(anEquivalenceClass)? anEquivalenceClass.size : 0
end
|
#each(&block) ⇒ Object
105
106
107
|
# File 'lib/histogram.rb', line 105
def each ( &block )
@hist.each(&block)
end
|
#equivalence_class_by_index(anInteger) ⇒ Object
83
84
85
|
# File 'lib/histogram.rb', line 83
def equivalence_class_by_index ( anInteger )
@hist[anInteger]
end
|
#equivalence_class_of(anObject) ⇒ Object
75
76
77
78
79
80
|
# File 'lib/histogram.rb', line 75
def equivalence_class_of ( anObject )
@hist.each do |anEquivalenceClass|
return anEquivalenceClass if anEquivalenceClass.include? anObject
end
return nil
end
|
#frequences ⇒ Object
Returns apparation frequences as an array which is the @support@ divided by the amount of samples.
63
64
65
66
67
|
# File 'lib/histogram.rb', line 63
def frequences
sup = support
total = sup.sum
sup.map { |x| x.to_f / total }
end
|
110
111
112
|
# File 'lib/histogram.rb', line 110
def size
@hist.size
end
|
Returns an array with size of each equivalence class.
56
57
58
|
# File 'lib/histogram.rb', line 56
def support
@hist.map { |equivalence_class| equivalence_class.size }
end
|
115
116
117
|
# File 'lib/histogram.rb', line 115
def to_a
@hist.dup
end
|
70
71
72
|
# File 'lib/histogram.rb', line 70
def total
support.sum
end
|