| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- #!/usr/bin/env python3
- import argparse
- from pathlib import Path
- import pandas as pd
- import matplotlib.pyplot as plt
- from copy import copy
- def remove_outliers_iqr(df):
- groups = ["model_type", "width", "depth"]
- q1 = df.groupby(groups)["simulation_time"].quantile(0.25)
- q3 = df.groupby(groups)["simulation_time"].quantile(0.75)
- iqr = q3 - q1
- lower = q1 - 1.5 * iqr
- upper = q3 + 1.5 * iqr
- # Join bounds back to original rows
- bounds = pd.concat([lower, upper], axis=1)
- bounds.columns = ["lower", "upper"]
- df = df.join(bounds, on=groups)
- return df[(df["simulation_time"] >= df["lower"]) &
- (df["simulation_time"] <= df["upper"])].drop(columns=["lower", "upper"])
- def process_file(path, max: int = 0):
- """Load file, remove outliers, compute atomic models, average per atomic count."""
- df = pd.read_csv(path).copy()
- if max > 0:
- df = df[df["width"] <= max].copy()
- df = df[df["depth"] <= max].copy()
- df = remove_outliers_iqr(df)
- df["atomic_models"] = (df["width"] - 1) * (df["depth"] - 1) + 1
- grouped = df.groupby("atomic_models", as_index=False)["simulation_time"].mean()
- label = path.parent.name + "-" + path.stem
- return label, grouped
- def plot_results(results_dict, name):
- plt.figure(figsize=(16, 9))
- for label, df in results_dict.items():
- plt.plot(
- df["atomic_models"],
- df["simulation_time"],
- marker="o",
- linestyle="-",
- label=label
- )
- plt.title("Mean Simulation Time vs Atomic Model Count")
- plt.xlabel("# Atomic Models")
- plt.ylabel("Mean Simulation Time (s)")
- plt.grid(True)
- plt.legend()
- plt.tight_layout()
- output_path = f"../Plots/{name}_NA.png"
- plt.savefig(output_path, dpi=300)
- print(f"Saved plot: {output_path}")
- def main():
- parser = argparse.ArgumentParser(description="Compare multiple model results by atomic-model count.")
- parser.add_argument("csv_files", nargs="+", type=Path, help="Input CSV files")
- parser.add_argument("-n", "--name", type=str, default="comparison", help="Output file name")
- parser.add_argument('-m', '--max', type=int, default=0, help='Maximum value of the varying parameter')
- args = parser.parse_args()
- results = {}
- for file in args.csv_files:
- label, grouped = process_file(file, args.max)
- results[label] = grouped
- plot_results(results, args.name)
- if __name__ == "__main__":
- main()
|