Class: Pest::Estimator::Frequency::Distribution
- Inherits:
-
Object
- Object
- Pest::Estimator::Frequency::Distribution
- Includes:
- Distribution
- Defined in:
- lib/pest/estimator/frequency.rb
Constant Summary collapse
- OFFSET =
0
Instance Attribute Summary collapse
-
#checksum ⇒ Object
readonly
Returns the value of attribute checksum.
-
#frequencies ⇒ Object
readonly
Returns the value of attribute frequencies.
Attributes included from Distribution
Instance Method Summary collapse
Methods included from Distribution
#batch_probability, #initialize, #variable_array
Instance Attribute Details
#checksum ⇒ Object (readonly)
Returns the value of attribute checksum.
16 17 18 |
# File 'lib/pest/estimator/frequency.rb', line 16 def checksum @checksum end |
#frequencies ⇒ Object (readonly)
Returns the value of attribute frequencies.
16 17 18 |
# File 'lib/pest/estimator/frequency.rb', line 16 def frequencies @frequencies end |
Instance Method Details
#cache_model ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/pest/estimator/frequency.rb', line 18 def cache_model if @frequencies.nil? @frequencies = Hash.new(0) @estimator.data.pick(*variable_array).each do |vector| # Make sure this vector is consistently ordered @frequencies[Array(vector)] += 1 end end end |
#entropy ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/pest/estimator/frequency.rb', line 37 def entropy cache_model probabilities = probability(unique_event_dataset) (-probabilities * NMath.log2(probabilities)).sum end |
#probability(data) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/pest/estimator/frequency.rb', line 28 def probability(data) cache_model array = NArray[ data.pick(*variable_array).map do |vector| @frequencies[Array(vector)].to_f end ] (OFFSET + array.reshape!(data.length)) / (OFFSET + @estimator.data.length) end |