Class: Pest::Function::Entropy::Builder
- Inherits:
-
Object
- Object
- Pest::Function::Entropy::Builder
- Includes:
- Builder
- Defined in:
- lib/pest/function/entropy.rb
Instance Attribute Summary collapse
-
#estimator ⇒ Object
readonly
Returns the value of attribute estimator.
-
#event ⇒ Object
readonly
Returns the value of attribute event.
-
#givens ⇒ Object
readonly
Returns the value of attribute givens.
Instance Method Summary collapse
- #evaluate ⇒ Object
- #given(*variables) ⇒ Object
-
#initialize(estimator, variables) ⇒ Builder
constructor
A new instance of Builder.
Constructor Details
#initialize(estimator, variables) ⇒ Builder
Returns a new instance of Builder.
13 14 15 16 17 18 |
# File 'lib/pest/function/entropy.rb', line 13 def initialize(estimator, variables) @estimator = estimator @event = variables.to_set @givens = Set.new raise ArgumentError unless (@event - @estimator.variables).empty? end |
Instance Attribute Details
#estimator ⇒ Object (readonly)
Returns the value of attribute estimator.
11 12 13 |
# File 'lib/pest/function/entropy.rb', line 11 def estimator @estimator end |
#event ⇒ Object (readonly)
Returns the value of attribute event.
11 12 13 |
# File 'lib/pest/function/entropy.rb', line 11 def event @event end |
#givens ⇒ Object (readonly)
Returns the value of attribute givens.
11 12 13 |
# File 'lib/pest/function/entropy.rb', line 11 def givens @givens end |
Instance Method Details
#evaluate ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/pest/function/entropy.rb', line 26 def evaluate joint = estimator.distributions[event].entropy if givens.empty? joint else conditional = estimator.distributions[givens].entropy joint - conditional end end |
#given(*variables) ⇒ Object
20 21 22 23 24 |
# File 'lib/pest/function/entropy.rb', line 20 def given(*variables) @givens.merge variables.to_set raise ArgumentError unless (@givens - @estimator.variables).empty? self end |