Class: Prubybility::Binomial
- Inherits:
-
Object
- Object
- Prubybility::Binomial
- Defined in:
- lib/prubybility/binomial.rb
Overview
A representation of the Binomial probability distribution.
See README for example usages.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#expected_value ⇒ Object
(also: #mean)
readonly
Returns the value of attribute expected_value.
-
#n ⇒ Object
readonly
Returns the value of attribute n.
-
#theta ⇒ Object
readonly
Returns the value of attribute theta.
-
#variance ⇒ Object
readonly
Returns the value of attribute variance.
Instance Method Summary collapse
-
#initialize(number_of_trials, theta) ⇒ Binomial
constructor
A new instance of Binomial.
- #p(number_of_successes) ⇒ Object
Constructor Details
#initialize(number_of_trials, theta) ⇒ Binomial
Returns a new instance of Binomial.
12 13 14 15 16 17 |
# File 'lib/prubybility/binomial.rb', line 12 def initialize(number_of_trials, theta) @n = number_of_trials @theta = theta.to_d @expected_value = @n * @theta @variance = @n * @theta * (1 - @theta) end |
Instance Attribute Details
#expected_value ⇒ Object Also known as: mean
Returns the value of attribute expected_value.
8 9 10 |
# File 'lib/prubybility/binomial.rb', line 8 def expected_value @expected_value end |
#n ⇒ Object
Returns the value of attribute n.
8 9 10 |
# File 'lib/prubybility/binomial.rb', line 8 def n @n end |
#theta ⇒ Object
Returns the value of attribute theta.
8 9 10 |
# File 'lib/prubybility/binomial.rb', line 8 def theta @theta end |
#variance ⇒ Object
Returns the value of attribute variance.
8 9 10 |
# File 'lib/prubybility/binomial.rb', line 8 def variance @variance end |
Instance Method Details
#p(number_of_successes) ⇒ Object
19 20 21 22 |
# File 'lib/prubybility/binomial.rb', line 19 def p(number_of_successes) return unless valid_value?(number_of_successes) choose(number_of_successes) * (theta**number_of_successes) * ((1 - theta)**(n - number_of_successes)) end |