Class: ViralSeq::Math::PoissonDist
- Inherits:
-
Object
- Object
- ViralSeq::Math::PoissonDist
- Defined in:
- lib/viral_seq/math.rb
Overview
class for poisson distribution.
An event can occur 0, 1, 2,
calculate the probablity of 3 mutations on one sequence
new_poisson_dist = ViralSeq::Math::PoissonDist.new(0.01)
prob_hash = new_poisson_dist.poisson_hash
1000 * prob_hash[3].round(5)
=> 0.00017
Instance Attribute Summary collapse
-
#k ⇒ Integer
Maxinum events number shows in @poisson_hash.
-
#poisson_hash ⇒ Hash
readonly
Probablity hash of :event_number => :probablity.
-
#rate ⇒ Float
Event rate λ.
Instance Method Summary collapse
-
#initialize(rate, k = 5) ⇒ PoissonDist
constructor
initialize with given event rate λ, default events upper limit set to 5.
Constructor Details
#initialize(rate, k = 5) ⇒ PoissonDist
initialize with given event rate λ, default events upper limit set to 5
65 66 67 68 69 70 71 72 73 |
# File 'lib/viral_seq/math.rb', line 65 def initialize(rate,k = 5) @rate = rate @k = k @poisson_hash = {} (0..k).each do |n| p = (rate**n * ::Math::E**(-rate))/n.factorial @poisson_hash[n] = p end end |
Instance Attribute Details
#k ⇒ Integer
Returns maxinum events number shows in @poisson_hash.
78 79 80 |
# File 'lib/viral_seq/math.rb', line 78 def k @k end |
#poisson_hash ⇒ Hash (readonly)
Returns probablity hash of :event_number => :probablity.
80 81 82 |
# File 'lib/viral_seq/math.rb', line 80 def poisson_hash @poisson_hash end |
#rate ⇒ Float
Returns event rate λ.
76 77 78 |
# File 'lib/viral_seq/math.rb', line 76 def rate @rate end |