Module: BernoulliTrials
- Includes:
- Combinatorics, Math
- Defined in:
- lib/theory_of_probability.rb
Instance Method Summary
collapse
#arrangement, #combination, #factorial
Instance Method Details
220
221
222
223
224
225
226
227
228
229
230
231
232
|
# File 'lib/theory_of_probability.rb', line 220
def bernoulli_formula_and_laplace_theorem(n, k, all, suc = -1)
if suc != -1
p = suc.fdiv all
else
p = all
end
q = 1 - p
if n * p * q < 9 combination(n, k) * (p ** k) * (q ** (n - k)) else
gaussian_function((k - n * p).fdiv sqrt(n * p * q)).fdiv(sqrt(n * p * q)) end
end
|
#gaussian_function(x) ⇒ Object
234
235
236
237
238
239
|
# File 'lib/theory_of_probability.rb', line 234
def gaussian_function(x)
if x < 0 x * -1
end
exp(-(x ** 2) / 2).fdiv sqrt(2 * PI) end
|