-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwMath.py
More file actions
37 lines (26 loc) · 940 Bytes
/
wMath.py
File metadata and controls
37 lines (26 loc) · 940 Bytes
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
28
29
30
31
32
33
34
35
36
37
import numpy as np
import math
import random
def factorial(x):
if (x==0 or x==1):
return 1
return (factorial(x-1) * x)
def poisson(x, lambd, cumulative):
if(cumulative):
sumVar = float(0)
for i in range(0, x + 1):
sumVar += ( float((math.exp(-lambd)) * float(pow(lambd, i))) / float(factorial(i)))
return sumVar
else:
return (math.exp(-lambd) * pow(lambd, x) / factorial(x))
def random_test(probability):
precision = 100000
threshold = precision * probability
rn = random.uniform(0, 1) * precision
# print("prec" + str(precision))
# print("rn: " + str(rn))
return (threshold > rn)
def random_distribution(mean, std):
return mean + 2.0 * std * (random.uniform(0, 1) + random.uniform(0, 1) + random.uniform(0, 1) - 1.5)
def compound_probability(probability, factor):
return (1.0 - pow(1.0 - float(probability), float(factor)))