-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot_metrics.py
173 lines (129 loc) · 5.69 KB
/
plot_metrics.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
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
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
def plot_jaccard_vs_cache_size(data, name_reasoner):
datasets = data["dataset"].unique()
# Plot each dataset's Cache Size vs Avg Jaccard
for dataset_name in datasets:
# Filter data for the specific dataset
subset = data[data["dataset"] == dataset_name]
# Plot cache size vs avg jaccard for this dataset
plt.plot(subset["cache_size"], subset["avg_jaccard"], marker='o', label=dataset_name)
# Label the plot
plt.xlabel('Cache Size')
plt.ylabel('Average Jaccard Similarity')
# plt.title('Cache Size vs Avg Jaccard Similarity for Each Dataset')
plt.legend()
plt.grid()
plt.savefig(f'caching_results/jaccard_vs_cache_size_plot_{name_reasoner}.pdf', format='pdf')
plt.show()
def plot_RT_vs_RT_cache(data, name_reasoner):
datasets = data["dataset"].unique()
for dataset_name in datasets:
# Filter data for the specific dataset
subset = data[data["dataset"] == dataset_name]
# Define x and y values for the plot
x = subset["cache_size"]
y1 = subset["RT_cache"] # Runtime with cache
y2 = subset["RT"] # Runtime without cache
# Create a new figure for each dataset
plt.figure()
# Plot the data
plt.plot(x, y1, '-b', label='Runtime with Cache')
plt.plot(x, y2, '-r', label='Runtime without Cache')
# Add legend
plt.legend()
# Label the axes and title
plt.xlabel('Cache Size')
plt.ylabel('Runtime(s)')
plt.grid()
# plt.title(f'Cache Size vs. Runtime for {dataset_name}')
plt.savefig(f'caching_results/runtime_plot_{name_reasoner}.pdf', format='pdf')
# Show the plot
plt.show()
def plot_scale_factor(data, name_reasoner):
# Ensure 'RT' and 'RT_cache' are numeric
data["RT"] = pd.to_numeric(data["RT"], errors='coerce')
data["RT_cache"] = pd.to_numeric(data["RT_cache"], errors='coerce')
# Get unique datasets
datasets = data["dataset"].unique()
# Plot speedup factor for each dataset on the same plot
for dataset_name in datasets:
# Filter data for the specific dataset
subset = data[data["dataset"] == dataset_name]
# Calculate speedup factor
speedup_factor = subset["RT"] / subset["RT_cache"]
# Plot speedup factor vs cache size for this dataset
plt.plot(subset["cache_size"], speedup_factor, marker='o', label=dataset_name)
# Label the axes and add a title
plt.xlabel('Cache Size')
plt.ylabel('Speedup Factor(RT / RT_cache)')
# Add legend to identify each dataset
plt.legend()
plt.grid()
# Save the plot as a PDF
plt.savefig(f'caching_results/scale_factor_plot_{name_reasoner}.pdf', format='pdf')
# Show the plot
plt.show()
def bar_plot_all_data(data, cache_size, name_reasoner):
# Plotting
grouped_df = data.groupby(['dataset', 'Type', 'cache_size']).agg({
'time_ebr': 'mean',
'time_cache': 'mean',
'Jaccard': 'mean'
}).reset_index()
grouped_df = grouped_df[grouped_df["cache_size"]==cache_size]
df = grouped_df
fig, ax = plt.subplots(figsize=(10, 6))
# Creating unique labels for each combination of dataset, Type, and cache_size
df['label'] = df['dataset'] + "-" + df['Type']
# Set positions and width for bars
x = np.arange(len(df['label']))
width = 0.35
# Plot time_ebr and time_cache side-by-side for each label
ax.bar(x - width/2, df['time_ebr'], width, label='RT without Cache', color='skyblue')
ax.bar(x + width/2, df['time_cache'], width, label='RT With Cache', color='salmon')
# Labels and titles
# ax.set_xlabel('Instance Type and Cache Size')
ax.set_ylabel('Running Time (seconds)')
ax.set_title(f'Running Time Comparison With and Without Cache by Instance Type (cache size = {cache_size})')
ax.set_xticks(x)
ax.set_xticklabels(df['label'], rotation=35, ha='right')
ax.legend()
# Show plot
plt.tight_layout()
plt.savefig(f'caching_results/bar_plot_{name_reasoner}.pdf', format='pdf')
plt.show()
def bar_plot_separate_data(data, cache_size, name_reasoner):
grouped_df = data.groupby(['dataset', 'Type', 'cache_size']).agg({
'time_ebr': 'mean',
'time_cache': 'mean',
'Jaccard': 'mean'
}).reset_index()
grouped_df = grouped_df[grouped_df["cache_size"]==cache_size]
df = grouped_df
datasets = df['dataset'].unique()
# Plot for each dataset separately
for dataset in datasets:
subset = df[df['dataset'] == dataset]
# Creating unique labels for each Type and cache_size combination
subset['label'] = subset['Type']
# Set positions and width for bars
x = np.arange(len(subset['label']))
width = 0.35
# Initialize the figure
fig, ax = plt.subplots(figsize=(10, 6))
# Plot time_ebr and time_cache side-by-side for each label
ax.bar(x - width/2, subset['time_ebr'], width, label='RT without cache', color='skyblue')
ax.bar(x + width/2, subset['time_cache'], width, label='RT with Cache', color='salmon')
# Labels and titles
ax.set_xlabel('Instance Type')
ax.set_ylabel('Running Time (seconds)')
ax.set_title(f'Running Time Comparison With and Without Cache for {dataset}')
ax.set_xticks(x)
ax.set_xticklabels(subset['label'], rotation=35, ha='right')
ax.legend()
# Adjust layout and display
plt.tight_layout()
plt.savefig(f'caching_results/bar_plot_{dataset}_{name_reasoner}.pdf', format='pdf')
plt.show()