Download generate_example.py from shibo769/MediPFN: direct link, hf CLI and curl.
- Browser
- Download file 1.38 kB
-
https://huggingface.co/shibo769/MediPFN/resolve/main/generate_example.py
- Command line
-
hf download hf://shibo769/MediPFN/generate_example.py
-
curl -L -o generate_example.py https://huggingface.co/shibo769/MediPFN/resolve/main/generate_example.py
1.38 kB
| """Reproduce an adapted He-Song-Xu example; requires only Python 3. | |
| This smoke-check is not a table from the frozen 2,000-table benchmark run. | |
| """ | |
| from __future__ import annotations | |
| import argparse | |
| import csv | |
| import random | |
| from pathlib import Path | |
| def generate(n: int = 128, seed: int = 1729): | |
| if n < 1: | |
| raise ValueError('n must be a positive integer') | |
| rng = random.Random(seed) | |
| rows = [] | |
| for _ in range(n): | |
| x1 = rng.gauss(0.0, 1.0) | |
| x2 = int(rng.random() < 0.5) | |
| a = int(rng.random() < 0.5) | |
| m = 0.2 * a + 1.0 + x1 + x2 + rng.gauss(0.0, 0.5) | |
| y = 0.2 * m + 1.0 + x1 + x2 + a + rng.gauss(0.0, 0.5) | |
| rows.append({'X1': x1, 'X2': x2, 'A': a, 'M': m, 'Y': y}) | |
| return rows | |
| if __name__ == '__main__': | |
| p = argparse.ArgumentParser(description=__doc__) | |
| p.add_argument('--n', type=int, default=128) | |
| p.add_argument('--seed', type=int, default=1729) | |
| p.add_argument('--output', type=Path, default=Path('he_song_xu_example.csv')) | |
| args = p.parse_args() | |
| rows = generate(args.n, args.seed) | |
| with args.output.open('w', encoding='utf-8', newline='') as f: | |
| writer = csv.DictWriter(f, fieldnames=('X1', 'X2', 'A', 'M', 'Y'), lineterminator='\n') | |
| writer.writeheader() | |
| writer.writerows(rows) | |
| print(f'Wrote {len(rows)} observations to {args.output}; analytical NIE_1 = 0.04') | |