Class: Pest::Function::Probability::Builder

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, event) ⇒ Builder

Returns a new instance of Builder.



53
54
55
56
57
# File 'lib/pest/function/probability.rb', line 53

def initialize(estimator, event)
  @estimator    = estimator
  @event        = event
  @givens       = Hash.new
end

Instance Attribute Details

#estimatorObject

Returns the value of attribute estimator.



51
52
53
# File 'lib/pest/function/probability.rb', line 51

def estimator
  @estimator
end

#eventObject

Returns the value of attribute event.



51
52
53
# File 'lib/pest/function/probability.rb', line 51

def event
  @event
end

#givensObject

Returns the value of attribute givens.



51
52
53
# File 'lib/pest/function/probability.rb', line 51

def givens
  @givens
end

Instance Method Details

#evaluateObject



65
66
67
68
69
70
71
72
73
# File 'lib/pest/function/probability.rb', line 65

def evaluate
  data_hash = event.merge(givens)
  data_hash.each_key {|key| data_hash[key] = Array(data_hash[key])}

  data = Pest::DataSet::Hash.from_hash(data_hash)
  BatchBuilder.new(estimator, event.keys).
    given(*givens.keys).in(data).
    evaluate.first
end

#given(given) ⇒ Object

Raises:

  • (ArgumentError)


59
60
61
62
63
# File 'lib/pest/function/probability.rb', line 59

def given(given)
  givens.merge! given
  raise ArgumentError unless (given.keys.to_set - @estimator.variables).empty?
  self
end