Skip to content

Commit 7309497

Browse files
committed
Toy1D Exp1 - Fix scale
1 parent ffd0ada commit 7309497

3 files changed

Lines changed: 26 additions & 120 deletions

File tree

‎dev/toy1d_experiments/fix_results.ipynb‎

Lines changed: 15 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": 16,
5+
"execution_count": 55,
66
"id": "09c54280",
77
"metadata": {},
88
"outputs": [],
@@ -18,17 +18,23 @@
1818
},
1919
{
2020
"cell_type": "code",
21-
"execution_count": 17,
21+
"execution_count": 56,
2222
"id": "d58ad45e",
2323
"metadata": {},
2424
"outputs": [],
2525
"source": [
26-
"paths = glob.glob(\"toy1d_experiment0_protocol_test\\\\*\\\\run*\")"
26+
"EXPERIMENT0 = \"toy1d_experiment0_protocol_test\\\\*\\\\run*\"\n",
27+
"EXPERIMENT1 = \"toy1d_experiment1_configuration_test\\\\*\\\\run*\"\n",
28+
"EXPERIMENT2 = \"toy1d_experiment2_best_long\\\\*\\\\run*\"\n",
29+
"\n",
30+
"path_template = EXPERIMENT1\n",
31+
"\n",
32+
"paths = glob.glob(path_template)"
2733
]
2834
},
2935
{
3036
"cell_type": "code",
31-
"execution_count": 18,
37+
"execution_count": 57,
3238
"id": "72cf638e",
3339
"metadata": {},
3440
"outputs": [],
@@ -63,7 +69,7 @@
6369
},
6470
{
6571
"cell_type": "code",
66-
"execution_count": 19,
72+
"execution_count": 58,
6773
"id": "d35f852b",
6874
"metadata": {},
6975
"outputs": [],
@@ -75,121 +81,20 @@
7581
},
7682
{
7783
"cell_type": "code",
78-
"execution_count": 21,
84+
"execution_count": null,
7985
"id": "6154870b",
8086
"metadata": {},
8187
"outputs": [],
8288
"source": [
8389
"for run_path in paths:\n",
8490
" for name in patch_map:\n",
91+
" if name != \"metrics\" and path_template != EXPERIMENT0:\n",
92+
" continue\n",
93+
"\n",
8594
" metrics = load_metrics(run_path, name)\n",
8695
" metrics = patch_map[name](metrics, run_path)\n",
8796
" save_metrics(metrics, run_path, name)\n"
8897
]
89-
},
90-
{
91-
"cell_type": "code",
92-
"execution_count": 24,
93-
"id": "e702b2f7",
94-
"metadata": {},
95-
"outputs": [],
96-
"source": [
97-
"import os\n",
98-
"import time\n",
99-
"from typing import Any\n",
100-
"\n",
101-
"import torch\n",
102-
"import tqdm\n",
103-
"from hamilton import driver\n",
104-
"from hamilton.function_modifiers import source, value\n",
105-
"from numba import cuda\n",
106-
"\n",
107-
"from world_machine.data import WorldMachineDataset\n",
108-
"from world_machine_experiments import shared\n",
109-
"from world_machine_experiments.shared import function_variation\n",
110-
"from world_machine_experiments.shared.load_multiple_metrics import (\n",
111-
" load_multiple_metrics)\n",
112-
"from world_machine_experiments.shared.pipeline import save_pipeline\n",
113-
"from world_machine_experiments.shared.save_metrics import (\n",
114-
" load_metrics, save_metrics)\n",
115-
"from world_machine_experiments.shared.save_parameters import save_parameters\n",
116-
"from world_machine_experiments.shared.save_plots import save_plots\n",
117-
"from world_machine_experiments.shared.statistics import consolidated_metrics\n",
118-
"from world_machine_experiments.shared.train_plots import train_plots\n",
119-
"from world_machine_experiments.toy1d import base\n",
120-
"from world_machine_experiments.toy1d.base import toy1d_masks_sensory_plots\n",
121-
"\n",
122-
"aditional_outputs = [\"save_toy1d_metrics\",\n",
123-
" \"save_toy1d_metrics_sample_logits\",\n",
124-
" \"save_toy1d_metrics_sample_plots\",\n",
125-
"\n",
126-
" \"save_toy1d_mask_sensory_plot\",\n",
127-
" \"save_toy1d_mask_sensory_metrics\",\n",
128-
"\n",
129-
" \"save_toy1d_autoregressive_metrics\"]\n",
130-
"\n",
131-
"\n",
132-
"d = driver.Builder().with_modules(base, shared).build()\n",
133-
"\n",
134-
"final_vars = [\"toy1d_train_history\",\n",
135-
" \"save_toy1d_model\",\n",
136-
" \"save_toy1d_train_history\",\n",
137-
" \"save_toy1d_train_plots\",\n",
138-
" \"save_toy1d_prediction_plots\",\n",
139-
" \"toy1d_datasets\"]\n",
140-
"\n",
141-
"final_vars += aditional_outputs\n",
142-
"\n",
143-
"save_pipeline(d, final_vars, \"pipeline\", \".\", True)"
144-
]
145-
},
146-
{
147-
"cell_type": "code",
148-
"execution_count": 25,
149-
"id": "836a3f8e",
150-
"metadata": {},
151-
"outputs": [],
152-
"source": [
153-
"from world_machine_experiments.shared.pipeline import save_pipeline, load_graph"
154-
]
155-
},
156-
{
157-
"cell_type": "code",
158-
"execution_count": 26,
159-
"id": "8a7f048a",
160-
"metadata": {},
161-
"outputs": [],
162-
"source": [
163-
"graph = load_graph(\"pipeline\", \".\")"
164-
]
165-
},
166-
{
167-
"cell_type": "code",
168-
"execution_count": 35,
169-
"id": "b0e08812",
170-
"metadata": {},
171-
"outputs": [],
172-
"source": [
173-
"grafo2 = otimizar_layout_grafo_td_corrigido(graph)"
174-
]
175-
},
176-
{
177-
"cell_type": "code",
178-
"execution_count": 36,
179-
"id": "72573ffc",
180-
"metadata": {},
181-
"outputs": [],
182-
"source": [
183-
"grafo2.write_svg(\"pipeline2.svg\")"
184-
]
185-
},
186-
{
187-
"cell_type": "code",
188-
"execution_count": null,
189-
"id": "abfdb6b4",
190-
"metadata": {},
191-
"outputs": [],
192-
"source": []
19398
}
19499
],
195100
"metadata": {

‎experiments/src/world_machine_experiments/toy1d/specific/experiment1/joint_impact_test.py‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -144,20 +144,20 @@ def disjoint_mask(disjoint_groups: list[set[str]]) -> np.ndarray:
144144
return result
145145

146146

147+
EXPONENTS = {"normal": 4,
148+
"use_state": 4,
149+
"prediction": 2,
150+
"prediction_shallow": 2,
151+
"prediction_local": 3}
152+
153+
147154
def joint_impact_plots(joint_impact: dict,
148155
disjoint_mask: np.ndarray) -> dict[str, Figure]:
149156

150157
figures = {}
151158
for task in task_names:
152-
if task in ["prediction_shallow", "prediction"]:
153-
scale = 1e3
154-
scale_exponent = 3
155-
elif task in ["normal"]:
156-
scale = 1e5
157-
scale_exponent = 5
158-
else:
159-
scale = 1e4
160-
scale_exponent = 4
159+
scale_exponent = EXPONENTS[task]
160+
scale = 10**scale_exponent
161161

162162
fig = plt.figure(dpi=600)
163163

‎experiments/src/world_machine_experiments/toy1d/specific/experiment1/prepare_data.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ def _add_diverge_mask(df: pd.DataFrame) -> None:
3232
data = df[f"{metric}_mse"].to_numpy()
3333

3434
data_mask = np.bitwise_not(np.isnan(data))
35-
data_mask = np.bitwise_and(data_mask, data < 1)
35+
data_mask = np.bitwise_and(data_mask, np.bitwise_not(np.isinf(data)))
36+
data_mask = np.bitwise_and(data_mask, data < 1000)
3637

3738
data_max = data[data_mask].mean() + 3*data[data_mask].std()
3839

0 commit comments

Comments
 (0)