File size: 4,071 Bytes
f02626b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
"""Canonical sample budgets per task.

Single source of truth. Every family runner reads from here so that
cross-method comparison on each task is fair (same N for every method,
same instances, same indices).

Normalization principle:
- Forecasting / regression-with-subsample tasks (T1, T4, T7):
  N_eval = 1,000 / N_train = 10,000  (stratified subsample from larger pools)
- Ticker-holdout valuation tasks (T2, T5):
  N_eval = 1,324 / N_train = 2,673   (full 30% holdout, no subsampling)
- Filing-level generation tasks (T3, T6):
  N_eval = 1,058 (some holdout tickers lack complete XBRL); train varies

Sample sizes are intentionally conservative -- ~10x the median peer-benchmark
scale (CiK 125 / WIT 446 / EDINET 350 / SciTS 1,250) so reviewers cannot
claim small-sample noise, while keeping LLM eval (4 LLMs x 7 tasks x ~1K
samples = ~28K calls) tractable on 4xA100 within the wall-clock budget.

The values here are DEFAULTS; runners may override via the
`get_canonical_indices(task, split, n_eval=..., n_train=...)` keyword
arguments to regenerate (and re-cache) for a re-tune without rebuilding
any artifacts.
"""

from __future__ import annotations

from typing import Literal


Task = Literal["T1", "T2", "T3", "T4", "T5", "T6", "T7"]


# ── Canonical budgets ─────────────────────────────────────────────────────

EVAL_N_PER_TASK: dict[Task, int] = {
    "T1": 1_000,   # subsampled (full ~1.3M)
    "T2": 1_324,   # full 30% ticker holdout
    "T3": 1_058,   # filing-level holdout (subset of 1,324 with full XBRL)
    "T4": 1_000,   # subsampled (full ~3M scenario-ticker pairs)
    "T5": 1_324,   # full 30% ticker holdout
    "T6": 1_058,   # filing-level holdout
    "T7": 1_000,   # subsampled (full ~23K properties)
}

TRAIN_N_PER_TASK: dict[Task, int] = {
    "T1": 10_000,  # subsampled training windows, sector x mcap_q
    "T2": 2_673,   # latest snapshot per non-holdout ticker
    "T3": 9_458,   # prior fiscal years across non-holdout tickers
    "T4": 10_000,  # subsampled scenario-conditioned windows
    "T5": 2_673,   # latest snapshot per non-holdout ticker
    "T6": 1_377,   # prior fiscal years for filing-level holdout
    "T7": 10_000,  # subsampled training properties, property_type x state
}


# ── Seed + stratifier ─────────────────────────────────────────────────────

SEED: int = 42

# Bumped if the stratifier logic changes (forces cache invalidation
# without changing N values). Increment when:
#   - the panel column used for stratification changes
#   - the per-task stratifier columns change
#   - the sampler's tie-breaking / fallback logic changes
STRATIFIER_VERSION: int = 1


# ── Cache key derivation ──────────────────────────────────────────────────

def cache_key(
    *,
    n_eval: dict[Task, int] | None = None,
    n_train: dict[Task, int] | None = None,
    seed: int | None = None,
    stratifier_version: int | None = None,
) -> str:
    """Stable cache-directory name for the (budgets, seed, stratifier) tuple.

    Defaults to the module-level canonical values. Override any subset to
    generate a non-canonical cache (e.g. a re-tune at N_eval=2000 produces
    its own cache dir leaving the canonical cache intact).
    """
    ne = n_eval or EVAL_N_PER_TASK
    nt = n_train or TRAIN_N_PER_TASK
    s = SEED if seed is None else seed
    sv = STRATIFIER_VERSION if stratifier_version is None else stratifier_version

    # Compact, readable encoding -- avoids sha hashes so the directory
    # contents are inspectable.
    eval_str = "-".join(f"{t}={ne[t]}" for t in ("T1", "T2", "T3", "T4", "T5", "T6", "T7"))
    train_str = "-".join(f"{t}={nt[t]}" for t in ("T1", "T2", "T3", "T4", "T5", "T6", "T7"))
    return f"seed={s}_strat=v{sv}_eval[{eval_str}]_train[{train_str}]"