Class: CodeModels::CountingMap
- Inherits:
-
Object
- Object
- CodeModels::CountingMap
- Defined in:
- lib/emf/stats.rb
Instance Method Summary collapse
- #each(&block) ⇒ Object
- #inc(key) ⇒ Object
-
#initialize ⇒ CountingMap
constructor
A new instance of CountingMap.
- #n_values ⇒ Object
-
#p(key) ⇒ Object
number of times the value appeared divived by total frequency.
- #total_frequency ⇒ Object
- #value(key) ⇒ Object
Constructor Details
#initialize ⇒ CountingMap
Returns a new instance of CountingMap.
7 8 9 10 |
# File 'lib/emf/stats.rb', line 7 def initialize @map = {} @sum_values = 0 end |
Instance Method Details
#each(&block) ⇒ Object
28 29 30 |
# File 'lib/emf/stats.rb', line 28 def each(&block) @map.each(&block) end |
#inc(key) ⇒ Object
12 13 14 15 16 |
# File 'lib/emf/stats.rb', line 12 def inc(key) @map[key] = 0 unless @map[key] @map[key] = @map[key]+1 @sum_values += 1 end |
#n_values ⇒ Object
36 37 38 |
# File 'lib/emf/stats.rb', line 36 def n_values @map.count end |
#p(key) ⇒ Object
number of times the value appeared divived by total frequency
24 25 26 |
# File 'lib/emf/stats.rb', line 24 def p(key) @map[key].to_f/total_frequency.to_f end |
#total_frequency ⇒ Object
32 33 34 |
# File 'lib/emf/stats.rb', line 32 def total_frequency @sum_values end |
#value(key) ⇒ Object
18 19 20 21 |
# File 'lib/emf/stats.rb', line 18 def value(key) @map[key] = 0 unless @map[key] @map[key] end |