-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpoisson-distribution.py
More file actions
executable file
·95 lines (72 loc) · 2.9 KB
/
poisson-distribution.py
File metadata and controls
executable file
·95 lines (72 loc) · 2.9 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/python3
from random import uniform
from math import exp
import sys
print("""
_____ _
| __ \ (_)
| |__) |__ _ ___ ___ ___ _ __
| ___/ _ \| / __/ __|/ _ \| '_ \
| | | (_) | \__ \__ \ (_) | | | |
|_| \___/|_|___/___/\___/|_| |_|
_ _ _ _ _ _ _
| (_) | | (_) | | | (_)
__| |_ ___| |_ _ __ _| |__ _ _| |_ _ ___ _ __
/ _` | / __| __| '__| | '_ \| | | | __| |/ _ \| '_ \
| (_| | \__ \ |_| | | | |_) | |_| | |_| | (_) | | | |
\__,_|_|___/\__|_| |_|_.__/ \__,_|\__|_|\___/|_| |_|
[...] Owner: Arturo Negreiros Samanez [...]
[...] date: 09/07/2021 [...]
[...] follow me: https://twitter.com/DevTuron [...]
[...] source code: https://github.com/Arturo0911/Simulation [...]
""")
# achieving an array with the number of
# uniforms we will work
def make_uniform_values(k_times: int) -> list:
return [uniform(0,1) for _ in range(k_times)]
def implement_distribution(lambda_value, uniform_value):
p_value = exp(-lambda_value)
f_cumulator = p_value
counter = 0
x_val = 0
while True:
if uniform_value < f_cumulator:
x_val = counter
break
else:
p_value *= float((lambda_value)/(counter +1))
f_cumulator += p_value
counter += 1
return x_val
def make_simulations(lambda_value, k_items):
for x in make_uniform_values(k_items):
print("el número de evento es {} correspondiente al valor aleatorio {}".format(implement_distribution(lambda_value, x),x))
def main():
print("[*] Puedes salir en cualquier momento del programa presionando CTRL C")
while True:
try:
k_values = int(input("[*] Ingrese el número de simulaciones (k) que desee probar: "))
if k_values < 0:
print("[*] Ingresaste un número positivo, por lo que el número se lo tomará como positivo")
k_values = abs(k_values)
break
except KeyboardInterrupt as e:
print("\n[*] Saliendo...")
sys.exit(0)
except:
print("[*] Debe ingresar un número entero positivo")
while True:
try:
lambda_val = float(input("[*] Ingrese el valor de lambda: "))
if lambda_val <= - 1:
print("[!] debe ser un valor positivo lambda; por lo que se convertirá tu valor negativo a positivo")
lambda_val = abs(lambda_val)
break
except KeyboardInterrupt:
print("\n[*] Saliendo...")
sys.exit(0)
except:
print("[X] Debe ingresar un valor numérico")
make_simulations(lambda_val, k_values)
if __name__ == "__main__":
main()