initial commit
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
import os
|
||||
import pandas as pd
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
csv_file = "results/synthetic_data/raw/20260302_183202.csv"
|
||||
save_folder = f"results/synthetic_data/derived/{os.path.splitext(os.path.basename(csv_file))[0]}"
|
||||
os.makedirs(save_folder, exist_ok=True)
|
||||
|
||||
df = pd.read_csv(csv_file)
|
||||
df = df[df["algorithm"] == "binary"].copy()
|
||||
df["relax_success_ratio"] = df["relax_success"] / df["relax_attempts"]
|
||||
|
||||
# N vs extract_min_calls
|
||||
grouped = df.groupby("nodes")["extract_min_calls"].mean()
|
||||
|
||||
plt.figure(figsize=(6,4))
|
||||
plt.plot(grouped.index, grouped.values, marker='o')
|
||||
plt.xlabel("N (nodes)")
|
||||
plt.ylabel("Average extract_min_calls")
|
||||
plt.title("Nodes vs Extract-Min Calls")
|
||||
plt.grid(True)
|
||||
plt.tight_layout()
|
||||
plt.savefig(f"{save_folder}/N_vs_extract_min.png", dpi=300)
|
||||
plt.close()
|
||||
|
||||
# Density vs relax_attempts
|
||||
grouped = df.groupby("density")["relax_attempts"].mean()
|
||||
|
||||
plt.figure(figsize=(6,4))
|
||||
plt.plot(grouped.index, grouped.values, marker='o')
|
||||
plt.xlabel("Density")
|
||||
plt.ylabel("Average relax_attempts")
|
||||
plt.title("Density vs Relax Attempts")
|
||||
plt.grid(True)
|
||||
plt.tight_layout()
|
||||
plt.savefig(f"{save_folder}/density_vs_relax_attempts.png", dpi=300)
|
||||
plt.close()
|
||||
|
||||
# Sigma vs relax_success_ratio
|
||||
grouped = df.groupby("sigma")["relax_success_ratio"].mean()
|
||||
|
||||
plt.figure(figsize=(6,4))
|
||||
plt.plot(grouped.index, grouped.values, marker='o')
|
||||
plt.xlabel("Sigma (lognormal)")
|
||||
plt.ylabel("Relax Success Ratio")
|
||||
plt.title("Sigma vs Relax Success Ratio")
|
||||
plt.grid(True)
|
||||
plt.tight_layout()
|
||||
plt.savefig(f"{save_folder}/sigma_vs_relax_ratio.png", dpi=300)
|
||||
plt.close()
|
||||
@@ -0,0 +1,48 @@
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
from sklearn.linear_model import LinearRegression
|
||||
from sklearn.metrics import r2_score
|
||||
|
||||
def fit_op_cost_functional(df, algo):
|
||||
sub = df[(df["algorithm"] == algo) & (df["reached"] == True)].copy()
|
||||
|
||||
sub["logN"] = np.log(sub["nodes"])
|
||||
sub = sub.rename(columns={"relax_success":"decrease_key_calls",
|
||||
"nodes":"add_calls"})
|
||||
|
||||
if algo == "binary":
|
||||
sub["f_extract"] = sub["extract_min_calls"] * sub["logN"]
|
||||
sub["f_decrease"] = sub["decrease_key_calls"] * sub["logN"]
|
||||
else: # fibonacci
|
||||
sub["f_extract"] = sub["extract_min_calls"] * sub["logN"]
|
||||
sub["f_decrease"] = sub["decrease_key_calls"]
|
||||
|
||||
X = sub[["add_calls", "f_extract", "relax_attempts", "f_decrease"]].to_numpy()
|
||||
y = sub["time"].to_numpy()
|
||||
|
||||
model = LinearRegression()
|
||||
model.fit(X, y)
|
||||
|
||||
y_pred = model.predict(X)
|
||||
r2 = r2_score(y, y_pred)
|
||||
|
||||
return {
|
||||
"algo": algo,
|
||||
"intercept": model.intercept_,
|
||||
"coef_add": model.coef_[0],
|
||||
"coef_extract": model.coef_[1],
|
||||
"coef_relax": model.coef_[2],
|
||||
"coef_decrease": model.coef_[3],
|
||||
"r2": r2,
|
||||
"n_samples": len(sub)
|
||||
}
|
||||
|
||||
def op_cost_functional_analysis(df):
|
||||
return pd.DataFrame([
|
||||
fit_op_cost_functional(df, "binary"),
|
||||
fit_op_cost_functional(df, "fibonacci")
|
||||
])
|
||||
|
||||
df = pd.read_csv("results/synthetic_data/raw/20260302_183202.csv")
|
||||
summary = op_cost_functional_analysis(df)
|
||||
print(summary)
|
||||
@@ -0,0 +1,38 @@
|
||||
import pandas as pd
|
||||
import matplotlib.pyplot as plt
|
||||
import os
|
||||
|
||||
csv_file = "results/synthetic_data/raw/20260302_183202.csv"
|
||||
save_folder = f"results/synthetic_data/derived/{os.path.splitext(os.path.basename(csv_file))[0]}"
|
||||
os.makedirs(save_folder, exist_ok=True)
|
||||
|
||||
df = pd.read_csv(csv_file)
|
||||
# df = df[df["reached"] == True].copy()
|
||||
|
||||
key_cols = ["nodes", "density", "std", "sigma", "trial", "seed"]
|
||||
|
||||
pivot_time = (
|
||||
df.pivot_table(index=key_cols, columns="algorithm", values="time", aggfunc="mean")
|
||||
.reset_index()
|
||||
)
|
||||
pivot_time["speed_ratio"] = pivot_time["binary"] / pivot_time["fibonacci"]
|
||||
|
||||
# print((pivot_time["speed_ratio"] > 1).sum())
|
||||
# print((pivot_time["speed_ratio"] < 1).sum())
|
||||
|
||||
relax = (
|
||||
df[df["algorithm"] == "binary"][key_cols + ["relax_success"]]
|
||||
)
|
||||
|
||||
merged = pivot_time.merge(relax, on=key_cols, how="left")
|
||||
|
||||
plt.figure(figsize=(6, 4))
|
||||
plt.scatter(merged["relax_success"], merged["speed_ratio"], marker=".")
|
||||
plt.axhline(y=1.0, color='red', linestyle='--')
|
||||
plt.xlabel("decrease_key (binary)")
|
||||
plt.ylabel("speed_ratio (binary / fibonacci)")
|
||||
plt.title("decrease_key vs speed_ratio")
|
||||
plt.grid(True)
|
||||
plt.tight_layout()
|
||||
plt.savefig(f"{save_folder}/decrease_key_vs_speed_ratio.png", dpi=300)
|
||||
plt.close()
|
||||
Reference in New Issue
Block a user