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 (27 lines) | stat: -rw-r--r-- 747 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
module Distribution
       module Weibull
       	      module Ruby_
	      	     class << self
		     	   def pdf(x, k, lam)
		     	       return 0.0 if x < 0.0
			       return ((k.to_f/lam.to_f)*(x.to_f/lam.to_f)**(k-1.0))*Math.exp(-(x.to_f/lam.to_f)**k)
		     	   end

		     	   #Returns the integral of the Weibull distribution from [-Inf to x]

		     	   def cdf(x, k, lam)
		     	       return 0.0 if x < 0.0
			       return 1.0-Math.exp(-(x.to_f/lam.to_f)**k)
		     	   end

		     	   # Returns the P-value of weibull
		     
			   def p_value(y, k, lam)
		     	       return 1.0 if y > 1.0
			       return 0.0 if y < 0.0
		     	       return -lam*(Math.log(1.0-y))**(1.0/k)
		     	   end
		      end
	      	end
       end
end