-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprog_ass,py
113 lines (96 loc) · 3.81 KB
/
prog_ass,py
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# BERNOULLI RANDOM VARIABLE
# Your code goes here
# Generate 1000 samples of a Bernoulli Random Variable
p = 0.2 # Probability of Success
n = 1 # Number of states (When n = 1, Binomial Random Variable becomes a Bernoulli Random Variable)
size = 10 # Number of trials
X = np.random.binomial(n,p,size=size)
plt.title("Bernoulli Random Variable (p=0.2)")
plt.hist(X,bins='auto')
plt.show()
p = 0.8 # Probability of Success
n = 1 # Number of states (When n = 1, Binomial Random Variable becomes a Bernoulli Random Variable)
size = 10000000 # Number of trials
X = np.random.binomial(n,p,size=size)
plt.title("Bernoulli Random Variable (p=0.8)")
plt.hist(X,bins='auto')
plt.show()
# BINOMIAL RANDOM VARIABLE
# Your code goes here
# Generate 1000 samples of a Binomial Random Variable
p = 0.2 # Probability of a single success
n = 10 # Number of states
size = 100 # Number of trials
X = np.random.binomial(n,p,size=size)
plt.title("Binomial Random Variable (n=100, p=0.2)")
plt.hist(X,bins="auto");
plt.show()
p = 0.7 # Probability of a single success
n = 10000 # Number of states
size = 10000000 # Number of trials
X = np.random.binomial(n,p,size=size)
plt.title("Binomial Random Variable (n=10000, p=0.7)")
plt.hist(X,bins="auto");
plt.show()
# GEOMETRIC RANDOM VARIABLE
# Your code goes here
# Generate 1000 samples of a Geometric Random variables
p = 0.9
size = 10
plt.title("Geometric Random Variable (p = 0.9)")
X = np.random.geometric(p,size=size)
plt.hist(X,bins="auto")
plt.show()
p = 0.1
size = 1000000
plt.title("Geometric Random Variable (p = 0.1)")
X = np.random.geometric(p,size=size)
plt.hist(X,bins="auto")
plt.show()
# POISSON RANDOM VARIABLE
# Your code goes here
# Generate 5000 samples of a Poisson Random Variable
lambd = 1
X = np.random.poisson(lambd,size=5000)
plt.title("Poisson Random Variable (lambda = 1)")
plt.hist(X,bins="auto")
plt.show()
lambd = 6
X = np.random.poisson(lambd,size=5000)
plt.title("Poisson Random Variable (lambda = 1)")
plt.hist(X,bins="auto")
plt.show()
odi_data_df = pd.read_csv('ODIData.csv')
number_of_maiden_overs = np.array((odi_data_df['Mdns']))
over_bins = np.arange(102)
(bin_values_historical_data, bins, patches) = plt.hist(number_of_maiden_overs, bins=over_bins, rwidth = 0.5, density=True, align='left')
plt.title('Histogram of Maiden Overs in ODIs played in 21st Century')
plt.show()
# Generate 4000 samples of a Uniform Random Variable with a = 1, b = 10.
a = 1 # parameter a of uniform RV
b = 10 # parameter b of uniform RV
size = 4000 # Number of trials
X = np.random.randint(low=a,high=b+1, size=size)
plt.title("Uniform Random Variable (a=1, b=10)")
(bin_values_pmf_data, bins, patches) = plt.hist(X,bins=over_bins, rwidth = 0.5, density=True, align='left' );
plt.show()
difference_in_bin_values = bin_values_historical_data - bin_values_pmf_data
error = np.sum(abs(difference_in_bin_values))
print("Error when the Proposed PMF is Unifrom with parameter a=1 and b=10: " + str(error))
# Mathematical Model of Number of Maiden Overs in an ODI Cricket Match
# Your code goes here
odi_data_df = pd.read_csv('ODIData.csv')
number_of_maiden_overs = np.array((odi_data_df['Mdns']))
over_bins = np.arange(102)
(bin_values_historical_data, bins, patches) = plt.hist(number_of_maiden_overs, bins=over_bins, rwidth = 0.5, density=True, align='left')
plt.title('Histogram of Maiden Overs in ODIs played in 21st Century')
plt.show()
# Generate 4000 samples of a Uniform Random Variable with a = 1, b = 10.
lambd = 4
X = np.random.poisson(lambd,size=4000)
plt.title("Poisson Random Variable (lambda=4)")
(bin_values_pmf_data, bins, patches) = plt.hist(X,bins=over_bins, rwidth = 0.5, density=True, align='left' );
plt.show()
difference_in_bin_values = bin_values_historical_data - bin_values_pmf_data
error = np.sum(abs(difference_in_bin_values))
print("Error when the Proposed PMF is Unifrom with lambda = 4 : " + str(error))