-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_experiments.py
More file actions
72 lines (64 loc) · 2.22 KB
/
Copy pathplot_experiments.py
File metadata and controls
72 lines (64 loc) · 2.22 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
import os
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
prefix = "fast_results"
types = ["random", "reversed", "almost_sorted"]
thresholds = [5]
repetitions = 7
def read_csv(path):
return pd.read_csv(path)
def summarize(df):
runs = [c for c in df.columns if c.startswith("run")]
df["median"] = df[runs].median(axis=1)
df["mean"] = df[runs].mean(axis=1)
df["q1"] = df[runs].quantile(0.25, axis=1)
df["q3"] = df[runs].quantile(0.75, axis=1)
return df
for t in types:
std_path = f"{prefix}_{t}_std.csv"
if not os.path.exists(std_path):
print("Missing", std_path)
continue
df_std = summarize(read_csv(std_path))
plt.figure(figsize=(10,6))
plt.plot(df_std["size"], df_std["median"], label="merge_std (median)", linewidth=2)
plt.xlabel("size")
plt.ylabel("time (ms)")
plt.title(f"Merge sort standard — {t}")
plt.grid(True)
plt.legend()
plt.savefig(f"plot_{t}_std.png", dpi=200)
plt.close()
plt.figure(figsize=(12,8))
plt.plot(df_std["size"], df_std["median"], label="merge_std (median)", linewidth=2, linestyle='--')
for thr in thresholds:
path = f"{prefix}_{t}_hybrid_thr{thr}.csv"
if not os.path.exists(path):
print("Missing", path)
continue
df_h = summarize(read_csv(path))
plt.plot(df_h["size"], df_h["median"], label=f"hybrid thr={thr}")
plt.xlabel("size")
plt.ylabel("time (ms)")
plt.title(f"Merge vs Hybrid (median) — {t}")
plt.legend()
plt.grid(True)
plt.savefig(f"plot_{t}_compare_median.png", dpi=200)
plt.close()
plt.figure(figsize=(12,8))
for thr in thresholds:
path = f"{prefix}_{t}_hybrid_thr{thr}.csv"
if not os.path.exists(path): continue
df_h = summarize(read_csv(path))
ratio = df_h["median"].values / df_std["median"].values
plt.plot(df_std["size"], ratio, label=f"thr={thr}")
plt.axhline(1.0, color='k', linestyle='--')
plt.xlabel("size")
plt.ylabel("ratio hybrid/std")
plt.title(f"Ratio median(hybrid)/median(std) — {t}")
plt.legend()
plt.grid(True)
plt.savefig(f"plot_{t}_ratio.png", dpi=200)
plt.close()
print("Plots saved. Inspect PNG files.")