Class: LightModels::CountingMap

Inherits:
Object
  • Object
show all
Defined in:
lib/lightmodels/stats.rb

Instance Method Summary collapse

Constructor Details

#initializeCountingMap

Returns a new instance of CountingMap.



7
8
9
10
# File 'lib/lightmodels/stats.rb', line 7

def initialize
	@map = {}
	@sum_values = 0
end

Instance Method Details

#each(&block) ⇒ Object



28
29
30
# File 'lib/lightmodels/stats.rb', line 28

def each(&block)
	@map.each(&block)
end

#inc(key) ⇒ Object



12
13
14
15
16
# File 'lib/lightmodels/stats.rb', line 12

def inc(key)
	@map[key] = 0 unless @map[key]
	@map[key] = @map[key]+1
	@sum_values += 1
end

#n_valuesObject



36
37
38
# File 'lib/lightmodels/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/lightmodels/stats.rb', line 24

def p(key)
	@map[key].to_f/total_frequency.to_f
end

#total_frequencyObject



32
33
34
# File 'lib/lightmodels/stats.rb', line 32

def total_frequency
	@sum_values
end

#value(key) ⇒ Object



18
19
20
21
# File 'lib/lightmodels/stats.rb', line 18

def value(key)
	@map[key] = 0 unless @map[key]
	@map[key]
end