Datasets:
Formats:
csv
Languages:
English
Size:
< 1K
Tags:
mathematics
linear-algebra
convex-optimization
optimal-recovery
neural-representations
robustness
Download tables/export_tables.py from PureOne/luminous-hypercontinuum-foundation-v3: direct link, hf CLI and curl.
- Browser
- Download file 14.6 kB
-
https://huggingface.co/datasets/PureOne/luminous-hypercontinuum-foundation-v3/resolve/main/tables/export_tables.py
- Command line
-
hf download hf://datasets/PureOne/luminous-hypercontinuum-foundation-v3/tables/export_tables.py
-
curl -L -o export_tables.py https://huggingface.co/datasets/PureOne/luminous-hypercontinuum-foundation-v3/resolve/main/tables/export_tables.py
14.6 kB
| #!/usr/bin/env python3 | |
| """Export viewer tables from the recorded LHF v3 release; runs no experiments. | |
| Usage: python export_tables.py SOURCE_ROOT OUTPUT_DIR | |
| Both arguments are directories. SOURCE_ROOT contains the original data/ JSON | |
| files. Only scalar fields are exported; the original JSON remains authoritative. | |
| Uses Python's standard library and validates each CSV against its source values. | |
| """ | |
| from __future__ import annotations | |
| import argparse | |
| import csv | |
| import hashlib | |
| import json | |
| from pathlib import Path | |
| # Field name, CSV / Hugging Face type, units, meaning. | |
| SCHEMAS = { | |
| "neural_results.csv": [ | |
| ("seed", "int64", "none", "Training random seed; one of 7, 23, 61."), | |
| ("noise_norm", "float64", "latent-observation Euclidean norm", "Fixed norm of paired post-observation noise for each test sample and scenario."), | |
| ("method", "string", "none", "Transport contraction: uniform or optimized."), | |
| ("mean_scenario_accuracy", "float64", "fraction [0, 1]", "Mean test-label accuracy across eight observation scenarios."), | |
| ("worst_scenario_accuracy", "float64", "fraction [0, 1]", "Minimum test-label accuracy among the eight scenarios."), | |
| ("mean_reconstruction_RMSE", "float64", "latent-state Euclidean norm", "Mean across scenarios of sqrt(mean squared Euclidean state error across test samples); not per-coordinate RMSE."), | |
| ("maximum_state_error", "float64", "latent-state Euclidean norm", "Largest Euclidean state-reconstruction error across all tested samples and scenarios."), | |
| ("deterministic_error_radius", "float64", "latent-state Euclidean norm", "Recorded deterministic reconstruction bound noise_norm / sqrt(spectral information floor)."), | |
| ("certified_prediction_stability_fraction", "float64", "fraction [0, 1]", "Fraction of clean predictions certified unchanged under the prescribed radius; does not certify label correctness."), | |
| ("mean_prediction_stability", "float64", "fraction [0, 1]", "Mean across scenarios of the fraction of reconstructed predictions equal to clean predictions."), | |
| ], | |
| "neural_aggregates.csv": [ | |
| ("noise_norm", "float64", "latent-observation Euclidean norm", "Fixed norm of paired post-observation noise."), | |
| ("method", "string", "none", "Transport contraction: uniform or optimized."), | |
| ("mean_accuracy", "float64", "fraction [0, 1]", "Mean of mean_scenario_accuracy across the three training seeds."), | |
| ("seed_std", "float64", "accuracy fraction", "Sample standard deviation (ddof=1) of the three seeds' mean_scenario_accuracy."), | |
| ("mean_worst_scenario_accuracy", "float64", "fraction [0, 1]", "Mean across seeds of each seed's minimum scenario accuracy."), | |
| ("mean_reconstruction_RMSE", "float64", "latent-state Euclidean norm", "Mean across seeds of scenario-mean root-mean-squared Euclidean state error."), | |
| ("mean_certified_stability", "float64", "fraction [0, 1]", "Mean across seeds of certified_prediction_stability_fraction; does not certify label correctness."), | |
| ], | |
| "verification_groups.csv": [ | |
| ("name", "string", "none", "Recorded numerical-check group identifier."), | |
| ("status", "string", "none", "Status recorded in the original verification JSON; not a newly executed verification status."), | |
| ("cases", "int64", "cases", "Number of seeded cases recorded for the group."), | |
| ("max_residual", "float64", "group-dependent mathematical residual", "Largest residual recorded for this group; residual definitions differ by group and must not be compared as a common metric."), | |
| ("interpretation", "string", "none", "Original group interpretation, including empty strings when no interpretation was recorded."), | |
| ], | |
| "frontier_curve.csv": [ | |
| ("B", "float64", "dimensionless natural-log determinant budget", "Budget in |det(C)| = exp(-B) for the fixed two-dimensional noncommuting example."), | |
| ("exact", "float64", "spectral information floor in model coordinates", "Recorded float evaluation of the exact closed-form optimum; CSV contains the evaluation, not a symbolic expression."), | |
| ("computed", "float64", "spectral information floor in model coordinates", "Recorded numerical solver value for the same budget and example."), | |
| ("uniform", "float64", "spectral information floor in model coordinates", "Recorded uniform-contraction floor at the matched determinant budget."), | |
| ], | |
| "exact_checks.csv": [ | |
| ("identity", "string", "none", "Identifier from the original exact-certificate identities array."), | |
| ("recorded_status", "string", "none", "Original JSON's overall certificate-run status copied to each identity row. Individual identity statuses are not separately stored and were not independently rerun during packaging."), | |
| ("scope", "string", "none", "Scope statement copied verbatim from the original exact-certificate JSON."), | |
| ], | |
| } | |
| def load_json(path: Path) -> dict: | |
| with path.open(encoding="utf-8") as stream: | |
| value = json.load(stream) | |
| if not isinstance(value, dict): | |
| raise ValueError(f"Expected a JSON object: {path}") | |
| return value | |
| def scalar_projection(rows: list, filename: str) -> list[dict]: | |
| fields = [field[0] for field in SCHEMAS[filename]] | |
| projected = [] | |
| for index, source in enumerate(rows): | |
| row = {name: source[name] for name in fields} | |
| for name, type_name, _, _ in SCHEMAS[filename]: | |
| value = row[name] | |
| if type_name == "string": | |
| valid = isinstance(value, str) | |
| elif type_name == "int64": | |
| valid = isinstance(value, int) and not isinstance(value, bool) | |
| else: | |
| valid = isinstance(value, (float, int)) and not isinstance(value, bool) | |
| if not valid: | |
| raise TypeError(f"{filename}, row {index}, field {name}: invalid scalar type") | |
| projected.append(row) | |
| return projected | |
| def write_and_validate(path: Path, rows: list[dict]) -> dict: | |
| schema = SCHEMAS[path.name] | |
| fields = [field[0] for field in schema] | |
| with path.open("w", encoding="utf-8", newline="") as stream: | |
| writer = csv.DictWriter(stream, fieldnames=fields) | |
| writer.writeheader() | |
| writer.writerows(rows) | |
| with path.open(encoding="utf-8", newline="") as stream: | |
| reader = csv.DictReader(stream) | |
| if reader.fieldnames != fields: | |
| raise AssertionError(f"CSV header mismatch: {path.name}") | |
| parsed = list(reader) | |
| if len(parsed) != len(rows): | |
| raise AssertionError(f"CSV row-count mismatch: {path.name}") | |
| checked = 0 | |
| for index, (csv_row, source_row) in enumerate(zip(parsed, rows)): | |
| for name, type_name, _, _ in schema: | |
| value = csv_row[name] | |
| if type_name == "int64": | |
| value = int(value) | |
| elif type_name == "float64": | |
| value = float(value) | |
| if value != source_row[name]: | |
| raise AssertionError(f"CSV value mismatch: {path.name}, row {index}, {name}") | |
| checked += 1 | |
| return { | |
| "rows": len(rows), | |
| "columns": len(fields), | |
| "scalar_values_checked": checked, | |
| "validation": "PASS: parsed CSV values equal corresponding original JSON scalar values", | |
| } | |
| def dictionary_text(counts: dict) -> str: | |
| text = [ | |
| "# Viewer data dictionary", | |
| "", | |
| "These CSV files are packaging derivatives of recorded LHF v3.0.0 results. " | |
| "They add no experiments, recomputed outcomes, proof verification, or independent review. " | |
| "The original JSON, experiment code, saved arrays and manuscript remain the authoritative records.", | |
| "", | |
| "Numbers are written with Python's CSV writer without rounding or percentage conversion. " | |
| "Validation reads the CSV values back with their stated types and compares them to the " | |
| "original JSON-decoded scalar values. This preserves scalar numeric values, rather than the " | |
| "original JSON text formatting. Fractions such as 0.935 are accuracy proportions, not percentages.", | |
| "", | |
| "The neural study uses one fixed optical-digits split (1,257 training / 540 test samples), " | |
| "three training seeds, eight-dimensional frozen learned features, eight constructed observation " | |
| "scenarios, and six paired noise norms. Its transport comparison does not demonstrate " | |
| "general AI intelligence improvement or state-of-the-art superiority. Latent coordinates " | |
| "have no physical SI unit.", | |
| "", | |
| "Source mappings:", | |
| "", | |
| "| CSV | Original JSON field | Rows |", | |
| "|---|---|---:|", | |
| f"| neural_results.csv | data/neural_digits_results.json → records (scalar fields only) | {counts['neural_results.csv']} |", | |
| f"| neural_aggregates.csv | data/neural_digits_results.json → aggregates | {counts['neural_aggregates.csv']} |", | |
| f"| verification_groups.csv | data/mathematical_verification.json → groups | {counts['verification_groups.csv']} |", | |
| f"| frontier_curve.csv | data/mathematical_verification.json → frontier_curve | {counts['frontier_curve.csv']} |", | |
| f"| exact_checks.csv | data/exact_certificates.json → identities, overall status and scope | {counts['exact_checks.csv']} |", | |
| "", | |
| "The nested scenario_accuracies list is deliberately omitted from neural_results.csv; " | |
| "all original per-scenario values remain in data/neural_digits_results.json. " | |
| "The aggregate table copies the source aggregates; it does not recalculate them.", | |
| "", | |
| "The exact-check JSON records one overall PASS and twenty identity labels. " | |
| "Its recorded_status is therefore copied from the overall run to all twenty rows. " | |
| "These rows are not twenty independently rerun checks and do not supply proof-assistant verification.", | |
| "", | |
| ] | |
| for filename, schema in SCHEMAS.items(): | |
| text.extend([ | |
| f"## {filename}", "", | |
| "| Field | Type | Units | Definition |", | |
| "|---|---|---|---|", | |
| ]) | |
| for name, type_name, units, definition in schema: | |
| escaped_units = units.replace("|", "\\|") | |
| escaped_definition = definition.replace("|", "\\|") | |
| text.append(f"| {name} | {type_name} | {escaped_units} | {escaped_definition} |") | |
| text.append("") | |
| return "\n".join(text) | |
| def export_tables(source_root: Path, output_dir: Path) -> dict: | |
| paths = { | |
| "neural": source_root / "data" / "neural_digits_results.json", | |
| "verification": source_root / "data" / "mathematical_verification.json", | |
| "exact": source_root / "data" / "exact_certificates.json", | |
| } | |
| neural, verification, exact = (load_json(paths[name]) for name in ("neural", "verification", "exact")) | |
| if verification["group_count"] != len(verification["groups"]): | |
| raise AssertionError("Recorded verification group count disagrees with group list") | |
| if verification["total_cases"] != sum(group["cases"] for group in verification["groups"]): | |
| raise AssertionError("Recorded verification case total disagrees with group sum") | |
| if exact["checked_identities"] != len(exact["identities"]): | |
| raise AssertionError("Recorded exact-identity count disagrees with identity list") | |
| rows = { | |
| "neural_results.csv": scalar_projection(neural["records"], "neural_results.csv"), | |
| "neural_aggregates.csv": scalar_projection(neural["aggregates"], "neural_aggregates.csv"), | |
| "verification_groups.csv": scalar_projection(verification["groups"], "verification_groups.csv"), | |
| "frontier_curve.csv": scalar_projection(verification["frontier_curve"], "frontier_curve.csv"), | |
| "exact_checks.csv": scalar_projection([ | |
| {"identity": identity, "recorded_status": exact["status"], "scope": exact["scope"]} | |
| for identity in exact["identities"] | |
| ], "exact_checks.csv"), | |
| } | |
| output_dir.mkdir(parents=True, exist_ok=True) | |
| reports = {name: write_and_validate(output_dir / name, table) for name, table in rows.items()} | |
| counts = {name: report["rows"] for name, report in reports.items()} | |
| (output_dir / "DATA_DICTIONARY.md").write_text(dictionary_text(counts), encoding="utf-8") | |
| source_names = { | |
| "neural_results.csv": "data/neural_digits_results.json:records", | |
| "neural_aggregates.csv": "data/neural_digits_results.json:aggregates", | |
| "verification_groups.csv": "data/mathematical_verification.json:groups", | |
| "frontier_curve.csv": "data/mathematical_verification.json:frontier_curve", | |
| "exact_checks.csv": "data/exact_certificates.json:identities + overall status + scope", | |
| } | |
| for name, report in reports.items(): | |
| report["source"] = source_names[name] | |
| report["csv_sha256"] = hashlib.sha256((output_dir / name).read_bytes()).hexdigest() | |
| report = { | |
| "status": "PASS", | |
| "kind": "data-packaging derivative validation; no new experiment execution", | |
| "source_release": "3.0.0", | |
| "source_json_sha256": { | |
| str(path.relative_to(source_root)): hashlib.sha256(path.read_bytes()).hexdigest() | |
| for path in paths.values() | |
| }, | |
| "tables": reports, | |
| "recorded_numerical_case_total": verification["total_cases"], | |
| "total_exported_rows": sum(counts.values()), | |
| "total_scalar_values_checked": sum(entry["scalar_values_checked"] for entry in reports.values()), | |
| "omitted_nested_neural_record_field": "scenario_accuracies", | |
| "exact_status_note": "The source stores overall PASS, not per-identity status. recorded_status copies the overall status; identities were not independently rerun during packaging.", | |
| "numeric_preservation": "CSV writer serializes JSON-decoded numbers without rounding; parsed CSV numeric values equal originals.", | |
| } | |
| (output_dir / "table_export_validation.json").write_text(json.dumps(report, indent=2) + "\n", encoding="utf-8") | |
| return report | |
| def main() -> None: | |
| parser = argparse.ArgumentParser(description=__doc__) | |
| parser.add_argument("source_root", type=Path) | |
| parser.add_argument("output_dir", type=Path) | |
| args = parser.parse_args() | |
| report = export_tables(args.source_root.resolve(), args.output_dir.resolve()) | |
| print(json.dumps({"status": report["status"], "rows": {name: value["rows"] for name, value in report["tables"].items()}, "scalar_values_checked": report["total_scalar_values_checked"]}, indent=2)) | |
| if __name__ == "__main__": | |
| main() | |