diff --git a/Makefile b/Makefile index e9e663d..326c97b 100644 --- a/Makefile +++ b/Makefile @@ -9,9 +9,9 @@ help: .PHONY: ch13-ci ch13-ci: - python scripts/sim_stroop.py --n-subjects 6 --n-trials 10 + python scripts/sim_stroop.py --n-subjects 6 --n-trials 10 --seed 2025 python scripts/ch13_stroop_within.py --save-plots - python scripts/sim_fitness_2x2.py --n-per-group 5 + python scripts/sim_fitness_2x2.py --n-per-group 5 --seed 2025 python scripts/ch13_fitness_mixed.py --save-plots .PHONY: ch13 diff --git a/scripts/sim_fitness_2x2.py b/scripts/sim_fitness_2x2.py index c4aac84..8481ab9 100644 --- a/scripts/sim_fitness_2x2.py +++ b/scripts/sim_fitness_2x2.py @@ -1,8 +1,9 @@ # SPDX-License-Identifier: MIT -import os, json, time +import os, json, time, argparse import numpy as np, pandas as pd -rng = np.random.default_rng(7) +# globals configured in main() +rng = np.random.default_rng() N = 80 GROUPS = ["ProgramA","ProgramB"] @@ -38,7 +39,7 @@ def simulate(): long.to_csv("data/synthetic/fitness_long.csv", index=False) meta = dict( - seed=7, + seed=int(getattr(rng, "seed_seq", np.random.SeedSequence()).entropy) if hasattr(rng, "seed_seq") else None, n=int(N), design="2x2 mixed (Group between × Time within)", programs=GROUPS, @@ -50,5 +51,14 @@ def simulate(): print("Wrote fitness_subjects.csv, fitness_long.csv, fitness_meta.json") +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--seed", type=int, default=7, help="RNG seed") + ap.add_argument("--n-per-group", type=int, default=5, help="(kept for CLI parity; not used here)") + args = ap.parse_args() + global rng + rng = np.random.default_rng(args.seed) + simulate() + if __name__ == "__main__": - simulate() \ No newline at end of file + main() \ No newline at end of file diff --git a/scripts/sim_stroop.py b/scripts/sim_stroop.py index 62a4f88..6162de9 100644 --- a/scripts/sim_stroop.py +++ b/scripts/sim_stroop.py @@ -73,7 +73,7 @@ def simulate(): # sprinkle outliers (anticipations & lapses) if rng.random() < OUTLIER_RATE_ANTICIP: - rt = rng.normal(OUTLIER_RT_ANTICIP_MU, OUTLIER_RT_ANTICIP_SD) # anticipatory + rt = rng.normal(OUTLIER_RT_ANTICIP_MU, OUTLIER_RT_ANTICIP_SD) # anticipatory if rng.random() < OUTLIER_RATE_LAPSE: rt = rng.normal(OUTLIER_RT_LAPSE_MU, OUTLIER_RT_LAPSE_SD) # lapse @@ -135,10 +135,6 @@ def write_meta(subjects: pd.DataFrame, trials: pd.DataFrame): json.dump(meta, f, indent=2) print("Wrote data/synthetic/psych_stroop_meta.json") -if __name__ == "__main__": - subjects_df, trials_df = simulate() - write_meta(subjects_df, trials_df) - def main(): ap = argparse.ArgumentParser() @@ -146,9 +142,13 @@ def main(): ap.add_argument("--n-subjects", type=int, default=60) ap.add_argument("--n-trials", type=int, default=100) args = ap.parse_args() - global N_SUBJ, N_TRIALS_PER_COND, rng + global N_SUBJ, N_TRIALS_PER_COND, rng, RNG_SEED N_SUBJ = args.n_subjects N_TRIALS_PER_COND = args.n_trials - rng = np.random.default_rng(args.seed) + RNG_SEED = args.seed + rng = np.random.default_rng(RNG_SEED) + subjects_df, trials_df = simulate() + write_meta(subjects_df, trials_df) + if __name__ == "__main__": main() \ No newline at end of file