forked from vongostev/202-Advanced-Python-1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPoisson.py
More file actions
55 lines (48 loc) · 1.14 KB
/
Poisson.py
File metadata and controls
55 lines (48 loc) · 1.14 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
import numpy as np
import scipy.special
import matplotlib.pyplot as plt
def poisson(aver, N):
n = np.arange(0, N)
p = (np.power(aver, n)*np.exp(-aver))/scipy.special.factorial(n)
if aver >= 0:
return p
else:
return 0
def poisson_1(aver, N):
p = (np.power(aver, N) * np.exp(-aver)) / scipy.special.factorial(N)
if aver >= 0:
return p
else:
return 0
def initial_moment(n, k):
N = np.size(n)
arr = np.arange(N)
x = np.power(arr, k)
y = n
m = np.dot(y, x)
if isinstance(k, int) == False or not(np.size(np.array(n)) > 1):
return 0
else:
return m
def average(n):
m = initial_moment(n, 1)
return m
def dispersion(n):
m = initial_moment(n, 2) - initial_moment(n, 1) ** 2
return m
def test(aver, N):
a = poisson(aver, N)
b = average(a)
c = dispersion(a)
plt.plot(a)
plt.scatter(b, poisson_1(b, b))
plt.scatter(c, poisson_1(c, c))
plt.show()
#test
a = poisson(3, 100)
b = average(a)
c = dispersion(a)
print('a = ', 3)
print('b = ', b)
print('c = ', c)
test(3, 100)