Buckets:
| import os | |
| import re | |
| import numpy as np | |
| from collections import defaultdict | |
| # -------- config -------- | |
| BASE_DIR = "./outputs/result_syn" | |
| # SETTINGS = ["MCAR"] | |
| SETTINGS = ["MCAR", "MNAR"] | |
| # SETTINGS = ["MCAR_perturbation_scale_0.0001", "MCAR_perturbation_scale_0.001", "MCAR_perturbation_scale_0.01", "MCAR_perturbation_scale_0.02", "MCAR_perturbation_scale_0.04", "MCAR_perturbation_scale_0.06", "MCAR_perturbation_scale_0.08", "MCAR_perturbation_scale_0.1"] | |
| OUT_FILE = "./outputs/result_syn/synthetic_summary.txt" | |
| # OUT_FILE = "./outputs/result_syn/synthetic_summary_0.0001.txt" | |
| SEEDS = range(10) | |
| LEVELS = ["low", "medium", "high"] | |
| METHODS = ["snn", "msnn"] | |
| # -------- regex -------- | |
| feasible_re = re.compile(r"Feasible ratio.*?:\s*([0-9.]+)") | |
| meanabs_norm_re = re.compile(r"meanabs_normalized_norm:\s*([0-9.]+)") | |
| # -------- storage -------- | |
| # results[setting][method][level] -> lists | |
| results = defaultdict( | |
| lambda: defaultdict( | |
| lambda: defaultdict(lambda: { | |
| "feasible": [], | |
| "meanabs_norm": [] | |
| }) | |
| ) | |
| ) | |
| parsed_cnt = defaultdict( | |
| lambda: defaultdict( | |
| lambda: defaultdict(int) | |
| ) | |
| ) | |
| non_zero_cnt = defaultdict( | |
| lambda: defaultdict( | |
| lambda: defaultdict(int) | |
| ) | |
| ) | |
| # -------- parse files -------- | |
| for setting in SETTINGS: | |
| base_path = os.path.join(BASE_DIR, setting) | |
| for level in LEVELS: | |
| for seed in SEEDS: | |
| for method in METHODS: | |
| fname = f"exp_{level}_seed{seed}_{method}.txt" | |
| # fname = f"exp_{level}_seed{seed}_sigma0.0001_{method}.txt" | |
| fpath = os.path.join(base_path, fname) | |
| if not os.path.exists(fpath): | |
| print("not recorded, ", fpath) | |
| continue | |
| with open(fpath, "r") as f: | |
| text = f.read() | |
| m1 = feasible_re.search(text) | |
| m2 = meanabs_norm_re.search(text) | |
| if m1 is None: | |
| print("m1 none, ", fpath) | |
| continue | |
| parsed_cnt[setting][method][level] += 1 | |
| results[setting][method][level]["feasible"].append(float(m1.group(1))) | |
| if m2 is None: | |
| print("m2 none, ", fpath) | |
| continue | |
| non_zero_cnt[setting][method][level] += 1 | |
| results[setting][method][level]["meanabs_norm"].append(float(m2.group(1))) | |
| # -------- write summary -------- | |
| with open(OUT_FILE, "w") as f: | |
| f.write("===== Synthetic Results Summary =====\n") | |
| f.write("Statistics: mean ± sample std (ddof=1) over seeds 0-9\n\n") | |
| for setting in SETTINGS: | |
| f.write(f"========== {setting} ==========\n\n") | |
| for method in METHODS: | |
| f.write(f"Method: {method.upper()}\n") | |
| for level in LEVELS: | |
| feas = np.array(results[setting][method][level]["feasible"]) | |
| meanabs = np.array(results[setting][method][level]["meanabs_norm"]) | |
| total = len(SEEDS) | |
| parsed = parsed_cnt[setting][method][level] | |
| if parsed == 0: | |
| f.write(f" {level:6s} | parse: 0/{total} | NO DATA\n") | |
| continue | |
| feas_mean = feas.mean() | |
| feas_std = feas.std(ddof=1) | |
| meanabs_mean = meanabs.mean() | |
| meanabs_std = meanabs.std(ddof=1) | |
| f.write( | |
| f" {level:6s} | parse: {parsed}/{total} | feasible existence: {non_zero_cnt[setting][method][level]}/{total} | " | |
| f"Feasible ratio: {feas_mean:.6f} ± {feas_std:.6f} | " | |
| f"meanabs_normalized_norm: {meanabs_mean:.6f} ± {meanabs_std:.6f}\n" | |
| ) | |
| f.write("\n") | |
| f.write("\n") | |
| print(f"[Done] Summary written to {OUT_FILE}") | |
Xet Storage Details
- Size:
- 3.86 kB
- Xet hash:
- 9000586a9456adada2e8150d428ccdd09f078c94f3aa47e9f8c254b29e5c2251
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.