File: ruby.rb

package info (click to toggle)
ruby-distribution 0.7.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 624 kB
  • ctags: 379
  • sloc: ruby: 4,283; makefile: 7
file content (21 lines) | stat: -rw-r--r-- 462 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
module Distribution
  module Poisson
    module Ruby_
      class << self
        def pdf(k,l )
          (l**k*Math.exp(-l)).quo(Math.factorial(k))
        end
        def cdf(k,l)
          Math.exp(-l)*(0..k).inject(0) {|ac,i| ac+ (l**i).quo(Math.factorial(i))}
        end
        def p_value(prob,l)
          ac=0
          (0..100).each do |i|
            ac+=pdf(i,l)
            return i if prob<=ac
          end
        end
      end
    end
  end
end