Download example.py from zeechimp/chaos-chip-census: direct link, hf CLI and curl.
- Browser
- Download file 1.7 kB
-
https://huggingface.co/zeechimp/chaos-chip-census/resolve/main/example.py
- Command line
-
hf download hf://zeechimp/chaos-chip-census/example.py
-
curl -L -o example.py https://huggingface.co/zeechimp/chaos-chip-census/resolve/main/example.py
1.7 kB
| #!/usr/bin/env python3 | |
| """ | |
| Example usage of the chaos-chip-census dataset. | |
| Requires: pandas, numpy. | |
| """ | |
| import pandas as pd | |
| import numpy as np | |
| def main(): | |
| df = pd.read_csv("census.csv") | |
| print(f"loaded {len(df)} rows") | |
| print() | |
| # 1. rate table | |
| rates = df.groupby(["n", "k"])["solved"].agg(["sum", "mean"]) | |
| rates.columns = ["solved", "rate"] | |
| print("Solve rate per instance:") | |
| print(rates) | |
| print() | |
| # 2. find K_12 solving chips | |
| k12 = df[(df.n == 12) & (df.k == 4) & (df.solved == 1)] | |
| print(f"K_12 solving chips ({len(k12)}):") | |
| print(k12[["hex", "q", "s"]].to_string(index=False)) | |
| print() | |
| # 3. find K_14, k=6 chips | |
| k14k6 = df[(df.n == 14) & (df.k == 6) & (df.solved == 1)] | |
| print(f"K_14, k=6 solving chips: {len(k14k6)}/256") | |
| print() | |
| # 4. D-metric check | |
| from math import comb, log2 | |
| def D(n, k): | |
| return log2(comb(n, k)) / comb(k, 2) | |
| summary = [] | |
| for (n, k), grp in df.groupby(["n", "k"]): | |
| summary.append({ | |
| "n": n, "k": k, | |
| "D": D(n, k), | |
| "rate": grp["solved"].mean(), | |
| }) | |
| s = pd.DataFrame(summary).sort_values("D") | |
| print("D-metric ordering:") | |
| print(s.to_string(index=False)) | |
| print() | |
| # 5. fit log(rate) vs D | |
| valid = s[s.rate > 0] | |
| if len(valid) > 2: | |
| x = valid["D"].values | |
| y = np.log(valid["rate"].values) | |
| a, b = np.polyfit(x, y, 1) | |
| y_pred = a * x + b | |
| ss_res = np.sum((y - y_pred) ** 2) | |
| ss_tot = np.sum((y - y.mean()) ** 2) | |
| r2 = 1 - ss_res / ss_tot | |
| print(f"D-metric fit: log(rate) = {a:.3f}·D + {b:.3f} R² = {r2:.4f}") | |
| if __name__ == "__main__": | |
| main() |