-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathcheck_data.py
More file actions
155 lines (135 loc) · 5.46 KB
/
Copy pathcheck_data.py
File metadata and controls
155 lines (135 loc) · 5.46 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
"""Marimo notebook: inspect HP-screen results and individual training runs.
Run with: marimo edit check_data.py
"""
import marimo
__generated_with = "0.23.5"
app = marimo.App(width="medium")
@app.cell
def __():
from pathlib import Path
import json as jsonlib
import pandas as pd
import numpy as np
import plotly.express as px
import plotly.graph_objects as go
import marimo as mo
return Path, go, jsonlib, mo, np, pd, px
@app.cell
def __(Path):
# Default relative paths to diagnostic outputs (from project root)
ROOT = Path(".")
SCREEN_8_CSV = ROOT / "artifacts" / "hp_postbounds.csv"
SCREEN_27_CSV = ROOT / "artifacts" / "hp_postbounds_27.csv"
RUNS_DIR = ROOT / "artifacts" / "daily_runs"
return RUNS_DIR, SCREEN_27_CSV, SCREEN_8_CSV
@app.cell
def __(SCREEN_27_CSV, SCREEN_8_CSV, mo, pd):
# Live screen results — re-run this cell to refresh as screens write rows.
s8 = pd.read_csv(SCREEN_8_CSV) if SCREEN_8_CSV.exists() else pd.DataFrame()
s27 = pd.read_csv(SCREEN_27_CSV) if SCREEN_27_CSV.exists() else pd.DataFrame()
mo.md(f"**Screens:** 8-cell `{len(s8)}` rows, 27-cell `{len(s27)}` rows")
return s27, s8
@app.cell
def __(mo, pd, s27, s8):
# Cell-level aggregation by asymmetric_score (mean across seeds).
GROUP_KEYS = ["position_bounds_penalty", "reward_scale", "entropy_coef"]
def aggregate(df):
if df.empty or "asymmetric_score" not in df.columns:
return pd.DataFrame()
return (df.groupby(GROUP_KEYS)
.agg(asym=("asymmetric_score", "mean"),
asym_std=("asymmetric_score", "std"),
mean_pnl=("final_net_pnl", "mean"),
std_pnl=("final_std_net_pnl", "mean"),
p5=("final_p5_net_pnl", "mean"),
worst=("final_worst_net_pnl", "mean"),
trade=("final_action_abs", "mean"))
.sort_values("asym", ascending=False)
.reset_index())
cells_8 = aggregate(s8)
cells_27 = aggregate(s27)
mo.vstack([
mo.md("### 8-cell screen — ranked by mean asymmetric_score across seeds"),
cells_8,
mo.md("### 27-cell screen — ranked by mean asymmetric_score across seeds"),
cells_27,
])
return GROUP_KEYS, cells_27, cells_8
@app.cell
def __(GROUP_KEYS, cells_27, cells_8, mo, px):
# Per-knob marginal effect on asymmetric_score (uses 27-cell screen if populated, else 8-cell).
src = cells_27 if not cells_27.empty else cells_8
if src.empty:
plots = mo.md("_No data yet_")
else:
figs = []
for k in GROUP_KEYS:
agg = src.groupby(k)["asym"].agg(["mean", "min", "max"]).reset_index()
scatter_fig = px.scatter(agg, x=k, y="mean", error_y=agg["max"] - agg["mean"],
error_y_minus=agg["mean"] - agg["min"], log_x=True,
title=f"{k} → asymmetric_score")
figs.append(scatter_fig)
plots = mo.hstack(figs)
plots
return
@app.cell
def __(RUNS_DIR, mo):
# Browse individual daily-run dirs and pick one.
if RUNS_DIR.exists():
run_dirs = sorted([p.name for p in RUNS_DIR.iterdir() if p.is_dir()], reverse=True)
else:
run_dirs = []
selected_run = mo.ui.dropdown(options=run_dirs, value=run_dirs[0] if run_dirs else None,
label="Run dir")
selected_run
return selected_run,
@app.cell
def __(RUNS_DIR, jsonlib, mo, pd, selected_run):
# Load the chosen run's summary.csv + config.json.
run_summary = pd.DataFrame()
run_config = {}
run_path = None
if selected_run.value:
run_path = RUNS_DIR / selected_run.value
sp = run_path / "summary.csv"
cp = run_path / "config.json"
if sp.exists():
run_summary = pd.read_csv(sp)
if cp.exists():
run_config = jsonlib.loads(cp.read_text())
mo.vstack([
mo.md(f"### `{selected_run.value or 'no run selected'}`"),
mo.md("**Config:**"),
run_config,
mo.md("**Summary (full distribution):**"),
run_summary,
])
return run_path,
@app.cell
def __(go, mo, pd, run_path):
# Plot per-day total |position| trajectories for best/worst/p5/p95/mean cases.
# ML = solid, textbook = dashed; color encodes case.
fig = go.Figure()
if run_path is not None:
for label, fname, dash in (("ml", "ml_paths.csv", "solid"),
("textbook", "textbook_paths.csv", "dash")):
csv = run_path / fname
if not csv.exists():
continue
df = pd.read_csv(csv)
df["day"] = pd.to_datetime(df["day"])
for case in df["case"].unique():
sub = df[df["case"] == case]
total_abs = sub.filter(like="_position").abs().sum(axis=1)
fig.add_scatter(x=sub["day"], y=total_abs, mode="lines",
name=f"{label}:{case}",
line=dict(dash=dash),
legendgroup=case)
fig.update_layout(title="Total |position| over time — ML (solid) vs textbook (dash)",
xaxis_title="date", yaxis_title="Σ|position_i| (contracts)")
if not fig.data:
fig.add_annotation(text="no paths CSV", showarrow=False)
mo.ui.plotly(fig)
return
if __name__ == "__main__":
app.run()