Method: Distribution::Normal::Ruby_.cdf
- Defined in:
- lib/distribution/normal/ruby.rb
.cdf(z) ⇒ Object
Normal cumulative distribution function (cdf).
Returns the integral of normal distribution over (-Infty, z].
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/distribution/normal/ruby.rb', line 58 def cdf(z) return 0.0 if z < -12 return 1.0 if z > 12 return 0.5 if z == 0.0 if z > 0.0 e = true else e = false z = -z end z = z.to_f z2 = z * z t = q = z * Math.exp(-0.5 * z2) / SQ2PI 3.step(199, 2) do |i| prev = q t *= z2 / i q += t return(e ? 0.5 + q : 0.5 - q) if q <= prev end e ? 1.0 : 0.0 end |