Class: Pest::Function::Probability::BatchBuilder

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(estimator, variables) ⇒ BatchBuilder

Returns a new instance of BatchBuilder.

Raises:

  • (ArgumentError)


18
19
20
21
22
23
# File 'lib/pest/function/probability.rb', line 18

def initialize(estimator, variables)
  @estimator      = estimator
  @event          = variables.to_set
  @givens         = [].to_set
  raise ArgumentError unless (@event - @estimator.variables).empty?
end

Instance Attribute Details

#data_sourceObject (readonly)

Returns the value of attribute data_source.



16
17
18
# File 'lib/pest/function/probability.rb', line 16

def data_source
  @data_source
end

#estimatorObject (readonly)

Returns the value of attribute estimator.



16
17
18
# File 'lib/pest/function/probability.rb', line 16

def estimator
  @estimator
end

#eventObject (readonly)

Returns the value of attribute event.



16
17
18
# File 'lib/pest/function/probability.rb', line 16

def event
  @event
end

#givensObject (readonly)

Returns the value of attribute givens.



16
17
18
# File 'lib/pest/function/probability.rb', line 16

def givens
  @givens
end

Instance Method Details

#evaluateObject



36
37
38
39
40
41
42
43
44
45
# File 'lib/pest/function/probability.rb', line 36

def evaluate
  if givens.empty?
    estimator.distributions[*event].probability(data_source).to_a
  else
    joint = estimator.distributions[*(event + givens)].probability(data_source)
    conditional = estimator.distributions[*givens].probability(data_source)

    (joint / conditional).to_a
  end
end

#given(*variables) ⇒ Object

Raises:

  • (ArgumentError)


25
26
27
28
29
# File 'lib/pest/function/probability.rb', line 25

def given(*variables)
  @givens += variables
  raise ArgumentError unless (@givens - @estimator.variables).empty?
  self
end

#in(data_set) ⇒ Object



31
32
33
34
# File 'lib/pest/function/probability.rb', line 31

def in(data_set)
  @data_source = data_set
  self
end