-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot.py
More file actions
113 lines (86 loc) · 2.71 KB
/
plot.py
File metadata and controls
113 lines (86 loc) · 2.71 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import random
import sys
import numpy as np
import math
import matplotlib.pyplot as plt
s = sys.argv[1]
para = np.loadtxt(f"config/para_{s}.txt")
interarrival = np.loadtxt(f"config/interarrival_{s}.txt")
with open(f"config/service_{s}.txt", "r") as f:
lines = f.readlines()
service = [line.split() for line in lines]
time_end = 1000
lamb = interarrival[0]
a_2l = interarrival[1]
a_2u = interarrival[2]
p_0 = float(service[0][0])
alpha_0 = float(service[1][0])
beta_0 = float(service[1][1])
eta_0 = float(service[1][2])
gamma_0 = math.pow(alpha_0, -eta_0) - math.pow(beta_0, -eta_0)
alpha_1 = float(service[2][0])
eta_1 = float(service[2][1])
gamma_1 = math.pow(alpha_1, -eta_1)
a = []
b = []
c = []
for i in range(time_end):
d = random.uniform(a_2l, a_2u)
e = random.expovariate(lamb)
a.append(d)
b.append(e)
c.append(d * e)
figure1, axis = plt.subplots(1, 3)
axis[0].hist(b, bins=50)
axis[0].set_title("a_1k")
axis[1].hist(a, bins=50)
axis[1].set_title("a_2k")
axis[2].hist(c, bins=50)
axis[2].set_title("a_k")
print(np.mean(b), np.mean(a), np.mean(c))
f = []
for i in range(time_end):
if random.random() < p_0:
f.append(0)
else:
f.append(1)
figure2, axis = plt.subplots(1, 1)
axis.bar([0,1], [f.count(0), f.count(1)], width = 0.4)
axis.set_xticks([0,1], [0,1])
axis.set_title("Group Distribution")
print(f.count(0), f.count(1))
h = []
j = []
m = []
n = []
for i in np.arange(alpha_0, beta_0+0.1, 0.1):
j.append(eta_0 / (gamma_0 * math.pow(i, eta_0 + 1)))
h.append((math.pow(alpha_0, -eta_0) - math.pow(i, -eta_0)) / gamma_0)
haha = math.exp(math.log(math.pow(alpha_1, -eta_1) - gamma_1 * 0.9995) / -eta_1)
for i in np.arange(alpha_1, haha, 0.1):
n.append(eta_1 / (gamma_1 * math.pow(i, eta_1 + 1)))
m.append((math.pow(alpha_1, -eta_1) - math.pow(i, -eta_1)) / gamma_1)
figure3, axis = plt.subplots(1, 2)
axis[0].plot(np.arange(alpha_0, beta_0+0.1, 0.1), j)
axis[0].set_title("Class 0")
axis[1].plot(np.arange(alpha_1, haha, 0.1), n)
axis[1].set_title("Class 1")
figure4, axis = plt.subplots(1, 2)
axis[0].plot(np.arange(alpha_0, beta_0+0.1, 0.1), h)
axis[0].set_title("Class 0")
axis[1].plot(np.arange(alpha_1, haha, 0.1), m)
axis[1].set_title("Class 1")
g = []
k = []
for i in range(time_end):
g.append(math.exp(math.log(math.pow(alpha_0, -eta_0) - gamma_0 * random.random()) / -eta_0))
k.append(math.exp(math.log(math.pow(alpha_1, -eta_1) - gamma_1 * random.random()) / -eta_1))
figure5, axis = plt.subplots(1, 2)
axis[0].hist(g, bins=50)
axis[0].set_title("Class 0")
axis[1].hist(k, bins=50)
axis[1].set_title("Class 1")
plt.show()
plt.clf()