Class: Pest::Function::Probability::BatchBuilder
- Inherits:
-
Object
- Object
- Pest::Function::Probability::BatchBuilder
- Includes:
- Builder
- Defined in:
- lib/pest/function/probability.rb
Instance Attribute Summary collapse
-
#data_source ⇒ Object
readonly
Returns the value of attribute data_source.
-
#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
- #in(data_set) ⇒ Object
-
#initialize(estimator, variables) ⇒ BatchBuilder
constructor
A new instance of BatchBuilder.
Constructor Details
#initialize(estimator, variables) ⇒ BatchBuilder
Returns a new instance of BatchBuilder.
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_source ⇒ Object (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 |
#estimator ⇒ Object (readonly)
Returns the value of attribute estimator.
16 17 18 |
# File 'lib/pest/function/probability.rb', line 16 def estimator @estimator end |
#event ⇒ Object (readonly)
Returns the value of attribute event.
16 17 18 |
# File 'lib/pest/function/probability.rb', line 16 def event @event end |
#givens ⇒ Object (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
#evaluate ⇒ Object
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
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 |