Class: Pest::Function::Entropy::Builder

Inherits:
Object
  • Object
show all
Includes:
Builder
Defined in:
lib/pest/function/entropy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(estimator, variables) ⇒ Builder

Returns a new instance of Builder.

Raises:

  • (ArgumentError)


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

#estimatorObject (readonly)

Returns the value of attribute estimator.



11
12
13
# File 'lib/pest/function/entropy.rb', line 11

def estimator
  @estimator
end

#eventObject (readonly)

Returns the value of attribute event.



11
12
13
# File 'lib/pest/function/entropy.rb', line 11

def event
  @event
end

#givensObject (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

#evaluateObject



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

Raises:

  • (ArgumentError)


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