Download code/experiments/result_schema.py from DeepAuto-AI/MacroLens: direct link, hf CLI and curl.
- Browser
- Download file 6.9 kB
-
https://huggingface.co/datasets/DeepAuto-AI/MacroLens/resolve/main/code/experiments/result_schema.py
- Command line
-
hf download hf://datasets/DeepAuto-AI/MacroLens/code/experiments/result_schema.py
-
curl -L -o result_schema.py https://huggingface.co/datasets/DeepAuto-AI/MacroLens/resolve/main/code/experiments/result_schema.py
6.9 kB
| """Pydantic v2 result schemas for MacroLens task runners. | |
| These models replace the legacy ``TypedDict`` shapes used pre-Phase-4. The | |
| orchestrator (:mod:`experiments.run_all`) persists results as | |
| :class:`macrolens.RunRecord` (full reproducibility envelope); these | |
| per-task models capture the *metric content* of a single record's | |
| ``metrics`` field and are used by post-hoc tools (``gen_tables.py``, | |
| ``analysis.py``) that need a typed handle on the per-task metric set. | |
| Every model: | |
| * Uses ``model_config = ConfigDict(extra="forbid", frozen=True)`` so unknown | |
| keys raise at construction and instances are hashable. | |
| * Allows every metric to be ``None`` — runners that legitimately skip a | |
| metric (e.g., a deterministic naive method that does not report CRPS) | |
| emit ``None``, not a sentinel string. | |
| * Adds T5/T6/T7 (the legacy schema was missing T5/T6/T7). | |
| """ | |
| from __future__ import annotations | |
| import pydantic | |
| # ── Shared sub-schemas ──────────────────────────────────────────────────── | |
| class BootstrapCI(pydantic.BaseModel): | |
| """Bootstrap 95% CI for a scalar metric (matches ``MetricValue``).""" | |
| model_config = pydantic.ConfigDict(extra="forbid", frozen=True) | |
| mean: float | None = None | |
| ci_lo: float | None = None | |
| ci_hi: float | None = None | |
| std: float | None = None | |
| class MultiSeedStats(pydantic.BaseModel): | |
| """Mean +/- std over the headline T1 multi-seed subset.""" | |
| model_config = pydantic.ConfigDict(extra="forbid", frozen=True) | |
| seed_mean: float | None = None | |
| seed_std: float | None = None | |
| per_seed: dict[int, float] | None = None | |
| # ── Per-task metric schemas ─────────────────────────────────────────────── | |
| class T1Metrics(pydantic.BaseModel): | |
| """T1 — Contextual Time-Series Forecasting.""" | |
| model_config = pydantic.ConfigDict(extra="forbid", frozen=True) | |
| method_id: str | |
| task: str = "T1" | |
| horizon: int | None = None | |
| granularity: str = "daily" | |
| seed: int = 42 | |
| mse: float | None = None | |
| mae: float | None = None | |
| rmse: float | None = None | |
| directional_accuracy: float | None = None | |
| mse_ci: BootstrapCI | None = None | |
| mae_ci: BootstrapCI | None = None | |
| da_ci: BootstrapCI | None = None | |
| multiseed: MultiSeedStats | None = None | |
| n_instances: int | None = None | |
| inference_time_sec: float | None = None | |
| train_time_sec: float | None = None | |
| class T2Metrics(pydantic.BaseModel): | |
| """T2 — Point-in-Time Equity Valuation.""" | |
| model_config = pydantic.ConfigDict(extra="forbid", frozen=True) | |
| method_id: str | |
| task: str = "T2" | |
| granularity: str = "daily" | |
| seed: int = 42 | |
| mape: float | None = None | |
| median_ape: float | None = None | |
| rank_correlation: float | None = None | |
| rank_p_value: float | None = None | |
| mape_ci: BootstrapCI | None = None | |
| n_predictions: int | None = None | |
| n_tickers: int | None = None | |
| inference_time_sec: float | None = None | |
| class T3Metrics(pydantic.BaseModel): | |
| """T3 — Statement Generation (per-field MAPE + balance equation).""" | |
| model_config = pydantic.ConfigDict(extra="forbid", frozen=True) | |
| method_id: str | |
| task: str = "T3" | |
| granularity: str = "daily" | |
| seed: int = 42 | |
| overall_mape: float | None = None | |
| per_field_mape: dict[str, float] | None = None | |
| balance_equation_accuracy: float | None = None | |
| balance_equation_checked: int | None = None | |
| success_rate: float | None = None | |
| n_fields_matched: int | None = None | |
| n_field_misses: int | None = None | |
| n_tickers: int | None = None | |
| inference_time_sec: float | None = None | |
| class T4Metrics(pydantic.BaseModel): | |
| """T4 — Scenario-Conditioned Return Forecasting.""" | |
| model_config = pydantic.ConfigDict(extra="forbid", frozen=True) | |
| method_id: str | |
| task: str = "T4" | |
| granularity: str = "daily" | |
| seed: int = 42 | |
| return_mae_pct: float | None = None | |
| directional_accuracy: float | None = None | |
| ci_calibration_95: float | None = None | |
| return_mae_ci: BootstrapCI | None = None | |
| n_predictions: int | None = None | |
| n_scenarios: int | None = None | |
| inference_time_sec: float | None = None | |
| class T5Metrics(pydantic.BaseModel): | |
| """T5 — Private-Company Valuation (no market prices).""" | |
| model_config = pydantic.ConfigDict(extra="forbid", frozen=True) | |
| method_id: str | |
| task: str = "T5" | |
| granularity: str = "daily" | |
| seed: int = 42 | |
| mape: float | None = None | |
| median_ape: float | None = None | |
| rank_correlation: float | None = None | |
| rank_p_value: float | None = None | |
| mape_ci: BootstrapCI | None = None | |
| n_predictions: int | None = None | |
| n_tickers: int | None = None | |
| gap_vs_t2: float | None = None | |
| inference_time_sec: float | None = None | |
| class T6Metrics(pydantic.BaseModel): | |
| """T6 — Generator Evaluation (NL description -> XBRL).""" | |
| model_config = pydantic.ConfigDict(extra="forbid", frozen=True) | |
| method_id: str | |
| task: str = "T6" | |
| granularity: str = "daily" | |
| seed: int = 42 | |
| overall_mape: float | None = None | |
| per_field_mape: dict[str, float] | None = None | |
| success_rate: float | None = None | |
| n_fields_matched: int | None = None | |
| n_field_misses: int | None = None | |
| n_tickers: int | None = None | |
| inference_time_sec: float | None = None | |
| class T7Metrics(pydantic.BaseModel): | |
| """T7 — Real-Estate Valuation.""" | |
| model_config = pydantic.ConfigDict(extra="forbid", frozen=True) | |
| method_id: str | |
| task: str = "T7" | |
| granularity: str = "daily" | |
| seed: int = 42 | |
| rent_MAPE: float | None = None | |
| price_MAPE: float | None = None | |
| rent_median_APE: float | None = None | |
| price_median_APE: float | None = None | |
| rent_n_valid: int | None = None | |
| price_n_valid: int | None = None | |
| n_predictions: int | None = None | |
| inference_time_sec: float | None = None | |
| # ── Family-level container ──────────────────────────────────────────────── | |
| class FamilyResults(pydantic.BaseModel): | |
| """Container emitted by each family's ``run_all_*()`` function.""" | |
| model_config = pydantic.ConfigDict(extra="forbid", frozen=True) | |
| family: str | |
| panel_version: str | None = None | |
| methods: dict[str, list[dict]] = pydantic.Field(default_factory=dict) | |
| # ── Task dispatch map ───────────────────────────────────────────────────── | |
| TASK_RESULT_TYPES: dict[str, type[pydantic.BaseModel]] = { | |
| "T1": T1Metrics, | |
| "T2": T2Metrics, | |
| "T3": T3Metrics, | |
| "T4": T4Metrics, | |
| "T5": T5Metrics, | |
| "T6": T6Metrics, | |
| "T7": T7Metrics, | |
| } | |