-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruntime.py
More file actions
180 lines (128 loc) · 4.8 KB
/
runtime.py
File metadata and controls
180 lines (128 loc) · 4.8 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
"""
Temp codes
"""
import shutil
import sqlite3, os
from itertools import product
import pandas as pd
import matplotlib.pyplot as plt
conn = sqlite3.connect('data/runnin.db')
# Read data from the 'results' table into a DataFrame
df = pd.read_sql_query("SELECT * FROM classif", conn)
conn.close()
df = df.loc[df.param!=2,:]
df = df.loc[df.data!='Net',:]
df = df.loc[df.model!='Laste']
ds = pd.unique(df.data)
nets = pd.unique(df.net)
net = 'BA'
dfn = df.loc[df.net=='BA',:]
dfx = dfn.loc[dfn.data==ds[0],:]
fig, axes = plt.subplots(len(nets), figsize=(12, 10),
sharex=True, sharey=True)
for i, net in enumerate(nets):
dfn = df.loc[df.net==net,:]
ax = axes[i]
for j, dt in enumerate(ds):
dfx = dfn.loc[dfn.data==dt,:]
ax.boxplot(dfx['acc'], positions=j)
#ax.set_title(f'{ + j + 1}')
# Adjust spacing between subplots and set overall title
plt.tight_layout()
plt.suptitle('Model x Reduct', fontsize=16)
# Show the plot
plt.show()
# combinations of classes
combos = list(product([0, 1], repeat=4))
# load data
datae = []
for combo in combos:
cname = ''.join([str(d) for d in combo])
fname = f"../seirs2/{cname}.xz"
nname = f"../datasetI/{cname}.xz"
shutil.copyfile(fname, nname)
import torch
# Assuming you have a one-hot encoded tensor
one_hot_tensor = torch.tensor([
[0, 1, 0, 0],
[0, 0, 1, 0],
[1, 0, 0, 0],
[0, 0, 0, 1]
])
# Get the indices of non-zero values
nonzero_indices = torch.nonzero(one_hot_tensor, as_tuple=True)
# Create a tensor with categorical values based on nonzero indices
reversed_tensor = torch.zeros_like(one_hot_tensor, dtype=torch.int)
reversed_tensor[nonzero_indices] = 1 # Set non-zero indices to 1
# If you want to convert the reversed tensor to categorical labels
category_labels = []
for row in reversed_tensor:
indices = torch.nonzero(row, as_tuple=False)
if indices.size(0) == 0:
category_labels.append(None) # No category found
else:
category_index = indices[0].item()
category_labels.append(f'category_{category_index + 1}')
print(category_labels)
import matplotlib.pyplot as plt
import numpy as np
# Generate some example data for vertical boxplots
data = [np.random.normal(0, 1, 100) for _ in range(5)] # 20 sets of data
# Create a figure with a single set of axes
fig, ax = plt.subplots(figsize=(10, 6))
# Plot row-wise vertical boxplots in the same set of axes
boxprops = dict(linestyle='-', linewidth=2, color='b')
medianprops = dict(linestyle='-', linewidth=2, color='r')
ax.boxplot(data, vert=True, positions=[i * 2 + 1 for i in range(5)],
boxprops=boxprops, medianprops=medianprops)
ax.set_title('Row-wise Vertical Boxplots')
ax.set_xticks([i * 2 + 1 for i in range(5)])
ax.set_xticklabels([f'Boxplot {i + 1}' for i in range(5)], rotation=45, ha='right')
# Set an overall title
plt.suptitle('Row-wise Vertical Boxplots in One Figure', fontsize=16)
# Show the plot
plt.show()
# Create a figure with a single set of axes
fig, axes = plt.subplots(len(nets), figsize=(10, 10), sharex=True)
# Plot row-wise vertical boxplots in the same set of axes
boxprops = dict(linestyle='-', linewidth=2, color='b')
medianprops = dict(linestyle='-', linewidth=2, color='r')
for i, net in enumerate(nets):
dfn = df.loc[df.net==net,:]
ax = axes[i]
data = []
for j, dt in enumerate(ds):
dfx = dfn.loc[dfn.data==dt,:]
data.append(dfx.acc.values)
ax.boxplot(data, vert=True, positions=[i * 2 + 1 for i in range(len(data))],
boxprops=boxprops, medianprops=medianprops)
ax.set_xticks([i * 2 + 1 for i in range(len(data))])
ax.set_xticklabels([f'{dt}' for dt in ds], rotation=90, ha='right')
ax.set_ylabel(net, rotation=90, labelpad=10)
# Set an overall title
plt.suptitle('Network-wise Performance of Network Reduction Models',
fontsize=16, y=1)
plt.tight_layout()
# Show the plot
#plt.savefig('plots/AccByNetxRed.png')
# Create a figure with a single set of axes
fig, ax = plt.subplots(figsize=(10, 6))
# Plot row-wise vertical boxplots in the same set of axes
boxprops = dict(linestyle='-', linewidth=2, color='b')
medianprops = dict(linestyle='-', linewidth=2, color='r')
dfn = df.loc[df.net==net,:]
data = []
for j, dt in enumerate(ds):
dfx = df.loc[df.data==dt,:]
data.append(dfx.acc.values)
ax.boxplot(data, vert=True, positions=[i * 2 + 1 for i in range(len(data))],
boxprops=boxprops, medianprops=medianprops)
ax.set_xticks([i * 2 + 1 for i in range(len(data))])
ax.set_xticklabels([f'{dt}' for dt in ds], rotation=90, ha='right')
ax.set_ylabel(net, rotation=90, labelpad=10)
# Set an overall title
plt.suptitle('Network-wise Performance of Network Reduction Models',
fontsize=16, y=1)
plt.tight_layout()
# Show the plot
#plt.savefig('plots/AccByNetxRed.png')