rli14 commited on
Commit
4e64113
·
verified ·
1 Parent(s): e09eb59

rsm_rise code snapshot (HF_PUSH_ALL) (part 7)

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +174 -0
  2. gen_q_rsm/preliminary_analysis/experiments/visual_pointmaze_medium_navigate_v0/figures/mse.png +0 -0
  3. gen_q_rsm/preliminary_analysis/experiments/visual_pointmaze_medium_navigate_v0/results/0/genq.json +122 -0
  4. gen_q_rsm/preliminary_analysis/experiments/visual_pointmaze_medium_navigate_v0/results/0/mc.json +124 -0
  5. gen_q_rsm/preliminary_analysis/experiments/visual_pointmaze_medium_navigate_v0/results/0/td.json +124 -0
  6. gen_q_rsm/preliminary_analysis/experiments/visual_pointmaze_medium_navigate_v0/results/1/genq.json +122 -0
  7. gen_q_rsm/preliminary_analysis/experiments/visual_pointmaze_medium_navigate_v0/results/1/mc.json +124 -0
  8. gen_q_rsm/preliminary_analysis/experiments/visual_pointmaze_medium_navigate_v0/results/1/td.json +124 -0
  9. gen_q_rsm/preliminary_analysis/experiments/visual_pointmaze_medium_navigate_v0/results/2/genq.json +122 -0
  10. gen_q_rsm/preliminary_analysis/experiments/visual_pointmaze_medium_navigate_v0/results/2/mc.json +124 -0
  11. gen_q_rsm/preliminary_analysis/experiments/visual_pointmaze_medium_navigate_v0/results/2/td.json +124 -0
  12. gen_q_rsm/preliminary_analysis/experiments/visual_pointmaze_medium_navigate_v0/results/3/genq.json +122 -0
  13. gen_q_rsm/preliminary_analysis/experiments/visual_pointmaze_medium_navigate_v0/results/3/mc.json +124 -0
  14. gen_q_rsm/preliminary_analysis/experiments/visual_pointmaze_medium_navigate_v0/results/3/td.json +124 -0
  15. gen_q_rsm/preliminary_analysis/experiments/visual_pointmaze_medium_navigate_v0/results/4/genq.json +122 -0
  16. gen_q_rsm/preliminary_analysis/experiments/visual_pointmaze_medium_navigate_v0/results/4/mc.json +124 -0
  17. gen_q_rsm/preliminary_analysis/experiments/visual_pointmaze_medium_navigate_v0/results/4/td.json +124 -0
  18. gen_q_rsm/preliminary_analysis/experiments/visual_pointmaze_medium_navigate_v0/run_genq.py +87 -0
  19. gen_q_rsm/preliminary_analysis/experiments/visual_pointmaze_medium_navigate_v0/run_seq.sh +68 -0
  20. gen_q_rsm/preliminary_analysis/experiments/visual_puzzle_3x3_play_v0/NOTES.md +52 -0
  21. gen_q_rsm/preliminary_analysis/experiments/visual_puzzle_3x3_play_v0/figures/.gitkeep +0 -0
  22. gen_q_rsm/preliminary_analysis/experiments/visual_puzzle_3x3_play_v0/figures/corr.png +0 -0
  23. gen_q_rsm/preliminary_analysis/experiments/visual_puzzle_3x3_play_v0/figures/mse.png +0 -0
  24. gen_q_rsm/preliminary_analysis/experiments/visual_puzzle_3x3_play_v0/results/.gitkeep +0 -0
  25. gen_q_rsm/preliminary_analysis/experiments/visual_puzzle_3x3_play_v0/results/0/genq.json +121 -0
  26. gen_q_rsm/preliminary_analysis/experiments/visual_puzzle_3x3_play_v0/results/0/mc.json +123 -0
  27. gen_q_rsm/preliminary_analysis/experiments/visual_puzzle_3x3_play_v0/results/0/td.json +123 -0
  28. gen_q_rsm/preliminary_analysis/experiments/visual_puzzle_3x3_play_v0/results/1/genq.json +121 -0
  29. gen_q_rsm/preliminary_analysis/experiments/visual_puzzle_3x3_play_v0/results/1/mc.json +123 -0
  30. gen_q_rsm/preliminary_analysis/experiments/visual_puzzle_3x3_play_v0/results/1/td.json +123 -0
  31. gen_q_rsm/preliminary_analysis/experiments/visual_puzzle_3x3_play_v0/results/2/genq.json +121 -0
  32. gen_q_rsm/preliminary_analysis/experiments/visual_puzzle_3x3_play_v0/results/2/mc.json +123 -0
  33. gen_q_rsm/preliminary_analysis/experiments/visual_puzzle_3x3_play_v0/results/2/td.json +123 -0
  34. gen_q_rsm/preliminary_analysis/experiments/visual_puzzle_3x3_play_v0/results/3/genq.json +121 -0
  35. gen_q_rsm/preliminary_analysis/experiments/visual_puzzle_3x3_play_v0/results/3/mc.json +123 -0
  36. gen_q_rsm/preliminary_analysis/experiments/visual_puzzle_3x3_play_v0/results/3/td.json +123 -0
  37. gen_q_rsm/preliminary_analysis/experiments/visual_puzzle_3x3_play_v0/results/4/genq.json +121 -0
  38. gen_q_rsm/preliminary_analysis/experiments/visual_puzzle_3x3_play_v0/results/4/mc.json +123 -0
  39. gen_q_rsm/preliminary_analysis/experiments/visual_puzzle_3x3_play_v0/results/4/td.json +123 -0
  40. gen_q_rsm/preliminary_analysis/experiments/visual_puzzle_3x3_play_v0/run_seed.py +76 -0
  41. gen_q_rsm/preliminary_analysis/experiments/visual_puzzle_3x3_play_v0/run_seq.sh +66 -0
  42. gen_q_rsm/preliminary_analysis/gc_core.py +1612 -0
  43. gen_q_rsm/preliminary_analysis/genq.py +115 -0
  44. gen_q_rsm/preliminary_analysis/genq_reward_latent.py +202 -0
  45. gen_q_rsm/preliminary_analysis/genq_visual.py +450 -0
  46. gen_q_rsm/preliminary_analysis/genq_visual_cube.py +409 -0
  47. gen_q_rsm/preliminary_analysis/genq_visual_puzzle.py +439 -0
  48. gen_q_rsm/preliminary_analysis/illustration.py +112 -0
  49. gen_q_rsm/preliminary_analysis/mc.py +150 -0
  50. gen_q_rsm/preliminary_analysis/models.py +487 -0
.gitattributes CHANGED
@@ -72,3 +72,177 @@ gen_q_rsm/preliminary_analysis/experiments/antmaze_large_navigate_v0/figures/ill
72
  gen_q_rsm/preliminary_analysis/experiments/antmaze_medium_navigate_v0/figures/illustration.gif filter=lfs diff=lfs merge=lfs -text
73
  gen_q_rsm/preliminary_analysis/experiments/pointmaze_large_navigate_v0/figures/illustration.gif filter=lfs diff=lfs merge=lfs -text
74
  gen_q_rsm/preliminary_analysis/experiments/pointmaze_medium_navigate_v0/figures/illustration.gif filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  gen_q_rsm/preliminary_analysis/experiments/antmaze_medium_navigate_v0/figures/illustration.gif filter=lfs diff=lfs merge=lfs -text
73
  gen_q_rsm/preliminary_analysis/experiments/pointmaze_large_navigate_v0/figures/illustration.gif filter=lfs diff=lfs merge=lfs -text
74
  gen_q_rsm/preliminary_analysis/experiments/pointmaze_medium_navigate_v0/figures/illustration.gif filter=lfs diff=lfs merge=lfs -text
75
+ gen_q_rsm/rsm_libero/notes/action_contrast.pdf filter=lfs diff=lfs merge=lfs -text
76
+ gen_q_rsm/rsm_libero/notes/rsm_formula_comparison.pdf filter=lfs diff=lfs merge=lfs -text
77
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/pixdec/fidelity.png filter=lfs diff=lfs merge=lfs -text
78
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/pixdec/fidelity_mug_expert_suboptimal.png filter=lfs diff=lfs merge=lfs -text
79
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/pixdec/fidelity_mug_mgen.png filter=lfs diff=lfs merge=lfs -text
80
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/pixdec/fidelity_square_expert_play.png filter=lfs diff=lfs merge=lfs -text
81
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/pixdec/fidelity_square_expert_suboptimal.png filter=lfs diff=lfs merge=lfs -text
82
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/pixdec/fidelity_square_sub_20100.png filter=lfs diff=lfs merge=lfs -text
83
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/pixdec/fidelity_threading_expert_play.png filter=lfs diff=lfs merge=lfs -text
84
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/pixdec/fidelity_threading_mgen.png filter=lfs diff=lfs merge=lfs -text
85
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/pixdec/fidelity_two_piece_expert_play.png filter=lfs diff=lfs merge=lfs -text
86
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/pixdec/fidelity_two_piece_expert_play_tipping.png filter=lfs diff=lfs merge=lfs -text
87
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/pixdec/fidelity_two_piece_expert_suboptimal.png filter=lfs diff=lfs merge=lfs -text
88
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/pixdec/r84/fidelity_mug_expert_suboptimal.png filter=lfs diff=lfs merge=lfs -text
89
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/pixdec/r84/fidelity_mug_mgen.png filter=lfs diff=lfs merge=lfs -text
90
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/pixdec/r84/fidelity_square_expert_play.png filter=lfs diff=lfs merge=lfs -text
91
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/pixdec/r84/fidelity_square_expert_suboptimal.png filter=lfs diff=lfs merge=lfs -text
92
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/pixdec/r84/fidelity_square_sub_20100.png filter=lfs diff=lfs merge=lfs -text
93
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/pixdec/r84/fidelity_threading_expert_play.png filter=lfs diff=lfs merge=lfs -text
94
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/pixdec/r84/fidelity_threading_mgen.png filter=lfs diff=lfs merge=lfs -text
95
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/pixdec/r84/fidelity_two_piece_expert_play.png filter=lfs diff=lfs merge=lfs -text
96
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/pixdec/r84/fidelity_two_piece_expert_play_tipping.png filter=lfs diff=lfs merge=lfs -text
97
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/pixdec/r84/fidelity_two_piece_expert_suboptimal.png filter=lfs diff=lfs merge=lfs -text
98
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/real_proposal_curves.png filter=lfs diff=lfs merge=lfs -text
99
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/real_stages/end_stage1_combo.png filter=lfs diff=lfs merge=lfs -text
100
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/real_stages/end_stage1_global.png filter=lfs diff=lfs merge=lfs -text
101
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/real_stages/end_stage1_wrist.png filter=lfs diff=lfs merge=lfs -text
102
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/real_stages/end_stage2_combo.png filter=lfs diff=lfs merge=lfs -text
103
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/real_stages/end_stage2_global.png filter=lfs diff=lfs merge=lfs -text
104
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/real_stages/end_stage2_wrist.png filter=lfs diff=lfs merge=lfs -text
105
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/real_stages/end_stage3_combo.png filter=lfs diff=lfs merge=lfs -text
106
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/real_stages/end_stage3_wrist.png filter=lfs diff=lfs merge=lfs -text
107
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/real_stages/end_stage4_wrist.png filter=lfs diff=lfs merge=lfs -text
108
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/real_stages/end_stage5_combo.png filter=lfs diff=lfs merge=lfs -text
109
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/real_stages/end_stage5_wrist.png filter=lfs diff=lfs merge=lfs -text
110
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/real_stages/end_stage6_combo.png filter=lfs diff=lfs merge=lfs -text
111
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/real_stages/end_stage6_wrist.png filter=lfs diff=lfs merge=lfs -text
112
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/real_stages/pour_strip_ep148.png filter=lfs diff=lfs merge=lfs -text
113
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/real_stages/reward_strip_subopt.png filter=lfs diff=lfs merge=lfs -text
114
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/real_stages/reward_strip_success.png filter=lfs diff=lfs merge=lfs -text
115
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/real_stages/reward_timelines.png filter=lfs diff=lfs merge=lfs -text
116
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/real_stages/stage0_ep000_wrist_start.png filter=lfs diff=lfs merge=lfs -text
117
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/real_stages/stage0_ep001_wrist_start.png filter=lfs diff=lfs merge=lfs -text
118
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/real_stages/stage1_ep050_global_arrival.png filter=lfs diff=lfs merge=lfs -text
119
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/real_stages/stage1_ep050_wrist_arrival.png filter=lfs diff=lfs merge=lfs -text
120
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/real_stages/stage1_ep051_global_arrival.png filter=lfs diff=lfs merge=lfs -text
121
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/real_stages/stage1_ep051_wrist_arrival.png filter=lfs diff=lfs merge=lfs -text
122
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/real_stages/stage2_ep100_global_arrival.png filter=lfs diff=lfs merge=lfs -text
123
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/real_stages/stage2_ep100_wrist_arrival.png filter=lfs diff=lfs merge=lfs -text
124
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/real_stages/stage2_ep101_global_arrival.png filter=lfs diff=lfs merge=lfs -text
125
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/real_stages/stage2_ep101_wrist_arrival.png filter=lfs diff=lfs merge=lfs -text
126
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/real_stages/stage2_ep148_wrist_start.png filter=lfs diff=lfs merge=lfs -text
127
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/real_stages/stage3_ep050_wrist_arrival.png filter=lfs diff=lfs merge=lfs -text
128
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/real_stages/stage3_ep051_wrist_arrival.png filter=lfs diff=lfs merge=lfs -text
129
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/real_stages/stage4_ep148_wrist_arrival.png filter=lfs diff=lfs merge=lfs -text
130
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/real_stages/stage4_ep149_wrist_arrival.png filter=lfs diff=lfs merge=lfs -text
131
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/real_stages/stage5_ep000_wrist_arrival.png filter=lfs diff=lfs merge=lfs -text
132
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/real_stages/stage5_ep001_wrist_arrival.png filter=lfs diff=lfs merge=lfs -text
133
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/real_stages/stage6_ep198_wrist_arrival.png filter=lfs diff=lfs merge=lfs -text
134
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/real_stages/stage6_ep199_wrist_arrival.png filter=lfs diff=lfs merge=lfs -text
135
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/real_stages/stage_grid_global.png filter=lfs diff=lfs merge=lfs -text
136
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/real_stages/stage_grid_wrist.png filter=lfs diff=lfs merge=lfs -text
137
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/real_stages/story_grid_global.png filter=lfs diff=lfs merge=lfs -text
138
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/real_stages/story_start_combo.png filter=lfs diff=lfs merge=lfs -text
139
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/real_stages/success_final_grid.png filter=lfs diff=lfs merge=lfs -text
140
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/real_stitch/endpoints_hop4_A.png filter=lfs diff=lfs merge=lfs -text
141
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/real_stitch/endpoints_hop4_B.png filter=lfs diff=lfs merge=lfs -text
142
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/real_stitch/endpoints_hop4_C3.png filter=lfs diff=lfs merge=lfs -text
143
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/real_stitch/endpoints_hop4_v0lit.png filter=lfs diff=lfs merge=lfs -text
144
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitch_unseen/square_expert_play/unseen_square_expert_play_demo_181_t0135_L40best_b0.95_L8_N128_P16.png filter=lfs diff=lfs merge=lfs -text
145
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitch_unseen/square_expert_play/unseen_square_expert_play_demo_198_t0110_L40best_b0.95_L8_N128_P16.png filter=lfs diff=lfs merge=lfs -text
146
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitch_unseen/square_expert_play/unseen_square_expert_play_demo_54_t0122_L40best_b0.95_L8_N128_P16.png filter=lfs diff=lfs merge=lfs -text
147
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitch_unseen/square_sub_20100/unseen_square_sub_20100_demo_116_t0062_Mbest_b0.95_L8_N128_P16.png filter=lfs diff=lfs merge=lfs -text
148
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitch_unseen/square_sub_20100/unseen_square_sub_20100_demo_147_t0234_Mbest_b0.95_L8_N128_P16.png filter=lfs diff=lfs merge=lfs -text
149
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitch_unseen/square_sub_20100/unseen_square_sub_20100_demo_181_t0252_Mbest_b0.95_L8_N128_P16.png filter=lfs diff=lfs merge=lfs -text
150
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitch_unseen/two_piece_expert_play/unseen_two_piece_expert_play_demo_128_t0115_L40best_b0.95_L8_N128_P16.png filter=lfs diff=lfs merge=lfs -text
151
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitch_unseen/two_piece_expert_play/unseen_two_piece_expert_play_demo_18_t0096_L40best_b0.95_L8_N128_P16.png filter=lfs diff=lfs merge=lfs -text
152
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitch_unseen/two_piece_expert_play/unseen_two_piece_expert_play_demo_38_t0067_L40best_b0.95_L8_N128_P16.png filter=lfs diff=lfs merge=lfs -text
153
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitch_unseen/two_piece_expert_suboptimal/unseen_two_piece_expert_suboptimal_demo_1_t0070_Mproghead_b0.95_L8_N128_P16.png filter=lfs diff=lfs merge=lfs -text
154
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitch_unseen/two_piece_expert_suboptimal/unseen_two_piece_expert_suboptimal_demo_27_t0156_Mproghead_b0.95_L8_N128_P16.png filter=lfs diff=lfs merge=lfs -text
155
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitch_unseen/two_piece_expert_suboptimal/unseen_two_piece_expert_suboptimal_demo_5_t0159_Mproghead_b0.95_L8_N128_P16.png filter=lfs diff=lfs merge=lfs -text
156
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/square_expert_play/tree_square_expert_play_demo_102_t0145_L40best_b0.95_L8_N128_P16.png filter=lfs diff=lfs merge=lfs -text
157
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/square_expert_play/tree_square_expert_play_demo_102_t0145_L40best_b0.95_L8_N128_P16_dec.png filter=lfs diff=lfs merge=lfs -text
158
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/square_expert_play/tree_square_expert_play_demo_102_t0145_L40best_b0.95_L8_N128_P16_dec256.png filter=lfs diff=lfs merge=lfs -text
159
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/square_expert_play/tree_square_expert_play_demo_102_t0145_L40best_b0.95_L8_N128_P16_r256.png filter=lfs diff=lfs merge=lfs -text
160
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/square_expert_play/tree_square_expert_play_demo_110_t0104_L40best_b0.95_L8_N128_P16.png filter=lfs diff=lfs merge=lfs -text
161
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/square_expert_play/tree_square_expert_play_demo_110_t0104_L40best_b0.95_L8_N128_P16_dec.png filter=lfs diff=lfs merge=lfs -text
162
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/square_expert_play/tree_square_expert_play_demo_110_t0104_L40best_b0.95_L8_N128_P16_dec256.png filter=lfs diff=lfs merge=lfs -text
163
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/square_expert_play/tree_square_expert_play_demo_110_t0104_L40best_b0.95_L8_N128_P16_r256.png filter=lfs diff=lfs merge=lfs -text
164
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/square_expert_play/tree_square_expert_play_demo_160_t0165_L40best_b0.95_L8_N128_P16.png filter=lfs diff=lfs merge=lfs -text
165
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/square_expert_play/tree_square_expert_play_demo_160_t0165_L40best_b0.95_L8_N128_P16_dec.png filter=lfs diff=lfs merge=lfs -text
166
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/square_expert_play/tree_square_expert_play_demo_160_t0165_L40best_b0.95_L8_N128_P16_dec256.png filter=lfs diff=lfs merge=lfs -text
167
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/square_expert_play/tree_square_expert_play_demo_160_t0165_L40best_b0.95_L8_N128_P16_r256.png filter=lfs diff=lfs merge=lfs -text
168
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/square_expert_play/tree_square_expert_play_demo_172_t0038_L40best_b0.95_L8_N128_P16_split2b256.png filter=lfs diff=lfs merge=lfs -text
169
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/square_expert_play/tree_square_expert_play_demo_181_t0135_L40best_b0.95_L8_N128_P16_split256.png filter=lfs diff=lfs merge=lfs -text
170
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/square_expert_play/tree_square_expert_play_demo_181_t0135_L40best_b0.95_L8_N128_P16_split2b256.png filter=lfs diff=lfs merge=lfs -text
171
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/square_expert_play/tree_square_expert_play_demo_221_t0249_L40best_b0.95_L8_N128_P16.png filter=lfs diff=lfs merge=lfs -text
172
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/square_expert_play/tree_square_expert_play_demo_221_t0249_L40best_b0.95_L8_N128_P16_dec.png filter=lfs diff=lfs merge=lfs -text
173
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/square_expert_play/tree_square_expert_play_demo_221_t0249_L40best_b0.95_L8_N128_P16_dec256.png filter=lfs diff=lfs merge=lfs -text
174
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/square_expert_play/tree_square_expert_play_demo_221_t0249_L40best_b0.95_L8_N128_P16_r256.png filter=lfs diff=lfs merge=lfs -text
175
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/square_expert_play/tree_square_expert_play_demo_36_t0056_L40best_b0.95_L8_N128_P16.png filter=lfs diff=lfs merge=lfs -text
176
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/square_expert_play/tree_square_expert_play_demo_36_t0056_L40best_b0.95_L8_N128_P16_dec.png filter=lfs diff=lfs merge=lfs -text
177
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/square_expert_play/tree_square_expert_play_demo_36_t0056_L40best_b0.95_L8_N128_P16_dec256.png filter=lfs diff=lfs merge=lfs -text
178
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/square_expert_play/tree_square_expert_play_demo_36_t0056_L40best_b0.95_L8_N128_P16_r256.png filter=lfs diff=lfs merge=lfs -text
179
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/square_expert_play/tree_square_expert_play_demo_36_t0056_L40best_b0.95_L8_N128_P16_split2b256.png filter=lfs diff=lfs merge=lfs -text
180
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/square_expert_play/tree_square_expert_play_demo_84_t0390_L40best_b0.95_L8_N128_P16.png filter=lfs diff=lfs merge=lfs -text
181
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/square_expert_play/tree_square_expert_play_demo_84_t0390_L40best_b0.95_L8_N128_P16_dec.png filter=lfs diff=lfs merge=lfs -text
182
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/square_expert_play/tree_square_expert_play_demo_84_t0390_L40best_b0.95_L8_N128_P16_dec256.png filter=lfs diff=lfs merge=lfs -text
183
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/square_expert_play/tree_square_expert_play_demo_84_t0390_L40best_b0.95_L8_N128_P16_r256.png filter=lfs diff=lfs merge=lfs -text
184
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/two_piece_expert_play/tree_two_piece_expert_play_demo_102_t0198_L40best_b0.95_L8_N128_P16.png filter=lfs diff=lfs merge=lfs -text
185
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/two_piece_expert_play/tree_two_piece_expert_play_demo_102_t0198_L40best_b0.95_L8_N128_P16_dec.png filter=lfs diff=lfs merge=lfs -text
186
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/two_piece_expert_play/tree_two_piece_expert_play_demo_102_t0198_L40best_b0.95_L8_N128_P16_dec256.png filter=lfs diff=lfs merge=lfs -text
187
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/two_piece_expert_play/tree_two_piece_expert_play_demo_102_t0198_L40best_b0.95_L8_N128_P16_r256.png filter=lfs diff=lfs merge=lfs -text
188
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/two_piece_expert_play/tree_two_piece_expert_play_demo_106_t0035_L40best_b0.95_L8_N128_P16.png filter=lfs diff=lfs merge=lfs -text
189
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/two_piece_expert_play/tree_two_piece_expert_play_demo_106_t0035_L40best_b0.95_L8_N128_P16_dec.png filter=lfs diff=lfs merge=lfs -text
190
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/two_piece_expert_play/tree_two_piece_expert_play_demo_106_t0035_L40best_b0.95_L8_N128_P16_dec256.png filter=lfs diff=lfs merge=lfs -text
191
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/two_piece_expert_play/tree_two_piece_expert_play_demo_106_t0035_L40best_b0.95_L8_N128_P16_r256.png filter=lfs diff=lfs merge=lfs -text
192
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/two_piece_expert_play/tree_two_piece_expert_play_demo_129_t0084_L40best_b0.95_L8_N128_P16.png filter=lfs diff=lfs merge=lfs -text
193
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/two_piece_expert_play/tree_two_piece_expert_play_demo_129_t0084_L40best_b0.95_L8_N128_P16_dec.png filter=lfs diff=lfs merge=lfs -text
194
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/two_piece_expert_play/tree_two_piece_expert_play_demo_129_t0084_L40best_b0.95_L8_N128_P16_dec256.png filter=lfs diff=lfs merge=lfs -text
195
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/two_piece_expert_play/tree_two_piece_expert_play_demo_129_t0084_L40best_b0.95_L8_N128_P16_r256.png filter=lfs diff=lfs merge=lfs -text
196
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/two_piece_expert_play/tree_two_piece_expert_play_demo_136_t0154_L40best_b0.95_L8_N128_P16_split256.png filter=lfs diff=lfs merge=lfs -text
197
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/two_piece_expert_play/tree_two_piece_expert_play_demo_143_t0154_L40best_b0.95_L8_N128_P16.png filter=lfs diff=lfs merge=lfs -text
198
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/two_piece_expert_play/tree_two_piece_expert_play_demo_143_t0154_L40best_b0.95_L8_N128_P16_dec.png filter=lfs diff=lfs merge=lfs -text
199
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/two_piece_expert_play/tree_two_piece_expert_play_demo_143_t0154_L40best_b0.95_L8_N128_P16_dec256.png filter=lfs diff=lfs merge=lfs -text
200
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/two_piece_expert_play/tree_two_piece_expert_play_demo_143_t0154_L40best_b0.95_L8_N128_P16_r256.png filter=lfs diff=lfs merge=lfs -text
201
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/two_piece_expert_play/tree_two_piece_expert_play_demo_153_t0112_L40best_b0.95_L8_N128_P16_split2b256.png filter=lfs diff=lfs merge=lfs -text
202
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/two_piece_expert_play/tree_two_piece_expert_play_demo_171_t0244_L40best_b0.95_L8_N128_P16.png filter=lfs diff=lfs merge=lfs -text
203
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/two_piece_expert_play/tree_two_piece_expert_play_demo_171_t0244_L40best_b0.95_L8_N128_P16_dec.png filter=lfs diff=lfs merge=lfs -text
204
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/two_piece_expert_play/tree_two_piece_expert_play_demo_171_t0244_L40best_b0.95_L8_N128_P16_dec256.png filter=lfs diff=lfs merge=lfs -text
205
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/two_piece_expert_play/tree_two_piece_expert_play_demo_171_t0244_L40best_b0.95_L8_N128_P16_r256.png filter=lfs diff=lfs merge=lfs -text
206
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/two_piece_expert_play/tree_two_piece_expert_play_demo_18_t0096_L40best_b0.95_L8_N128_P16_split256.png filter=lfs diff=lfs merge=lfs -text
207
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/two_piece_expert_play/tree_two_piece_expert_play_demo_198_t0166_L40best_b0.95_L8_N128_P16_split2b256.png filter=lfs diff=lfs merge=lfs -text
208
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/two_piece_expert_play/tree_two_piece_expert_play_demo_64_t0192_L40best_b0.95_L8_N128_P16_split2b256.png filter=lfs diff=lfs merge=lfs -text
209
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/two_piece_expert_play/tree_two_piece_expert_play_demo_6_t0180_L40best_b0.95_L8_N128_P16_split2b256.png filter=lfs diff=lfs merge=lfs -text
210
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/two_piece_expert_play/tree_two_piece_expert_play_demo_80_t0025_L40best_b0.95_L8_N128_P16_split2b256.png filter=lfs diff=lfs merge=lfs -text
211
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/two_piece_expert_play/tree_two_piece_expert_play_demo_99_t0057_L40best_b0.95_L8_N128_P16.png filter=lfs diff=lfs merge=lfs -text
212
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/two_piece_expert_play/tree_two_piece_expert_play_demo_99_t0057_L40best_b0.95_L8_N128_P16_dec.png filter=lfs diff=lfs merge=lfs -text
213
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/two_piece_expert_play/tree_two_piece_expert_play_demo_99_t0057_L40best_b0.95_L8_N128_P16_dec256.png filter=lfs diff=lfs merge=lfs -text
214
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/two_piece_expert_play/tree_two_piece_expert_play_demo_99_t0057_L40best_b0.95_L8_N128_P16_r256.png filter=lfs diff=lfs merge=lfs -text
215
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/two_piece_expert_play_tipping/tree_two_piece_expert_play_tipping_demo_209_t0155_Mbest_b0.95_L8_N128_P16_dec256.png filter=lfs diff=lfs merge=lfs -text
216
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/two_piece_expert_play_tipping/tree_two_piece_expert_play_tipping_demo_239_t0258_Mbest_b0.95_L8_N128_P16_dec256.png filter=lfs diff=lfs merge=lfs -text
217
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/two_piece_expert_play_tipping/tree_two_piece_expert_play_tipping_demo_433_t0082_Mbest_b0.95_L8_N128_P16_dec256.png filter=lfs diff=lfs merge=lfs -text
218
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/two_piece_expert_play_tipping/tree_two_piece_expert_play_tipping_demo_459_t0032_Mbest_b0.95_L8_N128_P16_dec256.png filter=lfs diff=lfs merge=lfs -text
219
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/two_piece_expert_play_tipping/tree_two_piece_expert_play_tipping_demo_510_t0054_Mbest_b0.95_L8_N128_P16_dec256.png filter=lfs diff=lfs merge=lfs -text
220
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching/two_piece_expert_play_tipping/tree_two_piece_expert_play_tipping_demo_695_t0099_Mbest_b0.95_L8_N128_P16_dec256.png filter=lfs diff=lfs merge=lfs -text
221
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching_chain/square_expert_play/tree_square_expert_play_demo_102_t0145_L40best_b0.95_L34_N128_P16_dec256.png filter=lfs diff=lfs merge=lfs -text
222
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching_chain/square_expert_play/tree_square_expert_play_demo_110_t0104_L40best_b0.95_L34_N128_P16_dec256.png filter=lfs diff=lfs merge=lfs -text
223
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching_chain/square_expert_play/tree_square_expert_play_demo_160_t0165_L40best_b0.95_L34_N128_P16_dec256.png filter=lfs diff=lfs merge=lfs -text
224
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching_chain/square_expert_play/tree_square_expert_play_demo_221_t0249_L40best_b0.95_L34_N128_P16_dec256.png filter=lfs diff=lfs merge=lfs -text
225
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching_chain/square_expert_play/tree_square_expert_play_demo_36_t0056_L40best_b0.95_L34_N128_P16_dec256.png filter=lfs diff=lfs merge=lfs -text
226
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching_chain/square_expert_play/tree_square_expert_play_demo_84_t0390_L40best_b0.95_L34_N128_P16_dec256.png filter=lfs diff=lfs merge=lfs -text
227
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching_chain/two_piece_expert_play/tree_two_piece_expert_play_demo_102_t0198_L40best_b0.95_L34_N128_P16_dec256.png filter=lfs diff=lfs merge=lfs -text
228
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching_chain/two_piece_expert_play/tree_two_piece_expert_play_demo_106_t0035_L40best_b0.95_L34_N128_P16_dec256.png filter=lfs diff=lfs merge=lfs -text
229
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching_chain/two_piece_expert_play/tree_two_piece_expert_play_demo_129_t0084_L40best_b0.95_L34_N128_P16_dec256.png filter=lfs diff=lfs merge=lfs -text
230
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching_chain/two_piece_expert_play/tree_two_piece_expert_play_demo_143_t0154_L40best_b0.95_L34_N128_P16_dec256.png filter=lfs diff=lfs merge=lfs -text
231
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching_chain/two_piece_expert_play/tree_two_piece_expert_play_demo_171_t0244_L40best_b0.95_L34_N128_P16_dec256.png filter=lfs diff=lfs merge=lfs -text
232
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching_chain/two_piece_expert_play/tree_two_piece_expert_play_demo_99_t0057_L40best_b0.95_L34_N128_P16_dec256.png filter=lfs diff=lfs merge=lfs -text
233
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching_chain/two_piece_expert_play_tipping/tree_two_piece_expert_play_tipping_demo_209_t0155_Mbest_b0.95_L34_N128_P16_dec256.png filter=lfs diff=lfs merge=lfs -text
234
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching_chain/two_piece_expert_play_tipping/tree_two_piece_expert_play_tipping_demo_209_t0155_Mbest_b0.95_L34_N128_P16_foldsame.png filter=lfs diff=lfs merge=lfs -text
235
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching_chain/two_piece_expert_play_tipping/tree_two_piece_expert_play_tipping_demo_239_t0258_Mbest_b0.95_L34_N128_P16_dec256.png filter=lfs diff=lfs merge=lfs -text
236
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching_chain/two_piece_expert_play_tipping/tree_two_piece_expert_play_tipping_demo_239_t0258_Mbest_b0.95_L34_N128_P16_foldsame.png filter=lfs diff=lfs merge=lfs -text
237
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching_chain/two_piece_expert_play_tipping/tree_two_piece_expert_play_tipping_demo_433_t0082_Mbest_b0.95_L34_N128_P16_dec256.png filter=lfs diff=lfs merge=lfs -text
238
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching_chain/two_piece_expert_play_tipping/tree_two_piece_expert_play_tipping_demo_433_t0082_Mbest_b0.95_L34_N128_P16_foldsame.png filter=lfs diff=lfs merge=lfs -text
239
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching_chain/two_piece_expert_play_tipping/tree_two_piece_expert_play_tipping_demo_459_t0032_Mbest_b0.95_L34_N128_P16_dec256.png filter=lfs diff=lfs merge=lfs -text
240
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching_chain/two_piece_expert_play_tipping/tree_two_piece_expert_play_tipping_demo_459_t0032_Mbest_b0.95_L34_N128_P16_foldsame.png filter=lfs diff=lfs merge=lfs -text
241
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching_chain/two_piece_expert_play_tipping/tree_two_piece_expert_play_tipping_demo_510_t0054_Mbest_b0.95_L34_N128_P16_dec256.png filter=lfs diff=lfs merge=lfs -text
242
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching_chain/two_piece_expert_play_tipping/tree_two_piece_expert_play_tipping_demo_510_t0054_Mbest_b0.95_L34_N128_P16_foldsame.png filter=lfs diff=lfs merge=lfs -text
243
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching_chain/two_piece_expert_play_tipping/tree_two_piece_expert_play_tipping_demo_695_t0099_Mbest_b0.95_L34_N128_P16_dec256.png filter=lfs diff=lfs merge=lfs -text
244
+ gen_q_rsm/rsm_rise/pipeline/docs/figs/stitching_chain/two_piece_expert_play_tipping/tree_two_piece_expert_play_tipping_demo_695_t0099_Mbest_b0.95_L34_N128_P16_foldsame.png filter=lfs diff=lfs merge=lfs -text
245
+ gen_q_rsm/rsm_rise/pipeline/docs/real_proposal_report.pdf filter=lfs diff=lfs merge=lfs -text
246
+ gen_q_rsm/rsm_rise/pipeline/docs/real_reward_study.pdf filter=lfs diff=lfs merge=lfs -text
247
+ gen_q_rsm/rsm_rise/pipeline/docs/tex/flagship_paper.pdf filter=lfs diff=lfs merge=lfs -text
248
+ gen_q_rsm/rsm_rise/pipeline/docs/tex/flagship_tables_latest.pdf filter=lfs diff=lfs merge=lfs -text
gen_q_rsm/preliminary_analysis/experiments/visual_pointmaze_medium_navigate_v0/figures/mse.png ADDED
gen_q_rsm/preliminary_analysis/experiments/visual_pointmaze_medium_navigate_v0/results/0/genq.json ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "method": "genq_reward_latent",
3
+ "env": "visual-pointmaze-medium-navigate-v0",
4
+ "seed": 0,
5
+ "wandb_url": null,
6
+ "representation": "image_reward_predictive_latent",
7
+ "occ_model": "diffusion",
8
+ "z_dim": 8,
9
+ "reward": "dense",
10
+ "truth_kind": "fresh_rollout",
11
+ "gen_sample_counts": [
12
+ 1,
13
+ 2,
14
+ 4,
15
+ 8,
16
+ 16,
17
+ 32,
18
+ 64,
19
+ 128,
20
+ 256
21
+ ],
22
+ "train/loss": [
23
+ 1.023522973060608,
24
+ 0.19105927646160126,
25
+ 0.1606016755104065,
26
+ 0.18757879734039307,
27
+ 0.18000784516334534,
28
+ 0.13725411891937256,
29
+ 0.14592890441417694,
30
+ 0.14458250999450684,
31
+ 0.13206292688846588,
32
+ 0.13802334666252136,
33
+ 0.1301162838935852,
34
+ 0.16003751754760742,
35
+ 0.1559370756149292,
36
+ 0.13223066926002502,
37
+ 0.15051677823066711,
38
+ 0.12414824962615967,
39
+ 0.14838171005249023,
40
+ 0.1357429176568985,
41
+ 0.12985064089298248,
42
+ 0.13411641120910645,
43
+ 0.13461871445178986,
44
+ 0.1175081878900528,
45
+ 0.15497374534606934,
46
+ 0.1391388177871704,
47
+ 0.12791691720485687,
48
+ 0.14376839995384216,
49
+ 0.12200479209423065,
50
+ 0.1354222595691681,
51
+ 0.12789097428321838,
52
+ 0.1462569534778595,
53
+ 0.11730469018220901,
54
+ 0.13860100507736206,
55
+ 0.12506838142871857,
56
+ 0.14251679182052612,
57
+ 0.15122273564338684,
58
+ 0.12967534363269806,
59
+ 0.11680444329977036,
60
+ 0.13652893900871277,
61
+ 0.11743645370006561,
62
+ 0.12052425742149353,
63
+ 0.12437745928764343,
64
+ 0.13077199459075928,
65
+ 0.11803334951400757,
66
+ 0.14000144600868225,
67
+ 0.12209025770425797,
68
+ 0.13256481289863586,
69
+ 0.11510388553142548,
70
+ 0.11319650709629059,
71
+ 0.13896140456199646,
72
+ 0.13421301543712616,
73
+ 0.1303102672100067
74
+ ],
75
+ "train/q_mse": [
76
+ 0.02418842547168858
77
+ ],
78
+ "latent/reward_mse": 0.0004603317065630108,
79
+ "eval/q_mse": 0.02418842547168858,
80
+ "eval/q_mae": 0.11661465483356177,
81
+ "eval/q_corr": 0.7688938001942438,
82
+ "eval/q_spearman": 0.7925993287458046,
83
+ "eval/q_mse_by_n": {
84
+ "1": 0.10427708295616979,
85
+ "2": 0.05951837038308591,
86
+ "4": 0.042929799724609516,
87
+ "8": 0.03615196083966341,
88
+ "16": 0.027244554452114746,
89
+ "32": 0.026974146359083698,
90
+ "64": 0.02428700414242801,
91
+ "128": 0.024489868299928785,
92
+ "256": 0.024278866972587534
93
+ },
94
+ "eval/q_corr_by_n": {
95
+ "1": 0.4259941946101464,
96
+ "2": 0.5729064749947367,
97
+ "4": 0.653214372303005,
98
+ "8": 0.6969564579575995,
99
+ "16": 0.7326162891774732,
100
+ "32": 0.7516596854054147,
101
+ "64": 0.7608004812015723,
102
+ "128": 0.7657684814654997,
103
+ "256": 0.7693020782172023
104
+ },
105
+ "eval/q_mse_vs_N": [
106
+ 0.10427708295616979,
107
+ 0.05951837038308591,
108
+ 0.042929799724609516,
109
+ 0.03615196083966341,
110
+ 0.027244554452114746,
111
+ 0.026974146359083698,
112
+ 0.02428700414242801,
113
+ 0.024489868299928785,
114
+ 0.024278866972587534
115
+ ],
116
+ "eval/N_final": 256,
117
+ "eval/truth_std": 0.17342706411927783,
118
+ "wall_clock_s": 211.27295351028442,
119
+ "n_anchors": 400,
120
+ "anchor_protocol": "dataset_anchor",
121
+ "dataset_note": "self_rendered_from_state_pointmaze (no OGBench visual-pointmaze exists)"
122
+ }
gen_q_rsm/preliminary_analysis/experiments/visual_pointmaze_medium_navigate_v0/results/0/mc.json ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "method": "mc",
3
+ "env": "visual-pointmaze-medium-navigate-v0",
4
+ "seed": 0,
5
+ "wandb_url": null,
6
+ "representation": "ant_state_29d",
7
+ "reward": "dense",
8
+ "truth_kind": "fresh_rollout",
9
+ "train/loss": [
10
+ 0.300428181886673,
11
+ 0.02267445996403694,
12
+ 0.0215071402490139,
13
+ 0.02142311818897724,
14
+ 0.028002843260765076,
15
+ 0.020109882578253746,
16
+ 0.020046889781951904,
17
+ 0.02153805084526539,
18
+ 0.018007999286055565,
19
+ 0.01716446503996849,
20
+ 0.01681779883801937,
21
+ 0.017358364537358284,
22
+ 0.02150731161236763,
23
+ 0.018860554322600365,
24
+ 0.020630372688174248,
25
+ 0.01959878019988537,
26
+ 0.018222834914922714,
27
+ 0.017338993027806282,
28
+ 0.01767083629965782,
29
+ 0.01721610687673092,
30
+ 0.016842637211084366,
31
+ 0.01914386823773384,
32
+ 0.015379784628748894,
33
+ 0.01741034723818302,
34
+ 0.018324950709939003,
35
+ 0.015394306741654873,
36
+ 0.01669416017830372,
37
+ 0.01766800507903099,
38
+ 0.01653364673256874,
39
+ 0.015180330723524094,
40
+ 0.015547486953437328,
41
+ 0.013367079198360443,
42
+ 0.015776604413986206,
43
+ 0.015588213689625263,
44
+ 0.014996509999036789,
45
+ 0.015366061590611935,
46
+ 0.01568116620182991,
47
+ 0.015002715401351452,
48
+ 0.016817599534988403,
49
+ 0.018457632511854172,
50
+ 0.013548828661441803,
51
+ 0.015665411949157715,
52
+ 0.013671178370714188,
53
+ 0.016047248616814613,
54
+ 0.01627308875322342,
55
+ 0.013607887551188469,
56
+ 0.017151955515146255,
57
+ 0.015409056097269058,
58
+ 0.01558898389339447,
59
+ 0.012062326073646545,
60
+ 0.015025422908365726
61
+ ],
62
+ "train/q_mse": [
63
+ 0.300428181886673,
64
+ 0.02267445996403694,
65
+ 0.0215071402490139,
66
+ 0.02142311818897724,
67
+ 0.028002843260765076,
68
+ 0.020109882578253746,
69
+ 0.020046889781951904,
70
+ 0.02153805084526539,
71
+ 0.018007999286055565,
72
+ 0.01716446503996849,
73
+ 0.01681779883801937,
74
+ 0.017358364537358284,
75
+ 0.02150731161236763,
76
+ 0.018860554322600365,
77
+ 0.020630372688174248,
78
+ 0.01959878019988537,
79
+ 0.018222834914922714,
80
+ 0.017338993027806282,
81
+ 0.01767083629965782,
82
+ 0.01721610687673092,
83
+ 0.016842637211084366,
84
+ 0.01914386823773384,
85
+ 0.015379784628748894,
86
+ 0.01741034723818302,
87
+ 0.018324950709939003,
88
+ 0.015394306741654873,
89
+ 0.01669416017830372,
90
+ 0.01766800507903099,
91
+ 0.01653364673256874,
92
+ 0.015180330723524094,
93
+ 0.015547486953437328,
94
+ 0.013367079198360443,
95
+ 0.015776604413986206,
96
+ 0.015588213689625263,
97
+ 0.014996509999036789,
98
+ 0.015366061590611935,
99
+ 0.01568116620182991,
100
+ 0.015002715401351452,
101
+ 0.016817599534988403,
102
+ 0.018457632511854172,
103
+ 0.013548828661441803,
104
+ 0.015665411949157715,
105
+ 0.013671178370714188,
106
+ 0.016047248616814613,
107
+ 0.01627308875322342,
108
+ 0.013607887551188469,
109
+ 0.017151955515146255,
110
+ 0.015409056097269058,
111
+ 0.01558898389339447,
112
+ 0.012062326073646545,
113
+ 0.015025422908365726
114
+ ],
115
+ "eval/q_mse": 0.02082740504568421,
116
+ "eval/q_mae": 0.09879234870651768,
117
+ "eval/q_corr": 0.8353318666663025,
118
+ "eval/q_spearman": 0.8860669754185964,
119
+ "eval/truth_std": 0.17342706411927783,
120
+ "wall_clock_s": 51.000584840774536,
121
+ "n_anchors": 400,
122
+ "anchor_protocol": "dataset_anchor",
123
+ "dataset_note": "self_rendered_from_state_pointmaze (no OGBench visual-pointmaze exists)"
124
+ }
gen_q_rsm/preliminary_analysis/experiments/visual_pointmaze_medium_navigate_v0/results/0/td.json ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "method": "td",
3
+ "env": "visual-pointmaze-medium-navigate-v0",
4
+ "seed": 0,
5
+ "wandb_url": null,
6
+ "representation": "ant_state_29d",
7
+ "reward": "dense",
8
+ "truth_kind": "fresh_rollout",
9
+ "train/loss": [
10
+ 0.12668415904045105,
11
+ 1.8332171748625115e-05,
12
+ 1.2668673662119545e-05,
13
+ 5.6685854360694066e-05,
14
+ 2.666049294930417e-05,
15
+ 0.00012213226000312716,
16
+ 1.2408975635480601e-05,
17
+ 7.281507714651525e-05,
18
+ 1.4251440006773919e-05,
19
+ 2.8672966436715797e-05,
20
+ 1.9756591427722014e-05,
21
+ 1.800885183911305e-05,
22
+ 2.9631743018398993e-05,
23
+ 2.119257078447845e-05,
24
+ 2.3705892090220004e-05,
25
+ 3.014030517078936e-05,
26
+ 5.9920595958828926e-05,
27
+ 3.7254212656989694e-05,
28
+ 0.0001071523511200212,
29
+ 5.2011237130500376e-05,
30
+ 3.0067789339227602e-05,
31
+ 1.841087214415893e-05,
32
+ 3.670252408483066e-05,
33
+ 3.926284261979163e-05,
34
+ 3.8311438402161e-05,
35
+ 6.802458665333688e-05,
36
+ 7.342189201153815e-05,
37
+ 0.0001920453505590558,
38
+ 4.1177685488946736e-05,
39
+ 4.1980551031883806e-05,
40
+ 0.00010299332643626258,
41
+ 4.048525806865655e-05,
42
+ 0.00014721110346727073,
43
+ 4.002904461231083e-05,
44
+ 0.00011492889461806044,
45
+ 5.7826000556815416e-05,
46
+ 5.0739210564643145e-05,
47
+ 2.990572465932928e-05,
48
+ 6.57828277326189e-05,
49
+ 4.4449054257711396e-05,
50
+ 9.90485496004112e-05,
51
+ 6.106894579716027e-05,
52
+ 3.74849587387871e-05,
53
+ 4.809353413293138e-05,
54
+ 8.4279352449812e-05,
55
+ 9.354538633488119e-05,
56
+ 3.541153637343086e-05,
57
+ 4.724852624349296e-05,
58
+ 3.650022699730471e-05,
59
+ 6.568254320882261e-05,
60
+ 6.494991248473525e-05
61
+ ],
62
+ "train/q_mse": [
63
+ 0.12668415904045105,
64
+ 1.8332171748625115e-05,
65
+ 1.2668673662119545e-05,
66
+ 5.6685854360694066e-05,
67
+ 2.666049294930417e-05,
68
+ 0.00012213226000312716,
69
+ 1.2408975635480601e-05,
70
+ 7.281507714651525e-05,
71
+ 1.4251440006773919e-05,
72
+ 2.8672966436715797e-05,
73
+ 1.9756591427722014e-05,
74
+ 1.800885183911305e-05,
75
+ 2.9631743018398993e-05,
76
+ 2.119257078447845e-05,
77
+ 2.3705892090220004e-05,
78
+ 3.014030517078936e-05,
79
+ 5.9920595958828926e-05,
80
+ 3.7254212656989694e-05,
81
+ 0.0001071523511200212,
82
+ 5.2011237130500376e-05,
83
+ 3.0067789339227602e-05,
84
+ 1.841087214415893e-05,
85
+ 3.670252408483066e-05,
86
+ 3.926284261979163e-05,
87
+ 3.8311438402161e-05,
88
+ 6.802458665333688e-05,
89
+ 7.342189201153815e-05,
90
+ 0.0001920453505590558,
91
+ 4.1177685488946736e-05,
92
+ 4.1980551031883806e-05,
93
+ 0.00010299332643626258,
94
+ 4.048525806865655e-05,
95
+ 0.00014721110346727073,
96
+ 4.002904461231083e-05,
97
+ 0.00011492889461806044,
98
+ 5.7826000556815416e-05,
99
+ 5.0739210564643145e-05,
100
+ 2.990572465932928e-05,
101
+ 6.57828277326189e-05,
102
+ 4.4449054257711396e-05,
103
+ 9.90485496004112e-05,
104
+ 6.106894579716027e-05,
105
+ 3.74849587387871e-05,
106
+ 4.809353413293138e-05,
107
+ 8.4279352449812e-05,
108
+ 9.354538633488119e-05,
109
+ 3.541153637343086e-05,
110
+ 4.724852624349296e-05,
111
+ 3.650022699730471e-05,
112
+ 6.568254320882261e-05,
113
+ 6.494991248473525e-05
114
+ ],
115
+ "eval/q_mse": 0.047415442621615254,
116
+ "eval/q_mae": 0.17140060018722703,
117
+ "eval/q_corr": 0.6945215405391422,
118
+ "eval/q_spearman": 0.7104207526297038,
119
+ "eval/truth_std": 0.17342706411927783,
120
+ "wall_clock_s": 128.8499734401703,
121
+ "n_anchors": 400,
122
+ "anchor_protocol": "dataset_anchor",
123
+ "dataset_note": "self_rendered_from_state_pointmaze (no OGBench visual-pointmaze exists)"
124
+ }
gen_q_rsm/preliminary_analysis/experiments/visual_pointmaze_medium_navigate_v0/results/1/genq.json ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "method": "genq_reward_latent",
3
+ "env": "visual-pointmaze-medium-navigate-v0",
4
+ "seed": 1,
5
+ "wandb_url": null,
6
+ "representation": "image_reward_predictive_latent",
7
+ "occ_model": "diffusion",
8
+ "z_dim": 8,
9
+ "reward": "dense",
10
+ "truth_kind": "fresh_rollout",
11
+ "gen_sample_counts": [
12
+ 1,
13
+ 2,
14
+ 4,
15
+ 8,
16
+ 16,
17
+ 32,
18
+ 64,
19
+ 128,
20
+ 256
21
+ ],
22
+ "train/loss": [
23
+ 0.9809990525245667,
24
+ 0.17933084070682526,
25
+ 0.16511279344558716,
26
+ 0.1322927176952362,
27
+ 0.1478947550058365,
28
+ 0.13946112990379333,
29
+ 0.15920886397361755,
30
+ 0.14355158805847168,
31
+ 0.12853004038333893,
32
+ 0.12848305702209473,
33
+ 0.1428503841161728,
34
+ 0.13594722747802734,
35
+ 0.12514980137348175,
36
+ 0.12934759259223938,
37
+ 0.14530916512012482,
38
+ 0.1301221251487732,
39
+ 0.13413327932357788,
40
+ 0.1347767412662506,
41
+ 0.1427159607410431,
42
+ 0.13929331302642822,
43
+ 0.14646552503108978,
44
+ 0.1483486294746399,
45
+ 0.15737994015216827,
46
+ 0.1122862696647644,
47
+ 0.11022555083036423,
48
+ 0.10935921221971512,
49
+ 0.1225469708442688,
50
+ 0.13203954696655273,
51
+ 0.13515713810920715,
52
+ 0.11667963862419128,
53
+ 0.11377006769180298,
54
+ 0.13136602938175201,
55
+ 0.12783783674240112,
56
+ 0.12338382005691528,
57
+ 0.12003913521766663,
58
+ 0.10868240147829056,
59
+ 0.11822055280208588,
60
+ 0.12240321189165115,
61
+ 0.1288052499294281,
62
+ 0.13882607221603394,
63
+ 0.124045729637146,
64
+ 0.14778918027877808,
65
+ 0.12555858492851257,
66
+ 0.10658851265907288,
67
+ 0.11684204638004303,
68
+ 0.11461761593818665,
69
+ 0.12805622816085815,
70
+ 0.11907884478569031,
71
+ 0.1175164133310318,
72
+ 0.12526899576187134,
73
+ 0.12224960327148438
74
+ ],
75
+ "train/q_mse": [
76
+ 0.034146342858883016
77
+ ],
78
+ "latent/reward_mse": 0.00025965768145397305,
79
+ "eval/q_mse": 0.034146342858883016,
80
+ "eval/q_mae": 0.14120046044467233,
81
+ "eval/q_corr": 0.841380566438283,
82
+ "eval/q_spearman": 0.8576217351358445,
83
+ "eval/q_mse_by_n": {
84
+ "1": 0.10166398215520857,
85
+ "2": 0.06788726373972398,
86
+ "4": 0.05383199234810165,
87
+ "8": 0.042872705614016536,
88
+ "16": 0.04083606126413326,
89
+ "32": 0.03533675406431094,
90
+ "64": 0.03641804118495191,
91
+ "128": 0.03474232110105016,
92
+ "256": 0.03467494483447413
93
+ },
94
+ "eval/q_corr_by_n": {
95
+ "1": 0.5432091431547831,
96
+ "2": 0.6889803738721912,
97
+ "4": 0.7474373967836503,
98
+ "8": 0.7723009237960272,
99
+ "16": 0.8134244967202252,
100
+ "32": 0.8309243589671356,
101
+ "64": 0.8304903471946687,
102
+ "128": 0.8355637822877324,
103
+ "256": 0.8395095947416329
104
+ },
105
+ "eval/q_mse_vs_N": [
106
+ 0.10166398215520857,
107
+ 0.06788726373972398,
108
+ 0.05383199234810165,
109
+ 0.042872705614016536,
110
+ 0.04083606126413326,
111
+ 0.03533675406431094,
112
+ 0.03641804118495191,
113
+ 0.03474232110105016,
114
+ 0.03467494483447413
115
+ ],
116
+ "eval/N_final": 256,
117
+ "eval/truth_std": 0.16826422062875934,
118
+ "wall_clock_s": 190.27805066108704,
119
+ "n_anchors": 400,
120
+ "anchor_protocol": "dataset_anchor",
121
+ "dataset_note": "self_rendered_from_state_pointmaze (no OGBench visual-pointmaze exists)"
122
+ }
gen_q_rsm/preliminary_analysis/experiments/visual_pointmaze_medium_navigate_v0/results/1/mc.json ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "method": "mc",
3
+ "env": "visual-pointmaze-medium-navigate-v0",
4
+ "seed": 1,
5
+ "wandb_url": null,
6
+ "representation": "ant_state_29d",
7
+ "reward": "dense",
8
+ "truth_kind": "fresh_rollout",
9
+ "train/loss": [
10
+ 0.7778210639953613,
11
+ 0.02339986339211464,
12
+ 0.023852061480283737,
13
+ 0.02484820783138275,
14
+ 0.020530669018626213,
15
+ 0.020015805959701538,
16
+ 0.02033216878771782,
17
+ 0.020929066464304924,
18
+ 0.02100355550646782,
19
+ 0.018495939671993256,
20
+ 0.016828354448080063,
21
+ 0.018103748559951782,
22
+ 0.015990406274795532,
23
+ 0.015134772285819054,
24
+ 0.017066648229956627,
25
+ 0.019263707101345062,
26
+ 0.01830333098769188,
27
+ 0.016004566103219986,
28
+ 0.01835515722632408,
29
+ 0.018100393936038017,
30
+ 0.016789056360721588,
31
+ 0.01756531558930874,
32
+ 0.017896192148327827,
33
+ 0.019197577610611916,
34
+ 0.01762261986732483,
35
+ 0.01672225259244442,
36
+ 0.016293030232191086,
37
+ 0.015451420098543167,
38
+ 0.01821363903582096,
39
+ 0.015113407745957375,
40
+ 0.017661530524492264,
41
+ 0.017328113317489624,
42
+ 0.017640316858887672,
43
+ 0.018558043986558914,
44
+ 0.015614695847034454,
45
+ 0.017359744757413864,
46
+ 0.014327095821499825,
47
+ 0.019603803753852844,
48
+ 0.01634526252746582,
49
+ 0.01730777695775032,
50
+ 0.015174825675785542,
51
+ 0.016079675406217575,
52
+ 0.018623583018779755,
53
+ 0.016195299103856087,
54
+ 0.014258256182074547,
55
+ 0.012366688810288906,
56
+ 0.012679745443165302,
57
+ 0.015978572890162468,
58
+ 0.01520790345966816,
59
+ 0.013839712366461754,
60
+ 0.0132619459182024
61
+ ],
62
+ "train/q_mse": [
63
+ 0.7778210639953613,
64
+ 0.02339986339211464,
65
+ 0.023852061480283737,
66
+ 0.02484820783138275,
67
+ 0.020530669018626213,
68
+ 0.020015805959701538,
69
+ 0.02033216878771782,
70
+ 0.020929066464304924,
71
+ 0.02100355550646782,
72
+ 0.018495939671993256,
73
+ 0.016828354448080063,
74
+ 0.018103748559951782,
75
+ 0.015990406274795532,
76
+ 0.015134772285819054,
77
+ 0.017066648229956627,
78
+ 0.019263707101345062,
79
+ 0.01830333098769188,
80
+ 0.016004566103219986,
81
+ 0.01835515722632408,
82
+ 0.018100393936038017,
83
+ 0.016789056360721588,
84
+ 0.01756531558930874,
85
+ 0.017896192148327827,
86
+ 0.019197577610611916,
87
+ 0.01762261986732483,
88
+ 0.01672225259244442,
89
+ 0.016293030232191086,
90
+ 0.015451420098543167,
91
+ 0.01821363903582096,
92
+ 0.015113407745957375,
93
+ 0.017661530524492264,
94
+ 0.017328113317489624,
95
+ 0.017640316858887672,
96
+ 0.018558043986558914,
97
+ 0.015614695847034454,
98
+ 0.017359744757413864,
99
+ 0.014327095821499825,
100
+ 0.019603803753852844,
101
+ 0.01634526252746582,
102
+ 0.01730777695775032,
103
+ 0.015174825675785542,
104
+ 0.016079675406217575,
105
+ 0.018623583018779755,
106
+ 0.016195299103856087,
107
+ 0.014258256182074547,
108
+ 0.012366688810288906,
109
+ 0.012679745443165302,
110
+ 0.015978572890162468,
111
+ 0.01520790345966816,
112
+ 0.013839712366461754,
113
+ 0.0132619459182024
114
+ ],
115
+ "eval/q_mse": 0.02434390918869931,
116
+ "eval/q_mae": 0.10471990462915841,
117
+ "eval/q_corr": 0.8223561782154234,
118
+ "eval/q_spearman": 0.8820593253707835,
119
+ "eval/truth_std": 0.16826422062875934,
120
+ "wall_clock_s": 82.57715368270874,
121
+ "n_anchors": 400,
122
+ "anchor_protocol": "dataset_anchor",
123
+ "dataset_note": "self_rendered_from_state_pointmaze (no OGBench visual-pointmaze exists)"
124
+ }
gen_q_rsm/preliminary_analysis/experiments/visual_pointmaze_medium_navigate_v0/results/1/td.json ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "method": "td",
3
+ "env": "visual-pointmaze-medium-navigate-v0",
4
+ "seed": 1,
5
+ "wandb_url": null,
6
+ "representation": "ant_state_29d",
7
+ "reward": "dense",
8
+ "truth_kind": "fresh_rollout",
9
+ "train/loss": [
10
+ 0.08922570943832397,
11
+ 2.3586251700180583e-05,
12
+ 3.551862755557522e-05,
13
+ 0.00023087025329004973,
14
+ 4.25379621447064e-05,
15
+ 3.934617416234687e-05,
16
+ 0.00012464394967537373,
17
+ 3.5465072869556025e-05,
18
+ 1.847404746513348e-05,
19
+ 5.548719491343945e-05,
20
+ 0.00011864618863910437,
21
+ 3.941592149203643e-05,
22
+ 5.4817210184410214e-05,
23
+ 0.0001261690049432218,
24
+ 6.886602204758674e-05,
25
+ 4.5921126002212986e-05,
26
+ 0.00026340721524320543,
27
+ 3.491710958769545e-05,
28
+ 6.15324461250566e-05,
29
+ 3.6591445677913725e-05,
30
+ 4.809158053831197e-05,
31
+ 3.477423160802573e-05,
32
+ 3.493107942631468e-05,
33
+ 8.450048335362226e-05,
34
+ 5.450391472550109e-05,
35
+ 0.0003894520632456988,
36
+ 0.00010916698374785483,
37
+ 4.6757017116760835e-05,
38
+ 4.382079350762069e-05,
39
+ 6.6999280534219e-05,
40
+ 4.934016760671511e-05,
41
+ 5.072278145235032e-05,
42
+ 4.0917060687206686e-05,
43
+ 7.26800863048993e-05,
44
+ 9.916475391946733e-05,
45
+ 5.48424432054162e-05,
46
+ 0.00011761068890336901,
47
+ 8.198009163606912e-05,
48
+ 8.76081467140466e-05,
49
+ 5.357425834517926e-05,
50
+ 7.92598002590239e-05,
51
+ 0.00025363703025504947,
52
+ 6.0045160353183746e-05,
53
+ 4.806789002032019e-05,
54
+ 5.262159538688138e-05,
55
+ 5.703686474589631e-05,
56
+ 0.0001106592026189901,
57
+ 9.103187767323107e-05,
58
+ 5.136866093380377e-05,
59
+ 0.0001198111058329232,
60
+ 5.662136391038075e-05
61
+ ],
62
+ "train/q_mse": [
63
+ 0.08922570943832397,
64
+ 2.3586251700180583e-05,
65
+ 3.551862755557522e-05,
66
+ 0.00023087025329004973,
67
+ 4.25379621447064e-05,
68
+ 3.934617416234687e-05,
69
+ 0.00012464394967537373,
70
+ 3.5465072869556025e-05,
71
+ 1.847404746513348e-05,
72
+ 5.548719491343945e-05,
73
+ 0.00011864618863910437,
74
+ 3.941592149203643e-05,
75
+ 5.4817210184410214e-05,
76
+ 0.0001261690049432218,
77
+ 6.886602204758674e-05,
78
+ 4.5921126002212986e-05,
79
+ 0.00026340721524320543,
80
+ 3.491710958769545e-05,
81
+ 6.15324461250566e-05,
82
+ 3.6591445677913725e-05,
83
+ 4.809158053831197e-05,
84
+ 3.477423160802573e-05,
85
+ 3.493107942631468e-05,
86
+ 8.450048335362226e-05,
87
+ 5.450391472550109e-05,
88
+ 0.0003894520632456988,
89
+ 0.00010916698374785483,
90
+ 4.6757017116760835e-05,
91
+ 4.382079350762069e-05,
92
+ 6.6999280534219e-05,
93
+ 4.934016760671511e-05,
94
+ 5.072278145235032e-05,
95
+ 4.0917060687206686e-05,
96
+ 7.26800863048993e-05,
97
+ 9.916475391946733e-05,
98
+ 5.48424432054162e-05,
99
+ 0.00011761068890336901,
100
+ 8.198009163606912e-05,
101
+ 8.76081467140466e-05,
102
+ 5.357425834517926e-05,
103
+ 7.92598002590239e-05,
104
+ 0.00025363703025504947,
105
+ 6.0045160353183746e-05,
106
+ 4.806789002032019e-05,
107
+ 5.262159538688138e-05,
108
+ 5.703686474589631e-05,
109
+ 0.0001106592026189901,
110
+ 9.103187767323107e-05,
111
+ 5.136866093380377e-05,
112
+ 0.0001198111058329232,
113
+ 5.662136391038075e-05
114
+ ],
115
+ "eval/q_mse": 0.046722826478564225,
116
+ "eval/q_mae": 0.18053077077449248,
117
+ "eval/q_corr": 0.6928299200693895,
118
+ "eval/q_spearman": 0.6980194251214069,
119
+ "eval/truth_std": 0.16826422062875934,
120
+ "wall_clock_s": 135.48422956466675,
121
+ "n_anchors": 400,
122
+ "anchor_protocol": "dataset_anchor",
123
+ "dataset_note": "self_rendered_from_state_pointmaze (no OGBench visual-pointmaze exists)"
124
+ }
gen_q_rsm/preliminary_analysis/experiments/visual_pointmaze_medium_navigate_v0/results/2/genq.json ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "method": "genq_reward_latent",
3
+ "env": "visual-pointmaze-medium-navigate-v0",
4
+ "seed": 2,
5
+ "wandb_url": null,
6
+ "representation": "image_reward_predictive_latent",
7
+ "occ_model": "diffusion",
8
+ "z_dim": 8,
9
+ "reward": "dense",
10
+ "truth_kind": "fresh_rollout",
11
+ "gen_sample_counts": [
12
+ 1,
13
+ 2,
14
+ 4,
15
+ 8,
16
+ 16,
17
+ 32,
18
+ 64,
19
+ 128,
20
+ 256
21
+ ],
22
+ "train/loss": [
23
+ 1.024316668510437,
24
+ 0.1793454885482788,
25
+ 0.15517249703407288,
26
+ 0.1340932697057724,
27
+ 0.13335293531417847,
28
+ 0.13150489330291748,
29
+ 0.13454917073249817,
30
+ 0.14695987105369568,
31
+ 0.13363848626613617,
32
+ 0.12148027122020721,
33
+ 0.12004993110895157,
34
+ 0.15736988186836243,
35
+ 0.12241700291633606,
36
+ 0.12524090707302094,
37
+ 0.12828771770000458,
38
+ 0.1318449079990387,
39
+ 0.15014547109603882,
40
+ 0.12478946149349213,
41
+ 0.12095083296298981,
42
+ 0.13287462294101715,
43
+ 0.11742374300956726,
44
+ 0.13670894503593445,
45
+ 0.14853531122207642,
46
+ 0.1266043484210968,
47
+ 0.14328953623771667,
48
+ 0.12064675986766815,
49
+ 0.13112778961658478,
50
+ 0.11093735694885254,
51
+ 0.12830224633216858,
52
+ 0.13057976961135864,
53
+ 0.10531724989414215,
54
+ 0.13120026886463165,
55
+ 0.13122409582138062,
56
+ 0.12979282438755035,
57
+ 0.10491982102394104,
58
+ 0.12394106388092041,
59
+ 0.13706372678279877,
60
+ 0.13685330748558044,
61
+ 0.12740539014339447,
62
+ 0.11308732628822327,
63
+ 0.1389036774635315,
64
+ 0.13147905468940735,
65
+ 0.11338790506124496,
66
+ 0.11925211548805237,
67
+ 0.13030390441417694,
68
+ 0.11573618650436401,
69
+ 0.11731089651584625,
70
+ 0.12009034305810928,
71
+ 0.12889808416366577,
72
+ 0.10449075698852539,
73
+ 0.11116305738687515
74
+ ],
75
+ "train/q_mse": [
76
+ 0.024432747446616034
77
+ ],
78
+ "latent/reward_mse": 0.0002573542296886444,
79
+ "eval/q_mse": 0.024432747446616034,
80
+ "eval/q_mae": 0.11475445740433432,
81
+ "eval/q_corr": 0.8041591442347077,
82
+ "eval/q_spearman": 0.8449954062212889,
83
+ "eval/q_mse_by_n": {
84
+ "1": 0.0998142523482076,
85
+ "2": 0.07049776675502882,
86
+ "4": 0.042721090125311195,
87
+ "8": 0.037813734067507834,
88
+ "16": 0.026469064864782607,
89
+ "32": 0.026449487809399503,
90
+ "64": 0.02434675654013557,
91
+ "128": 0.02408864906773499,
92
+ "256": 0.024358060718852038
93
+ },
94
+ "eval/q_corr_by_n": {
95
+ "1": 0.4527950314830981,
96
+ "2": 0.5788944407145811,
97
+ "4": 0.6266348581722568,
98
+ "8": 0.7055368038021134,
99
+ "16": 0.7794822560595883,
100
+ "32": 0.7870327906012677,
101
+ "64": 0.7987446807160185,
102
+ "128": 0.80674082562435,
103
+ "256": 0.8059638740570279
104
+ },
105
+ "eval/q_mse_vs_N": [
106
+ 0.0998142523482076,
107
+ 0.07049776675502882,
108
+ 0.042721090125311195,
109
+ 0.037813734067507834,
110
+ 0.026469064864782607,
111
+ 0.026449487809399503,
112
+ 0.02434675654013557,
113
+ 0.02408864906773499,
114
+ 0.024358060718852038
115
+ ],
116
+ "eval/N_final": 256,
117
+ "eval/truth_std": 0.17654507489690366,
118
+ "wall_clock_s": 190.1649649143219,
119
+ "n_anchors": 400,
120
+ "anchor_protocol": "dataset_anchor",
121
+ "dataset_note": "self_rendered_from_state_pointmaze (no OGBench visual-pointmaze exists)"
122
+ }
gen_q_rsm/preliminary_analysis/experiments/visual_pointmaze_medium_navigate_v0/results/2/mc.json ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "method": "mc",
3
+ "env": "visual-pointmaze-medium-navigate-v0",
4
+ "seed": 2,
5
+ "wandb_url": null,
6
+ "representation": "ant_state_29d",
7
+ "reward": "dense",
8
+ "truth_kind": "fresh_rollout",
9
+ "train/loss": [
10
+ 0.4429917633533478,
11
+ 0.022357996553182602,
12
+ 0.023187624290585518,
13
+ 0.021833859384059906,
14
+ 0.0202195905148983,
15
+ 0.019669605419039726,
16
+ 0.017073694616556168,
17
+ 0.020152775570750237,
18
+ 0.01691555790603161,
19
+ 0.01923917606472969,
20
+ 0.016583403572440147,
21
+ 0.018169526010751724,
22
+ 0.017124615609645844,
23
+ 0.01890822872519493,
24
+ 0.02017965354025364,
25
+ 0.019468169659376144,
26
+ 0.02015000954270363,
27
+ 0.017852913588285446,
28
+ 0.016369212418794632,
29
+ 0.017571432515978813,
30
+ 0.016337791457772255,
31
+ 0.016603713855147362,
32
+ 0.015020797029137611,
33
+ 0.016736339777708054,
34
+ 0.015627248212695122,
35
+ 0.013909053057432175,
36
+ 0.01728198677301407,
37
+ 0.02094826102256775,
38
+ 0.016746126115322113,
39
+ 0.017170626670122147,
40
+ 0.017031293362379074,
41
+ 0.016752181574702263,
42
+ 0.016802242025732994,
43
+ 0.020353741943836212,
44
+ 0.014388898387551308,
45
+ 0.015708858147263527,
46
+ 0.017150770872831345,
47
+ 0.015197831206023693,
48
+ 0.015437373891472816,
49
+ 0.017017479985952377,
50
+ 0.013739853166043758,
51
+ 0.01366988755762577,
52
+ 0.015335265547037125,
53
+ 0.01730331778526306,
54
+ 0.014708343893289566,
55
+ 0.01554938592016697,
56
+ 0.01459048967808485,
57
+ 0.012942909263074398,
58
+ 0.015236981213092804,
59
+ 0.01549330074340105,
60
+ 0.013740262016654015
61
+ ],
62
+ "train/q_mse": [
63
+ 0.4429917633533478,
64
+ 0.022357996553182602,
65
+ 0.023187624290585518,
66
+ 0.021833859384059906,
67
+ 0.0202195905148983,
68
+ 0.019669605419039726,
69
+ 0.017073694616556168,
70
+ 0.020152775570750237,
71
+ 0.01691555790603161,
72
+ 0.01923917606472969,
73
+ 0.016583403572440147,
74
+ 0.018169526010751724,
75
+ 0.017124615609645844,
76
+ 0.01890822872519493,
77
+ 0.02017965354025364,
78
+ 0.019468169659376144,
79
+ 0.02015000954270363,
80
+ 0.017852913588285446,
81
+ 0.016369212418794632,
82
+ 0.017571432515978813,
83
+ 0.016337791457772255,
84
+ 0.016603713855147362,
85
+ 0.015020797029137611,
86
+ 0.016736339777708054,
87
+ 0.015627248212695122,
88
+ 0.013909053057432175,
89
+ 0.01728198677301407,
90
+ 0.02094826102256775,
91
+ 0.016746126115322113,
92
+ 0.017170626670122147,
93
+ 0.017031293362379074,
94
+ 0.016752181574702263,
95
+ 0.016802242025732994,
96
+ 0.020353741943836212,
97
+ 0.014388898387551308,
98
+ 0.015708858147263527,
99
+ 0.017150770872831345,
100
+ 0.015197831206023693,
101
+ 0.015437373891472816,
102
+ 0.017017479985952377,
103
+ 0.013739853166043758,
104
+ 0.01366988755762577,
105
+ 0.015335265547037125,
106
+ 0.01730331778526306,
107
+ 0.014708343893289566,
108
+ 0.01554938592016697,
109
+ 0.01459048967808485,
110
+ 0.012942909263074398,
111
+ 0.015236981213092804,
112
+ 0.01549330074340105,
113
+ 0.013740262016654015
114
+ ],
115
+ "eval/q_mse": 0.028572852573103207,
116
+ "eval/q_mae": 0.1124454424148431,
117
+ "eval/q_corr": 0.8065496786031818,
118
+ "eval/q_spearman": 0.8727120169501059,
119
+ "eval/truth_std": 0.17654507489690366,
120
+ "wall_clock_s": 72.24020314216614,
121
+ "n_anchors": 400,
122
+ "anchor_protocol": "dataset_anchor",
123
+ "dataset_note": "self_rendered_from_state_pointmaze (no OGBench visual-pointmaze exists)"
124
+ }
gen_q_rsm/preliminary_analysis/experiments/visual_pointmaze_medium_navigate_v0/results/2/td.json ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "method": "td",
3
+ "env": "visual-pointmaze-medium-navigate-v0",
4
+ "seed": 2,
5
+ "wandb_url": null,
6
+ "representation": "ant_state_29d",
7
+ "reward": "dense",
8
+ "truth_kind": "fresh_rollout",
9
+ "train/loss": [
10
+ 0.12534111738204956,
11
+ 1.9910268747480586e-05,
12
+ 1.6004145436454564e-05,
13
+ 4.661513230530545e-05,
14
+ 0.0003531512338668108,
15
+ 3.990440018242225e-05,
16
+ 5.7517652749083936e-05,
17
+ 2.0071815015398897e-05,
18
+ 1.9873396013281308e-05,
19
+ 1.5575658835587092e-05,
20
+ 5.665469143423252e-05,
21
+ 9.225113899447024e-05,
22
+ 3.0335413612192497e-05,
23
+ 5.0036567699862644e-05,
24
+ 5.527953544515185e-05,
25
+ 4.24383906647563e-05,
26
+ 3.107404336333275e-05,
27
+ 8.414429612457752e-05,
28
+ 3.052110696444288e-05,
29
+ 3.6292054574005306e-05,
30
+ 8.18166954559274e-05,
31
+ 8.938631799537688e-05,
32
+ 6.787099118810147e-05,
33
+ 7.867449312470853e-05,
34
+ 0.00014428363647311926,
35
+ 4.576490755425766e-05,
36
+ 3.0030154448468238e-05,
37
+ 2.6521336621954106e-05,
38
+ 5.1336428441572934e-05,
39
+ 9.244908869732171e-05,
40
+ 6.353151547955349e-05,
41
+ 4.4155141949886456e-05,
42
+ 0.0001034806773532182,
43
+ 7.633137283846736e-05,
44
+ 0.00010885050141951069,
45
+ 0.00014073187776375562,
46
+ 9.10240487428382e-05,
47
+ 0.00021795034990645945,
48
+ 8.466524013783783e-05,
49
+ 0.00012538922601379454,
50
+ 7.03674741089344e-05,
51
+ 4.6943401684984565e-05,
52
+ 5.272848284221254e-05,
53
+ 4.764578989124857e-05,
54
+ 9.951114770956337e-05,
55
+ 8.630350203020498e-05,
56
+ 0.00010707996261771768,
57
+ 0.00011547016765689477,
58
+ 5.236967990640551e-05,
59
+ 0.00011771705612773076,
60
+ 6.523892807308584e-05
61
+ ],
62
+ "train/q_mse": [
63
+ 0.12534111738204956,
64
+ 1.9910268747480586e-05,
65
+ 1.6004145436454564e-05,
66
+ 4.661513230530545e-05,
67
+ 0.0003531512338668108,
68
+ 3.990440018242225e-05,
69
+ 5.7517652749083936e-05,
70
+ 2.0071815015398897e-05,
71
+ 1.9873396013281308e-05,
72
+ 1.5575658835587092e-05,
73
+ 5.665469143423252e-05,
74
+ 9.225113899447024e-05,
75
+ 3.0335413612192497e-05,
76
+ 5.0036567699862644e-05,
77
+ 5.527953544515185e-05,
78
+ 4.24383906647563e-05,
79
+ 3.107404336333275e-05,
80
+ 8.414429612457752e-05,
81
+ 3.052110696444288e-05,
82
+ 3.6292054574005306e-05,
83
+ 8.18166954559274e-05,
84
+ 8.938631799537688e-05,
85
+ 6.787099118810147e-05,
86
+ 7.867449312470853e-05,
87
+ 0.00014428363647311926,
88
+ 4.576490755425766e-05,
89
+ 3.0030154448468238e-05,
90
+ 2.6521336621954106e-05,
91
+ 5.1336428441572934e-05,
92
+ 9.244908869732171e-05,
93
+ 6.353151547955349e-05,
94
+ 4.4155141949886456e-05,
95
+ 0.0001034806773532182,
96
+ 7.633137283846736e-05,
97
+ 0.00010885050141951069,
98
+ 0.00014073187776375562,
99
+ 9.10240487428382e-05,
100
+ 0.00021795034990645945,
101
+ 8.466524013783783e-05,
102
+ 0.00012538922601379454,
103
+ 7.03674741089344e-05,
104
+ 4.6943401684984565e-05,
105
+ 5.272848284221254e-05,
106
+ 4.764578989124857e-05,
107
+ 9.951114770956337e-05,
108
+ 8.630350203020498e-05,
109
+ 0.00010707996261771768,
110
+ 0.00011547016765689477,
111
+ 5.236967990640551e-05,
112
+ 0.00011771705612773076,
113
+ 6.523892807308584e-05
114
+ ],
115
+ "eval/q_mse": 0.04703190033019146,
116
+ "eval/q_mae": 0.17782433999639735,
117
+ "eval/q_corr": 0.6880166747998998,
118
+ "eval/q_spearman": 0.7019134494590591,
119
+ "eval/truth_std": 0.17654507489690366,
120
+ "wall_clock_s": 173.68622732162476,
121
+ "n_anchors": 400,
122
+ "anchor_protocol": "dataset_anchor",
123
+ "dataset_note": "self_rendered_from_state_pointmaze (no OGBench visual-pointmaze exists)"
124
+ }
gen_q_rsm/preliminary_analysis/experiments/visual_pointmaze_medium_navigate_v0/results/3/genq.json ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "method": "genq_reward_latent",
3
+ "env": "visual-pointmaze-medium-navigate-v0",
4
+ "seed": 3,
5
+ "wandb_url": null,
6
+ "representation": "image_reward_predictive_latent",
7
+ "occ_model": "diffusion",
8
+ "z_dim": 8,
9
+ "reward": "dense",
10
+ "truth_kind": "fresh_rollout",
11
+ "gen_sample_counts": [
12
+ 1,
13
+ 2,
14
+ 4,
15
+ 8,
16
+ 16,
17
+ 32,
18
+ 64,
19
+ 128,
20
+ 256
21
+ ],
22
+ "train/loss": [
23
+ 0.9786122441291809,
24
+ 0.1813828945159912,
25
+ 0.16335684061050415,
26
+ 0.15657462179660797,
27
+ 0.14482948184013367,
28
+ 0.15136945247650146,
29
+ 0.1602517068386078,
30
+ 0.14487171173095703,
31
+ 0.1275518387556076,
32
+ 0.14118008315563202,
33
+ 0.13817457854747772,
34
+ 0.1265709549188614,
35
+ 0.14510628581047058,
36
+ 0.1097148209810257,
37
+ 0.12812486290931702,
38
+ 0.11592552810907364,
39
+ 0.14503419399261475,
40
+ 0.11103656888008118,
41
+ 0.13784858584403992,
42
+ 0.10638585686683655,
43
+ 0.12266869097948074,
44
+ 0.13578736782073975,
45
+ 0.11891372501850128,
46
+ 0.11895227432250977,
47
+ 0.12104280292987823,
48
+ 0.11480166018009186,
49
+ 0.10633327066898346,
50
+ 0.13845336437225342,
51
+ 0.10790373384952545,
52
+ 0.11080335080623627,
53
+ 0.12742257118225098,
54
+ 0.10211851447820663,
55
+ 0.1400298923254013,
56
+ 0.12587080895900726,
57
+ 0.1037636399269104,
58
+ 0.11045695096254349,
59
+ 0.12478771060705185,
60
+ 0.11771151423454285,
61
+ 0.14330628514289856,
62
+ 0.11053226888179779,
63
+ 0.11037909984588623,
64
+ 0.12294399738311768,
65
+ 0.1331074982881546,
66
+ 0.11681242287158966,
67
+ 0.1415989100933075,
68
+ 0.12663546204566956,
69
+ 0.10575957596302032,
70
+ 0.10996787250041962,
71
+ 0.11652432382106781,
72
+ 0.1042134165763855,
73
+ 0.11657209694385529
74
+ ],
75
+ "train/q_mse": [
76
+ 0.03261971514659783
77
+ ],
78
+ "latent/reward_mse": 0.00018257884948980063,
79
+ "eval/q_mse": 0.03261971514659783,
80
+ "eval/q_mae": 0.13390268875282402,
81
+ "eval/q_corr": 0.7574858238002674,
82
+ "eval/q_spearman": 0.8033770836067724,
83
+ "eval/q_mse_by_n": {
84
+ "1": 0.11800017661099597,
85
+ "2": 0.06831705131717261,
86
+ "4": 0.049247032290697046,
87
+ "8": 0.04359604283427686,
88
+ "16": 0.03706276048290737,
89
+ "32": 0.03516112533392767,
90
+ "64": 0.03321869847703921,
91
+ "128": 0.03189653154641794,
92
+ "256": 0.03161514213291374
93
+ },
94
+ "eval/q_corr_by_n": {
95
+ "1": 0.4650659249309307,
96
+ "2": 0.567179225609397,
97
+ "4": 0.613312688133767,
98
+ "8": 0.6924841970155693,
99
+ "16": 0.7218435078278452,
100
+ "32": 0.7363646775038664,
101
+ "64": 0.7393515761838985,
102
+ "128": 0.752980012927233,
103
+ "256": 0.7597189862536244
104
+ },
105
+ "eval/q_mse_vs_N": [
106
+ 0.11800017661099597,
107
+ 0.06831705131717261,
108
+ 0.049247032290697046,
109
+ 0.04359604283427686,
110
+ 0.03706276048290737,
111
+ 0.03516112533392767,
112
+ 0.03321869847703921,
113
+ 0.03189653154641794,
114
+ 0.03161514213291374
115
+ ],
116
+ "eval/N_final": 256,
117
+ "eval/truth_std": 0.1676409617116019,
118
+ "wall_clock_s": 214.69173336029053,
119
+ "n_anchors": 400,
120
+ "anchor_protocol": "dataset_anchor",
121
+ "dataset_note": "self_rendered_from_state_pointmaze (no OGBench visual-pointmaze exists)"
122
+ }
gen_q_rsm/preliminary_analysis/experiments/visual_pointmaze_medium_navigate_v0/results/3/mc.json ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "method": "mc",
3
+ "env": "visual-pointmaze-medium-navigate-v0",
4
+ "seed": 3,
5
+ "wandb_url": null,
6
+ "representation": "ant_state_29d",
7
+ "reward": "dense",
8
+ "truth_kind": "fresh_rollout",
9
+ "train/loss": [
10
+ 0.11427582055330276,
11
+ 0.025900479406118393,
12
+ 0.02182270586490631,
13
+ 0.018609585240483284,
14
+ 0.02048398181796074,
15
+ 0.02097250521183014,
16
+ 0.019679706543684006,
17
+ 0.01927187666296959,
18
+ 0.016564100980758667,
19
+ 0.02113707736134529,
20
+ 0.01816052943468094,
21
+ 0.01731155999004841,
22
+ 0.01948174461722374,
23
+ 0.01947575993835926,
24
+ 0.020028414204716682,
25
+ 0.017292534932494164,
26
+ 0.018862828612327576,
27
+ 0.0204632505774498,
28
+ 0.017529692500829697,
29
+ 0.01708166114985943,
30
+ 0.01849568821489811,
31
+ 0.01659216359257698,
32
+ 0.01689644157886505,
33
+ 0.01867891661822796,
34
+ 0.018060501664876938,
35
+ 0.018033597618341446,
36
+ 0.017130481079220772,
37
+ 0.014515886083245277,
38
+ 0.01813732273876667,
39
+ 0.01816505566239357,
40
+ 0.01644013077020645,
41
+ 0.019669361412525177,
42
+ 0.016517076641321182,
43
+ 0.01640458032488823,
44
+ 0.017151495441794395,
45
+ 0.019820772111415863,
46
+ 0.017135582864284515,
47
+ 0.015625646337866783,
48
+ 0.015960179269313812,
49
+ 0.01435169205069542,
50
+ 0.015589943155646324,
51
+ 0.019253745675086975,
52
+ 0.014245660975575447,
53
+ 0.015107457526028156,
54
+ 0.015367028303444386,
55
+ 0.015443369746208191,
56
+ 0.016586344689130783,
57
+ 0.012922870926558971,
58
+ 0.015143996104598045,
59
+ 0.014632021076977253,
60
+ 0.017257817089557648
61
+ ],
62
+ "train/q_mse": [
63
+ 0.11427582055330276,
64
+ 0.025900479406118393,
65
+ 0.02182270586490631,
66
+ 0.018609585240483284,
67
+ 0.02048398181796074,
68
+ 0.02097250521183014,
69
+ 0.019679706543684006,
70
+ 0.01927187666296959,
71
+ 0.016564100980758667,
72
+ 0.02113707736134529,
73
+ 0.01816052943468094,
74
+ 0.01731155999004841,
75
+ 0.01948174461722374,
76
+ 0.01947575993835926,
77
+ 0.020028414204716682,
78
+ 0.017292534932494164,
79
+ 0.018862828612327576,
80
+ 0.0204632505774498,
81
+ 0.017529692500829697,
82
+ 0.01708166114985943,
83
+ 0.01849568821489811,
84
+ 0.01659216359257698,
85
+ 0.01689644157886505,
86
+ 0.01867891661822796,
87
+ 0.018060501664876938,
88
+ 0.018033597618341446,
89
+ 0.017130481079220772,
90
+ 0.014515886083245277,
91
+ 0.01813732273876667,
92
+ 0.01816505566239357,
93
+ 0.01644013077020645,
94
+ 0.019669361412525177,
95
+ 0.016517076641321182,
96
+ 0.01640458032488823,
97
+ 0.017151495441794395,
98
+ 0.019820772111415863,
99
+ 0.017135582864284515,
100
+ 0.015625646337866783,
101
+ 0.015960179269313812,
102
+ 0.01435169205069542,
103
+ 0.015589943155646324,
104
+ 0.019253745675086975,
105
+ 0.014245660975575447,
106
+ 0.015107457526028156,
107
+ 0.015367028303444386,
108
+ 0.015443369746208191,
109
+ 0.016586344689130783,
110
+ 0.012922870926558971,
111
+ 0.015143996104598045,
112
+ 0.014632021076977253,
113
+ 0.017257817089557648
114
+ ],
115
+ "eval/q_mse": 0.03152841940559754,
116
+ "eval/q_mae": 0.11649606934512256,
117
+ "eval/q_corr": 0.7776767608263415,
118
+ "eval/q_spearman": 0.8543777773611083,
119
+ "eval/truth_std": 0.1676409617116019,
120
+ "wall_clock_s": 75.966548204422,
121
+ "n_anchors": 400,
122
+ "anchor_protocol": "dataset_anchor",
123
+ "dataset_note": "self_rendered_from_state_pointmaze (no OGBench visual-pointmaze exists)"
124
+ }
gen_q_rsm/preliminary_analysis/experiments/visual_pointmaze_medium_navigate_v0/results/3/td.json ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "method": "td",
3
+ "env": "visual-pointmaze-medium-navigate-v0",
4
+ "seed": 3,
5
+ "wandb_url": null,
6
+ "representation": "ant_state_29d",
7
+ "reward": "dense",
8
+ "truth_kind": "fresh_rollout",
9
+ "train/loss": [
10
+ 0.13432824611663818,
11
+ 2.9250650186440907e-05,
12
+ 2.1772801119368523e-05,
13
+ 1.998736843233928e-05,
14
+ 0.0001087924829334952,
15
+ 4.3424755858723074e-05,
16
+ 3.897686838172376e-05,
17
+ 2.1876137907383963e-05,
18
+ 7.836107397451997e-05,
19
+ 1.8753249605651945e-05,
20
+ 0.00012637728650588542,
21
+ 3.2191601349040866e-05,
22
+ 6.535898137371987e-05,
23
+ 7.396026194328442e-05,
24
+ 2.215734639321454e-05,
25
+ 4.957913915859535e-05,
26
+ 0.00018714769976213574,
27
+ 0.00010593638580758125,
28
+ 2.382395541644655e-05,
29
+ 2.576542647148017e-05,
30
+ 2.5808321879594587e-05,
31
+ 7.161621761042625e-05,
32
+ 5.069085455033928e-05,
33
+ 9.0986599388998e-05,
34
+ 8.170856744982302e-05,
35
+ 3.36167577188462e-05,
36
+ 6.0377988120308146e-05,
37
+ 4.2951814975822344e-05,
38
+ 0.00010280728747602552,
39
+ 8.601638546679169e-05,
40
+ 0.00011885826097568497,
41
+ 4.1312734538223594e-05,
42
+ 6.003670932841487e-05,
43
+ 4.013587022200227e-05,
44
+ 2.867394869099371e-05,
45
+ 0.0001542841928312555,
46
+ 4.245143645675853e-05,
47
+ 4.938837082590908e-05,
48
+ 4.1362305637449026e-05,
49
+ 3.563420250429772e-05,
50
+ 0.00010009656398324296,
51
+ 0.00010307768388884142,
52
+ 6.730636232532561e-05,
53
+ 5.510987466550432e-05,
54
+ 0.00011000169615726918,
55
+ 5.2625480748247355e-05,
56
+ 5.1343056838959455e-05,
57
+ 4.147748404648155e-05,
58
+ 0.000153022599988617,
59
+ 3.814846422756091e-05,
60
+ 5.6674896768527105e-05
61
+ ],
62
+ "train/q_mse": [
63
+ 0.13432824611663818,
64
+ 2.9250650186440907e-05,
65
+ 2.1772801119368523e-05,
66
+ 1.998736843233928e-05,
67
+ 0.0001087924829334952,
68
+ 4.3424755858723074e-05,
69
+ 3.897686838172376e-05,
70
+ 2.1876137907383963e-05,
71
+ 7.836107397451997e-05,
72
+ 1.8753249605651945e-05,
73
+ 0.00012637728650588542,
74
+ 3.2191601349040866e-05,
75
+ 6.535898137371987e-05,
76
+ 7.396026194328442e-05,
77
+ 2.215734639321454e-05,
78
+ 4.957913915859535e-05,
79
+ 0.00018714769976213574,
80
+ 0.00010593638580758125,
81
+ 2.382395541644655e-05,
82
+ 2.576542647148017e-05,
83
+ 2.5808321879594587e-05,
84
+ 7.161621761042625e-05,
85
+ 5.069085455033928e-05,
86
+ 9.0986599388998e-05,
87
+ 8.170856744982302e-05,
88
+ 3.36167577188462e-05,
89
+ 6.0377988120308146e-05,
90
+ 4.2951814975822344e-05,
91
+ 0.00010280728747602552,
92
+ 8.601638546679169e-05,
93
+ 0.00011885826097568497,
94
+ 4.1312734538223594e-05,
95
+ 6.003670932841487e-05,
96
+ 4.013587022200227e-05,
97
+ 2.867394869099371e-05,
98
+ 0.0001542841928312555,
99
+ 4.245143645675853e-05,
100
+ 4.938837082590908e-05,
101
+ 4.1362305637449026e-05,
102
+ 3.563420250429772e-05,
103
+ 0.00010009656398324296,
104
+ 0.00010307768388884142,
105
+ 6.730636232532561e-05,
106
+ 5.510987466550432e-05,
107
+ 0.00011000169615726918,
108
+ 5.2625480748247355e-05,
109
+ 5.1343056838959455e-05,
110
+ 4.147748404648155e-05,
111
+ 0.000153022599988617,
112
+ 3.814846422756091e-05,
113
+ 5.6674896768527105e-05
114
+ ],
115
+ "eval/q_mse": 0.062091866483208545,
116
+ "eval/q_mae": 0.19175105180722984,
117
+ "eval/q_corr": 0.653040559134656,
118
+ "eval/q_spearman": 0.6757079106744416,
119
+ "eval/truth_std": 0.1676409617116019,
120
+ "wall_clock_s": 150.6241955757141,
121
+ "n_anchors": 400,
122
+ "anchor_protocol": "dataset_anchor",
123
+ "dataset_note": "self_rendered_from_state_pointmaze (no OGBench visual-pointmaze exists)"
124
+ }
gen_q_rsm/preliminary_analysis/experiments/visual_pointmaze_medium_navigate_v0/results/4/genq.json ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "method": "genq_reward_latent",
3
+ "env": "visual-pointmaze-medium-navigate-v0",
4
+ "seed": 4,
5
+ "wandb_url": null,
6
+ "representation": "image_reward_predictive_latent",
7
+ "occ_model": "diffusion",
8
+ "z_dim": 8,
9
+ "reward": "dense",
10
+ "truth_kind": "fresh_rollout",
11
+ "gen_sample_counts": [
12
+ 1,
13
+ 2,
14
+ 4,
15
+ 8,
16
+ 16,
17
+ 32,
18
+ 64,
19
+ 128,
20
+ 256
21
+ ],
22
+ "train/loss": [
23
+ 1.0221143960952759,
24
+ 0.15464206039905548,
25
+ 0.13698916137218475,
26
+ 0.15096651017665863,
27
+ 0.1399756371974945,
28
+ 0.13827411830425262,
29
+ 0.15386801958084106,
30
+ 0.14700762927532196,
31
+ 0.1270446479320526,
32
+ 0.14089421927928925,
33
+ 0.14881587028503418,
34
+ 0.13726650178432465,
35
+ 0.14134633541107178,
36
+ 0.10434136539697647,
37
+ 0.14067550003528595,
38
+ 0.12321922183036804,
39
+ 0.14194923639297485,
40
+ 0.12255091965198517,
41
+ 0.12179884314537048,
42
+ 0.11405657231807709,
43
+ 0.13789606094360352,
44
+ 0.13840842247009277,
45
+ 0.14163300395011902,
46
+ 0.12925845384597778,
47
+ 0.14221712946891785,
48
+ 0.11165930330753326,
49
+ 0.11027666926383972,
50
+ 0.134271040558815,
51
+ 0.11549004167318344,
52
+ 0.12998327612876892,
53
+ 0.11937310546636581,
54
+ 0.1511804759502411,
55
+ 0.10254085063934326,
56
+ 0.13579848408699036,
57
+ 0.11421668529510498,
58
+ 0.11789098381996155,
59
+ 0.12832027673721313,
60
+ 0.1332865059375763,
61
+ 0.12517359852790833,
62
+ 0.11915998160839081,
63
+ 0.13494136929512024,
64
+ 0.1402449905872345,
65
+ 0.11254194378852844,
66
+ 0.11143847554922104,
67
+ 0.1254590004682541,
68
+ 0.11728259921073914,
69
+ 0.13448892533779144,
70
+ 0.12565918266773224,
71
+ 0.10986718535423279,
72
+ 0.1203315481543541,
73
+ 0.1103968620300293
74
+ ],
75
+ "train/q_mse": [
76
+ 0.0325285088809079
77
+ ],
78
+ "latent/reward_mse": 0.00012722922838293016,
79
+ "eval/q_mse": 0.0325285088809079,
80
+ "eval/q_mae": 0.14042291027594347,
81
+ "eval/q_corr": 0.8343707391026225,
82
+ "eval/q_spearman": 0.859819811373821,
83
+ "eval/q_mse_by_n": {
84
+ "1": 0.11749048527107937,
85
+ "2": 0.06507731086298359,
86
+ "4": 0.05152496529628317,
87
+ "8": 0.038036719248839834,
88
+ "16": 0.04049392737856005,
89
+ "32": 0.034567335346529574,
90
+ "64": 0.03224953411325952,
91
+ "128": 0.032026738340288394,
92
+ "256": 0.03178017218581198
93
+ },
94
+ "eval/q_corr_by_n": {
95
+ "1": 0.5001571625411021,
96
+ "2": 0.6424750229272684,
97
+ "4": 0.7033067227423613,
98
+ "8": 0.7732711422483145,
99
+ "16": 0.790210644271934,
100
+ "32": 0.8066095136313705,
101
+ "64": 0.8267415568147836,
102
+ "128": 0.8369205649892222,
103
+ "256": 0.8349037227999108
104
+ },
105
+ "eval/q_mse_vs_N": [
106
+ 0.11749048527107937,
107
+ 0.06507731086298359,
108
+ 0.05152496529628317,
109
+ 0.038036719248839834,
110
+ 0.04049392737856005,
111
+ 0.034567335346529574,
112
+ 0.03224953411325952,
113
+ 0.032026738340288394,
114
+ 0.03178017218581198
115
+ ],
116
+ "eval/N_final": 256,
117
+ "eval/truth_std": 0.17247575124413256,
118
+ "wall_clock_s": 204.09846472740173,
119
+ "n_anchors": 400,
120
+ "anchor_protocol": "dataset_anchor",
121
+ "dataset_note": "self_rendered_from_state_pointmaze (no OGBench visual-pointmaze exists)"
122
+ }
gen_q_rsm/preliminary_analysis/experiments/visual_pointmaze_medium_navigate_v0/results/4/mc.json ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "method": "mc",
3
+ "env": "visual-pointmaze-medium-navigate-v0",
4
+ "seed": 4,
5
+ "wandb_url": null,
6
+ "representation": "ant_state_29d",
7
+ "reward": "dense",
8
+ "truth_kind": "fresh_rollout",
9
+ "train/loss": [
10
+ 0.34835368394851685,
11
+ 0.021781086921691895,
12
+ 0.022151704877614975,
13
+ 0.02001960203051567,
14
+ 0.020774640142917633,
15
+ 0.02400769107043743,
16
+ 0.02091117948293686,
17
+ 0.022001339122653008,
18
+ 0.019430074840784073,
19
+ 0.019683439284563065,
20
+ 0.02220391482114792,
21
+ 0.021904882043600082,
22
+ 0.021217767149209976,
23
+ 0.01888200454413891,
24
+ 0.01898941770195961,
25
+ 0.016956716775894165,
26
+ 0.015432142652571201,
27
+ 0.014268948696553707,
28
+ 0.015532889403402805,
29
+ 0.01790783181786537,
30
+ 0.015784412622451782,
31
+ 0.019660845398902893,
32
+ 0.0204515028744936,
33
+ 0.013847408816218376,
34
+ 0.015860646963119507,
35
+ 0.016796434298157692,
36
+ 0.017031237483024597,
37
+ 0.016207076609134674,
38
+ 0.01771123707294464,
39
+ 0.016995955258607864,
40
+ 0.016243355348706245,
41
+ 0.016266588121652603,
42
+ 0.015557675622403622,
43
+ 0.015755996108055115,
44
+ 0.01845301315188408,
45
+ 0.017771422863006592,
46
+ 0.013419459573924541,
47
+ 0.016886193305253983,
48
+ 0.015301067382097244,
49
+ 0.01601841300725937,
50
+ 0.01298343762755394,
51
+ 0.017222832888364792,
52
+ 0.017420273274183273,
53
+ 0.01316698919981718,
54
+ 0.016125483438372612,
55
+ 0.016258180141448975,
56
+ 0.018020782619714737,
57
+ 0.016702108085155487,
58
+ 0.014704195782542229,
59
+ 0.014174933545291424,
60
+ 0.014707410708069801
61
+ ],
62
+ "train/q_mse": [
63
+ 0.34835368394851685,
64
+ 0.021781086921691895,
65
+ 0.022151704877614975,
66
+ 0.02001960203051567,
67
+ 0.020774640142917633,
68
+ 0.02400769107043743,
69
+ 0.02091117948293686,
70
+ 0.022001339122653008,
71
+ 0.019430074840784073,
72
+ 0.019683439284563065,
73
+ 0.02220391482114792,
74
+ 0.021904882043600082,
75
+ 0.021217767149209976,
76
+ 0.01888200454413891,
77
+ 0.01898941770195961,
78
+ 0.016956716775894165,
79
+ 0.015432142652571201,
80
+ 0.014268948696553707,
81
+ 0.015532889403402805,
82
+ 0.01790783181786537,
83
+ 0.015784412622451782,
84
+ 0.019660845398902893,
85
+ 0.0204515028744936,
86
+ 0.013847408816218376,
87
+ 0.015860646963119507,
88
+ 0.016796434298157692,
89
+ 0.017031237483024597,
90
+ 0.016207076609134674,
91
+ 0.01771123707294464,
92
+ 0.016995955258607864,
93
+ 0.016243355348706245,
94
+ 0.016266588121652603,
95
+ 0.015557675622403622,
96
+ 0.015755996108055115,
97
+ 0.01845301315188408,
98
+ 0.017771422863006592,
99
+ 0.013419459573924541,
100
+ 0.016886193305253983,
101
+ 0.015301067382097244,
102
+ 0.01601841300725937,
103
+ 0.01298343762755394,
104
+ 0.017222832888364792,
105
+ 0.017420273274183273,
106
+ 0.01316698919981718,
107
+ 0.016125483438372612,
108
+ 0.016258180141448975,
109
+ 0.018020782619714737,
110
+ 0.016702108085155487,
111
+ 0.014704195782542229,
112
+ 0.014174933545291424,
113
+ 0.014707410708069801
114
+ ],
115
+ "eval/q_mse": 0.025218780195969598,
116
+ "eval/q_mae": 0.10768196192798157,
117
+ "eval/q_corr": 0.8232307744599302,
118
+ "eval/q_spearman": 0.8845570284814278,
119
+ "eval/truth_std": 0.17247575124413256,
120
+ "wall_clock_s": 80.08448624610901,
121
+ "n_anchors": 400,
122
+ "anchor_protocol": "dataset_anchor",
123
+ "dataset_note": "self_rendered_from_state_pointmaze (no OGBench visual-pointmaze exists)"
124
+ }
gen_q_rsm/preliminary_analysis/experiments/visual_pointmaze_medium_navigate_v0/results/4/td.json ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "method": "td",
3
+ "env": "visual-pointmaze-medium-navigate-v0",
4
+ "seed": 4,
5
+ "wandb_url": null,
6
+ "representation": "ant_state_29d",
7
+ "reward": "dense",
8
+ "truth_kind": "fresh_rollout",
9
+ "train/loss": [
10
+ 0.12689602375030518,
11
+ 5.8314453781349584e-05,
12
+ 0.0002390430890955031,
13
+ 4.2148400098085403e-05,
14
+ 6.272075552260503e-05,
15
+ 0.00012217811308801174,
16
+ 3.392712096683681e-05,
17
+ 1.4556029782397673e-05,
18
+ 2.6110506951226853e-05,
19
+ 5.428169606602751e-05,
20
+ 1.7343005310976878e-05,
21
+ 1.8382921552984044e-05,
22
+ 2.6903804609901272e-05,
23
+ 2.159901850973256e-05,
24
+ 0.00012590631376951933,
25
+ 3.1839350413065404e-05,
26
+ 0.00014260338502936065,
27
+ 2.5799236027523875e-05,
28
+ 4.8569097998552024e-05,
29
+ 5.67318857065402e-05,
30
+ 3.83693040930666e-05,
31
+ 3.2438882044516504e-05,
32
+ 3.35777185682673e-05,
33
+ 2.5082532374653965e-05,
34
+ 5.6030432460829616e-05,
35
+ 4.5425469579640776e-05,
36
+ 8.850930316839367e-05,
37
+ 4.3394320528022945e-05,
38
+ 7.397429726552218e-05,
39
+ 7.845193613320589e-05,
40
+ 2.165625846828334e-05,
41
+ 6.838806439191103e-05,
42
+ 9.929090447258204e-05,
43
+ 2.5584453396731988e-05,
44
+ 2.6925225029117428e-05,
45
+ 3.4887045330833644e-05,
46
+ 7.293863745871931e-05,
47
+ 5.698925087926909e-05,
48
+ 4.541434464044869e-05,
49
+ 0.00011787991388700902,
50
+ 2.5135776013485156e-05,
51
+ 2.705133374547586e-05,
52
+ 9.204699017573148e-05,
53
+ 0.00019238758250139654,
54
+ 6.033916724845767e-05,
55
+ 6.98754665791057e-05,
56
+ 0.00014157664554659277,
57
+ 6.125553045421839e-05,
58
+ 6.424242747016251e-05,
59
+ 5.788148337160237e-05,
60
+ 7.827226363588125e-05
61
+ ],
62
+ "train/q_mse": [
63
+ 0.12689602375030518,
64
+ 5.8314453781349584e-05,
65
+ 0.0002390430890955031,
66
+ 4.2148400098085403e-05,
67
+ 6.272075552260503e-05,
68
+ 0.00012217811308801174,
69
+ 3.392712096683681e-05,
70
+ 1.4556029782397673e-05,
71
+ 2.6110506951226853e-05,
72
+ 5.428169606602751e-05,
73
+ 1.7343005310976878e-05,
74
+ 1.8382921552984044e-05,
75
+ 2.6903804609901272e-05,
76
+ 2.159901850973256e-05,
77
+ 0.00012590631376951933,
78
+ 3.1839350413065404e-05,
79
+ 0.00014260338502936065,
80
+ 2.5799236027523875e-05,
81
+ 4.8569097998552024e-05,
82
+ 5.67318857065402e-05,
83
+ 3.83693040930666e-05,
84
+ 3.2438882044516504e-05,
85
+ 3.35777185682673e-05,
86
+ 2.5082532374653965e-05,
87
+ 5.6030432460829616e-05,
88
+ 4.5425469579640776e-05,
89
+ 8.850930316839367e-05,
90
+ 4.3394320528022945e-05,
91
+ 7.397429726552218e-05,
92
+ 7.845193613320589e-05,
93
+ 2.165625846828334e-05,
94
+ 6.838806439191103e-05,
95
+ 9.929090447258204e-05,
96
+ 2.5584453396731988e-05,
97
+ 2.6925225029117428e-05,
98
+ 3.4887045330833644e-05,
99
+ 7.293863745871931e-05,
100
+ 5.698925087926909e-05,
101
+ 4.541434464044869e-05,
102
+ 0.00011787991388700902,
103
+ 2.5135776013485156e-05,
104
+ 2.705133374547586e-05,
105
+ 9.204699017573148e-05,
106
+ 0.00019238758250139654,
107
+ 6.033916724845767e-05,
108
+ 6.98754665791057e-05,
109
+ 0.00014157664554659277,
110
+ 6.125553045421839e-05,
111
+ 6.424242747016251e-05,
112
+ 5.788148337160237e-05,
113
+ 7.827226363588125e-05
114
+ ],
115
+ "eval/q_mse": 0.045694480890922005,
116
+ "eval/q_mae": 0.1738537517968264,
117
+ "eval/q_corr": 0.6883529997958632,
118
+ "eval/q_spearman": 0.7279944874655466,
119
+ "eval/truth_std": 0.17247575124413256,
120
+ "wall_clock_s": 132.9508650302887,
121
+ "n_anchors": 400,
122
+ "anchor_protocol": "dataset_anchor",
123
+ "dataset_note": "self_rendered_from_state_pointmaze (no OGBench visual-pointmaze exists)"
124
+ }
gen_q_rsm/preliminary_analysis/experiments/visual_pointmaze_medium_navigate_v0/run_genq.py ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Run the (self-rendered) visual-pointmaze policy-evaluation cells for one seed.
2
+
3
+ python run_genq.py --method genq --seed 0
4
+ python run_genq.py --method mc --seed 0
5
+ python run_genq.py --method td --seed 0
6
+
7
+ genq uses the reward-predictive CNN latent occupancy in a FROZEN latent
8
+ (genq_visual.run) over rendered 64x64x3 images — NEVER raw pixels in the occupancy
9
+ model. mc/td run on the 4-D pointmaze state (qpos[2]+qvel[2]) as the non-latent
10
+ reference (genq_visual.run_mc / run_td). All score against FRESH-ROLLOUT truth: the
11
+ PointMaze scripted oracle-subgoal+noise controller, reset from the dataset anchor's xy
12
+ (qpos), via gc_core.gc_fresh_truth_pointmaze. Protocol = dataset_anchor.
13
+
14
+ NOTE: `visual-pointmaze-medium-navigate-v0` is NOT an OGBench env (no registry entry,
15
+ dataset 404s). The images are SELF-RENDERED from the state pointmaze dataset's qpos
16
+ (build_visual_pointmaze_data.py). Truth never uses pixels, so it is unaffected.
17
+ Writes results/{seed}/{method}.json.
18
+ """
19
+ import argparse
20
+ import json
21
+ import os
22
+ import sys
23
+
24
+ _HERE = os.path.dirname(os.path.abspath(__file__))
25
+ sys.path.insert(0, os.path.join(_HERE, "..", "..")) # preliminary_analysis on path
26
+
27
+ import torch # noqa: E402
28
+ _nt = int(os.environ.get("OMP_NUM_THREADS", "0") or 0)
29
+ if _nt > 0:
30
+ torch.set_num_threads(_nt)
31
+
32
+ from config import make_cfg # noqa: E402
33
+ import genq_visual # noqa: E402
34
+
35
+ ENV = "visual-pointmaze-medium-navigate-v0"
36
+ _FN = {"genq": "run", "mc": "run_mc", "td": "run_td"}
37
+ _OUT_NAME = {"genq": "genq", "mc": "mc", "td": "td"}
38
+
39
+
40
+ def result_path(seed, method):
41
+ d = os.path.join(_HERE, "results", str(seed))
42
+ os.makedirs(d, exist_ok=True)
43
+ return os.path.join(d, f"{_OUT_NAME[method]}.json")
44
+
45
+
46
+ def run_one(method, seed, **ov):
47
+ cfg = make_cfg(**ov)
48
+ result = getattr(genq_visual, _FN[method])(ENV, seed, cfg)
49
+ # PointMaze obs IS rendered from the resettable maze state; the truth resets to the
50
+ # dataset validation anchor's xy and rolls the scripted oracle (dataset-anchor protocol).
51
+ result["anchor_protocol"] = "dataset_anchor"
52
+ result["dataset_note"] = "self_rendered_from_state_pointmaze (no OGBench visual-pointmaze exists)"
53
+ path = result_path(seed, method)
54
+ with open(path, "w") as f:
55
+ json.dump(result, f, indent=2, allow_nan=True)
56
+ print(f"[visual-pointmaze] wrote {path} eval/q_mse={result['eval/q_mse']:.5f} "
57
+ f"eval/q_corr={result.get('eval/q_corr')}", flush=True)
58
+ return result
59
+
60
+
61
+ def main():
62
+ ap = argparse.ArgumentParser()
63
+ ap.add_argument("--method", choices=list(_FN), default="genq")
64
+ ap.add_argument("--seed", type=int, default=None, help="single seed; default 0..4")
65
+ ap.add_argument("--reward", default="dense")
66
+ ap.add_argument("--steps", type=int, default=None)
67
+ ap.add_argument("--latent_steps", type=int, default=None)
68
+ ap.add_argument("--n_anchors", type=int, default=None)
69
+ ap.add_argument("--truth_M", type=int, default=None)
70
+ ap.add_argument("--truth_H", type=int, default=None)
71
+ ap.add_argument("--vis_train_traj", type=int, default=None)
72
+ ap.add_argument("--vis_val_traj", type=int, default=None)
73
+ ap.add_argument("--wandb_mode", default=None)
74
+ args = ap.parse_args()
75
+ seeds = [args.seed] if args.seed is not None else list(range(5))
76
+ ov = {"reward": args.reward}
77
+ for k in ("steps", "latent_steps", "n_anchors", "truth_M", "truth_H",
78
+ "vis_train_traj", "vis_val_traj", "wandb_mode"):
79
+ v = getattr(args, k)
80
+ if v is not None:
81
+ ov[k] = v
82
+ for s in seeds:
83
+ run_one(args.method, s, **ov)
84
+
85
+
86
+ if __name__ == "__main__":
87
+ main()
gen_q_rsm/preliminary_analysis/experiments/visual_pointmaze_medium_navigate_v0/run_seq.sh ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ # SEQUENTIAL policy-eval runner for the self-rendered visual-pointmaze cell.
3
+ #
4
+ # Blue Vela GPUs are mode=exclusive_process -> only ONE CUDA context per GPU. The
5
+ # packed "&"+wait pattern collides (cudaErrorDevicesUnavailable), so cells run
6
+ # SEQUENTIALLY, one (method,seed) per loop iteration. The image CNN encoder is heavier
7
+ # than the state MLPs, so keep <=1-2 cells per GPU; sequential is the safe default.
8
+ #
9
+ # Usage:
10
+ # SEEDS="0" METHODS="genq mc td" bash run_seq.sh
11
+ # Resume-safe: only runs a (method,seed) cell whose JSON is missing / not fresh_rollout.
12
+ set -u
13
+
14
+ HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
15
+ ROOT="$(cd "$HERE/../../.." && pwd)"
16
+ PA="$ROOT/preliminary_analysis"
17
+ PY="$ROOT/.venv/bin/python"
18
+ [ -x "$PY" ] || PY="/proj/inf-scaling/zwhong/projs/gen_q/.venv/bin/python"
19
+ DRIVER="$HERE/run_genq.py"
20
+
21
+ SEEDS="${SEEDS:-0}"
22
+ METHODS="${METHODS:-genq mc td}"
23
+ REWARD="${REWARD:-dense}"
24
+ GENQ_STEPS="${GENQ_STEPS:-40000}"
25
+ LATENT_STEPS="${LATENT_STEPS:-20000}"
26
+ TRUTH_M="${TRUTH_M:-8}"
27
+ TRUTH_H="${TRUTH_H:-350}"
28
+ N_ANCHORS="${N_ANCHORS:-400}"
29
+ # rendered dataset is 300 train / 100 val traj; use all of it.
30
+ VIS_TRAIN_TRAJ="${VIS_TRAIN_TRAJ:-300}"
31
+ VIS_VAL_TRAJ="${VIS_VAL_TRAJ:-100}"
32
+
33
+ if [ -f "$ROOT/.env" ]; then set -a; . "$ROOT/.env"; set +a; fi
34
+ export OMP_NUM_THREADS=3 MKL_NUM_THREADS=3 OPENBLAS_NUM_THREADS=3
35
+ export NUMEXPR_NUM_THREADS=3 VECLIB_MAXIMUM_THREADS=3
36
+ export XLA_FLAGS="--xla_cpu_multi_thread_eigen=false intra_op_parallelism_threads=3"
37
+ export JAX_PLATFORMS=cpu
38
+ export XLA_PYTHON_CLIENT_MEM_FRACTION=0.1
39
+ export MUJOCO_GL=egl
40
+
41
+ cd "$PA"
42
+ mkdir -p "$HERE/results"
43
+ echo "[run_seq vpm] SEEDS='$SEEDS' METHODS='$METHODS' steps=$GENQ_STEPS latent=$LATENT_STEPS M=$TRUTH_M H=$TRUTH_H anchors=$N_ANCHORS"
44
+
45
+ fail=0
46
+ for SEED in $SEEDS; do
47
+ for METHOD in $METHODS; do
48
+ out="$HERE/results/$SEED/$METHOD.json"
49
+ if [ -f "$out" ] && grep -q '"truth_kind": "fresh_rollout"' "$out" 2>/dev/null; then
50
+ echo "[run_seq vpm] SKIP existing $METHOD s$SEED"; continue
51
+ fi
52
+ echo "[run_seq vpm] === $METHOD seed=$SEED ==="
53
+ args=(--method "$METHOD" --seed "$SEED" --reward "$REWARD" \
54
+ --steps "$GENQ_STEPS" --n_anchors "$N_ANCHORS" \
55
+ --truth_M "$TRUTH_M" --truth_H "$TRUTH_H" \
56
+ --vis_train_traj "$VIS_TRAIN_TRAJ" --vis_val_traj "$VIS_VAL_TRAJ")
57
+ if [ "$METHOD" = "genq" ]; then args+=(--latent_steps "$LATENT_STEPS"); fi
58
+ if ! "$PY" "$DRIVER" "${args[@]}" > "$HERE/results/${METHOD}_s${SEED}.log" 2>&1; then
59
+ echo "[run_seq vpm] CELL FAILED: $METHOD-s$SEED"
60
+ tail -8 "$HERE/results/${METHOD}_s${SEED}.log"
61
+ fail=1
62
+ fi
63
+ done
64
+ done
65
+
66
+ "$PY" plots.py --env "visual-pointmaze-medium-navigate-v0" || true
67
+ echo "[run_seq vpm] done (fail=$fail)"
68
+ exit "$fail"
gen_q_rsm/preliminary_analysis/experiments/visual_puzzle_3x3_play_v0/NOTES.md ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # visual-puzzle-3x3-play-v0 — Milestone 1 (Policy Evaluation), issue #35
2
+
3
+ Image-observation + combinatorial cell. **Expected outcome: an HONEST NEGATIVE,
4
+ inherited from the STATE `puzzle-3x3-play-v0` honest negative** (all of mc/td/genq at
5
+ ~0 correlation). This is the correct, reported finding — not a failure of the image
6
+ recipe and not something to tune away.
7
+
8
+ ## What this cell runs
9
+
10
+ - **genq** = image reward-predictive **latent** occupancy (`genq_visual_puzzle.run`).
11
+ CNN encoder `z = E(image 64x64x3)`; goal-conditioned reward decoder `R(z, g)` fit to
12
+ the puzzle **match-fraction** reward (`gc_core.puzzle_reward`, the issue-#35 reward);
13
+ freeze; conditional **diffusion** occupancy `p(z' | z_now, a, g)` on
14
+ `z' = stopgrad(E(image_{t+k}))`, `k ~ Geom(1-γ)`; `Q = mean_i R(z_i, g)`. NEVER raw
15
+ pixels (CLAUDE.md image rule).
16
+ - **mc / td** = trained-MC / IQL-TD critics over the **46-D `[qpos|qvel]` state**
17
+ (the non-latent reference, documented via `representation`), with the SAME
18
+ match-fraction reward and the button-state vector as the occupancy target. This
19
+ mirrors the `genq_visual` (visual-antmaze) precedent where mc/td run on the
20
+ underlying ant state.
21
+ - **Ground truth** = fresh-RESET fresh rollouts (Protocol B), **identical to the STATE
22
+ puzzle**: `ButtonMarkovOracle(gripper_always_closed=True)` rolled from
23
+ `set_state(qpos, qvel, button_states)`, renormalized discounted match-fraction reward
24
+ toward the target button pattern, averaged over M rollouts. The live PuzzleEnv has
25
+ all privileged info, so the truth is independent of whether the model observation is
26
+ an image or a state vector — the image-ness only changes the occupancy MODEL input.
27
+ The shared anchor pack (`gc_core.fresh_reset_anchors`) is built ONCE per seed and
28
+ shared by genq/mc/td so all three score the SAME (s, a, g).
29
+
30
+ ## Why the negative is expected (mechanism)
31
+
32
+ The STATE puzzle is an honest negative because the truth is near-degenerate: the
33
+ discounted match-fraction return toward a single-target-button goal has **truth std
34
+ ~0.011–0.014** across anchors (vs ~0.38 for the graded visual-antmaze navigation
35
+ truth). The Lights-Out button task is essentially "the target button gets pressed
36
+ within the horizon, or it doesn't" — there is no graded, rankable Q across anchors, so
37
+ Pearson/Spearman correlation against truth is ~0 for **every** estimator (the state
38
+ puzzle's mc/td/genq all land at |corr| ≤ 0.15). Passing the same degenerate truth
39
+ through an image reward-latent does not create signal that the task does not contain.
40
+
41
+ So the image case is expected to **confirm** the state negative. If it differs, that is
42
+ itself the reportable finding — but it must come from an honest run, never from tuning.
43
+
44
+ ## Files
45
+
46
+ - Driver: `../../genq_visual_puzzle.py` (genq image-latent + mc/td state reference).
47
+ - Per-seed runner: `run_seed.py` (builds shared truth once, runs genq+mc+td).
48
+ - Batch runner: `run_seq.sh` (one seed per process inside one bsub `-gpu num=1`).
49
+ - Results: `results/{seed}/{genq,mc,td}.json` — schema matches the other M1 envs
50
+ (`eval/q_mse`, `eval/q_corr`, `eval/q_mse_by_n`, `eval/q_corr_by_n`,
51
+ `truth_kind="fresh_rollout"`, `anchor_protocol="fresh_reset"`).
52
+ - Figures: `figures/{mse,corr}.png` (Gen-Q curve vs N, MC/TD reference lines).
gen_q_rsm/preliminary_analysis/experiments/visual_puzzle_3x3_play_v0/figures/.gitkeep ADDED
File without changes
gen_q_rsm/preliminary_analysis/experiments/visual_puzzle_3x3_play_v0/figures/corr.png ADDED
gen_q_rsm/preliminary_analysis/experiments/visual_puzzle_3x3_play_v0/figures/mse.png ADDED
gen_q_rsm/preliminary_analysis/experiments/visual_puzzle_3x3_play_v0/results/.gitkeep ADDED
File without changes
gen_q_rsm/preliminary_analysis/experiments/visual_puzzle_3x3_play_v0/results/0/genq.json ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "method": "genq_reward_latent",
3
+ "env": "visual-puzzle-3x3-play-v0",
4
+ "seed": 0,
5
+ "wandb_url": null,
6
+ "representation": "image_reward_predictive_latent",
7
+ "occ_model": "diffusion",
8
+ "z_dim": 8,
9
+ "reward": "dense",
10
+ "truth_kind": "fresh_rollout",
11
+ "anchor_protocol": "fresh_reset",
12
+ "gen_sample_counts": [
13
+ 1,
14
+ 2,
15
+ 4,
16
+ 8,
17
+ 16,
18
+ 32,
19
+ 64,
20
+ 128,
21
+ 256
22
+ ],
23
+ "train/loss": [
24
+ 1.021519422531128,
25
+ 0.4601687490940094,
26
+ 0.2952587604522705,
27
+ 0.29642564058303833,
28
+ 0.2566065192222595,
29
+ 0.2608852982521057,
30
+ 0.2649744153022766,
31
+ 0.21888938546180725,
32
+ 0.22235921025276184,
33
+ 0.21022295951843262,
34
+ 0.2057866007089615,
35
+ 0.2536538243293762,
36
+ 0.25915318727493286,
37
+ 0.19905629754066467,
38
+ 0.23954977095127106,
39
+ 0.2539094388484955,
40
+ 0.254019558429718,
41
+ 0.23310111463069916,
42
+ 0.23211494088172913,
43
+ 0.2157919853925705,
44
+ 0.19920235872268677,
45
+ 0.20999859273433685,
46
+ 0.26213425397872925,
47
+ 0.23050303757190704,
48
+ 0.20321311056613922,
49
+ 0.15958988666534424,
50
+ 0.2099725306034088,
51
+ 0.22476862370967865,
52
+ 0.2110440880060196,
53
+ 0.2102266550064087,
54
+ 0.20764213800430298,
55
+ 0.2283616065979004,
56
+ 0.19830217957496643,
57
+ 0.21698564291000366,
58
+ 0.19947651028633118,
59
+ 0.19465507566928864,
60
+ 0.23041236400604248,
61
+ 0.23858603835105896,
62
+ 0.20363286137580872,
63
+ 0.18325605988502502,
64
+ 0.179934561252594,
65
+ 0.2046785056591034,
66
+ 0.2069043219089508,
67
+ 0.21145755052566528,
68
+ 0.17085985839366913,
69
+ 0.17966949939727783,
70
+ 0.17462216317653656,
71
+ 0.17755067348480225,
72
+ 0.20074118673801422,
73
+ 0.220272958278656,
74
+ 0.20178523659706116
75
+ ],
76
+ "train/q_mse": [
77
+ 0.07146202586195333
78
+ ],
79
+ "latent/reward_mse": 2.6356749003753066e-05,
80
+ "eval/q_mse": 0.07146202586195333,
81
+ "eval/q_mae": 0.2648176458120056,
82
+ "eval/q_corr": -0.004094141213230109,
83
+ "eval/q_spearman": -0.0030695840290528957,
84
+ "eval/q_mse_by_n": {
85
+ "1": 0.1073083887446366,
86
+ "2": 0.0790610194466088,
87
+ "4": 0.08006403860746969,
88
+ "8": 0.0804523668037022,
89
+ "16": 0.07249970764970978,
90
+ "32": 0.07105027784024304,
91
+ "64": 0.07174116280155583,
92
+ "128": 0.07225206335540099,
93
+ "256": 0.07167250843326349
94
+ },
95
+ "eval/q_corr_by_n": {
96
+ "1": 0.06457914123567231,
97
+ "2": 0.10567364195550466,
98
+ "4": -0.03288992926825715,
99
+ "8": -0.007945798637642304,
100
+ "16": -0.0037951998332696603,
101
+ "32": 0.0016083051179053229,
102
+ "64": 0.021072154041039445,
103
+ "128": -0.007717643607183906,
104
+ "256": 0.007820503672876053
105
+ },
106
+ "eval/q_mse_vs_N": [
107
+ 0.1073083887446366,
108
+ 0.0790610194466088,
109
+ 0.08006403860746969,
110
+ 0.0804523668037022,
111
+ 0.07249970764970978,
112
+ 0.07105027784024304,
113
+ 0.07174116280155583,
114
+ 0.07225206335540099,
115
+ 0.07167250843326349
116
+ ],
117
+ "eval/N_final": 256,
118
+ "eval/truth_std": 0.01520020918542479,
119
+ "wall_clock_s": 216.02018404006958,
120
+ "n_anchors": 200
121
+ }
gen_q_rsm/preliminary_analysis/experiments/visual_puzzle_3x3_play_v0/results/0/mc.json ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "method": "mc",
3
+ "env": "visual-puzzle-3x3-play-v0",
4
+ "seed": 0,
5
+ "wandb_url": null,
6
+ "representation": "puzzle_state_46d",
7
+ "reward": "dense",
8
+ "truth_kind": "fresh_rollout",
9
+ "anchor_protocol": "fresh_reset",
10
+ "train/loss": [
11
+ 0.27377158403396606,
12
+ 0.01449478231370449,
13
+ 0.02048783376812935,
14
+ 0.015084651298820972,
15
+ 0.01668834313750267,
16
+ 0.014009361155331135,
17
+ 0.012490876019001007,
18
+ 0.014363992027938366,
19
+ 0.016287554055452347,
20
+ 0.01540954690426588,
21
+ 0.012552689760923386,
22
+ 0.015072048641741276,
23
+ 0.014254258945584297,
24
+ 0.012741902843117714,
25
+ 0.013847781345248222,
26
+ 0.01286780834197998,
27
+ 0.012072085402905941,
28
+ 0.013999857008457184,
29
+ 0.011457929387688637,
30
+ 0.012684045359492302,
31
+ 0.012237176299095154,
32
+ 0.01200703252106905,
33
+ 0.01054402906447649,
34
+ 0.007818711921572685,
35
+ 0.010167859494686127,
36
+ 0.009926622733473778,
37
+ 0.00923527404665947,
38
+ 0.0085448008030653,
39
+ 0.008351923897862434,
40
+ 0.00709732249379158,
41
+ 0.006109965965151787,
42
+ 0.005684474483132362,
43
+ 0.006194375921040773,
44
+ 0.007862245664000511,
45
+ 0.005147951189428568,
46
+ 0.008025170303881168,
47
+ 0.005333418026566505,
48
+ 0.0056441547349095345,
49
+ 0.004884111694991589,
50
+ 0.005278090946376324,
51
+ 0.004985888954252005,
52
+ 0.0041185906156897545,
53
+ 0.004817157052457333,
54
+ 0.0044778380542993546,
55
+ 0.0044335005804896355,
56
+ 0.0047149658203125,
57
+ 0.003720856737345457,
58
+ 0.004310415126383305,
59
+ 0.003513350849971175,
60
+ 0.004647546447813511,
61
+ 0.0034227771684527397
62
+ ],
63
+ "train/q_mse": [
64
+ 0.27377158403396606,
65
+ 0.01449478231370449,
66
+ 0.02048783376812935,
67
+ 0.015084651298820972,
68
+ 0.01668834313750267,
69
+ 0.014009361155331135,
70
+ 0.012490876019001007,
71
+ 0.014363992027938366,
72
+ 0.016287554055452347,
73
+ 0.01540954690426588,
74
+ 0.012552689760923386,
75
+ 0.015072048641741276,
76
+ 0.014254258945584297,
77
+ 0.012741902843117714,
78
+ 0.013847781345248222,
79
+ 0.01286780834197998,
80
+ 0.012072085402905941,
81
+ 0.013999857008457184,
82
+ 0.011457929387688637,
83
+ 0.012684045359492302,
84
+ 0.012237176299095154,
85
+ 0.01200703252106905,
86
+ 0.01054402906447649,
87
+ 0.007818711921572685,
88
+ 0.010167859494686127,
89
+ 0.009926622733473778,
90
+ 0.00923527404665947,
91
+ 0.0085448008030653,
92
+ 0.008351923897862434,
93
+ 0.00709732249379158,
94
+ 0.006109965965151787,
95
+ 0.005684474483132362,
96
+ 0.006194375921040773,
97
+ 0.007862245664000511,
98
+ 0.005147951189428568,
99
+ 0.008025170303881168,
100
+ 0.005333418026566505,
101
+ 0.0056441547349095345,
102
+ 0.004884111694991589,
103
+ 0.005278090946376324,
104
+ 0.004985888954252005,
105
+ 0.0041185906156897545,
106
+ 0.004817157052457333,
107
+ 0.0044778380542993546,
108
+ 0.0044335005804896355,
109
+ 0.0047149658203125,
110
+ 0.003720856737345457,
111
+ 0.004310415126383305,
112
+ 0.003513350849971175,
113
+ 0.004647546447813511,
114
+ 0.0034227771684527397
115
+ ],
116
+ "eval/q_mse": 0.19029518513677396,
117
+ "eval/q_mae": 0.41816644217965093,
118
+ "eval/q_corr": 0.06425732763454055,
119
+ "eval/q_spearman": 0.08165093517280701,
120
+ "eval/truth_std": 0.01520020918542479,
121
+ "wall_clock_s": 45.317344188690186,
122
+ "n_anchors": 200
123
+ }
gen_q_rsm/preliminary_analysis/experiments/visual_puzzle_3x3_play_v0/results/0/td.json ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "method": "td",
3
+ "env": "visual-puzzle-3x3-play-v0",
4
+ "seed": 0,
5
+ "wandb_url": null,
6
+ "representation": "puzzle_state_46d",
7
+ "reward": "dense",
8
+ "truth_kind": "fresh_rollout",
9
+ "anchor_protocol": "fresh_reset",
10
+ "train/loss": [
11
+ 0.0031114162411540747,
12
+ 5.278137450659415e-06,
13
+ 4.615293619281147e-06,
14
+ 4.854130111198174e-06,
15
+ 6.227544872672297e-06,
16
+ 4.015372724097688e-06,
17
+ 4.181146323389839e-06,
18
+ 5.594997674052138e-06,
19
+ 3.2843117878655903e-06,
20
+ 5.333041372068692e-06,
21
+ 5.873735972272698e-06,
22
+ 8.308212272822857e-06,
23
+ 5.001714725949569e-06,
24
+ 5.982739821774885e-06,
25
+ 5.971228347334545e-06,
26
+ 3.7389995668490883e-06,
27
+ 3.4900795071735047e-06,
28
+ 3.7658824112440925e-06,
29
+ 9.169029908662196e-06,
30
+ 6.395014224835904e-06,
31
+ 2.927656851170468e-06,
32
+ 4.1803928070294205e-06,
33
+ 7.145042218326125e-06,
34
+ 4.241586793796159e-06,
35
+ 3.831414232990937e-06,
36
+ 3.6492870094662067e-06,
37
+ 4.057833393744659e-06,
38
+ 4.213066858937964e-06,
39
+ 8.094826625892892e-06,
40
+ 5.4807915148558095e-06,
41
+ 3.109188583039213e-06,
42
+ 6.9497018557740375e-06,
43
+ 3.9180404201033525e-06,
44
+ 4.068935595569201e-06,
45
+ 7.827791705494747e-06,
46
+ 4.551379333861405e-06,
47
+ 3.7780212096549803e-06,
48
+ 5.656886514771031e-06,
49
+ 3.2655070754117332e-06,
50
+ 4.729612101073144e-06,
51
+ 4.336786332714837e-06,
52
+ 4.0762784010439645e-06,
53
+ 2.9380630621744785e-06,
54
+ 5.181247615837492e-06,
55
+ 3.665640178951435e-06,
56
+ 3.3901685583259678e-06,
57
+ 3.6557812563842162e-06,
58
+ 3.735813834282453e-06,
59
+ 9.290849448007066e-06,
60
+ 3.672404545795871e-06,
61
+ 4.4350563257467e-06
62
+ ],
63
+ "train/q_mse": [
64
+ 0.0031114162411540747,
65
+ 5.278137450659415e-06,
66
+ 4.615293619281147e-06,
67
+ 4.854130111198174e-06,
68
+ 6.227544872672297e-06,
69
+ 4.015372724097688e-06,
70
+ 4.181146323389839e-06,
71
+ 5.594997674052138e-06,
72
+ 3.2843117878655903e-06,
73
+ 5.333041372068692e-06,
74
+ 5.873735972272698e-06,
75
+ 8.308212272822857e-06,
76
+ 5.001714725949569e-06,
77
+ 5.982739821774885e-06,
78
+ 5.971228347334545e-06,
79
+ 3.7389995668490883e-06,
80
+ 3.4900795071735047e-06,
81
+ 3.7658824112440925e-06,
82
+ 9.169029908662196e-06,
83
+ 6.395014224835904e-06,
84
+ 2.927656851170468e-06,
85
+ 4.1803928070294205e-06,
86
+ 7.145042218326125e-06,
87
+ 4.241586793796159e-06,
88
+ 3.831414232990937e-06,
89
+ 3.6492870094662067e-06,
90
+ 4.057833393744659e-06,
91
+ 4.213066858937964e-06,
92
+ 8.094826625892892e-06,
93
+ 5.4807915148558095e-06,
94
+ 3.109188583039213e-06,
95
+ 6.9497018557740375e-06,
96
+ 3.9180404201033525e-06,
97
+ 4.068935595569201e-06,
98
+ 7.827791705494747e-06,
99
+ 4.551379333861405e-06,
100
+ 3.7780212096549803e-06,
101
+ 5.656886514771031e-06,
102
+ 3.2655070754117332e-06,
103
+ 4.729612101073144e-06,
104
+ 4.336786332714837e-06,
105
+ 4.0762784010439645e-06,
106
+ 2.9380630621744785e-06,
107
+ 5.181247615837492e-06,
108
+ 3.665640178951435e-06,
109
+ 3.3901685583259678e-06,
110
+ 3.6557812563842162e-06,
111
+ 3.735813834282453e-06,
112
+ 9.290849448007066e-06,
113
+ 3.672404545795871e-06,
114
+ 4.4350563257467e-06
115
+ ],
116
+ "eval/q_mse": 0.18432445600994302,
117
+ "eval/q_mae": 0.4290393310427376,
118
+ "eval/q_corr": -0.07532079281012344,
119
+ "eval/q_spearman": -0.10866327462847249,
120
+ "eval/truth_std": 0.01520020918542479,
121
+ "wall_clock_s": 113.64547228813171,
122
+ "n_anchors": 200
123
+ }
gen_q_rsm/preliminary_analysis/experiments/visual_puzzle_3x3_play_v0/results/1/genq.json ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "method": "genq_reward_latent",
3
+ "env": "visual-puzzle-3x3-play-v0",
4
+ "seed": 1,
5
+ "wandb_url": null,
6
+ "representation": "image_reward_predictive_latent",
7
+ "occ_model": "diffusion",
8
+ "z_dim": 8,
9
+ "reward": "dense",
10
+ "truth_kind": "fresh_rollout",
11
+ "anchor_protocol": "fresh_reset",
12
+ "gen_sample_counts": [
13
+ 1,
14
+ 2,
15
+ 4,
16
+ 8,
17
+ 16,
18
+ 32,
19
+ 64,
20
+ 128,
21
+ 256
22
+ ],
23
+ "train/loss": [
24
+ 0.9807145595550537,
25
+ 0.4400460720062256,
26
+ 0.3610970675945282,
27
+ 0.2688695192337036,
28
+ 0.28034707903862,
29
+ 0.26231133937835693,
30
+ 0.2494300901889801,
31
+ 0.25018224120140076,
32
+ 0.22944794595241547,
33
+ 0.2130129635334015,
34
+ 0.24376246333122253,
35
+ 0.21491679549217224,
36
+ 0.2273327112197876,
37
+ 0.2546854615211487,
38
+ 0.2323516309261322,
39
+ 0.2361908107995987,
40
+ 0.24614675343036652,
41
+ 0.24467571079730988,
42
+ 0.20755019783973694,
43
+ 0.21395747363567352,
44
+ 0.20720559358596802,
45
+ 0.2488359808921814,
46
+ 0.2267460823059082,
47
+ 0.2283811867237091,
48
+ 0.2064915895462036,
49
+ 0.21840515732765198,
50
+ 0.20661449432373047,
51
+ 0.22264894843101501,
52
+ 0.20823489129543304,
53
+ 0.21716240048408508,
54
+ 0.18364380300045013,
55
+ 0.1748126745223999,
56
+ 0.20742008090019226,
57
+ 0.1701427400112152,
58
+ 0.17814505100250244,
59
+ 0.1915898323059082,
60
+ 0.2118266522884369,
61
+ 0.2002684473991394,
62
+ 0.20539897680282593,
63
+ 0.19456911087036133,
64
+ 0.1846393644809723,
65
+ 0.22991949319839478,
66
+ 0.24090014398097992,
67
+ 0.1669967770576477,
68
+ 0.2002880573272705,
69
+ 0.19123905897140503,
70
+ 0.19090206921100616,
71
+ 0.20155873894691467,
72
+ 0.187917560338974,
73
+ 0.20528344810009003,
74
+ 0.18759356439113617
75
+ ],
76
+ "train/q_mse": [
77
+ 0.05793036026812584
78
+ ],
79
+ "latent/reward_mse": 3.492172254482284e-05,
80
+ "eval/q_mse": 0.05793036026812584,
81
+ "eval/q_mae": 0.23773052804047787,
82
+ "eval/q_corr": 0.07948781752793167,
83
+ "eval/q_spearman": 0.08533443600767049,
84
+ "eval/q_mse_by_n": {
85
+ "1": 0.09512565332175407,
86
+ "2": 0.08388511346914757,
87
+ "4": 0.06447527291491785,
88
+ "8": 0.06367595947903232,
89
+ "16": 0.059387474398493616,
90
+ "32": 0.057744328526531954,
91
+ "64": 0.05741584154619247,
92
+ "128": 0.05834494982701078,
93
+ "256": 0.05779518197889028
94
+ },
95
+ "eval/q_corr_by_n": {
96
+ "1": -0.009039003390065904,
97
+ "2": 0.09248342893143635,
98
+ "4": 0.009978365452553872,
99
+ "8": 0.16447670988236304,
100
+ "16": 0.14018888300798776,
101
+ "32": 0.06812872585293074,
102
+ "64": 0.09095566774236519,
103
+ "128": 0.03979257628922054,
104
+ "256": 0.04134770628953202
105
+ },
106
+ "eval/q_mse_vs_N": [
107
+ 0.09512565332175407,
108
+ 0.08388511346914757,
109
+ 0.06447527291491785,
110
+ 0.06367595947903232,
111
+ 0.059387474398493616,
112
+ 0.057744328526531954,
113
+ 0.05741584154619247,
114
+ 0.05834494982701078,
115
+ 0.05779518197889028
116
+ ],
117
+ "eval/N_final": 256,
118
+ "eval/truth_std": 0.014050113983847026,
119
+ "wall_clock_s": 241.66425371170044,
120
+ "n_anchors": 200
121
+ }
gen_q_rsm/preliminary_analysis/experiments/visual_puzzle_3x3_play_v0/results/1/mc.json ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "method": "mc",
3
+ "env": "visual-puzzle-3x3-play-v0",
4
+ "seed": 1,
5
+ "wandb_url": null,
6
+ "representation": "puzzle_state_46d",
7
+ "reward": "dense",
8
+ "truth_kind": "fresh_rollout",
9
+ "anchor_protocol": "fresh_reset",
10
+ "train/loss": [
11
+ 0.33153998851776123,
12
+ 0.016061093658208847,
13
+ 0.017301592975854874,
14
+ 0.016898270696401596,
15
+ 0.01317935436964035,
16
+ 0.015605157241225243,
17
+ 0.015999682247638702,
18
+ 0.013921011239290237,
19
+ 0.013126138597726822,
20
+ 0.016829876229166985,
21
+ 0.01352191437035799,
22
+ 0.01486215740442276,
23
+ 0.015201425179839134,
24
+ 0.013477513566613197,
25
+ 0.012067161500453949,
26
+ 0.010814988985657692,
27
+ 0.013562566600739956,
28
+ 0.013427294790744781,
29
+ 0.01393778994679451,
30
+ 0.01043575070798397,
31
+ 0.01355486549437046,
32
+ 0.009328169748187065,
33
+ 0.009050591848790646,
34
+ 0.010213538073003292,
35
+ 0.00885345134884119,
36
+ 0.006860203109681606,
37
+ 0.01009971834719181,
38
+ 0.010200081393122673,
39
+ 0.007873302325606346,
40
+ 0.008852760307490826,
41
+ 0.008487625047564507,
42
+ 0.007925750687718391,
43
+ 0.006615819409489632,
44
+ 0.0068536484614014626,
45
+ 0.005707425065338612,
46
+ 0.00560744758695364,
47
+ 0.0063984571024775505,
48
+ 0.005186611320823431,
49
+ 0.005942762829363346,
50
+ 0.004300490487366915,
51
+ 0.005335991270840168,
52
+ 0.004683281295001507,
53
+ 0.00566362589597702,
54
+ 0.004111667163670063,
55
+ 0.004999744705855846,
56
+ 0.005114395171403885,
57
+ 0.0035127270966768265,
58
+ 0.00385737675242126,
59
+ 0.004656015429645777,
60
+ 0.003737775608897209,
61
+ 0.003998672589659691
62
+ ],
63
+ "train/q_mse": [
64
+ 0.33153998851776123,
65
+ 0.016061093658208847,
66
+ 0.017301592975854874,
67
+ 0.016898270696401596,
68
+ 0.01317935436964035,
69
+ 0.015605157241225243,
70
+ 0.015999682247638702,
71
+ 0.013921011239290237,
72
+ 0.013126138597726822,
73
+ 0.016829876229166985,
74
+ 0.01352191437035799,
75
+ 0.01486215740442276,
76
+ 0.015201425179839134,
77
+ 0.013477513566613197,
78
+ 0.012067161500453949,
79
+ 0.010814988985657692,
80
+ 0.013562566600739956,
81
+ 0.013427294790744781,
82
+ 0.01393778994679451,
83
+ 0.01043575070798397,
84
+ 0.01355486549437046,
85
+ 0.009328169748187065,
86
+ 0.009050591848790646,
87
+ 0.010213538073003292,
88
+ 0.00885345134884119,
89
+ 0.006860203109681606,
90
+ 0.01009971834719181,
91
+ 0.010200081393122673,
92
+ 0.007873302325606346,
93
+ 0.008852760307490826,
94
+ 0.008487625047564507,
95
+ 0.007925750687718391,
96
+ 0.006615819409489632,
97
+ 0.0068536484614014626,
98
+ 0.005707425065338612,
99
+ 0.00560744758695364,
100
+ 0.0063984571024775505,
101
+ 0.005186611320823431,
102
+ 0.005942762829363346,
103
+ 0.004300490487366915,
104
+ 0.005335991270840168,
105
+ 0.004683281295001507,
106
+ 0.00566362589597702,
107
+ 0.004111667163670063,
108
+ 0.004999744705855846,
109
+ 0.005114395171403885,
110
+ 0.0035127270966768265,
111
+ 0.00385737675242126,
112
+ 0.004656015429645777,
113
+ 0.003737775608897209,
114
+ 0.003998672589659691
115
+ ],
116
+ "eval/q_mse": 0.1666778275137994,
117
+ "eval/q_mae": 0.3882469346361848,
118
+ "eval/q_corr": -0.03360009612223268,
119
+ "eval/q_spearman": -0.046043760435793425,
120
+ "eval/truth_std": 0.014050113983847026,
121
+ "wall_clock_s": 84.53309535980225,
122
+ "n_anchors": 200
123
+ }
gen_q_rsm/preliminary_analysis/experiments/visual_puzzle_3x3_play_v0/results/1/td.json ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "method": "td",
3
+ "env": "visual-puzzle-3x3-play-v0",
4
+ "seed": 1,
5
+ "wandb_url": null,
6
+ "representation": "puzzle_state_46d",
7
+ "reward": "dense",
8
+ "truth_kind": "fresh_rollout",
9
+ "anchor_protocol": "fresh_reset",
10
+ "train/loss": [
11
+ 0.0012204032391309738,
12
+ 6.125352228991687e-06,
13
+ 5.217079888097942e-06,
14
+ 4.791495484823827e-06,
15
+ 3.2437026220577536e-06,
16
+ 3.5753496376855765e-06,
17
+ 4.218249159748666e-06,
18
+ 4.293704023439204e-06,
19
+ 3.894338078680448e-06,
20
+ 4.730663931695744e-06,
21
+ 4.639120561478194e-06,
22
+ 3.2838054266903782e-06,
23
+ 3.957793978770496e-06,
24
+ 6.253728770388989e-06,
25
+ 3.5554949135985225e-06,
26
+ 4.4017469917889684e-06,
27
+ 3.6687652027467266e-06,
28
+ 3.864938662445638e-06,
29
+ 4.212437033856986e-06,
30
+ 4.194202574581141e-06,
31
+ 3.5583732369559584e-06,
32
+ 3.567800831660861e-06,
33
+ 3.91760841012001e-06,
34
+ 4.5055608097754885e-06,
35
+ 3.901361196767539e-06,
36
+ 4.029919637105195e-06,
37
+ 3.964070401707431e-06,
38
+ 3.7007548598921858e-06,
39
+ 4.193703716737218e-06,
40
+ 4.805036041943822e-06,
41
+ 3.574690708774142e-06,
42
+ 4.073217496625148e-06,
43
+ 6.4449277488165535e-06,
44
+ 5.942266398051288e-06,
45
+ 3.554948307282757e-06,
46
+ 4.008534233435057e-06,
47
+ 4.516137778409757e-06,
48
+ 3.960966751037631e-06,
49
+ 3.709805696416879e-06,
50
+ 3.565084398360341e-06,
51
+ 5.899311872781254e-06,
52
+ 3.450305939622922e-06,
53
+ 3.187440142937703e-06,
54
+ 4.070351678819861e-06,
55
+ 2.9936820737930248e-06,
56
+ 3.9672340790275484e-06,
57
+ 2.9289030862855725e-06,
58
+ 3.862484845740255e-06,
59
+ 4.573448677547276e-06,
60
+ 3.3329736197629245e-06,
61
+ 3.6034641652804567e-06
62
+ ],
63
+ "train/q_mse": [
64
+ 0.0012204032391309738,
65
+ 6.125352228991687e-06,
66
+ 5.217079888097942e-06,
67
+ 4.791495484823827e-06,
68
+ 3.2437026220577536e-06,
69
+ 3.5753496376855765e-06,
70
+ 4.218249159748666e-06,
71
+ 4.293704023439204e-06,
72
+ 3.894338078680448e-06,
73
+ 4.730663931695744e-06,
74
+ 4.639120561478194e-06,
75
+ 3.2838054266903782e-06,
76
+ 3.957793978770496e-06,
77
+ 6.253728770388989e-06,
78
+ 3.5554949135985225e-06,
79
+ 4.4017469917889684e-06,
80
+ 3.6687652027467266e-06,
81
+ 3.864938662445638e-06,
82
+ 4.212437033856986e-06,
83
+ 4.194202574581141e-06,
84
+ 3.5583732369559584e-06,
85
+ 3.567800831660861e-06,
86
+ 3.91760841012001e-06,
87
+ 4.5055608097754885e-06,
88
+ 3.901361196767539e-06,
89
+ 4.029919637105195e-06,
90
+ 3.964070401707431e-06,
91
+ 3.7007548598921858e-06,
92
+ 4.193703716737218e-06,
93
+ 4.805036041943822e-06,
94
+ 3.574690708774142e-06,
95
+ 4.073217496625148e-06,
96
+ 6.4449277488165535e-06,
97
+ 5.942266398051288e-06,
98
+ 3.554948307282757e-06,
99
+ 4.008534233435057e-06,
100
+ 4.516137778409757e-06,
101
+ 3.960966751037631e-06,
102
+ 3.709805696416879e-06,
103
+ 3.565084398360341e-06,
104
+ 5.899311872781254e-06,
105
+ 3.450305939622922e-06,
106
+ 3.187440142937703e-06,
107
+ 4.070351678819861e-06,
108
+ 2.9936820737930248e-06,
109
+ 3.9672340790275484e-06,
110
+ 2.9289030862855725e-06,
111
+ 3.862484845740255e-06,
112
+ 4.573448677547276e-06,
113
+ 3.3329736197629245e-06,
114
+ 3.6034641652804567e-06
115
+ ],
116
+ "eval/q_mse": 0.189145102131425,
117
+ "eval/q_mae": 0.43468024216468065,
118
+ "eval/q_corr": 0.08796130859680275,
119
+ "eval/q_spearman": 0.10375194018198786,
120
+ "eval/truth_std": 0.014050113983847026,
121
+ "wall_clock_s": 176.03912734985352,
122
+ "n_anchors": 200
123
+ }
gen_q_rsm/preliminary_analysis/experiments/visual_puzzle_3x3_play_v0/results/2/genq.json ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "method": "genq_reward_latent",
3
+ "env": "visual-puzzle-3x3-play-v0",
4
+ "seed": 2,
5
+ "wandb_url": null,
6
+ "representation": "image_reward_predictive_latent",
7
+ "occ_model": "diffusion",
8
+ "z_dim": 8,
9
+ "reward": "dense",
10
+ "truth_kind": "fresh_rollout",
11
+ "anchor_protocol": "fresh_reset",
12
+ "gen_sample_counts": [
13
+ 1,
14
+ 2,
15
+ 4,
16
+ 8,
17
+ 16,
18
+ 32,
19
+ 64,
20
+ 128,
21
+ 256
22
+ ],
23
+ "train/loss": [
24
+ 1.0270042419433594,
25
+ 0.4926109313964844,
26
+ 0.25451451539993286,
27
+ 0.24574831128120422,
28
+ 0.2283048927783966,
29
+ 0.20877614617347717,
30
+ 0.2705289125442505,
31
+ 0.2481229305267334,
32
+ 0.2179751694202423,
33
+ 0.2228512316942215,
34
+ 0.18179479241371155,
35
+ 0.24287348985671997,
36
+ 0.2439499795436859,
37
+ 0.2246687263250351,
38
+ 0.23155605792999268,
39
+ 0.20789775252342224,
40
+ 0.23746022582054138,
41
+ 0.17210029065608978,
42
+ 0.19767284393310547,
43
+ 0.1915525197982788,
44
+ 0.20987069606781006,
45
+ 0.18757885694503784,
46
+ 0.22028657793998718,
47
+ 0.20491041243076324,
48
+ 0.2406948208808899,
49
+ 0.17528264224529266,
50
+ 0.17716437578201294,
51
+ 0.21971076726913452,
52
+ 0.23385220766067505,
53
+ 0.21838140487670898,
54
+ 0.20587867498397827,
55
+ 0.20277276635169983,
56
+ 0.19320036470890045,
57
+ 0.209520161151886,
58
+ 0.2010309249162674,
59
+ 0.18754874169826508,
60
+ 0.20517519116401672,
61
+ 0.1789780706167221,
62
+ 0.19141335785388947,
63
+ 0.1696317493915558,
64
+ 0.21181648969650269,
65
+ 0.20939485728740692,
66
+ 0.14459873735904694,
67
+ 0.2180784046649933,
68
+ 0.21029719710350037,
69
+ 0.18462111055850983,
70
+ 0.1691209077835083,
71
+ 0.15534928441047668,
72
+ 0.22393280267715454,
73
+ 0.188382089138031,
74
+ 0.1731264293193817
75
+ ],
76
+ "train/q_mse": [
77
+ 0.05786949887487825
78
+ ],
79
+ "latent/reward_mse": 2.9891922167735174e-05,
80
+ "eval/q_mse": 0.05786949887487825,
81
+ "eval/q_mae": 0.2373290019754777,
82
+ "eval/q_corr": 0.01914517078675529,
83
+ "eval/q_spearman": 0.031309757096339534,
84
+ "eval/q_mse_by_n": {
85
+ "1": 0.09020440271734823,
86
+ "2": 0.08067756407134383,
87
+ "4": 0.06299363260594396,
88
+ "8": 0.06765017370959912,
89
+ "16": 0.06134006430543755,
90
+ "32": 0.06051339577774429,
91
+ "64": 0.05766905909917022,
92
+ "128": 0.05903817699298815,
93
+ "256": 0.05837154201006975
94
+ },
95
+ "eval/q_corr_by_n": {
96
+ "1": -0.005713607682170413,
97
+ "2": -0.07272741581351423,
98
+ "4": 0.03221002397828272,
99
+ "8": -0.11647711909730074,
100
+ "16": -0.06127867419748186,
101
+ "32": 0.07472428029086302,
102
+ "64": 0.00941746659748049,
103
+ "128": -0.01715974434839922,
104
+ "256": 0.04954112923775513
105
+ },
106
+ "eval/q_mse_vs_N": [
107
+ 0.09020440271734823,
108
+ 0.08067756407134383,
109
+ 0.06299363260594396,
110
+ 0.06765017370959912,
111
+ 0.06134006430543755,
112
+ 0.06051339577774429,
113
+ 0.05766905909917022,
114
+ 0.05903817699298815,
115
+ 0.05837154201006975
116
+ ],
117
+ "eval/N_final": 256,
118
+ "eval/truth_std": 0.011446896413730248,
119
+ "wall_clock_s": 214.33634328842163,
120
+ "n_anchors": 200
121
+ }
gen_q_rsm/preliminary_analysis/experiments/visual_puzzle_3x3_play_v0/results/2/mc.json ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "method": "mc",
3
+ "env": "visual-puzzle-3x3-play-v0",
4
+ "seed": 2,
5
+ "wandb_url": null,
6
+ "representation": "puzzle_state_46d",
7
+ "reward": "dense",
8
+ "truth_kind": "fresh_rollout",
9
+ "anchor_protocol": "fresh_reset",
10
+ "train/loss": [
11
+ 0.40898996591567993,
12
+ 0.015920303761959076,
13
+ 0.014010515064001083,
14
+ 0.013672862201929092,
15
+ 0.017288688570261,
16
+ 0.015668045729398727,
17
+ 0.01285402849316597,
18
+ 0.014039140194654465,
19
+ 0.014095981605350971,
20
+ 0.016332391649484634,
21
+ 0.016876138746738434,
22
+ 0.01484333910048008,
23
+ 0.013885890133678913,
24
+ 0.011035697534680367,
25
+ 0.012117761187255383,
26
+ 0.010388154536485672,
27
+ 0.011715492233633995,
28
+ 0.013304205611348152,
29
+ 0.010947076603770256,
30
+ 0.01304270327091217,
31
+ 0.010827884078025818,
32
+ 0.013813907280564308,
33
+ 0.010653816163539886,
34
+ 0.007922614924609661,
35
+ 0.009903037920594215,
36
+ 0.010088683106005192,
37
+ 0.009109705686569214,
38
+ 0.009340403601527214,
39
+ 0.008670229464769363,
40
+ 0.008110998198390007,
41
+ 0.008070522919297218,
42
+ 0.007171010598540306,
43
+ 0.007696999236941338,
44
+ 0.0073455688543617725,
45
+ 0.007664284203201532,
46
+ 0.006526111159473658,
47
+ 0.005847295746207237,
48
+ 0.0065309698693454266,
49
+ 0.00772154051810503,
50
+ 0.005802817642688751,
51
+ 0.005282590165734291,
52
+ 0.005653972737491131,
53
+ 0.005036684684455395,
54
+ 0.0042710937559604645,
55
+ 0.004249030724167824,
56
+ 0.0037705216091126204,
57
+ 0.0037338915280997753,
58
+ 0.004787066485732794,
59
+ 0.004263255745172501,
60
+ 0.004285373724997044,
61
+ 0.003377311397343874
62
+ ],
63
+ "train/q_mse": [
64
+ 0.40898996591567993,
65
+ 0.015920303761959076,
66
+ 0.014010515064001083,
67
+ 0.013672862201929092,
68
+ 0.017288688570261,
69
+ 0.015668045729398727,
70
+ 0.01285402849316597,
71
+ 0.014039140194654465,
72
+ 0.014095981605350971,
73
+ 0.016332391649484634,
74
+ 0.016876138746738434,
75
+ 0.01484333910048008,
76
+ 0.013885890133678913,
77
+ 0.011035697534680367,
78
+ 0.012117761187255383,
79
+ 0.010388154536485672,
80
+ 0.011715492233633995,
81
+ 0.013304205611348152,
82
+ 0.010947076603770256,
83
+ 0.01304270327091217,
84
+ 0.010827884078025818,
85
+ 0.013813907280564308,
86
+ 0.010653816163539886,
87
+ 0.007922614924609661,
88
+ 0.009903037920594215,
89
+ 0.010088683106005192,
90
+ 0.009109705686569214,
91
+ 0.009340403601527214,
92
+ 0.008670229464769363,
93
+ 0.008110998198390007,
94
+ 0.008070522919297218,
95
+ 0.007171010598540306,
96
+ 0.007696999236941338,
97
+ 0.0073455688543617725,
98
+ 0.007664284203201532,
99
+ 0.006526111159473658,
100
+ 0.005847295746207237,
101
+ 0.0065309698693454266,
102
+ 0.00772154051810503,
103
+ 0.005802817642688751,
104
+ 0.005282590165734291,
105
+ 0.005653972737491131,
106
+ 0.005036684684455395,
107
+ 0.0042710937559604645,
108
+ 0.004249030724167824,
109
+ 0.0037705216091126204,
110
+ 0.0037338915280997753,
111
+ 0.004787066485732794,
112
+ 0.004263255745172501,
113
+ 0.004285373724997044,
114
+ 0.003377311397343874
115
+ ],
116
+ "eval/q_mse": 0.18494481683358927,
117
+ "eval/q_mae": 0.40741203380782176,
118
+ "eval/q_corr": -0.00558418397262717,
119
+ "eval/q_spearman": -0.001841750417431737,
120
+ "eval/truth_std": 0.011446896413730248,
121
+ "wall_clock_s": 49.77327489852905,
122
+ "n_anchors": 200
123
+ }
gen_q_rsm/preliminary_analysis/experiments/visual_puzzle_3x3_play_v0/results/2/td.json ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "method": "td",
3
+ "env": "visual-puzzle-3x3-play-v0",
4
+ "seed": 2,
5
+ "wandb_url": null,
6
+ "representation": "puzzle_state_46d",
7
+ "reward": "dense",
8
+ "truth_kind": "fresh_rollout",
9
+ "anchor_protocol": "fresh_reset",
10
+ "train/loss": [
11
+ 0.0009117407607845962,
12
+ 5.4393603932112455e-06,
13
+ 4.474584784475155e-06,
14
+ 4.81739289170946e-06,
15
+ 4.826188160222955e-06,
16
+ 5.254487405181862e-06,
17
+ 5.732536010327749e-06,
18
+ 4.0249865378427785e-06,
19
+ 4.44261240772903e-06,
20
+ 4.8801621232996695e-06,
21
+ 4.367894689494278e-06,
22
+ 8.360007996088825e-06,
23
+ 4.803511728823651e-06,
24
+ 4.238138444634387e-06,
25
+ 5.181236701901071e-06,
26
+ 3.949918209400494e-06,
27
+ 4.308625193516491e-06,
28
+ 3.623529892138322e-06,
29
+ 3.5488419598550536e-06,
30
+ 3.957788067054935e-06,
31
+ 3.946439392166212e-06,
32
+ 4.449716016097227e-06,
33
+ 3.952579845645232e-06,
34
+ 4.324317615100881e-06,
35
+ 4.5290798880159855e-06,
36
+ 3.1656122700951528e-06,
37
+ 5.1037868615821935e-06,
38
+ 4.201405317871831e-06,
39
+ 8.674192940816283e-06,
40
+ 4.629396244126838e-06,
41
+ 4.312078090151772e-06,
42
+ 3.1061936169862747e-06,
43
+ 3.6707233448396437e-06,
44
+ 4.410880592331523e-06,
45
+ 3.857937826978741e-06,
46
+ 5.9873386817344e-06,
47
+ 5.843794497195631e-06,
48
+ 3.567578687579953e-06,
49
+ 5.250517460808624e-06,
50
+ 4.246754542691633e-06,
51
+ 7.172588993853424e-06,
52
+ 7.115767857612809e-06,
53
+ 3.6871113024972146e-06,
54
+ 3.488460151856998e-06,
55
+ 3.4000220239249757e-06,
56
+ 5.6668345678190235e-06,
57
+ 3.277311861893395e-06,
58
+ 3.5255882266937988e-06,
59
+ 4.133057245780947e-06,
60
+ 4.664694642997347e-06,
61
+ 3.9704059417999815e-06
62
+ ],
63
+ "train/q_mse": [
64
+ 0.0009117407607845962,
65
+ 5.4393603932112455e-06,
66
+ 4.474584784475155e-06,
67
+ 4.81739289170946e-06,
68
+ 4.826188160222955e-06,
69
+ 5.254487405181862e-06,
70
+ 5.732536010327749e-06,
71
+ 4.0249865378427785e-06,
72
+ 4.44261240772903e-06,
73
+ 4.8801621232996695e-06,
74
+ 4.367894689494278e-06,
75
+ 8.360007996088825e-06,
76
+ 4.803511728823651e-06,
77
+ 4.238138444634387e-06,
78
+ 5.181236701901071e-06,
79
+ 3.949918209400494e-06,
80
+ 4.308625193516491e-06,
81
+ 3.623529892138322e-06,
82
+ 3.5488419598550536e-06,
83
+ 3.957788067054935e-06,
84
+ 3.946439392166212e-06,
85
+ 4.449716016097227e-06,
86
+ 3.952579845645232e-06,
87
+ 4.324317615100881e-06,
88
+ 4.5290798880159855e-06,
89
+ 3.1656122700951528e-06,
90
+ 5.1037868615821935e-06,
91
+ 4.201405317871831e-06,
92
+ 8.674192940816283e-06,
93
+ 4.629396244126838e-06,
94
+ 4.312078090151772e-06,
95
+ 3.1061936169862747e-06,
96
+ 3.6707233448396437e-06,
97
+ 4.410880592331523e-06,
98
+ 3.857937826978741e-06,
99
+ 5.9873386817344e-06,
100
+ 5.843794497195631e-06,
101
+ 3.567578687579953e-06,
102
+ 5.250517460808624e-06,
103
+ 4.246754542691633e-06,
104
+ 7.172588993853424e-06,
105
+ 7.115767857612809e-06,
106
+ 3.6871113024972146e-06,
107
+ 3.488460151856998e-06,
108
+ 3.4000220239249757e-06,
109
+ 5.6668345678190235e-06,
110
+ 3.277311861893395e-06,
111
+ 3.5255882266937988e-06,
112
+ 4.133057245780947e-06,
113
+ 4.664694642997347e-06,
114
+ 3.9704059417999815e-06
115
+ ],
116
+ "eval/q_mse": 0.1951895251679614,
117
+ "eval/q_mae": 0.44165005798381674,
118
+ "eval/q_corr": 0.07182346057517712,
119
+ "eval/q_spearman": 0.08533443600767049,
120
+ "eval/truth_std": 0.011446896413730248,
121
+ "wall_clock_s": 118.18665862083435,
122
+ "n_anchors": 200
123
+ }
gen_q_rsm/preliminary_analysis/experiments/visual_puzzle_3x3_play_v0/results/3/genq.json ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "method": "genq_reward_latent",
3
+ "env": "visual-puzzle-3x3-play-v0",
4
+ "seed": 3,
5
+ "wandb_url": null,
6
+ "representation": "image_reward_predictive_latent",
7
+ "occ_model": "diffusion",
8
+ "z_dim": 8,
9
+ "reward": "dense",
10
+ "truth_kind": "fresh_rollout",
11
+ "anchor_protocol": "fresh_reset",
12
+ "gen_sample_counts": [
13
+ 1,
14
+ 2,
15
+ 4,
16
+ 8,
17
+ 16,
18
+ 32,
19
+ 64,
20
+ 128,
21
+ 256
22
+ ],
23
+ "train/loss": [
24
+ 0.9782455563545227,
25
+ 0.44427141547203064,
26
+ 0.2513529062271118,
27
+ 0.25645506381988525,
28
+ 0.25300535559654236,
29
+ 0.22159214317798615,
30
+ 0.24054694175720215,
31
+ 0.24258647859096527,
32
+ 0.21553190052509308,
33
+ 0.22055687010288239,
34
+ 0.23031868040561676,
35
+ 0.1973576545715332,
36
+ 0.2200295776128769,
37
+ 0.17224003374576569,
38
+ 0.24014726281166077,
39
+ 0.2027468979358673,
40
+ 0.23267236351966858,
41
+ 0.2181975543498993,
42
+ 0.22526872158050537,
43
+ 0.20029038190841675,
44
+ 0.1863209307193756,
45
+ 0.19829438626766205,
46
+ 0.22926747798919678,
47
+ 0.18782304227352142,
48
+ 0.19903340935707092,
49
+ 0.21145157516002655,
50
+ 0.20335812866687775,
51
+ 0.21936026215553284,
52
+ 0.19507180154323578,
53
+ 0.161751389503479,
54
+ 0.20948335528373718,
55
+ 0.16540610790252686,
56
+ 0.17502406239509583,
57
+ 0.227451354265213,
58
+ 0.18766430020332336,
59
+ 0.21271398663520813,
60
+ 0.18983983993530273,
61
+ 0.21147474646568298,
62
+ 0.20223787426948547,
63
+ 0.17084136605262756,
64
+ 0.18709564208984375,
65
+ 0.181624636054039,
66
+ 0.19940930604934692,
67
+ 0.18329596519470215,
68
+ 0.2112322747707367,
69
+ 0.1833573281764984,
70
+ 0.17285016179084778,
71
+ 0.17316660284996033,
72
+ 0.20006756484508514,
73
+ 0.18272365629673004,
74
+ 0.19811692833900452
75
+ ],
76
+ "train/q_mse": [
77
+ 0.05627379084375046
78
+ ],
79
+ "latent/reward_mse": 2.1702486264985055e-05,
80
+ "eval/q_mse": 0.05627379084375046,
81
+ "eval/q_mae": 0.23506933954390952,
82
+ "eval/q_corr": 0.050921992630317124,
83
+ "eval/q_spearman": 0.07428393350308007,
84
+ "eval/q_mse_by_n": {
85
+ "1": 0.0890390743371805,
86
+ "2": 0.06560755607663402,
87
+ "4": 0.06144249002532289,
88
+ "8": 0.055597929424343696,
89
+ "16": 0.06065228176157518,
90
+ "32": 0.0582575657367786,
91
+ "64": 0.05718524699761326,
92
+ "128": 0.05662805287235198,
93
+ "256": 0.057369118352628055
94
+ },
95
+ "eval/q_corr_by_n": {
96
+ "1": 0.08379193345611254,
97
+ "2": -0.029921736963810452,
98
+ "4": -0.007816767436413236,
99
+ "8": -0.06402912864250075,
100
+ "16": -0.017607984206427386,
101
+ "32": 0.01195957887538429,
102
+ "64": -0.11360552681113051,
103
+ "128": 0.04791701715106784,
104
+ "256": 0.04951509644648982
105
+ },
106
+ "eval/q_mse_vs_N": [
107
+ 0.0890390743371805,
108
+ 0.06560755607663402,
109
+ 0.06144249002532289,
110
+ 0.055597929424343696,
111
+ 0.06065228176157518,
112
+ 0.0582575657367786,
113
+ 0.05718524699761326,
114
+ 0.05662805287235198,
115
+ 0.057369118352628055
116
+ ],
117
+ "eval/N_final": 256,
118
+ "eval/truth_std": 0.01145595607353215,
119
+ "wall_clock_s": 208.27379155158997,
120
+ "n_anchors": 200
121
+ }
gen_q_rsm/preliminary_analysis/experiments/visual_puzzle_3x3_play_v0/results/3/mc.json ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "method": "mc",
3
+ "env": "visual-puzzle-3x3-play-v0",
4
+ "seed": 3,
5
+ "wandb_url": null,
6
+ "representation": "puzzle_state_46d",
7
+ "reward": "dense",
8
+ "truth_kind": "fresh_rollout",
9
+ "anchor_protocol": "fresh_reset",
10
+ "train/loss": [
11
+ 0.32887721061706543,
12
+ 0.0184823889285326,
13
+ 0.016251366585493088,
14
+ 0.015726014971733093,
15
+ 0.016073077917099,
16
+ 0.015450923703610897,
17
+ 0.01689937710762024,
18
+ 0.01215272769331932,
19
+ 0.014407731592655182,
20
+ 0.017734870314598083,
21
+ 0.01689053326845169,
22
+ 0.01443566009402275,
23
+ 0.014742393977940083,
24
+ 0.014288846403360367,
25
+ 0.015843406319618225,
26
+ 0.012200770899653435,
27
+ 0.013554404489696026,
28
+ 0.011608617380261421,
29
+ 0.01359566766768694,
30
+ 0.011341533623635769,
31
+ 0.010478483512997627,
32
+ 0.01161889173090458,
33
+ 0.010681595653295517,
34
+ 0.00920659489929676,
35
+ 0.008972404524683952,
36
+ 0.010758858174085617,
37
+ 0.010782594792544842,
38
+ 0.006825141608715057,
39
+ 0.008270544931292534,
40
+ 0.007726939860731363,
41
+ 0.007580457255244255,
42
+ 0.007060015574097633,
43
+ 0.008039627224206924,
44
+ 0.0065657468512654305,
45
+ 0.00760623486712575,
46
+ 0.0070298947393894196,
47
+ 0.005899860057979822,
48
+ 0.0057176207192242146,
49
+ 0.005949524696916342,
50
+ 0.005750499665737152,
51
+ 0.0046784947626292706,
52
+ 0.004173046909272671,
53
+ 0.003770597046241164,
54
+ 0.004624794237315655,
55
+ 0.00455064419656992,
56
+ 0.004738840274512768,
57
+ 0.004517941270023584,
58
+ 0.0044085122644901276,
59
+ 0.004201848059892654,
60
+ 0.003777845995500684,
61
+ 0.0032655836548656225
62
+ ],
63
+ "train/q_mse": [
64
+ 0.32887721061706543,
65
+ 0.0184823889285326,
66
+ 0.016251366585493088,
67
+ 0.015726014971733093,
68
+ 0.016073077917099,
69
+ 0.015450923703610897,
70
+ 0.01689937710762024,
71
+ 0.01215272769331932,
72
+ 0.014407731592655182,
73
+ 0.017734870314598083,
74
+ 0.01689053326845169,
75
+ 0.01443566009402275,
76
+ 0.014742393977940083,
77
+ 0.014288846403360367,
78
+ 0.015843406319618225,
79
+ 0.012200770899653435,
80
+ 0.013554404489696026,
81
+ 0.011608617380261421,
82
+ 0.01359566766768694,
83
+ 0.011341533623635769,
84
+ 0.010478483512997627,
85
+ 0.01161889173090458,
86
+ 0.010681595653295517,
87
+ 0.00920659489929676,
88
+ 0.008972404524683952,
89
+ 0.010758858174085617,
90
+ 0.010782594792544842,
91
+ 0.006825141608715057,
92
+ 0.008270544931292534,
93
+ 0.007726939860731363,
94
+ 0.007580457255244255,
95
+ 0.007060015574097633,
96
+ 0.008039627224206924,
97
+ 0.0065657468512654305,
98
+ 0.00760623486712575,
99
+ 0.0070298947393894196,
100
+ 0.005899860057979822,
101
+ 0.0057176207192242146,
102
+ 0.005949524696916342,
103
+ 0.005750499665737152,
104
+ 0.0046784947626292706,
105
+ 0.004173046909272671,
106
+ 0.003770597046241164,
107
+ 0.004624794237315655,
108
+ 0.00455064419656992,
109
+ 0.004738840274512768,
110
+ 0.004517941270023584,
111
+ 0.0044085122644901276,
112
+ 0.004201848059892654,
113
+ 0.003777845995500684,
114
+ 0.0032655836548656225
115
+ ],
116
+ "eval/q_mse": 0.16179320176005468,
117
+ "eval/q_mae": 0.38252232596642183,
118
+ "eval/q_corr": 0.03019245794959327,
119
+ "eval/q_spearman": 0.047271594047414586,
120
+ "eval/truth_std": 0.01145595607353215,
121
+ "wall_clock_s": 50.29546141624451,
122
+ "n_anchors": 200
123
+ }
gen_q_rsm/preliminary_analysis/experiments/visual_puzzle_3x3_play_v0/results/3/td.json ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "method": "td",
3
+ "env": "visual-puzzle-3x3-play-v0",
4
+ "seed": 3,
5
+ "wandb_url": null,
6
+ "representation": "puzzle_state_46d",
7
+ "reward": "dense",
8
+ "truth_kind": "fresh_rollout",
9
+ "anchor_protocol": "fresh_reset",
10
+ "train/loss": [
11
+ 0.002337625715881586,
12
+ 5.740203505411046e-06,
13
+ 4.30700356446323e-06,
14
+ 5.171712473384105e-06,
15
+ 5.102906470710877e-06,
16
+ 4.104509116586996e-06,
17
+ 5.143627276993357e-06,
18
+ 4.495537268667249e-06,
19
+ 4.2764086174429394e-06,
20
+ 4.64982485937071e-06,
21
+ 3.9826500142225996e-06,
22
+ 5.766546109953197e-06,
23
+ 5.146061994310003e-06,
24
+ 3.4094923648808617e-06,
25
+ 4.137223186262418e-06,
26
+ 4.748269020637963e-06,
27
+ 3.421435849304544e-06,
28
+ 4.680872280005133e-06,
29
+ 5.169044925423805e-06,
30
+ 5.0218741307617165e-06,
31
+ 3.403627033549128e-06,
32
+ 7.118766916391905e-06,
33
+ 3.8282214518403634e-06,
34
+ 3.5068019315076526e-06,
35
+ 4.453886504052207e-06,
36
+ 4.005321443401044e-06,
37
+ 3.963611561630387e-06,
38
+ 3.5469520298647694e-06,
39
+ 3.3036731110769324e-06,
40
+ 8.62198976392392e-06,
41
+ 3.7550055367319146e-06,
42
+ 4.1472167140454985e-06,
43
+ 5.99345867158263e-06,
44
+ 3.56340137841471e-06,
45
+ 6.240554284886457e-06,
46
+ 4.807648110727314e-06,
47
+ 5.522140781977214e-06,
48
+ 4.200266175757861e-06,
49
+ 4.711405381385703e-06,
50
+ 5.466799848363735e-06,
51
+ 3.907559403160121e-06,
52
+ 3.46969591191737e-06,
53
+ 3.7734655506937997e-06,
54
+ 4.850208370044129e-06,
55
+ 3.5566936276154593e-06,
56
+ 4.298575731809251e-06,
57
+ 3.6074325180379674e-06,
58
+ 3.9186616049846634e-06,
59
+ 4.085369255335536e-06,
60
+ 6.069251412554877e-06,
61
+ 3.325084662719746e-06
62
+ ],
63
+ "train/q_mse": [
64
+ 0.002337625715881586,
65
+ 5.740203505411046e-06,
66
+ 4.30700356446323e-06,
67
+ 5.171712473384105e-06,
68
+ 5.102906470710877e-06,
69
+ 4.104509116586996e-06,
70
+ 5.143627276993357e-06,
71
+ 4.495537268667249e-06,
72
+ 4.2764086174429394e-06,
73
+ 4.64982485937071e-06,
74
+ 3.9826500142225996e-06,
75
+ 5.766546109953197e-06,
76
+ 5.146061994310003e-06,
77
+ 3.4094923648808617e-06,
78
+ 4.137223186262418e-06,
79
+ 4.748269020637963e-06,
80
+ 3.421435849304544e-06,
81
+ 4.680872280005133e-06,
82
+ 5.169044925423805e-06,
83
+ 5.0218741307617165e-06,
84
+ 3.403627033549128e-06,
85
+ 7.118766916391905e-06,
86
+ 3.8282214518403634e-06,
87
+ 3.5068019315076526e-06,
88
+ 4.453886504052207e-06,
89
+ 4.005321443401044e-06,
90
+ 3.963611561630387e-06,
91
+ 3.5469520298647694e-06,
92
+ 3.3036731110769324e-06,
93
+ 8.62198976392392e-06,
94
+ 3.7550055367319146e-06,
95
+ 4.1472167140454985e-06,
96
+ 5.99345867158263e-06,
97
+ 3.56340137841471e-06,
98
+ 6.240554284886457e-06,
99
+ 4.807648110727314e-06,
100
+ 5.522140781977214e-06,
101
+ 4.200266175757861e-06,
102
+ 4.711405381385703e-06,
103
+ 5.466799848363735e-06,
104
+ 3.907559403160121e-06,
105
+ 3.46969591191737e-06,
106
+ 3.7734655506937997e-06,
107
+ 4.850208370044129e-06,
108
+ 3.5566936276154593e-06,
109
+ 4.298575731809251e-06,
110
+ 3.6074325180379674e-06,
111
+ 3.9186616049846634e-06,
112
+ 4.085369255335536e-06,
113
+ 6.069251412554877e-06,
114
+ 3.325084662719746e-06
115
+ ],
116
+ "eval/q_mse": 0.18596360105044027,
117
+ "eval/q_mae": 0.4310753625336595,
118
+ "eval/q_corr": -0.03173402573719374,
119
+ "eval/q_spearman": -0.03990459237768764,
120
+ "eval/truth_std": 0.01145595607353215,
121
+ "wall_clock_s": 120.29559874534607,
122
+ "n_anchors": 200
123
+ }
gen_q_rsm/preliminary_analysis/experiments/visual_puzzle_3x3_play_v0/results/4/genq.json ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "method": "genq_reward_latent",
3
+ "env": "visual-puzzle-3x3-play-v0",
4
+ "seed": 4,
5
+ "wandb_url": null,
6
+ "representation": "image_reward_predictive_latent",
7
+ "occ_model": "diffusion",
8
+ "z_dim": 8,
9
+ "reward": "dense",
10
+ "truth_kind": "fresh_rollout",
11
+ "anchor_protocol": "fresh_reset",
12
+ "gen_sample_counts": [
13
+ 1,
14
+ 2,
15
+ 4,
16
+ 8,
17
+ 16,
18
+ 32,
19
+ 64,
20
+ 128,
21
+ 256
22
+ ],
23
+ "train/loss": [
24
+ 1.019892930984497,
25
+ 0.4248729646205902,
26
+ 0.24708840250968933,
27
+ 0.2582969665527344,
28
+ 0.22500845789909363,
29
+ 0.2464507818222046,
30
+ 0.21035492420196533,
31
+ 0.23091760277748108,
32
+ 0.21091020107269287,
33
+ 0.22798123955726624,
34
+ 0.22061222791671753,
35
+ 0.23976722359657288,
36
+ 0.23086977005004883,
37
+ 0.19707626104354858,
38
+ 0.22658410668373108,
39
+ 0.21895770728588104,
40
+ 0.2098456770181656,
41
+ 0.23431675136089325,
42
+ 0.2306627482175827,
43
+ 0.17886599898338318,
44
+ 0.21544533967971802,
45
+ 0.21031345427036285,
46
+ 0.19956238567829132,
47
+ 0.2020793855190277,
48
+ 0.22815555334091187,
49
+ 0.22237959504127502,
50
+ 0.18172472715377808,
51
+ 0.2112666368484497,
52
+ 0.2072489857673645,
53
+ 0.1945192962884903,
54
+ 0.20812903344631195,
55
+ 0.2288488745689392,
56
+ 0.19235049188137054,
57
+ 0.21484673023223877,
58
+ 0.19197353720664978,
59
+ 0.24012184143066406,
60
+ 0.19207161664962769,
61
+ 0.20557308197021484,
62
+ 0.1931607574224472,
63
+ 0.18545930087566376,
64
+ 0.21581211686134338,
65
+ 0.2206421196460724,
66
+ 0.2071656733751297,
67
+ 0.18323364853858948,
68
+ 0.2132566273212433,
69
+ 0.20354220271110535,
70
+ 0.19931909441947937,
71
+ 0.2050253450870514,
72
+ 0.20356571674346924,
73
+ 0.2419741153717041,
74
+ 0.17199712991714478
75
+ ],
76
+ "train/q_mse": [
77
+ 0.05085395739655462
78
+ ],
79
+ "latent/reward_mse": 2.5474451831541955e-05,
80
+ "eval/q_mse": 0.05085395739655462,
81
+ "eval/q_mae": 0.22185915743218212,
82
+ "eval/q_corr": -0.07876983680106972,
83
+ "eval/q_spearman": -0.09270143767739743,
84
+ "eval/q_mse_by_n": {
85
+ "1": 0.07356545741001524,
86
+ "2": 0.06689598549545636,
87
+ "4": 0.06212354072828871,
88
+ "8": 0.05356314045762392,
89
+ "16": 0.051019222542325,
90
+ "32": 0.051775144911726176,
91
+ "64": 0.05168495096245526,
92
+ "128": 0.05030355230130683,
93
+ "256": 0.05120412134205859
94
+ },
95
+ "eval/q_corr_by_n": {
96
+ "1": -0.03533544947859579,
97
+ "2": 0.028833294246466093,
98
+ "4": -0.05981882305186983,
99
+ "8": -0.022338602362678286,
100
+ "16": -0.08931320993877863,
101
+ "32": -0.00946746217080926,
102
+ "64": -0.12481975146034914,
103
+ "128": -0.04517909642739885,
104
+ "256": -0.07561273191550247
105
+ },
106
+ "eval/q_mse_vs_N": [
107
+ 0.07356545741001524,
108
+ 0.06689598549545636,
109
+ 0.06212354072828871,
110
+ 0.05356314045762392,
111
+ 0.051019222542325,
112
+ 0.051775144911726176,
113
+ 0.05168495096245526,
114
+ 0.05030355230130683,
115
+ 0.05120412134205859
116
+ ],
117
+ "eval/N_final": 256,
118
+ "eval/truth_std": 0.012477610209021018,
119
+ "wall_clock_s": 240.11588740348816,
120
+ "n_anchors": 200
121
+ }
gen_q_rsm/preliminary_analysis/experiments/visual_puzzle_3x3_play_v0/results/4/mc.json ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "method": "mc",
3
+ "env": "visual-puzzle-3x3-play-v0",
4
+ "seed": 4,
5
+ "wandb_url": null,
6
+ "representation": "puzzle_state_46d",
7
+ "reward": "dense",
8
+ "truth_kind": "fresh_rollout",
9
+ "anchor_protocol": "fresh_reset",
10
+ "train/loss": [
11
+ 0.3973221182823181,
12
+ 0.013537771999835968,
13
+ 0.015678435564041138,
14
+ 0.015875155106186867,
15
+ 0.017030376940965652,
16
+ 0.015400794334709644,
17
+ 0.015258473344147205,
18
+ 0.01566459611058235,
19
+ 0.010292736813426018,
20
+ 0.018598206341266632,
21
+ 0.016016345471143723,
22
+ 0.012465794570744038,
23
+ 0.014229320921003819,
24
+ 0.016180628910660744,
25
+ 0.01499403826892376,
26
+ 0.011049514636397362,
27
+ 0.012883918359875679,
28
+ 0.013760831207036972,
29
+ 0.011692577973008156,
30
+ 0.014100328087806702,
31
+ 0.012667085975408554,
32
+ 0.010539358481764793,
33
+ 0.010846260003745556,
34
+ 0.009626545011997223,
35
+ 0.010217661038041115,
36
+ 0.009936617687344551,
37
+ 0.009830178692936897,
38
+ 0.008203509263694286,
39
+ 0.006727797910571098,
40
+ 0.0091972965747118,
41
+ 0.007912425324320793,
42
+ 0.008086002431809902,
43
+ 0.008157597854733467,
44
+ 0.006099458783864975,
45
+ 0.006586033385246992,
46
+ 0.006268269848078489,
47
+ 0.006526589393615723,
48
+ 0.005477622151374817,
49
+ 0.004991190508008003,
50
+ 0.005297564435750246,
51
+ 0.004588456824421883,
52
+ 0.005517447367310524,
53
+ 0.004829523153603077,
54
+ 0.005221773404628038,
55
+ 0.004591044038534164,
56
+ 0.004627092741429806,
57
+ 0.004188260994851589,
58
+ 0.004291519522666931,
59
+ 0.0043603889644145966,
60
+ 0.0036656265147030354,
61
+ 0.004810389131307602
62
+ ],
63
+ "train/q_mse": [
64
+ 0.3973221182823181,
65
+ 0.013537771999835968,
66
+ 0.015678435564041138,
67
+ 0.015875155106186867,
68
+ 0.017030376940965652,
69
+ 0.015400794334709644,
70
+ 0.015258473344147205,
71
+ 0.01566459611058235,
72
+ 0.010292736813426018,
73
+ 0.018598206341266632,
74
+ 0.016016345471143723,
75
+ 0.012465794570744038,
76
+ 0.014229320921003819,
77
+ 0.016180628910660744,
78
+ 0.01499403826892376,
79
+ 0.011049514636397362,
80
+ 0.012883918359875679,
81
+ 0.013760831207036972,
82
+ 0.011692577973008156,
83
+ 0.014100328087806702,
84
+ 0.012667085975408554,
85
+ 0.010539358481764793,
86
+ 0.010846260003745556,
87
+ 0.009626545011997223,
88
+ 0.010217661038041115,
89
+ 0.009936617687344551,
90
+ 0.009830178692936897,
91
+ 0.008203509263694286,
92
+ 0.006727797910571098,
93
+ 0.0091972965747118,
94
+ 0.007912425324320793,
95
+ 0.008086002431809902,
96
+ 0.008157597854733467,
97
+ 0.006099458783864975,
98
+ 0.006586033385246992,
99
+ 0.006268269848078489,
100
+ 0.006526589393615723,
101
+ 0.005477622151374817,
102
+ 0.004991190508008003,
103
+ 0.005297564435750246,
104
+ 0.004588456824421883,
105
+ 0.005517447367310524,
106
+ 0.004829523153603077,
107
+ 0.005221773404628038,
108
+ 0.004591044038534164,
109
+ 0.004627092741429806,
110
+ 0.004188260994851589,
111
+ 0.004291519522666931,
112
+ 0.0043603889644145966,
113
+ 0.0036656265147030354,
114
+ 0.004810389131307602
115
+ ],
116
+ "eval/q_mse": 0.17283664920890093,
117
+ "eval/q_mae": 0.3975993708263472,
118
+ "eval/q_corr": 0.01978606616708757,
119
+ "eval/q_spearman": 0.03376542431958184,
120
+ "eval/truth_std": 0.012477610209021018,
121
+ "wall_clock_s": 84.21893644332886,
122
+ "n_anchors": 200
123
+ }
gen_q_rsm/preliminary_analysis/experiments/visual_puzzle_3x3_play_v0/results/4/td.json ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "method": "td",
3
+ "env": "visual-puzzle-3x3-play-v0",
4
+ "seed": 4,
5
+ "wandb_url": null,
6
+ "representation": "puzzle_state_46d",
7
+ "reward": "dense",
8
+ "truth_kind": "fresh_rollout",
9
+ "anchor_protocol": "fresh_reset",
10
+ "train/loss": [
11
+ 0.0016132708406075835,
12
+ 5.28473719896283e-06,
13
+ 4.727103259938303e-06,
14
+ 4.402791091706604e-06,
15
+ 3.3223111586266896e-06,
16
+ 3.7768290894746315e-06,
17
+ 5.115973181091249e-06,
18
+ 5.008134849049384e-06,
19
+ 4.792467279912671e-06,
20
+ 3.981813733844319e-06,
21
+ 3.7284023619577056e-06,
22
+ 5.092437277198769e-06,
23
+ 6.037279945303453e-06,
24
+ 3.4828635762096383e-06,
25
+ 3.96143286707229e-06,
26
+ 5.226540451985784e-06,
27
+ 4.216956313030096e-06,
28
+ 3.6615813314710977e-06,
29
+ 3.93502432416426e-06,
30
+ 4.533366336545441e-06,
31
+ 4.87484794575721e-06,
32
+ 4.411196186993038e-06,
33
+ 3.908722646883689e-06,
34
+ 3.9617702896066476e-06,
35
+ 3.2414773158961907e-06,
36
+ 3.4550882901385194e-06,
37
+ 3.6995527352701174e-06,
38
+ 3.507384462864138e-06,
39
+ 3.0945584512664936e-06,
40
+ 3.95306597056333e-06,
41
+ 5.549504749069456e-06,
42
+ 3.846819708996918e-06,
43
+ 5.695990694221109e-06,
44
+ 4.43494354840368e-06,
45
+ 4.27822487836238e-06,
46
+ 4.084134161530528e-06,
47
+ 3.250039753766032e-06,
48
+ 3.831450612779008e-06,
49
+ 6.13951215200359e-06,
50
+ 4.288238869776251e-06,
51
+ 4.407696906127967e-06,
52
+ 3.7216980217635864e-06,
53
+ 4.2679212128859945e-06,
54
+ 3.0003220672369935e-06,
55
+ 4.292792255000677e-06,
56
+ 5.7487836784275714e-06,
57
+ 5.628341114061186e-06,
58
+ 4.015937520307489e-06,
59
+ 3.1506799587077694e-06,
60
+ 3.535206815286074e-06,
61
+ 4.741995326185133e-06
62
+ ],
63
+ "train/q_mse": [
64
+ 0.0016132708406075835,
65
+ 5.28473719896283e-06,
66
+ 4.727103259938303e-06,
67
+ 4.402791091706604e-06,
68
+ 3.3223111586266896e-06,
69
+ 3.7768290894746315e-06,
70
+ 5.115973181091249e-06,
71
+ 5.008134849049384e-06,
72
+ 4.792467279912671e-06,
73
+ 3.981813733844319e-06,
74
+ 3.7284023619577056e-06,
75
+ 5.092437277198769e-06,
76
+ 6.037279945303453e-06,
77
+ 3.4828635762096383e-06,
78
+ 3.96143286707229e-06,
79
+ 5.226540451985784e-06,
80
+ 4.216956313030096e-06,
81
+ 3.6615813314710977e-06,
82
+ 3.93502432416426e-06,
83
+ 4.533366336545441e-06,
84
+ 4.87484794575721e-06,
85
+ 4.411196186993038e-06,
86
+ 3.908722646883689e-06,
87
+ 3.9617702896066476e-06,
88
+ 3.2414773158961907e-06,
89
+ 3.4550882901385194e-06,
90
+ 3.6995527352701174e-06,
91
+ 3.507384462864138e-06,
92
+ 3.0945584512664936e-06,
93
+ 3.95306597056333e-06,
94
+ 5.549504749069456e-06,
95
+ 3.846819708996918e-06,
96
+ 5.695990694221109e-06,
97
+ 4.43494354840368e-06,
98
+ 4.27822487836238e-06,
99
+ 4.084134161530528e-06,
100
+ 3.250039753766032e-06,
101
+ 3.831450612779008e-06,
102
+ 6.13951215200359e-06,
103
+ 4.288238869776251e-06,
104
+ 4.407696906127967e-06,
105
+ 3.7216980217635864e-06,
106
+ 4.2679212128859945e-06,
107
+ 3.0003220672369935e-06,
108
+ 4.292792255000677e-06,
109
+ 5.7487836784275714e-06,
110
+ 5.628341114061186e-06,
111
+ 4.015937520307489e-06,
112
+ 3.1506799587077694e-06,
113
+ 3.535206815286074e-06,
114
+ 4.741995326185133e-06
115
+ ],
116
+ "eval/q_mse": 0.19437737321053766,
117
+ "eval/q_mae": 0.4407005841027336,
118
+ "eval/q_corr": 0.0682576828322628,
119
+ "eval/q_spearman": 0.08410663393683149,
120
+ "eval/truth_std": 0.012477610209021018,
121
+ "wall_clock_s": 176.08823823928833,
122
+ "n_anchors": 200
123
+ }
gen_q_rsm/preliminary_analysis/experiments/visual_puzzle_3x3_play_v0/run_seed.py ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Run genq(image-latent) + mc + td for visual-puzzle-3x3-play-v0, ONE seed.
2
+
3
+ The fresh-RESET fresh-rollout truth (ButtonMarkovOracle, match-fraction reward) is the
4
+ EXPENSIVE part and is identical across the three methods, so we build the shared anchor
5
+ pack + truth ONCE and pass it to all three. This mirrors the STATE puzzle honest-negative
6
+ exactly, only the model observation differs (image latent for genq; 46-D [qpos|qvel]
7
+ state for the mc/td reference). See ../../genq_visual_puzzle.py for the recipe.
8
+
9
+ python run_seed.py --seed 0
10
+ python run_seed.py --seed 0 --methods genq # subset
11
+ """
12
+ import argparse
13
+ import json
14
+ import os
15
+ import sys
16
+
17
+ _HERE = os.path.dirname(os.path.abspath(__file__))
18
+ sys.path.insert(0, os.path.join(_HERE, "..", "..")) # preliminary_analysis on path
19
+
20
+ import torch # noqa: E402
21
+ _nt = int(os.environ.get("OMP_NUM_THREADS", "0") or 0)
22
+ if _nt > 0:
23
+ torch.set_num_threads(_nt)
24
+
25
+ from config import make_cfg # noqa: E402
26
+ import genq_visual_puzzle as gvp # noqa: E402
27
+
28
+ ENV = "visual-puzzle-3x3-play-v0"
29
+ _FN = {"genq": gvp.run, "mc": gvp.run_mc, "td": gvp.run_td}
30
+
31
+
32
+ def result_path(seed, method):
33
+ d = os.path.join(_HERE, "results", str(seed))
34
+ os.makedirs(d, exist_ok=True)
35
+ return os.path.join(d, f"{method}.json")
36
+
37
+
38
+ def main():
39
+ ap = argparse.ArgumentParser()
40
+ ap.add_argument("--seed", type=int, default=0)
41
+ ap.add_argument("--methods", default="genq,mc,td")
42
+ ap.add_argument("--reward", default="dense")
43
+ ap.add_argument("--steps", type=int, default=None)
44
+ ap.add_argument("--latent_steps", type=int, default=None)
45
+ ap.add_argument("--n_anchors", type=int, default=None)
46
+ ap.add_argument("--truth_M", type=int, default=None)
47
+ ap.add_argument("--truth_H", type=int, default=None)
48
+ ap.add_argument("--vis_train_traj", type=int, default=None)
49
+ ap.add_argument("--wandb_mode", default="offline")
50
+ args = ap.parse_args()
51
+
52
+ ov = {"reward": args.reward, "wandb_mode": args.wandb_mode}
53
+ for k in ("steps", "latent_steps", "n_anchors", "truth_M", "truth_H", "vis_train_traj"):
54
+ v = getattr(args, k)
55
+ if v is not None:
56
+ ov[k] = v
57
+ cfg = make_cfg(**ov)
58
+ # Puzzle reward scale: the match-fraction reward needs no sigma/eps tuning, but
59
+ # prepare_eval_anchors' manipspace branch (used only by the gc_core path) would set
60
+ # them; here we build the pack directly, so leave the (unused) defaults.
61
+
62
+ methods = [m.strip() for m in args.methods.split(",") if m.strip()]
63
+ pack = None
64
+ truth = None
65
+ for method in methods:
66
+ result, pack, truth = _FN[method](ENV, args.seed, cfg, pack=pack, truth=truth)
67
+ path = result_path(args.seed, method)
68
+ with open(path, "w") as f:
69
+ json.dump(result, f, indent=2, allow_nan=True)
70
+ print(f"[vis-puzzle] wrote {path} eval/q_mse={result['eval/q_mse']:.5f} "
71
+ f"eval/q_corr={result.get('eval/q_corr')} truth_std={result['eval/truth_std']:.5f}",
72
+ flush=True)
73
+
74
+
75
+ if __name__ == "__main__":
76
+ main()
gen_q_rsm/preliminary_analysis/experiments/visual_puzzle_3x3_play_v0/run_seq.sh ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ # Sequential visual-puzzle-3x3 policy-eval runner (#35). One seed at a time inside a
3
+ # single bsub -gpu num=1 allocation (Blue Vela GPUs are exclusive_process — no packed &).
4
+ # Each seed builds the fresh-RESET truth ONCE and shares it across genq/mc/td.
5
+ # Image CNN is heavy; keep ONE seed per process. Resume-safe.
6
+ #
7
+ # bsub -G grp_runtime -q normal -gpu "num=1/task:mode=shared" -M 128G \
8
+ # -o preliminary_analysis/bsub_outputs/vispuzzle_%J.out \
9
+ # -e preliminary_analysis/bsub_outputs/vispuzzle_%J.err \
10
+ # -- bash preliminary_analysis/experiments/visual_puzzle_3x3_play_v0/run_seq.sh "0"
11
+ set -u
12
+ SEEDS="${1:-0}"
13
+ STEPS="${STEPS:-40000}"
14
+ LATENT_STEPS="${LATENT_STEPS:-20000}"
15
+ N_ANCHORS="${N_ANCHORS:-200}"
16
+ TRUTH_M="${TRUTH_M:-8}"
17
+ TRUTH_H="${TRUTH_H:-200}"
18
+
19
+ HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
20
+ ROOT="$(cd "$HERE/../../.." && pwd)"
21
+ PA="$ROOT/preliminary_analysis"
22
+ PY="$ROOT/.venv/bin/python"
23
+ [ -x "$PY" ] || PY="/proj/inf-scaling/zwhong/projs/gen_q/.venv/bin/python"
24
+ DRIVER="$HERE/run_seed.py"
25
+
26
+ if [ -f "$ROOT/.env" ]; then set -a; . "$ROOT/.env"; set +a; fi
27
+ export OMP_NUM_THREADS=3 MKL_NUM_THREADS=3 OPENBLAS_NUM_THREADS=3
28
+ export NUMEXPR_NUM_THREADS=3 VECLIB_MAXIMUM_THREADS=3
29
+ export XLA_FLAGS="--xla_cpu_multi_thread_eigen=false intra_op_parallelism_threads=3"
30
+ export JAX_PLATFORMS=cpu XLA_PYTHON_CLIENT_MEM_FRACTION=0.3 MUJOCO_GL=egl
31
+ export WANDB_MODE=offline
32
+ # Resolve the OGBench data dir robustly: $HOME differs between login (/proj/...) and
33
+ # compute (/u/zwhong) nodes, so prefer the proj-space copy where the datasets live.
34
+ if [ -z "${OGBENCH_DATA_DIR:-}" ]; then
35
+ for cand in /proj/inf-scaling/zwhong/.ogbench/data "$HOME/.ogbench/data" /u/zwhong/.ogbench/data; do
36
+ [ -f "$cand/visual-puzzle-3x3-play-v0.npz" ] && OGBENCH_DATA_DIR="$cand" && break
37
+ done
38
+ fi
39
+ export OGBENCH_DATA_DIR="${OGBENCH_DATA_DIR:-/proj/inf-scaling/zwhong/.ogbench/data}"
40
+ echo "[vispuzzle-seq] OGBENCH_DATA_DIR=$OGBENCH_DATA_DIR"
41
+
42
+ mkdir -p "$HERE/results"
43
+ cd "$PA"
44
+ echo "[vispuzzle-seq] host=$(hostname) SEEDS='$SEEDS' steps=$STEPS latent=$LATENT_STEPS n_anchors=$N_ANCHORS M=$TRUTH_M H=$TRUTH_H"
45
+
46
+ fail=0
47
+ for SEED in $SEEDS; do
48
+ # Resume: skip a seed only if all three method JSONs already carry fresh_rollout truth.
49
+ done_all=1
50
+ for METHOD in genq mc td; do
51
+ out="$HERE/results/$SEED/$METHOD.json"
52
+ grep -q '"truth_kind": "fresh_rollout"' "$out" 2>/dev/null || done_all=0
53
+ done
54
+ if [ "$done_all" = "1" ]; then echo "[vispuzzle-seq] SKIP seed=$SEED (all done)"; continue; fi
55
+ echo "[vispuzzle-seq] === seed=$SEED ==="
56
+ "$PY" "$DRIVER" --seed "$SEED" --methods genq,mc,td \
57
+ --reward dense --steps "$STEPS" --latent_steps "$LATENT_STEPS" \
58
+ --n_anchors "$N_ANCHORS" --truth_M "$TRUTH_M" --truth_H "$TRUTH_H" \
59
+ --wandb_mode offline \
60
+ > "$HERE/results/seed${SEED}.log" 2>&1 \
61
+ || { echo "[vispuzzle-seq] FAILED seed=$SEED"; tail -15 "$HERE/results/seed${SEED}.log"; fail=1; }
62
+ done
63
+
64
+ "$PY" plots.py --env "visual-puzzle-3x3-play-v0" || true
65
+ echo "[vispuzzle-seq] done fail=$fail"
66
+ exit "$fail"
gen_q_rsm/preliminary_analysis/gc_core.py ADDED
@@ -0,0 +1,1612 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Self-contained goal-conditioned core for the policy-evaluation methods.
2
+
3
+ This module vendors (copies / lightly adapts) the goal-conditioned occupancy +
4
+ fresh-rollout machinery so ``preliminary_analysis/`` does not import from
5
+ any legacy tree at all. OGBench is goal-conditioned RL, so every quantity here is
6
+ conditioned on a goal g:
7
+
8
+ Q^pi(s, a, g) = E_{x ~ d^pi_gamma(. | s, a, g)} [ r(x; g) ],
9
+ r(x; g) = exp(-||x_xy - g||^2 / 2 sigma^2) (dense) or 1[||x_xy - g|| < eps] (sparse).
10
+
11
+ The occupancy model is a conditional diffusion (or flow-matching) model
12
+ p_theta(x_{t+k} | s_t, a_t, g), k ~ Geom(1-gamma).
13
+
14
+ Goals for training come from HINDSIGHT relabeling (the data has no goal labels):
15
+ g = xy of a state downstream of the occupancy target in the same trajectory.
16
+
17
+ GROUND TRUTH (headline, for MSE / correlation) is ALWAYS fresh on-policy rollouts:
18
+ ``gc_fresh_truth_pointmaze`` rolls the data-collection behaviour policy (OGBench
19
+ scripted oracle-subgoal controller + N(0,0.2) noise) M times from each anchor and
20
+ averages the renormalized discounted goal-reaching return. We never substitute
21
+ in-dataset return-to-go for the truth.
22
+ """
23
+ import numpy as np
24
+ import torch
25
+
26
+ import models
27
+
28
+
29
+ # ----------------------------------------------------------------------------
30
+ # dataset + geometric-horizon / hindsight-goal sampling
31
+ # ----------------------------------------------------------------------------
32
+ def trajectory_bounds(terminals):
33
+ N = len(terminals)
34
+ ends = np.where(terminals > 0.5)[0] + 1
35
+ if len(ends) == 0 or ends[-1] != N:
36
+ ends = np.append(ends, N)
37
+ end_per_idx = np.empty(N, dtype=np.int64)
38
+ start = 0
39
+ for e in ends:
40
+ end_per_idx[start:e] = e
41
+ start = e
42
+ return end_per_idx
43
+
44
+
45
+ MANIPSPACE_FAMILIES = ("cube", "scene", "puzzle")
46
+
47
+
48
+ def manipspace_family(env_id):
49
+ """Return 'cube' / 'scene' / 'puzzle' for a manipspace env_id, else None."""
50
+ for fam in MANIPSPACE_FAMILIES:
51
+ if env_id.startswith(fam) or f"-{fam}" in env_id or f"_{fam}" in env_id:
52
+ return fam
53
+ return None
54
+
55
+
56
+ def is_manipspace(env_id):
57
+ return manipspace_family(env_id) is not None
58
+
59
+
60
+ def load_ogbench_gc(env_id, gamma, dataset_dir="~/.ogbench/data", state_slice="auto"):
61
+ """Return (train, val) dicts with obs/act/end.
62
+
63
+ `state_slice` controls the CONDITIONING state representation in `obs`:
64
+ - "auto": xy (obs[:, :2]) for mazes, full obs otherwise (back-compat default).
65
+ - "full": keep the full observation (e.g. AntMaze raw 29-D state occupancy).
66
+ - "xy": force xy.
67
+ The occupancy TARGET is always the xy position (first 2 dims) for mazes; callers
68
+ slice `obs[:, :pos]` for the target. For full-state mazes the conditioning is the
69
+ full state while the target stays xy — that is "raw N-D state occupancy".
70
+
71
+ For the **manipspace** families (cube / scene / puzzle) the obs is a lossy
72
+ projection that does not expose raw object coordinates, so we load the dataset
73
+ with ``add_info=True`` and derive the per-step occupancy TARGET from privileged
74
+ qpos (object position; see ``manipspace_target_array``). The conditioning ``obs``
75
+ stays the full normalized observation; only the target/goal use privileged coords.
76
+ The returned dicts then also carry an ``obj`` array ([N, pos_dim]) — the privileged
77
+ occupancy target — and the methods use ``obj`` instead of ``obs[:, :pos]``.
78
+ """
79
+ import ogbench
80
+ fam = manipspace_family(env_id)
81
+ if fam is not None:
82
+ return _load_manipspace_gc(env_id, fam, dataset_dir)
83
+ # AntSoccer is special: the task is to dribble the BALL, not move the ant. The
84
+ # occupancy target / goal is the BALL xy (obs[:, 15:17]), NOT the ant xy (obs[:, :2]).
85
+ # Conditioning is the full 42-D state; the target rides in `obj` like the manipspace
86
+ # privileged target.
87
+ if "antsoccer" in env_id:
88
+ return _load_antsoccer_gc(env_id, dataset_dir)
89
+ env, train_ds, val_ds = ogbench.make_env_and_datasets(env_id, dataset_dir=dataset_dir)
90
+ is_maze = any(k in env_id for k in ("pointmaze", "antmaze", "humanoidmaze", "antsoccer"))
91
+ # AntSoccer: the reward / occupancy TARGET is the BALL xy, not the agent xy. The
92
+ # obs is the full MuJoCo state (qpos[22]+qvel[20] == obs[:42]); ball xy = obs[15:17]
93
+ # (the ball free-joint position). We therefore condition on the FULL 42-D state and
94
+ # carry a ``target_slice`` so ``_target_array`` / goal sampling read the ball xy.
95
+ is_antsoccer = "antsoccer" in env_id
96
+ target_slice = (15, 17) if is_antsoccer else None
97
+ if state_slice == "auto":
98
+ mode = "full" if is_antsoccer else ("xy" if is_maze else "full")
99
+ else:
100
+ mode = state_slice
101
+ sl = (lambda x: x[:, :2]) if mode == "xy" else (lambda x: x)
102
+ out = []
103
+ for ds in (train_ds, val_ds):
104
+ obs = sl(np.asarray(ds["observations"], dtype=np.float32))
105
+ act = np.asarray(ds["actions"], dtype=np.float32)
106
+ end = trajectory_bounds(np.asarray(ds["terminals"], dtype=np.float32))
107
+ d = dict(obs=obs, act=act, end=end, N=len(obs),
108
+ s_dim=obs.shape[1], a_dim=act.shape[1])
109
+ if target_slice is not None:
110
+ d["target_slice"] = target_slice
111
+ d["pos_dim"] = target_slice[1] - target_slice[0]
112
+ out.append(d)
113
+ return out[0], out[1], env, is_maze
114
+
115
+
116
+ # AntSoccer observation layout (verified empirically via set_agent_ball_xy + get_ob):
117
+ # obs[:, 0:2] = ant (agent) xy
118
+ # obs[:, 15:17] = BALL xy <- the task-relevant position / occupancy target
119
+ ANTSOCCER_BALL_SLICE = (15, 17)
120
+
121
+
122
+ def _load_antsoccer_gc(env_id, dataset_dir):
123
+ """AntSoccer loader. Conditioning obs = full 42-D state; occupancy TARGET = ball xy
124
+ (obs[:, 15:17]) carried in ``obj`` so ``_target_array`` returns the ball, NOT the ant.
125
+ ``add_info=True`` provides per-step qpos[22]/qvel[20] for resettable rollouts."""
126
+ import ogbench
127
+ lo, hi = ANTSOCCER_BALL_SLICE
128
+ env, train_ds, val_ds = ogbench.make_env_and_datasets(
129
+ env_id, dataset_dir=dataset_dir, add_info=True)
130
+ out = []
131
+ for ds in (train_ds, val_ds):
132
+ obs = np.asarray(ds["observations"], dtype=np.float32)
133
+ act = np.asarray(ds["actions"], dtype=np.float32)
134
+ end = trajectory_bounds(np.asarray(ds["terminals"], dtype=np.float32))
135
+ obj = obs[:, lo:hi].copy() # ball xy = occupancy target
136
+ out.append(dict(obs=obs, act=act, end=end, N=len(obs),
137
+ s_dim=obs.shape[1], a_dim=act.shape[1],
138
+ obj=obj, qpos=np.asarray(ds["qpos"], dtype=np.float32),
139
+ qvel=np.asarray(ds["qvel"], dtype=np.float32),
140
+ antsoccer=True, pos_dim=2))
141
+ return out[0], out[1], env, True
142
+
143
+
144
+ # qpos slices of EVERY block's free-joint position, per family.
145
+ # Verified for cube-single (block_0 free body is the last 7-D free joint, pos = qpos[14:17])
146
+ # and cube-double (block_0 = qpos[14:17], block_1 = qpos[21:24]) by matching
147
+ # info['privileged/block_<i>_pos'] to the qpos slice at reset.
148
+ def _manipspace_block_qpos_slices(env, fam):
149
+ """Resolve the per-block qpos slices [lo, hi) giving each cube's 3-D position.
150
+
151
+ Returns a LIST of (lo, hi) windows, one per block (cube-single -> 1 window,
152
+ cube-double -> 2). The occupancy TARGET concatenates all block positions so that
153
+ the model predicts the future configuration of EVERY block; this is required for
154
+ cube-double where the eval ``target_block`` alternates between blocks and a single
155
+ fixed block_0 target gives no Q-signal for target_block==1 (see issue #35).
156
+ For puzzle the occupancy target is the button-state vector (handled separately),
157
+ so this returns None.
158
+ """
159
+ if fam == "puzzle":
160
+ return None
161
+ ob, info = env.reset(seed=0)
162
+ qpos = np.asarray(info["qpos"], dtype=np.float64)
163
+ block_keys = sorted(k for k in info
164
+ if k.startswith("privileged/block_") and k.endswith("_pos"))
165
+ slices = []
166
+ for k in block_keys:
167
+ bp = np.asarray(info[k], dtype=np.float64)
168
+ found = None
169
+ for i in range(len(qpos) - 2):
170
+ if np.allclose(qpos[i:i + 3], bp, atol=1e-5):
171
+ found = (i, i + 3)
172
+ break
173
+ if found is None:
174
+ raise gc_core_error(f"could not locate qpos slice for {k} ({fam})")
175
+ slices.append(found)
176
+ if not slices:
177
+ raise gc_core_error(f"no block_*_pos keys found for {fam}")
178
+ return slices
179
+
180
+
181
+ class gc_core_error(RuntimeError):
182
+ pass
183
+
184
+
185
+ # ----------------------------------------------------------------------------
186
+ # Scene multi-task occupancy target: a fixed-dim, task-AGNOSTIC representation.
187
+ # ----------------------------------------------------------------------------
188
+ # scene-play-v0 is a *multi-task* env: each episode the data-collection oracle is
189
+ # keyed on info['privileged/target_task'] in {cube, button, drawer, window} and
190
+ # manipulates a DIFFERENT object. A cube-only occupancy target (as cube-single uses)
191
+ # is degenerate here — ~73% of anchors are NOT cube tasks, so the cube barely moves
192
+ # and a cube-position reward carries no signal. We therefore use the env's own 7-D
193
+ # *oracle goal representation* (SceneEnv.compute_oracle_observation) as the occupancy
194
+ # TARGET x and goal g for ALL four tasks. It is fixed-dim and exposes every
195
+ # manipulated object in one vector:
196
+ # [ (block_0_pos - center) * 10 (3) | button_states (2) | drawer_pos * 18 (1) |
197
+ # window_pos * 15 (1) ] == 7-D.
198
+ # The per-task goal g is this same vector with the manipulated component replaced by
199
+ # its target value. ||x - g|| then measures how close the manipulated object is to
200
+ # its target across every task, exactly mirroring the maze xy goal-reaching reward.
201
+ # See issue #35: this is the documented scene deviation from FRESH_RESET_SPEC's
202
+ # "target_block_pos" (which only covered the cube sub-task).
203
+ _SCENE_XYZ_CENTER = np.array([0.425, 0.0, 0.0])
204
+ _SCENE_XYZ_SCALER = 10.0
205
+ _SCENE_DRAWER_SCALER = 18.0
206
+ _SCENE_WINDOW_SCALER = 15.0
207
+ SCENE_OCC_DIM = 7
208
+
209
+
210
+ def _scene_oracle_vec_from_parts(block0_pos, button_states, drawer_pos, window_pos):
211
+ """Assemble the 7-D scene oracle representation from raw privileged parts."""
212
+ block0_pos = np.asarray(block0_pos, dtype=np.float64).reshape(3)
213
+ bs = np.asarray(button_states, dtype=np.float64).reshape(-1)[:2]
214
+ return np.concatenate([
215
+ (block0_pos - _SCENE_XYZ_CENTER) * _SCENE_XYZ_SCALER,
216
+ bs,
217
+ np.array([float(np.asarray(drawer_pos).ravel()[0]) * _SCENE_DRAWER_SCALER]),
218
+ np.array([float(np.asarray(window_pos).ravel()[0]) * _SCENE_WINDOW_SCALER]),
219
+ ]).astype(np.float64)
220
+
221
+
222
+ def _scene_oracle_vec_from_info(info):
223
+ """7-D scene oracle representation from a live env info dict (current state)."""
224
+ return _scene_oracle_vec_from_parts(
225
+ info["privileged/block_0_pos"],
226
+ info["button_states"],
227
+ info["privileged/drawer_pos"],
228
+ info["privileged/window_pos"])
229
+
230
+
231
+ def _scene_target_vec_from_info(info):
232
+ """7-D scene oracle TARGET config: the current oracle vector with the task's
233
+ manipulated component replaced by its target value."""
234
+ cur = _scene_oracle_vec_from_info(info)
235
+ task = info["privileged/target_task"]
236
+ if task == "cube":
237
+ cur[0:3] = (np.asarray(info["privileged/target_block_pos"], dtype=np.float64)
238
+ - _SCENE_XYZ_CENTER) * _SCENE_XYZ_SCALER
239
+ elif task == "button":
240
+ tb = int(info["privileged/target_button"])
241
+ cur[3 + tb] = float(np.asarray(info["privileged/target_button_state"]).ravel()[0])
242
+ elif task == "drawer":
243
+ cur[5] = float(np.asarray(info["privileged/target_drawer_pos"]).ravel()[0]) * _SCENE_DRAWER_SCALER
244
+ elif task == "window":
245
+ cur[6] = float(np.asarray(info["privileged/target_window_pos"]).ravel()[0]) * _SCENE_WINDOW_SCALER
246
+ return cur
247
+
248
+
249
+ def _scene_obj_array_from_dataset(ds):
250
+ """Reconstruct the per-row 7-D scene oracle target array from dataset qpos +
251
+ button_states. block_0_pos = qpos[14:17], drawer = qpos[23], window = qpos[24]
252
+ (verified against the live scene model joint qposadr)."""
253
+ qpos = np.asarray(ds["qpos"], dtype=np.float64)
254
+ bs = np.asarray(ds["button_states"], dtype=np.float64)
255
+ block0 = qpos[:, 14:17]
256
+ drawer = qpos[:, 23]
257
+ window = qpos[:, 24]
258
+ out = np.empty((len(qpos), SCENE_OCC_DIM), dtype=np.float32)
259
+ out[:, 0:3] = (block0 - _SCENE_XYZ_CENTER[None]) * _SCENE_XYZ_SCALER
260
+ out[:, 3:5] = bs[:, :2]
261
+ out[:, 5] = drawer * _SCENE_DRAWER_SCALER
262
+ out[:, 6] = window * _SCENE_WINDOW_SCALER
263
+ return out
264
+
265
+
266
+ def _load_manipspace_gc(env_id, fam, dataset_dir):
267
+ """Manipspace data loader: conditioning obs = full normalized observation,
268
+ occupancy TARGET = privileged object position (cube), the 7-D oracle representation
269
+ (scene, multi-task), or the button-state vector (puzzle), derived from the
270
+ add_info=True dataset (qpos / button_states)."""
271
+ import ogbench
272
+ env, train_ds, val_ds = ogbench.make_env_and_datasets(
273
+ env_id, dataset_dir=dataset_dir, add_info=True)
274
+ if fam == "puzzle":
275
+ slice_info = None
276
+ pos_dim = int(np.asarray(train_ds["button_states"]).shape[1])
277
+ elif fam == "scene":
278
+ slice_info = None
279
+ pos_dim = SCENE_OCC_DIM
280
+ else:
281
+ slice_info = _manipspace_block_qpos_slices(env, fam) # list of (lo, hi) per block
282
+ pos_dim = sum(hi - lo for (lo, hi) in slice_info)
283
+ out = []
284
+ for ds in (train_ds, val_ds):
285
+ obs = np.asarray(ds["observations"], dtype=np.float32)
286
+ act = np.asarray(ds["actions"], dtype=np.float32)
287
+ end = trajectory_bounds(np.asarray(ds["terminals"], dtype=np.float32))
288
+ if fam == "puzzle":
289
+ obj = np.asarray(ds["button_states"], dtype=np.float32)
290
+ elif fam == "scene":
291
+ obj = _scene_obj_array_from_dataset(ds)
292
+ else:
293
+ qpos = np.asarray(ds["qpos"], dtype=np.float32)
294
+ # occupancy target = ALL block positions concatenated [N, 3*n_blocks]
295
+ obj = np.concatenate([qpos[:, lo:hi] for (lo, hi) in slice_info],
296
+ axis=1).astype(np.float32)
297
+ out.append(dict(obs=obs, act=act, end=end, N=len(obs),
298
+ s_dim=obs.shape[1], a_dim=act.shape[1],
299
+ obj=obj, manipspace=True, family=fam, pos_dim=pos_dim))
300
+ env.close()
301
+ return out[0], out[1], env, False
302
+
303
+
304
+ def future_idx(t, end, gamma, rng):
305
+ """Truncated-geometric future index j = t + k, k ~ Geom(1-gamma)."""
306
+ L = end[t] - t
307
+ logg = np.log(gamma)
308
+ Fmax = np.maximum(1.0 - gamma ** L, 1e-12)
309
+ u = rng.random(len(t)) * Fmax
310
+ k = np.clip(np.ceil(np.log1p(-u) / logg).astype(np.int64) - 1, 0, L - 1)
311
+ return t + k
312
+
313
+
314
+ def sample_goal_after(j, end, rng):
315
+ """Hindsight goal index at or after the occupancy target j (same trajectory)."""
316
+ e = end[j]
317
+ span = np.maximum(e - j, 1)
318
+ return np.clip(j + (rng.random(len(j)) * span).astype(np.int64), 0, e - 1)
319
+
320
+
321
+ def sample_goal_idx(t, end, rng, frac_lo=0.25):
322
+ """Hindsight goal index downstream of anchor t (biased to latter half)."""
323
+ L = end[t] - t
324
+ lo = (frac_lo * L).astype(np.int64)
325
+ span = np.maximum(L - 1 - lo, 1)
326
+ return np.clip(t + lo + (rng.random(len(t)) * span).astype(np.int64), 0, end[t] - 1)
327
+
328
+
329
+ def anchors_with_min_horizon(ds, n, min_h, rng):
330
+ rem = ds["end"] - np.arange(ds["N"])
331
+ valid = np.where(rem >= min_h)[0]
332
+ if len(valid) == 0:
333
+ valid = np.arange(ds["N"])
334
+ return valid[rng.integers(0, len(valid), size=n)]
335
+
336
+
337
+ # ----------------------------------------------------------------------------
338
+ # goal-reaching reward
339
+ # ----------------------------------------------------------------------------
340
+ def reward_of_dist(d, kind, sigma, eps):
341
+ if kind == "sparse":
342
+ return (d < eps).astype(np.float64)
343
+ return np.exp(-(d ** 2) / (2 * sigma ** 2))
344
+
345
+
346
+ def reward_of_dist_t(d, kind, sigma, eps):
347
+ if kind == "sparse":
348
+ return (d < eps).float()
349
+ return torch.exp(-(d ** 2) / (2 * sigma ** 2))
350
+
351
+
352
+ # ----------------------------------------------------------------------------
353
+ # PUZZLE-specific button-state reward (issue #35 caveat fix)
354
+ # ----------------------------------------------------------------------------
355
+ # The puzzle occupancy TARGET x and goal g are BINARY button-state vectors
356
+ # (length = num_buttons: 9 for 3x3, 16 for 4x4), NOT object positions. The shared
357
+ # position-distance reward `reward_of_dist` with the manip default sigma=0.05 / eps=0.04
358
+ # is meaningless here: ||x - g|| = sqrt(Hamming distance), which is 0..sqrt(num_buttons)
359
+ # (and is exactly 1 at the anchor, where g differs from the current state in the single
360
+ # target button). exp(-1 / (2*0.05^2)) = exp(-200) ~ 0 saturates the reward to 0 for
361
+ # every realistic Hamming distance, so the truth has ~no spread and Q is unrankable.
362
+ #
363
+ # Principled replacement (used IDENTICALLY by occ_q, MC, TD and the fresh-rollout truth):
364
+ # r(x; g) = match-fraction = mean( round(x) == round(g) ) -- continuous in [0,1].
365
+ # This is the natural "task-progress toward the goal button pattern" reward: 1 when the
366
+ # realized button vector equals the goal pattern, ~ (num_buttons-1)/num_buttons at the
367
+ # anchor (one button off). It is invariant to the binary embedding scale and needs no
368
+ # sigma tuning. Occupancy samples x are continuous (diffusion output) so we round each
369
+ # coordinate to the nearest bit before comparison.
370
+ # sparse variant: r = 1[ all buttons match ] = 1[ Hamming(x,g) == 0 ] -- exact pattern
371
+ # match (== the env's own Lights-Out success), continuous methods see it as 1[ match
372
+ # fraction == 1 ].
373
+ PUZZLE_MATCH_TOL = 0.5 # |round to nearest bit| threshold
374
+
375
+
376
+ def puzzle_reward(x, g, kind):
377
+ """Button-state match-fraction reward (numpy). x, g: [..., num_buttons]."""
378
+ x = np.asarray(x, dtype=np.float64)
379
+ g = np.asarray(g, dtype=np.float64)
380
+ match = (np.abs(np.round(x) - np.round(g)) < PUZZLE_MATCH_TOL).astype(np.float64)
381
+ frac = match.mean(axis=-1)
382
+ if kind == "sparse":
383
+ return (frac >= 1.0 - 1e-9).astype(np.float64) # exact full-pattern match
384
+ return frac
385
+
386
+
387
+ def puzzle_reward_t(x, g, kind):
388
+ """Button-state match-fraction reward (torch). x: [..., D], g: [..., D]."""
389
+ match = (torch.abs(torch.round(x) - torch.round(g)) < PUZZLE_MATCH_TOL).float()
390
+ frac = match.mean(dim=-1)
391
+ if kind == "sparse":
392
+ return (frac >= 1.0 - 1e-9).float()
393
+ return frac
394
+
395
+
396
+ # ----------------------------------------------------------------------------
397
+ # occupancy model build / train / Q (all goal-conditioned)
398
+ # ----------------------------------------------------------------------------
399
+ def build_occupancy(occ_model, cond_dim, y_dim, cfg, device):
400
+ if occ_model == "diffusion":
401
+ m = models.ConditionalDiffusion(cond_dim, y_dim, hidden_dim=cfg["hidden_dim"],
402
+ num_layers=cfg["num_layers"],
403
+ T=cfg.get("diffusion_T", 100),
404
+ sample_steps=cfg.get("sample_steps", 30))
405
+ elif occ_model == "flow":
406
+ m = models.ConditionalFlowMatching(cond_dim, y_dim, hidden_dim=cfg["hidden_dim"],
407
+ num_layers=cfg["num_layers"],
408
+ sample_steps=cfg.get("sample_steps", 30))
409
+ else:
410
+ raise ValueError(f"occ_model must be 'diffusion' or 'flow', got {occ_model!r}")
411
+ return m.to(device)
412
+
413
+
414
+ def _target_array(ds, cfg):
415
+ """Occupancy TARGET x per dataset row: privileged object position for manipspace /
416
+ AntSoccer (``ds['obj']`` — ball xy for antsoccer), a non-leading slice of the obs
417
+ when ``target_slice`` is set, else the leading xy slice of the obs (mazes)."""
418
+ if ds.get("manipspace") or ds.get("antsoccer"):
419
+ return ds["obj"]
420
+ ts = ds.get("target_slice")
421
+ if ts is not None:
422
+ lo, hi = ts
423
+ return ds["obs"][:, lo:hi]
424
+ pos = cfg.get("pos_dim", 2)
425
+ return ds["obs"][:, :pos]
426
+
427
+
428
+ def train_gc_occupancy(occ, ds, gamma, cfg, device, seed, wandb_log=None):
429
+ """Train p_theta(x_{t+k} | s, a, g) on geometric-horizon targets x with hindsight
430
+ goals. For mazes x = future xy; for manipspace x = future privileged object
431
+ position (the goal g is a hindsight object position downstream). Returns the
432
+ periodic loss curve."""
433
+ obs, act, end = ds["obs"], ds["act"], ds["end"]
434
+ pos = cfg.get("pos_dim", 2)
435
+ xy = _target_array(ds, cfg) # [N, pos] occupancy target (obj pos or xy)
436
+ rng = np.random.default_rng(seed)
437
+ # normalization from a sample
438
+ t0 = rng.integers(0, ds["N"], 20000)
439
+ j0 = future_idx(t0, end, gamma, rng)
440
+ g0 = xy[sample_goal_after(j0, end, rng)]
441
+ c0 = np.concatenate([obs[t0], act[t0], g0], 1)
442
+ occ.set_normalization(c0.mean(0), c0.std(0) + 1e-6, xy[j0].mean(0), xy[j0].std(0) + 1e-6)
443
+ opt = torch.optim.Adam(occ.parameters(), lr=cfg["lr"])
444
+ losses = []
445
+ log_every = max(1, cfg["steps"] // 50)
446
+ for step in range(1, cfg["steps"] + 1):
447
+ t = rng.integers(0, ds["N"], cfg["batch_size"])
448
+ j = future_idx(t, end, gamma, rng)
449
+ g = xy[sample_goal_after(j, end, rng)]
450
+ c = np.concatenate([obs[t], act[t], g], 1)
451
+ loss = occ.training_loss(torch.as_tensor(c, dtype=torch.float32, device=device),
452
+ torch.as_tensor(xy[j], dtype=torch.float32, device=device))
453
+ opt.zero_grad(); loss.backward()
454
+ gn = torch.nn.utils.clip_grad_norm_(occ.parameters(), 10.0)
455
+ opt.step()
456
+ if step % log_every == 0 or step == 1:
457
+ losses.append(float(loss.item()))
458
+ if wandb_log:
459
+ wandb_log({"train/loss": float(loss.item()), "train/grad_norm": float(gn)}, step=step)
460
+ occ.eval()
461
+ return losses
462
+
463
+
464
+ @torch.no_grad()
465
+ def occ_q(occ, s, a, g, N, sigma, device, kind="dense", eps=0.5, batch=256, family=None):
466
+ """Q(s,a,g) = mean over N occupancy samples of the goal-reaching reward.
467
+
468
+ For puzzle (family=="puzzle") x,g are binary button-state vectors and the reward is
469
+ the match-fraction (``puzzle_reward_t``), NOT the position-distance reward — see
470
+ ``puzzle_reward`` for the rationale (issue #35). For all other families x,g are
471
+ positions and the reward is ``reward_of_dist_t(||x - g||)``."""
472
+ out = np.zeros(len(s))
473
+ for i in range(0, len(s), batch):
474
+ sb, ab, gb = s[i:i+batch], a[i:i+batch], g[i:i+batch]
475
+ c = np.concatenate([sb, ab, gb], 1)
476
+ ct = torch.as_tensor(c, dtype=torch.float32, device=device)
477
+ x = occ.sample(ct, N) # [B, N, pos]
478
+ gt = torch.as_tensor(gb, dtype=torch.float32, device=device).unsqueeze(1)
479
+ if family == "puzzle":
480
+ out[i:i+batch] = puzzle_reward_t(x, gt, kind).mean(1).cpu().numpy()
481
+ else:
482
+ d = torch.norm(x - gt, dim=-1)
483
+ out[i:i+batch] = reward_of_dist_t(d, kind, sigma, eps).mean(1).cpu().numpy()
484
+ return out
485
+
486
+
487
+ # ----------------------------------------------------------------------------
488
+ # fresh-rollout ground truth (PointMaze): goal-conditioned, on-policy
489
+ # ----------------------------------------------------------------------------
490
+ def build_vertex_cells(maze_map):
491
+ mm = np.asarray(maze_map); I, J = mm.shape
492
+ def free(i, j): return 0 <= i < I and 0 <= j < J and mm[i, j] == 0
493
+ vc = []
494
+ for i in range(I):
495
+ for j in range(J):
496
+ if mm[i, j] == 0:
497
+ hx = free(i, j - 1) or free(i, j + 1)
498
+ hy = free(i - 1, j) or free(i + 1, j)
499
+ if hx and hy:
500
+ vc.append((i, j))
501
+ return vc
502
+
503
+
504
+ def gc_fresh_truth_pointmaze(env_id, s_anc, a_anc, g_anc, gamma, kind, sigma, eps,
505
+ M=8, H=350, seed=0, verbose=True):
506
+ """Fresh-rollout Q^pi(s, a, g) truth for PointMaze anchors.
507
+
508
+ For each anchor (s_i, a_i, g_i): set the env to s_i, apply the recorded action
509
+ a_i first (conditioning Q on (s,a)), infer the latent navigation goal from a_i,
510
+ then roll the scripted oracle-subgoal + N(0,0.2) controller for H steps. Average
511
+ the renormalized discounted goal-reaching return toward g_i over M rollouts.
512
+ The rollout trajectory is independent of g_i (the controller follows its own
513
+ latent goal), so this is a low-variance unbiased estimate of Q^pi(s,a,g).
514
+ """
515
+ import ogbench
516
+ # For the self-rendered visual-pointmaze cell the env_id carries a "visual-" prefix,
517
+ # but only the STATE pointmaze env is registered (and its dynamics/oracle are what we
518
+ # roll for truth). Strip the prefix so the live env is created (cf. the antmaze truth,
519
+ # which does the same). The image-ness only affects the OCCUPANCY model input.
520
+ env_name = env_id.replace("visual-", "")
521
+ env, _, _ = ogbench.make_env_and_datasets(env_name)
522
+ u = env.unwrapped
523
+ env.reset()
524
+ vertex = build_vertex_cells(u.maze_map)
525
+ vertex_xy = np.array([u.ij_to_xy(ij) for ij in vertex])
526
+ rng = np.random.default_rng(seed)
527
+ disc = (1 - gamma) * gamma ** np.arange(H + 1)
528
+ mass = disc.sum()
529
+
530
+ def goal_posterior(s_xy, a):
531
+ dirs = np.zeros((len(vertex), 2))
532
+ for k, gxy in enumerate(vertex_xy):
533
+ sg, _ = u.get_oracle_subgoal(s_xy, gxy)
534
+ d = sg - s_xy
535
+ dirs[k] = d / (np.linalg.norm(d) + 1e-6)
536
+ w = np.exp(-((a[None, :2] - dirs) ** 2).sum(1) / (2 * 0.2 ** 2))
537
+ ssum = w.sum()
538
+ return (w / ssum) if ssum > 1e-12 else np.ones(len(vertex)) / len(vertex)
539
+
540
+ A = len(s_anc)
541
+ truth = np.zeros(A)
542
+ for ai in range(A):
543
+ s_i = np.asarray(s_anc[ai][:2], dtype=np.float64).copy()
544
+ a_i = np.asarray(a_anc[ai], dtype=np.float64).copy()
545
+ g_i = np.asarray(g_anc[ai][:2], dtype=np.float64)
546
+ gpost = goal_posterior(s_i, a_i)
547
+ ret = 0.0
548
+ for _ in range(M):
549
+ g_ij = vertex[rng.choice(len(vertex), p=gpost)]
550
+ u.set_xy(s_i.copy())
551
+ u.set_goal(goal_ij=g_ij)
552
+ xys = [u.get_xy().copy()]
553
+ _, _, _, _, info = u.step(a_i)
554
+ xys.append(u.get_xy().copy())
555
+ if info.get("success", False):
556
+ u.set_goal(goal_ij=vertex[rng.integers(len(vertex))])
557
+ for _t in range(1, H):
558
+ xy = u.get_xy()
559
+ sg, _ = u.get_oracle_subgoal(xy, u.cur_goal_xy)
560
+ d = sg - xy
561
+ d = d / (np.linalg.norm(d) + 1e-6)
562
+ a = np.clip(d + rng.normal(0, 0.2, 2), -1, 1)
563
+ _, _, _, _, info = u.step(a)
564
+ xys.append(u.get_xy().copy())
565
+ if info.get("success", False):
566
+ u.set_goal(goal_ij=vertex[rng.integers(len(vertex))])
567
+ xys = np.asarray(xys)
568
+ d2g = np.linalg.norm(xys - g_i[None], axis=1)
569
+ rr = reward_of_dist(d2g, kind, sigma, eps)
570
+ ret += float((disc * rr).sum() / mass)
571
+ truth[ai] = ret / M
572
+ if verbose and (ai + 1) % 100 == 0:
573
+ print(f" [gc-fresh-truth] anchor {ai+1}/{A}", flush=True)
574
+ env.close()
575
+ return truth
576
+
577
+
578
+ # ----------------------------------------------------------------------------
579
+ # fresh-rollout ground truth (AntMaze / visual-AntMaze): SAC expert + oracle subgoal
580
+ # ----------------------------------------------------------------------------
581
+ def _load_ant_sac_expert(seed=0):
582
+ """Load the OGBench SAC locomotion expert used to collect AntMaze data. The repo's
583
+ `utils`/`agents` packages clash with our module names, so we import with the repo on
584
+ the path, then clean sys.modules. Returns actor_fn(agent_ob, temperature)->action[8]."""
585
+ import os
586
+ import sys
587
+ import json
588
+ import numpy as np
589
+ here = os.path.dirname(os.path.abspath(__file__))
590
+ repo = os.path.normpath(os.path.join(here, "..", "ogbench_repo"))
591
+ impls = os.path.join(repo, "impls")
592
+ expert = os.path.join(repo, "data_gen_scripts", "experts", "ant")
593
+ if not os.path.exists(os.path.join(expert, "params_400000.pkl")):
594
+ raise FreshRolloutUnavailable(
595
+ f"AntMaze SAC expert checkpoint not found at {expert}/params_400000.pkl")
596
+ os.environ.setdefault("JAX_PLATFORMS", "cpu")
597
+ sys.path.insert(0, impls)
598
+ try:
599
+ from agents import SACAgent
600
+ from utils.flax_utils import restore_agent
601
+ from utils.evaluation import supply_rng
602
+ agent_cfg = json.load(open(os.path.join(expert, "flags.json")))["agent"]
603
+ agent = SACAgent.create(seed, np.zeros(29), np.zeros(8), agent_cfg)
604
+ agent = restore_agent(agent, expert, 400000)
605
+ actor_fn = supply_rng(agent.sample_actions, rng=agent.rng)
606
+ finally:
607
+ if impls in sys.path:
608
+ sys.path.remove(impls)
609
+ for mod in [m for m in list(sys.modules)
610
+ if m == "utils" or m.startswith("utils.")
611
+ or m == "agents" or m.startswith("agents.")]:
612
+ del sys.modules[mod]
613
+ return actor_fn
614
+
615
+
616
+ class FreshRolloutUnavailable(RuntimeError):
617
+ """Raised when an env *should* support fresh rollouts but a needed asset (e.g. the
618
+ SAC expert checkpoint) is missing — distinct from envs that fundamentally cannot."""
619
+
620
+
621
+ def gc_fresh_truth_antmaze(env_id, s_anc, a_anc, g_anc, gamma, kind, sigma, eps,
622
+ M=8, H=300, Khead=20, seed=0, verbose=True, anchor_full=None):
623
+ """Fresh-rollout Q^pi(s,a,g) truth for AntMaze, using the EXACT data-collection
624
+ policy: pretrained SAC locomotion expert + oracle-BFS subgoal waypoints + N(0,0.2)
625
+ noise. The 29-D obs is qpos[15]+qvel[14], so the env IS resettable to a dataset
626
+ anchor via set_state. Visual-AntMaze shares ant dynamics; pass `anchor_full` (the
627
+ [A,29] full qpos+qvel anchor states) when the obs itself is an image.
628
+ """
629
+ import numpy as np
630
+ import ogbench
631
+ actor_fn = _load_ant_sac_expert(seed)
632
+ env_name = env_id.replace("visual-", "")
633
+ env = ogbench.make_env_and_datasets(env_name, env_only=True)
634
+ u = env.unwrapped
635
+ env.reset()
636
+ vertex = build_vertex_cells(u.maze_map)
637
+ vertex_xy = np.array([u.ij_to_xy(ij) for ij in vertex])
638
+ rng = np.random.default_rng(seed)
639
+ disc = (1 - gamma) * gamma ** np.arange(H + 1)
640
+
641
+ full = anchor_full if anchor_full is not None else s_anc
642
+
643
+ def goal_posterior(s_xy, heading):
644
+ dirs = np.zeros((len(vertex), 2))
645
+ for k, gxy in enumerate(vertex_xy):
646
+ sg, _ = u.get_oracle_subgoal(s_xy, gxy)
647
+ d = sg - s_xy
648
+ dirs[k] = d / (np.linalg.norm(d) + 1e-6)
649
+ w = np.exp((dirs @ heading) / 0.3)
650
+ return w / w.sum()
651
+
652
+ A = len(full)
653
+ truth = np.zeros(A)
654
+ for ai in range(A):
655
+ s_full = np.asarray(full[ai], dtype=np.float64)
656
+ a_i = np.asarray(a_anc[ai], dtype=np.float64)
657
+ g_i = np.asarray(g_anc[ai][:2], dtype=np.float64)
658
+ # heading toward the recorded near-future: approximate via the action direction
659
+ head = a_i[:2] if np.linalg.norm(a_i[:2]) > 1e-6 else np.array([1.0, 0.0])
660
+ head = head / (np.linalg.norm(head) + 1e-6)
661
+ gpost = goal_posterior(s_full[:2], head)
662
+ ret = 0.0
663
+ for _ in range(M):
664
+ g_ij = vertex[rng.choice(len(vertex), p=gpost)]
665
+ u.set_state(s_full[:15].copy(), s_full[15:29].copy())
666
+ u.set_goal(goal_ij=g_ij)
667
+ xys = [u.get_xy().copy()]
668
+ _, _, term, trunc, info = env.step(a_i)
669
+ xys.append(u.get_xy().copy())
670
+ if info.get("success", False):
671
+ u.set_goal(goal_ij=vertex[rng.integers(len(vertex))])
672
+ for _t in range(1, H):
673
+ sg, _ = u.get_oracle_subgoal(u.get_xy(), u.cur_goal_xy)
674
+ d = sg - u.get_xy()
675
+ d = d / (np.linalg.norm(d) + 1e-6)
676
+ ag_ob = np.concatenate([u.get_ob(ob_type="states")[2:], d])
677
+ act = np.clip(np.asarray(actor_fn(ag_ob, temperature=0)) + rng.normal(0, 0.2, 8), -1, 1)
678
+ _, _, term, trunc, info = env.step(act)
679
+ xys.append(u.get_xy().copy())
680
+ if info.get("success", False):
681
+ u.set_goal(goal_ij=vertex[rng.integers(len(vertex))])
682
+ if term or trunc:
683
+ break
684
+ xys = np.asarray(xys)
685
+ n = len(xys)
686
+ d2g = np.linalg.norm(xys - g_i[None], axis=1)
687
+ rr = reward_of_dist(d2g, kind, sigma, eps)
688
+ ret += float((disc[:n] * rr).sum() / disc[:n].sum())
689
+ truth[ai] = ret / M
690
+ if verbose and (ai + 1) % 25 == 0:
691
+ print(f" [gc-fresh-truth-ant] anchor {ai+1}/{A}", flush=True)
692
+ env.close()
693
+ return truth
694
+
695
+
696
+ # ----------------------------------------------------------------------------
697
+ # fresh-rollout ground truth (AntSoccer): ant SAC loco expert + antball SAC dribble
698
+ # expert + oracle subgoal (the EXACT data-collection controller). Goal = BALL xy.
699
+ # ----------------------------------------------------------------------------
700
+ def _load_antball_sac_expert(seed=0):
701
+ """Load the TWO SAC experts that the AntSoccer data-collection controller uses
702
+ (``generate_antsoccer.py``):
703
+
704
+ * the ant *locomotion* expert (``experts/ant``, epoch 400000) that navigates the
705
+ ANT to the ball — agent obs = ob[2:15] (13 joint pos) + ob[22:36] (14 ant qvel)
706
+ + 2-D oracle-subgoal direction = 29-D, action = 8-D;
707
+ * the *antball* dribble expert (``experts/antball``, epoch 12000000) that dribbles
708
+ the BALL to a subgoal — agent obs = ob[2:15] (13) + ob[17:] (25: ball pose+all
709
+ qvel) + (ball_xy - agent_xy) (2) + (subgoal_xy - ball_xy) (2) = 42-D, action 8-D.
710
+
711
+ Mirrors ``_load_ant_sac_expert`` (import the repo's ``impls`` package, restore, then
712
+ clean sys.modules). Returns ``(loco_actor_fn, ball_actor_fn)``, each
713
+ ``actor_fn(agent_ob, temperature) -> action[8]``. JAX is forced to CPU."""
714
+ import os
715
+ import sys
716
+ import json
717
+ import glob
718
+ import numpy as np
719
+ here = os.path.dirname(os.path.abspath(__file__))
720
+ repo = os.path.normpath(os.path.join(here, "..", "ogbench_repo"))
721
+ impls = os.path.join(repo, "impls")
722
+ experts_dir = os.path.join(repo, "data_gen_scripts", "experts")
723
+ loco_dir = os.path.join(experts_dir, "ant")
724
+ ball_dir = os.path.join(experts_dir, "antball")
725
+ if not os.path.exists(os.path.join(loco_dir, "params_400000.pkl")):
726
+ raise FreshRolloutUnavailable(
727
+ f"AntSoccer ant loco expert not found at {loco_dir}/params_400000.pkl")
728
+ if not glob.glob(os.path.join(ball_dir, "params_12000000.pkl")):
729
+ raise FreshRolloutUnavailable(
730
+ f"AntSoccer antball dribble expert not found at {ball_dir}/params_12000000.pkl")
731
+ os.environ.setdefault("JAX_PLATFORMS", "cpu")
732
+ sys.path.insert(0, impls)
733
+ try:
734
+ from agents import SACAgent
735
+ from utils.flax_utils import restore_agent
736
+ from utils.evaluation import supply_rng
737
+
738
+ def _load(expert_dir, epoch, ob_dim):
739
+ cfg = json.load(open(os.path.join(expert_dir, "flags.json")))["agent"]
740
+ ag = SACAgent.create(seed, np.zeros(ob_dim), np.zeros(8), cfg)
741
+ ag = restore_agent(ag, expert_dir, epoch)
742
+ return supply_rng(ag.sample_actions, rng=ag.rng)
743
+
744
+ loco_actor_fn = _load(loco_dir, 400000, 29)
745
+ ball_actor_fn = _load(ball_dir, 12000000, 42)
746
+ finally:
747
+ if impls in sys.path:
748
+ sys.path.remove(impls)
749
+ for mod in [m for m in list(sys.modules)
750
+ if m == "utils" or m.startswith("utils.")
751
+ or m == "agents" or m.startswith("agents.")]:
752
+ del sys.modules[mod]
753
+ return loco_actor_fn, ball_actor_fn
754
+
755
+
756
+ def _nearest_free_cell_xy(u, cells_xy, xy):
757
+ """Index of the free maze cell whose center is closest to a target xy."""
758
+ return int(np.argmin(np.linalg.norm(cells_xy - np.asarray(xy)[None], axis=1)))
759
+
760
+
761
+ def gc_fresh_truth_antsoccer(env_id, s_anc, a_anc, g_anc, gamma, kind, sigma, eps,
762
+ M=4, H=300, seed=0, verbose=True, anchor_full=None):
763
+ """Fresh-rollout Q^pi(s, a, g) truth for AntSoccer, using the EXACT data-collection
764
+ controller from ``generate_antsoccer.py``: an ant SAC loco expert that walks the ant
765
+ to the ball when it is far (``||agent_xy - ball_xy|| > 2``), and an antball SAC
766
+ dribble expert that drives the ball toward the oracle subgoal otherwise, plus the
767
+ same N(0, 0.2) action noise. On goal success a new random goal cell is sampled (the
768
+ 'navigate' generator behaviour). The OCCUPANCY TARGET and REWARD are on the BALL xy
769
+ (obs[15:17]); g is a ball goal xy. The 42-D obs IS the full qpos[22]+qvel[20] state,
770
+ so each anchor is reset via ``set_state`` (dataset-anchor protocol, like AntMaze).
771
+ The controller dribbles toward the free maze cell nearest to the anchor goal g_i, so
772
+ the rolled policy is consistent with the goal Q(s,a,g) is queried at.
773
+ """
774
+ import numpy as np
775
+ import ogbench
776
+ loco_actor_fn, ball_actor_fn = _load_antball_sac_expert(seed)
777
+ # terminate_at_goal=False so a rollout keeps accumulating reward across multiple goal
778
+ # completions (per FRESH_RESET_SPEC) — the discounted occupancy reward is defined over
779
+ # the full geometric horizon, not cut short at the first ball-goal success.
780
+ env = ogbench.make_env_and_datasets(
781
+ env_id, env_only=True, terminate_at_goal=False, max_episode_steps=H + 5)
782
+ u = env.unwrapped
783
+ env.reset()
784
+ mm = np.asarray(u.maze_map)
785
+ cells = [(i, j) for i in range(mm.shape[0]) for j in range(mm.shape[1]) if mm[i, j] == 0]
786
+ cells_xy = np.array([u.ij_to_xy(ij) for ij in cells])
787
+ rng = np.random.default_rng(seed)
788
+ disc = (1 - gamma) * gamma ** np.arange(H + 1)
789
+
790
+ full = anchor_full if anchor_full is not None else s_anc
791
+
792
+ def loco_action(ob, goal_xy):
793
+ sg, _ = u.get_oracle_subgoal(ob[:2], goal_xy)
794
+ d = sg - ob[:2]
795
+ d = d / (np.linalg.norm(d) + 1e-6)
796
+ agent_ob = np.concatenate([ob[2:15], ob[22:36], d])
797
+ return np.asarray(loco_actor_fn(agent_ob, temperature=0))
798
+
799
+ def ball_action(ob, agent_xy, ball_xy, goal_xy):
800
+ sg, _ = u.get_oracle_subgoal(ball_xy, goal_xy)
801
+ agent_ob = np.concatenate([ob[2:15], ob[17:], ball_xy - agent_xy, sg - ball_xy])
802
+ return np.asarray(ball_actor_fn(agent_ob, temperature=0))
803
+
804
+ A = len(full)
805
+ truth = np.zeros(A)
806
+ for ai in range(A):
807
+ s_full = np.asarray(full[ai], dtype=np.float64)
808
+ a_i = np.asarray(a_anc[ai], dtype=np.float64)
809
+ g_i = np.asarray(g_anc[ai][:2], dtype=np.float64) # ball goal xy
810
+ g_cell0 = cells[_nearest_free_cell_xy(u, cells_xy, g_i)]
811
+ ret = 0.0
812
+ for _ in range(M):
813
+ u.set_state(s_full[:22].copy(), s_full[22:].copy())
814
+ u.set_goal(goal_ij=g_cell0)
815
+ ball_xy0 = np.asarray(u.get_agent_ball_xy()[1])
816
+ balls = [ball_xy0.copy()]
817
+ # step 0: the recorded behaviour action a_i (conditioning Q on (s,a)).
818
+ ob, _, term, trunc, info = env.step(np.clip(a_i, -1, 1))
819
+ balls.append(np.asarray(u.get_agent_ball_xy()[1]).copy())
820
+ if info.get("success", False):
821
+ u.set_goal(goal_ij=cells[rng.integers(len(cells))])
822
+ for _t in range(1, H):
823
+ agent_xy, ball_xy = map(np.asarray, u.get_agent_ball_xy())
824
+ goal_xy = np.asarray(u.cur_goal_xy)
825
+ if np.linalg.norm(agent_xy - ball_xy) > 2:
826
+ act = loco_action(ob, ball_xy)
827
+ else:
828
+ act = ball_action(ob, agent_xy, ball_xy, goal_xy)
829
+ act = np.clip(act + rng.normal(0, 0.2, act.shape), -1, 1)
830
+ ob, _, term, trunc, info = env.step(act)
831
+ balls.append(np.asarray(u.get_agent_ball_xy()[1]).copy())
832
+ if info.get("success", False):
833
+ u.set_goal(goal_ij=cells[rng.integers(len(cells))])
834
+ if term or trunc:
835
+ break
836
+ balls = np.asarray(balls)
837
+ n = len(balls)
838
+ d2g = np.linalg.norm(balls - g_i[None], axis=1)
839
+ rr = reward_of_dist(d2g, kind, sigma, eps)
840
+ ret += float((disc[:n] * rr).sum() / disc[:n].sum())
841
+ truth[ai] = ret / M
842
+ if verbose and (ai + 1) % 25 == 0:
843
+ print(f" [gc-fresh-truth-antsoccer] anchor {ai+1}/{A}", flush=True)
844
+ env.close()
845
+ return truth
846
+
847
+
848
+ # ----------------------------------------------------------------------------
849
+ # fresh-reset anchor protocol (manipspace: cube / scene / puzzle) — Protocol B
850
+ # ----------------------------------------------------------------------------
851
+ def _make_manipspace_env(env_id, dataset_dir="~/.ogbench/data"):
852
+ """Build the live manipspace env per FRESH_RESET_SPEC: data_collection mode,
853
+ terminate_at_goal=False, long horizon. Returns the gym env."""
854
+ import ogbench
855
+ return ogbench.make_env_and_datasets(
856
+ env_id, env_only=True, terminate_at_goal=False,
857
+ mode="data_collection", max_episode_steps=1001, dataset_dir=dataset_dir)
858
+
859
+
860
+ def _make_manipspace_oracles(env, fam):
861
+ """Family-keyed live markov oracles (NOISY-equivalent closed loop). Returns a dict
862
+ keyed by ``info['privileged/target_task']`` so set_new_target re-keying works."""
863
+ from ogbench.manipspace.oracles.markov.button_markov import ButtonMarkovOracle
864
+ from ogbench.manipspace.oracles.markov.cube_markov import CubeMarkovOracle
865
+ if fam == "cube":
866
+ return {"cube": CubeMarkovOracle(env=env, min_norm=0.4)}
867
+ if fam == "puzzle":
868
+ return {"button": ButtonMarkovOracle(env=env, min_norm=0.4, gripper_always_closed=True)}
869
+ if fam == "scene":
870
+ from ogbench.manipspace.oracles.markov.drawer_markov import DrawerMarkovOracle
871
+ from ogbench.manipspace.oracles.markov.window_markov import WindowMarkovOracle
872
+ return {
873
+ "cube": CubeMarkovOracle(env=env, min_norm=0.4, max_step=100),
874
+ "button": ButtonMarkovOracle(env=env, min_norm=0.4),
875
+ "drawer": DrawerMarkovOracle(env=env, min_norm=0.4),
876
+ "window": WindowMarkovOracle(env=env, min_norm=0.4),
877
+ }
878
+ raise gc_core_error(f"no manipspace oracle for family {fam!r}")
879
+
880
+
881
+ def _manipspace_block_positions(info):
882
+ """All blocks' current 3-D positions concatenated [3*n_blocks], in block index order
883
+ (matches the occupancy-target layout from ``_manipspace_block_qpos_slices``)."""
884
+ block_keys = sorted(k for k in info
885
+ if k.startswith("privileged/block_") and k.endswith("_pos")
886
+ and k != "privileged/target_block_pos")
887
+ return np.concatenate([np.asarray(info[k], dtype=np.float64) for k in block_keys])
888
+
889
+
890
+ def _manipspace_goal(info, fam):
891
+ """Privileged goal g for an anchor, in the SAME layout as the occupancy target:
892
+ cube: all-blocks position vector [3*n_blocks] where the target block's slot is its
893
+ goal (``target_block_pos``) and every distractor block's slot is its CURRENT
894
+ position — so ||x-g|| rewards moving the target block to its goal while the
895
+ distractors stay put (cube-single: identical to the old 3-D goal; cube-double:
896
+ 6-D, the fix for the alternating target_block).
897
+ scene: the 7-D scene oracle TARGET config (multi-task).
898
+ puzzle: target button-state vector.
899
+ """
900
+ if fam == "puzzle":
901
+ # full target button-state pattern (current states with the target button flipped)
902
+ cur = np.asarray(info["button_states"], dtype=np.float64).copy()
903
+ tb = int(info["privileged/target_button"])
904
+ cur[tb] = float(info["privileged/target_button_state"])
905
+ return cur
906
+ if fam == "scene":
907
+ return _scene_target_vec_from_info(info)
908
+ g = _manipspace_block_positions(info).copy() # current positions of all blocks
909
+ tb = int(info["privileged/target_block"])
910
+ g[tb * 3:tb * 3 + 3] = np.asarray(info["privileged/target_block_pos"], dtype=np.float64)
911
+ return g
912
+
913
+
914
+ def _manipspace_object(info, fam):
915
+ """Privileged current object value x for reward accumulation, SAME layout as the
916
+ occupancy target: all blocks' current positions (cube), the current 7-D scene oracle
917
+ vector (scene, multi-task), or the current button-state vector (puzzle)."""
918
+ if fam == "puzzle":
919
+ return np.asarray(info["button_states"], dtype=np.float64)
920
+ if fam == "scene":
921
+ return _scene_oracle_vec_from_info(info)
922
+ return _manipspace_block_positions(info)
923
+
924
+
925
+ def prepare_eval_anchors(env_id, val_ds, cfg, seed):
926
+ """Return the (s, a, g) anchors a method queries Q at, plus metadata for truth.
927
+
928
+ Returns a dict:
929
+ s, a, g : [A, .] conditioning state, behaviour action, goal (the model query)
930
+ anchor_idx : [A] dataset indices (mazes) or None (manipspace)
931
+ anchor_full : full qpos+qvel anchor states for antmaze-full, else None
932
+ anchors_pack : fresh-reset pack (manipspace) or None
933
+ anchor_protocol: "dataset_anchor" (mazes) | "fresh_reset" (manipspace)
934
+
935
+ Maze path is unchanged from the original per-method code; manipspace uses
936
+ ``fresh_reset_anchors`` so the SAME anchors feed both Q(s,a,g) and the truth.
937
+ """
938
+ pos = cfg.get("pos_dim", 2)
939
+ if is_manipspace(env_id):
940
+ # manipulation reward scale (NOT the maze sigma=5 / eps=0.5) unless the caller
941
+ # explicitly overrode it. The maze defaults are meaningless at object scale.
942
+ if not cfg.get("_reward_scale_set"):
943
+ fam = manipspace_family(env_id)
944
+ if fam == "scene":
945
+ # scene uses the 7-D oracle-space occupancy target (not raw 3-D meters):
946
+ # block xyz is scaled x10, drawer x18, window x15, button states are 0/1,
947
+ # so within-task moves are ~1-3 oracle units. Use a reward bandwidth at
948
+ # that scale (NOT the cube 0.05/0.04 meter scale).
949
+ if abs(cfg.get("sigma", 5.0) - 5.0) < 1e-9:
950
+ cfg["sigma"] = 0.5
951
+ if abs(cfg.get("epsilon", 0.5) - 0.5) < 1e-9:
952
+ cfg["epsilon"] = 0.5
953
+ else:
954
+ if abs(cfg.get("sigma", 5.0) - 5.0) < 1e-9:
955
+ cfg["sigma"] = 0.05
956
+ if abs(cfg.get("epsilon", 0.5) - 0.5) < 1e-9:
957
+ cfg["epsilon"] = 0.04
958
+ cfg["_reward_scale_set"] = True
959
+ pack = fresh_reset_anchors(env_id, cfg["n_anchors"], seed)
960
+ return dict(s=pack["s"], a=pack["a"], g=pack["g"], anchor_idx=None,
961
+ anchor_full=None, anchors_pack=pack,
962
+ anchor_protocol="fresh_reset")
963
+ rng = np.random.default_rng(seed)
964
+ anchors = anchors_with_min_horizon(val_ds, cfg["n_anchors"], cfg["min_horizon"], rng)
965
+ s_a = val_ds["obs"][anchors]; a_a = val_ds["act"][anchors]
966
+ # Goal lives in TARGET space: ball xy for antsoccer (via ds['obj']), agent xy for
967
+ # other mazes. _target_array returns ds['obj'] for antsoccer, obs xy slice for mazes.
968
+ target = _target_array(val_ds, cfg)
969
+ g_a = target[sample_goal_idx(anchors, val_ds["end"], rng)][:, :pos]
970
+ state_slice = cfg.get("state_slice", "auto")
971
+ # The fresh-rollout truth needs the FULL obs to set_state. AntSoccer obs IS the full
972
+ # qpos+qvel state (always full), so pass anchor_full unconditionally for it.
973
+ anchor_full = s_a if (("antsoccer" in env_id)
974
+ or (state_slice == "full"
975
+ and ("antmaze" in env_id or "humanoidmaze" in env_id))) else None
976
+ return dict(s=s_a, a=a_a, g=g_a, anchor_idx=anchors, anchor_full=anchor_full,
977
+ anchors_pack=None, anchor_protocol="dataset_anchor")
978
+
979
+
980
+ def fresh_reset_anchors(env_id, n_anchors, seed, dataset_dir="~/.ogbench/data"):
981
+ """Protocol B fresh-reset anchors for a manipspace env.
982
+
983
+ Does ``n_anchors`` independent ``env.reset(seed=...)`` calls (a valid
984
+ in-distribution start each time) and records per anchor:
985
+ s : obs (full normalized observation, the conditioning state)
986
+ qpos : full MuJoCo qpos qvel : full MuJoCo qvel (for set_state)
987
+ g : privileged goal (target object position 3-D, or puzzle target button-state)
988
+ a : first oracle action at the reset state (behavior-policy action for Q(s,a))
989
+ obj0 : privileged object value at reset (for reference)
990
+ The SAME anchors are used to query Q(s,a,g) AND to compute the fresh-rollout truth,
991
+ so the two align per-anchor. Returns a dict of stacked arrays + the family.
992
+ """
993
+ fam = manipspace_family(env_id)
994
+ if fam is None:
995
+ raise gc_core_error(f"fresh_reset_anchors called for non-manipspace env {env_id}")
996
+ env = _make_manipspace_env(env_id, dataset_dir)
997
+ u = env.unwrapped
998
+ oracles = _make_manipspace_oracles(env, fam)
999
+ S, A, G, QP, QV, OBJ, TGT = [], [], [], [], [], [], []
1000
+ for i in range(n_anchors):
1001
+ np.random.seed(seed * 100003 + i) # oracles use global np.random
1002
+ ob, info = env.reset(seed=seed * 100003 + i)
1003
+ oracle = oracles[info["privileged/target_task"]]
1004
+ oracle.reset(ob, info)
1005
+ a0 = np.clip(np.asarray(oracle.select_action(ob, info), dtype=np.float64), -1, 1)
1006
+ S.append(np.asarray(ob, dtype=np.float32))
1007
+ A.append(a0.astype(np.float32))
1008
+ G.append(_manipspace_goal(info, fam).astype(np.float32))
1009
+ QP.append(np.asarray(info["qpos"], dtype=np.float64))
1010
+ QV.append(np.asarray(info["qvel"], dtype=np.float64))
1011
+ OBJ.append(_manipspace_object(info, fam).astype(np.float32))
1012
+ TGT.append(_capture_manipspace_target(u, fam, info))
1013
+ env.close()
1014
+ # For puzzle, obj0 IS the button-state vector (needed by set_state).
1015
+ return dict(family=fam, s=np.stack(S), a=np.stack(A), g=np.stack(G),
1016
+ qpos=np.stack(QP), qvel=np.stack(QV), obj0=np.stack(OBJ),
1017
+ target=TGT)
1018
+
1019
+
1020
+ def _capture_manipspace_target(u, fam, info):
1021
+ """Snapshot the task target the oracle drives toward, so the truth env can restore
1022
+ it after set_state (set_state does NOT restore mocap / button / drawer / window
1023
+ targets). For cube: (target_block, mocap_pos, mocap_quat). For puzzle:
1024
+ (target_button, target_button_states). For scene the target depends on
1025
+ info['privileged/target_task'] — we snapshot ALL scene target state so the exact
1026
+ sub-task goal is reproduced (see _restore_manipspace_target)."""
1027
+ if fam == "puzzle":
1028
+ return dict(target_button=int(info["privileged/target_button"]),
1029
+ target_button_states=np.asarray(u._target_button_states).copy())
1030
+ if fam == "scene":
1031
+ # Capture everything the SceneEnv oracle keys / drives on for any of the 4 tasks,
1032
+ # plus the current button states (needed by SceneEnv.set_state).
1033
+ snap = dict(
1034
+ target_task=str(info["privileged/target_task"]),
1035
+ button_states=np.asarray(info["button_states"]).astype(np.int64).copy(),
1036
+ target_block=int(u._target_block),
1037
+ target_button=int(u._target_button),
1038
+ target_button_states=np.asarray(u._target_button_states).copy(),
1039
+ target_drawer_pos=float(u._target_drawer_pos),
1040
+ target_window_pos=float(u._target_window_pos),
1041
+ )
1042
+ snap["cube_mocap_pos"] = [np.asarray(u._data.mocap_pos[mid]).copy()
1043
+ for mid in u._cube_target_mocap_ids]
1044
+ snap["cube_mocap_quat"] = [np.asarray(u._data.mocap_quat[mid]).copy()
1045
+ for mid in u._cube_target_mocap_ids]
1046
+ # Drawer / window target SITE positions (the oracle reads target_*_handle_pos
1047
+ # off these sites; set_new_target writes them via site.pos).
1048
+ snap["drawer_target_site_pos"] = np.asarray(
1049
+ u._model.site("drawer_handle_center_target").pos).copy()
1050
+ snap["window_target_site_pos"] = np.asarray(
1051
+ u._model.site("window_handle_center_target").pos).copy()
1052
+ return snap
1053
+ tb = int(info["privileged/target_block"])
1054
+ mid = u._cube_target_mocap_ids[tb]
1055
+ return dict(target_block=tb,
1056
+ mocap_pos=np.asarray(u._data.mocap_pos[mid]).copy(),
1057
+ mocap_quat=np.asarray(u._data.mocap_quat[mid]).copy())
1058
+
1059
+
1060
+ def _restore_manipspace_target(u, fam, tgt):
1061
+ """Re-apply a captured target onto the live env after set_state, so the oracle
1062
+ drives toward the SAME goal that the recorded g / Q-query used."""
1063
+ import mujoco
1064
+ if fam == "puzzle":
1065
+ u._target_button = int(tgt["target_button"])
1066
+ u._target_button_states = np.asarray(tgt["target_button_states"]).copy()
1067
+ return
1068
+ if fam == "scene":
1069
+ u._target_task = tgt["target_task"]
1070
+ u._target_block = int(tgt["target_block"])
1071
+ u._target_button = int(tgt["target_button"])
1072
+ u._target_button_states = np.asarray(tgt["target_button_states"]).copy()
1073
+ u._target_drawer_pos = float(tgt["target_drawer_pos"])
1074
+ u._target_window_pos = float(tgt["target_window_pos"])
1075
+ for mid, p, q in zip(u._cube_target_mocap_ids,
1076
+ tgt["cube_mocap_pos"], tgt["cube_mocap_quat"]):
1077
+ u._data.mocap_pos[mid] = np.asarray(p).copy()
1078
+ u._data.mocap_quat[mid] = np.asarray(q).copy()
1079
+ u._model.site("drawer_handle_center_target").pos[:] = tgt["drawer_target_site_pos"]
1080
+ u._model.site("window_handle_center_target").pos[:] = tgt["window_target_site_pos"]
1081
+ mujoco.mj_forward(u._model, u._data)
1082
+ return
1083
+ tb = int(tgt["target_block"])
1084
+ u._target_block = tb
1085
+ mid = u._cube_target_mocap_ids[tb]
1086
+ u._data.mocap_pos[mid] = np.asarray(tgt["mocap_pos"]).copy()
1087
+ u._data.mocap_quat[mid] = np.asarray(tgt["mocap_quat"]).copy()
1088
+ mujoco.mj_forward(u._model, u._data)
1089
+
1090
+
1091
+ def gc_fresh_truth_manipspace(env_id, anchors, gamma, kind, sigma, eps,
1092
+ M=8, H=200, seed=0, verbose=True, dataset_dir="~/.ogbench/data"):
1093
+ """Fresh-rollout Q^pi(s,a,g) truth for manipspace anchors (Protocol B).
1094
+
1095
+ `anchors` is the dict returned by ``fresh_reset_anchors``. For each anchor, M times:
1096
+ 1. ``set_state(qpos, qvel)`` (mocap target persists from the original reset, so the
1097
+ goal g is held fixed across the M repeats — we never reset between repeats).
1098
+ 2. apply the recorded behaviour action ``a`` first (conditioning Q on (s,a)).
1099
+ 3. roll the live markov oracle for H steps, re-keying on ``oracle.done`` via
1100
+ ``env.unwrapped.set_new_target()`` (mirrors generate_manipspace.py), adding the
1101
+ same per-episode Gaussian action noise the "noisy" generator uses.
1102
+ Accumulate the renormalized discounted goal-reaching reward toward g, using the
1103
+ privileged OBJECT value each step. Average over M.
1104
+ """
1105
+ fam = anchors["family"]
1106
+ env = _make_manipspace_env(env_id, dataset_dir)
1107
+ u = env.unwrapped
1108
+ env.reset(seed=seed)
1109
+ oracles = _make_manipspace_oracles(env, fam)
1110
+ rng = np.random.default_rng(seed)
1111
+ disc = (1 - gamma) * gamma ** np.arange(H + 1)
1112
+
1113
+ def reward_to_goal(obj, g):
1114
+ # Goal-reaching reward, IDENTICAL to occ_q / MC / TD. For cube/scene x,g are 3-D
1115
+ # object positions and the reward is the position-distance reward_of_dist(||x-g||).
1116
+ # For PUZZLE x,g are binary button-state vectors; the position-distance reward with
1117
+ # the manip sigma is meaningless (||x-g||=sqrt Hamming, saturates exp() to 0), so we
1118
+ # use the match-fraction reward (issue #35 fix) consistently with occ_q/MC/TD.
1119
+ if fam == "puzzle":
1120
+ return float(puzzle_reward(obj, g, kind))
1121
+ d = float(np.linalg.norm(np.asarray(obj, dtype=np.float64)
1122
+ - np.asarray(g, dtype=np.float64)))
1123
+ return float(reward_of_dist(np.array([d]), kind, sigma, eps)[0])
1124
+
1125
+ A = len(anchors["s"])
1126
+ truth = np.zeros(A)
1127
+ for ai in range(A):
1128
+ qpos = anchors["qpos"][ai].copy()
1129
+ qvel = anchors["qvel"][ai].copy()
1130
+ a_i = anchors["a"][ai].astype(np.float64)
1131
+ g_i = anchors["g"][ai].astype(np.float64)
1132
+ tgt = anchors["target"][ai]
1133
+ ret = 0.0
1134
+ for _ in range(M):
1135
+ # restore the anchor state, then re-apply the captured task target so the
1136
+ # oracle drives toward the SAME goal g the Q-query used (set_state alone does
1137
+ # NOT restore the mocap / button target).
1138
+ if fam == "puzzle":
1139
+ # puzzle set_state needs the (integer) button-state vector.
1140
+ u.set_state(qpos.copy(), qvel.copy(),
1141
+ np.asarray(anchors["obj0"][ai]).astype(np.int64))
1142
+ elif fam == "scene":
1143
+ # SceneEnv.set_state(qpos, qvel, button_states) requires the (integer)
1144
+ # current button-state vector, captured per anchor in target["button_states"].
1145
+ u.set_state(qpos.copy(), qvel.copy(),
1146
+ np.asarray(tgt["button_states"]).astype(np.int64).copy())
1147
+ else:
1148
+ u.set_state(qpos.copy(), qvel.copy())
1149
+ _restore_manipspace_target(u, fam, tgt)
1150
+ info = u.compute_ob_info()
1151
+ ob = u.compute_observation()
1152
+ xi = rng.uniform(0, 0.1) # noisy-oracle action noise
1153
+ oracle = oracles[info["privileged/target_task"]]
1154
+ oracle.reset(ob, info)
1155
+ # step 0: the recorded behaviour action a_i
1156
+ ob, _, term, trunc, info = env.step(np.clip(a_i, -1, 1))
1157
+ objs = [_manipspace_object(info, fam)]
1158
+ if oracle.done:
1159
+ ag_ob, ag_info = u.set_new_target()
1160
+ oracle = oracles[ag_info["privileged/target_task"]]
1161
+ oracle.reset(ag_ob, ag_info)
1162
+ for _t in range(1, H):
1163
+ action = np.asarray(oracle.select_action(ob, info), dtype=np.float64)
1164
+ action = action + rng.normal(0, [xi, xi, xi, xi * 3, xi * 10], action.shape)
1165
+ action = np.clip(action, -1, 1)
1166
+ ob, _, term, trunc, info = env.step(action)
1167
+ objs.append(_manipspace_object(info, fam))
1168
+ if oracle.done:
1169
+ ag_ob, ag_info = u.set_new_target()
1170
+ oracle = oracles[ag_info["privileged/target_task"]]
1171
+ oracle.reset(ag_ob, ag_info)
1172
+ if term or trunc:
1173
+ break
1174
+ objs = np.asarray(objs)
1175
+ n = len(objs)
1176
+ rr = np.array([reward_to_goal(objs[k], g_i) for k in range(n)])
1177
+ ret += float((disc[:n] * rr).sum() / disc[:n].sum())
1178
+ truth[ai] = ret / M
1179
+ if verbose and (ai + 1) % 25 == 0:
1180
+ print(f" [gc-fresh-truth-manip] anchor {ai+1}/{A}", flush=True)
1181
+ env.close()
1182
+ return truth
1183
+
1184
+
1185
+ # ----------------------------------------------------------------------------
1186
+ # fresh-rollout ground truth (HumanoidMaze): humanoid SAC expert + oracle subgoal
1187
+ # ----------------------------------------------------------------------------
1188
+ def _load_humanoid_sac_expert(seed=0):
1189
+ """Load the OGBench SAC locomotion expert used to collect HumanoidMaze data.
1190
+
1191
+ Mirrors ``_load_ant_sac_expert`` exactly (same import-and-clean trick around the
1192
+ repo's ``impls/`` package), but with the HUMANOID body: the xy-env agent
1193
+ observation is 69-D (``get_ob(states)[2:]`` = 67-D + 2-D subgoal direction) and the
1194
+ action is 21-D. The expert checkpoint is ``params_40000000.pkl`` (restore_epoch
1195
+ 40000000, per ``experts/humanoid/flags.json``). Returns
1196
+ actor_fn(agent_ob[69], temperature) -> action[21]. JAX is forced to CPU."""
1197
+ import os
1198
+ import sys
1199
+ import json
1200
+ import numpy as np
1201
+ here = os.path.dirname(os.path.abspath(__file__))
1202
+ repo = os.path.normpath(os.path.join(here, "..", "ogbench_repo"))
1203
+ impls = os.path.join(repo, "impls")
1204
+ expert = os.path.join(repo, "data_gen_scripts", "experts", "humanoid")
1205
+ restore_epoch = 40000000
1206
+ ckpt = os.path.join(expert, f"params_{restore_epoch}.pkl")
1207
+ if not os.path.exists(ckpt):
1208
+ raise FreshRolloutUnavailable(
1209
+ f"HumanoidMaze SAC expert checkpoint not found at {ckpt}")
1210
+ os.environ.setdefault("JAX_PLATFORMS", "cpu")
1211
+ sys.path.insert(0, impls)
1212
+ try:
1213
+ from agents import SACAgent
1214
+ from utils.flax_utils import restore_agent
1215
+ from utils.evaluation import supply_rng
1216
+ agent_cfg = json.load(open(os.path.join(expert, "flags.json")))["agent"]
1217
+ # agent_ob = get_ob(states)[2:] (67) + subgoal_dir (2) = 69; action = 21.
1218
+ agent = SACAgent.create(seed, np.zeros(69), np.zeros(21), agent_cfg)
1219
+ agent = restore_agent(agent, expert, restore_epoch)
1220
+ actor_fn = supply_rng(agent.sample_actions, rng=agent.rng)
1221
+ finally:
1222
+ if impls in sys.path:
1223
+ sys.path.remove(impls)
1224
+ for mod in [m for m in list(sys.modules)
1225
+ if m == "utils" or m.startswith("utils.")
1226
+ or m == "agents" or m.startswith("agents.")]:
1227
+ del sys.modules[mod]
1228
+ return actor_fn
1229
+
1230
+
1231
+ def _humanoid_full_state_from_obs(u, ob):
1232
+ """Reconstruct a (qpos[nq], qvel[nv]) reset state from a 69-D HumanoidMaze obs.
1233
+
1234
+ The HumanoidMaze observation is NOT raw qpos+qvel (unlike AntMaze's 29-D). It is a
1235
+ derived feature vector (see ogbench/locomaze/humanoid.py:get_ob):
1236
+ xy(2) | joint_angles(21) | head_height(1) | extremities(12) |
1237
+ torso_vertical_orientation(3) | com_velocity(3) | velocity=qvel(27)
1238
+ qpos = [xy(2), root_z+quat(5), joint_angles(21)] (nq=28); qvel = velocity (nv=27).
1239
+ Everything except qpos[2:7] (root height + orientation quaternion, which only enter
1240
+ the obs through xpos/xmat-derived features that are not analytically invertible) is
1241
+ recoverable EXACTLY from the obs. We fill qpos[2:7] from the env's canonical upright
1242
+ init_qpos, so the anchor is a valid upright humanoid at the recorded xy with the
1243
+ recorded joint configuration and full velocity — the closest physically-consistent
1244
+ reset the dataset (which ships no qpos/qvel) permits."""
1245
+ import numpy as np
1246
+ ob = np.asarray(ob, dtype=np.float64)
1247
+ qpos = u.init_qpos.copy()
1248
+ qvel = u.init_qvel.copy()
1249
+ qpos[:2] = ob[:2] # xy
1250
+ qpos[7:] = ob[2:23] # 21 joint angles
1251
+ qvel[:] = ob[-27:] # 27-D qvel (tail of obs)
1252
+ return qpos, qvel
1253
+
1254
+
1255
+ def gc_fresh_truth_humanoidmaze(env_id, s_anc, a_anc, g_anc, gamma, kind, sigma, eps,
1256
+ M=8, H=300, Khead=20, seed=0, verbose=True, anchor_full=None):
1257
+ """Fresh-rollout Q^pi(s,a,g) truth for HumanoidMaze, using the EXACT data-collection
1258
+ policy: pretrained HUMANOID SAC locomotion expert + oracle-BFS subgoal waypoints +
1259
+ N(0,0.2) action noise (same controller family as AntMaze, different body).
1260
+
1261
+ Unlike AntMaze, the HumanoidMaze obs is a 69-D derived feature vector, not raw
1262
+ qpos+qvel, and the dataset ships no qpos/qvel. We reconstruct a valid reset state
1263
+ via ``_humanoid_full_state_from_obs`` (exact xy / joint-angles / qvel; canonical
1264
+ upright root height+quat) and reset with ``set_state``. The agent observation fed to
1265
+ the expert is ``get_ob(states)[2:]`` concatenated with the unit oracle-subgoal
1266
+ direction, exactly as generate_locomaze.py builds it."""
1267
+ import numpy as np
1268
+ import ogbench
1269
+ actor_fn = _load_humanoid_sac_expert(seed)
1270
+ env_name = env_id.replace("visual-", "")
1271
+ env = ogbench.make_env_and_datasets(env_name, env_only=True)
1272
+ u = env.unwrapped
1273
+ env.reset()
1274
+ vertex = build_vertex_cells(u.maze_map)
1275
+ vertex_xy = np.array([u.ij_to_xy(ij) for ij in vertex])
1276
+ rng = np.random.default_rng(seed)
1277
+ disc = (1 - gamma) * gamma ** np.arange(H + 1)
1278
+
1279
+ # For HumanoidMaze the conditioning obs IS the 69-D state (state_slice="full"), and
1280
+ # `anchor_full` (when passed) carries those same 69-D obs to reconstruct the reset.
1281
+ full = anchor_full if anchor_full is not None else s_anc
1282
+
1283
+ def goal_posterior(s_xy, heading):
1284
+ dirs = np.zeros((len(vertex), 2))
1285
+ for k, gxy in enumerate(vertex_xy):
1286
+ sg, _ = u.get_oracle_subgoal(s_xy, gxy)
1287
+ d = sg - s_xy
1288
+ dirs[k] = d / (np.linalg.norm(d) + 1e-6)
1289
+ w = np.exp((dirs @ heading) / 0.3)
1290
+ return w / w.sum()
1291
+
1292
+ A = len(full)
1293
+ truth = np.zeros(A)
1294
+ for ai in range(A):
1295
+ ob_full = np.asarray(full[ai], dtype=np.float64)
1296
+ a_i = np.asarray(a_anc[ai], dtype=np.float64)
1297
+ g_i = np.asarray(g_anc[ai][:2], dtype=np.float64)
1298
+ qpos0, qvel0 = _humanoid_full_state_from_obs(u, ob_full)
1299
+ s_xy0 = ob_full[:2]
1300
+ # heading toward the recorded near-future: approximate via the com-velocity xy
1301
+ # (obs com_velocity is 3-D at index 39:42); fall back to a fixed heading.
1302
+ head = ob_full[39:41] if np.linalg.norm(ob_full[39:41]) > 1e-6 else np.array([1.0, 0.0])
1303
+ head = head / (np.linalg.norm(head) + 1e-6)
1304
+ gpost = goal_posterior(s_xy0, head)
1305
+ ret = 0.0
1306
+ for _ in range(M):
1307
+ g_ij = vertex[rng.choice(len(vertex), p=gpost)]
1308
+ u.set_state(qpos0.copy(), qvel0.copy())
1309
+ u.set_goal(goal_ij=g_ij)
1310
+ xys = [u.get_xy().copy()]
1311
+ _, _, term, trunc, info = env.step(a_i)
1312
+ xys.append(u.get_xy().copy())
1313
+ if info.get("success", False):
1314
+ u.set_goal(goal_ij=vertex[rng.integers(len(vertex))])
1315
+ for _t in range(1, H):
1316
+ sg, _ = u.get_oracle_subgoal(u.get_xy(), u.cur_goal_xy)
1317
+ d = sg - u.get_xy()
1318
+ d = d / (np.linalg.norm(d) + 1e-6)
1319
+ ag_ob = np.concatenate([u.get_ob(ob_type="states")[2:], d])
1320
+ act = np.clip(np.asarray(actor_fn(ag_ob, temperature=0)) + rng.normal(0, 0.2, 21), -1, 1)
1321
+ _, _, term, trunc, info = env.step(act)
1322
+ xys.append(u.get_xy().copy())
1323
+ if info.get("success", False):
1324
+ u.set_goal(goal_ij=vertex[rng.integers(len(vertex))])
1325
+ if term or trunc:
1326
+ break
1327
+ xys = np.asarray(xys)
1328
+ n = len(xys)
1329
+ d2g = np.linalg.norm(xys - g_i[None], axis=1)
1330
+ rr = reward_of_dist(d2g, kind, sigma, eps)
1331
+ ret += float((disc[:n] * rr).sum() / disc[:n].sum())
1332
+ truth[ai] = ret / M
1333
+ if verbose and (ai + 1) % 25 == 0:
1334
+ print(f" [gc-fresh-truth-humanoid] anchor {ai+1}/{A}", flush=True)
1335
+ env.close()
1336
+ return truth
1337
+
1338
+
1339
+ # ----------------------------------------------------------------------------
1340
+ # fresh-rollout ground truth (Powderworld) — Protocol B, image obs + discrete action
1341
+ # ----------------------------------------------------------------------------
1342
+ def gc_fresh_truth_powderworld(anchors, gamma, kind, sigma, eps,
1343
+ M=8, H=120, seed=0, verbose=True, num_elems=2):
1344
+ """Fresh-rollout Q^pi(s, a, g) truth for Powderworld anchors (Protocol B).
1345
+
1346
+ Powderworld's obs is a (32,32,6) image and its data-collection behaviour policy is
1347
+ OPEN-LOOP scripted drawing (Fill / Line / Square + 50% random semantic actions),
1348
+ matching ``data_gen_scripts/generate_powderworld.py``. ``anchors`` is the dict from
1349
+ ``powderworld_fresh_reset_anchors`` carrying, per anchor, the saved pw ``world`` array
1350
+ (to restore the start), the recorded behaviour action ``a`` (a single discrete int),
1351
+ the matching ``action_step`` phase, and the goal world-summary ``g`` (phi in R^2).
1352
+
1353
+ For each anchor, M times:
1354
+ 1. restore the saved world + action phase (the env start).
1355
+ 2. apply the recorded discrete action ``a`` first (conditioning Q on (s,a)).
1356
+ 3. roll the scripted behaviour policy (Fill/Line/Square + 50% random) for H *agent
1357
+ decisions* (each = 3 env steps), exactly as the generator does, recording the
1358
+ world summary phi after every completed 3-step draw.
1359
+ Accumulate the renormalized discounted reward toward g over the phi sequence; average
1360
+ over M. The behaviour is state-independent, so each rollout is a fresh draw of the
1361
+ SAME action distribution the dataset was collected with — a low-variance unbiased
1362
+ estimate of Q^pi(s,a,g) under the data policy.
1363
+ """
1364
+ import gymnasium
1365
+ import numpy as np
1366
+ from ogbench.powderworld.behaviors import FillBehavior, LineBehavior, SquareBehavior
1367
+ import sys
1368
+ import os
1369
+ # phi extractor (lives in the env experiment dir to keep gc_core env-agnostic)
1370
+ here = os.path.dirname(os.path.abspath(__file__))
1371
+ pwdir = os.path.join(here, "experiments", "powderworld_easy_play_v0")
1372
+ if pwdir not in sys.path:
1373
+ sys.path.insert(0, pwdir)
1374
+ import pw_core
1375
+
1376
+ env_name = "powderworld-easy-v0" if num_elems == 2 else (
1377
+ "powderworld-medium-v0" if num_elems == 5 else "powderworld-v0")
1378
+ env = gymnasium.make(env_name, mode="data_collection", max_episode_steps=10_000_000)
1379
+ u = env.unwrapped
1380
+ env.reset(seed=seed)
1381
+ elems = u._elems
1382
+ agents = [FillBehavior(env=env), LineBehavior(env=env), SquareBehavior(env=env)]
1383
+ probs = np.array([1, 3, 3], dtype=np.float64)
1384
+ probs = probs / probs.sum()
1385
+ rng = np.random.default_rng(seed)
1386
+ disc = (1 - gamma) * gamma ** np.arange(H + 1)
1387
+
1388
+ def reward_to_goal(phi, g):
1389
+ d = float(np.linalg.norm(np.asarray(phi, np.float64) - np.asarray(g, np.float64)))
1390
+ return float(reward_of_dist(np.array([d]), kind, sigma, eps)[0])
1391
+
1392
+ state = {"agent": None}
1393
+
1394
+ def pick_semantic(ob, info):
1395
+ """50% random semantic action (matching the 0.5 generator), else scripted; re-keys
1396
+ the agent before selecting if its sequence is exhausted."""
1397
+ if rng.random() < 0.5:
1398
+ return u.sample_semantic_action()
1399
+ ag = state["agent"]
1400
+ if ag.done:
1401
+ ag = agents[rng.choice(len(agents), p=probs)]
1402
+ ag.reset(ob, info)
1403
+ state["agent"] = ag
1404
+ return ag.select_action(ob, info)
1405
+
1406
+ A = len(anchors["world"])
1407
+ truth = np.zeros(A)
1408
+ for ai in range(A):
1409
+ world0 = anchors["world"][ai]
1410
+ astep0 = int(anchors["action_step"][ai])
1411
+ a_i = int(anchors["a"][ai])
1412
+ g_i = np.asarray(anchors["g"][ai], np.float64)
1413
+ ret = 0.0
1414
+ for _ in range(M):
1415
+ # restore env to the anchor start (world + action phase)
1416
+ u._world = np.array(world0).copy()
1417
+ u._action_step = astep0
1418
+ u._action_elem_id = None
1419
+ u._action_x = None
1420
+ u._action_y = None
1421
+ # set global np.random seed so Fill/Line/Square draws are reproducible per repeat
1422
+ ob = u._get_ob()
1423
+ info = {}
1424
+ phis = [pw_core.pw_phi_from_world(u._world[0, 0], elems)]
1425
+ # step 0: the recorded behaviour action a_i (advances the 3-phase action cycle)
1426
+ ob, _, term, trunc, info = env.step(a_i)
1427
+ if u._action_step == 0:
1428
+ phis.append(pw_core.pw_phi_from_world(u._world[0, 0], elems))
1429
+ # roll the scripted behaviour policy for the remaining horizon
1430
+ state["agent"] = agents[rng.choice(len(agents), p=probs)]
1431
+ state["agent"].reset(ob, info)
1432
+ decisions = 0
1433
+ # seed a semantic action for any mid-cycle phases left by applying a_i; use a
1434
+ # random one so we do NOT consume an agent.select_action mid-sequence.
1435
+ sa = u.sample_semantic_action()
1436
+ while decisions < H:
1437
+ if u._action_step == 0:
1438
+ sa = pick_semantic(ob, info)
1439
+ action = u.semantic_action_to_action(*sa)
1440
+ ob, _, term, trunc, info = env.step(action)
1441
+ if u._action_step == 0:
1442
+ phis.append(pw_core.pw_phi_from_world(u._world[0, 0], elems))
1443
+ decisions += 1
1444
+ if term or trunc:
1445
+ break
1446
+ phis = np.asarray(phis)
1447
+ n = len(phis)
1448
+ rr = np.array([reward_to_goal(phis[k], g_i) for k in range(n)])
1449
+ ret += float((disc[:n] * rr).sum() / disc[:n].sum())
1450
+ truth[ai] = ret / M
1451
+ if verbose and (ai + 1) % 25 == 0:
1452
+ print(f" [gc-fresh-truth-pw] anchor {ai+1}/{A}", flush=True)
1453
+ env.close()
1454
+ return truth
1455
+
1456
+
1457
+ def powderworld_fresh_reset_anchors(n_anchors, seed, num_elems=2, warmup_lo=10, warmup_hi=120):
1458
+ """Protocol B fresh-reset anchors for Powderworld.
1459
+
1460
+ Each anchor is its own ``env.reset`` start, advanced by a random number of scripted
1461
+ behaviour-policy decisions (so the anchor world is in-distribution, not blank), then:
1462
+ world : saved pw world array (to restore the exact start for the truth)
1463
+ action_step : the env action-phase at the anchor (0/1/2)
1464
+ obs : the (32,32,6) image observation (conditioning state)
1465
+ a : the next behaviour-policy action (discrete int) — the Q(s,a) action
1466
+ g : a hindsight future world-summary phi in R^2 (the goal), obtained by
1467
+ rolling the behaviour policy forward a random downstream amount.
1468
+ phi0 : world summary at the anchor (reference).
1469
+ The SAME anchors feed both Q(s,a,g) and the fresh-rollout truth.
1470
+ """
1471
+ import gymnasium
1472
+ import numpy as np
1473
+ from ogbench.powderworld.behaviors import FillBehavior, LineBehavior, SquareBehavior
1474
+ import sys
1475
+ import os
1476
+ here = os.path.dirname(os.path.abspath(__file__))
1477
+ pwdir = os.path.join(here, "experiments", "powderworld_easy_play_v0")
1478
+ if pwdir not in sys.path:
1479
+ sys.path.insert(0, pwdir)
1480
+ import pw_core
1481
+
1482
+ env_name = "powderworld-easy-v0" if num_elems == 2 else (
1483
+ "powderworld-medium-v0" if num_elems == 5 else "powderworld-v0")
1484
+ env = gymnasium.make(env_name, mode="data_collection", max_episode_steps=10_000_000)
1485
+ u = env.unwrapped
1486
+ agents = [FillBehavior(env=env), LineBehavior(env=env), SquareBehavior(env=env)]
1487
+ probs = np.array([1, 3, 3], dtype=np.float64); probs = probs / probs.sum()
1488
+ rng = np.random.default_rng(seed)
1489
+
1490
+ # holder so the closure can swap the live agent on `done`
1491
+ state = {"agent": None}
1492
+
1493
+ def pick_semantic(ob, info):
1494
+ """Return a semantic action: 50% random (matching the 0.5 generator), else from
1495
+ the scripted agent. Re-keys the agent first if it has exhausted its sequence, so
1496
+ ``select_action`` is never called past the end (mirrors generate_powderworld.py)."""
1497
+ if rng.random() < 0.5:
1498
+ return u.sample_semantic_action()
1499
+ ag = state["agent"]
1500
+ if ag.done:
1501
+ ag = agents[rng.choice(len(agents), p=probs)]
1502
+ ag.reset(ob, info)
1503
+ state["agent"] = ag
1504
+ return ag.select_action(ob, info)
1505
+
1506
+ WORLD, ASTEP, OBS, ACT, G, PHI0 = [], [], [], [], [], []
1507
+ for i in range(n_anchors):
1508
+ ob, info = env.reset(seed=seed * 100003 + i)
1509
+ state["agent"] = agents[rng.choice(len(agents), p=probs)]
1510
+ state["agent"].reset(ob, info)
1511
+ warmup = int(rng.integers(warmup_lo, warmup_hi)) # agent decisions before anchor
1512
+ sa = u.sample_semantic_action()
1513
+ d = 0
1514
+ while d < warmup:
1515
+ if u._action_step == 0:
1516
+ sa = pick_semantic(ob, info)
1517
+ ob, _, term, trunc, info = env.step(u.semantic_action_to_action(*sa))
1518
+ if u._action_step == 0:
1519
+ d += 1
1520
+ if term or trunc:
1521
+ ob, info = env.reset(seed=seed * 100003 + i + 7777)
1522
+ state["agent"] = agents[rng.choice(len(agents), p=probs)]
1523
+ state["agent"].reset(ob, info)
1524
+ # at an action-phase==0 boundary: record the anchor
1525
+ world0 = np.array(u._world).copy()
1526
+ astep0 = int(u._action_step)
1527
+ obs0 = np.asarray(ob, np.uint8).copy()
1528
+ phi0 = pw_core.pw_phi_from_world(u._world[0, 0], elems=u._elems)
1529
+ # the next behaviour action a (a single discrete int) at this state
1530
+ sa = pick_semantic(ob, info)
1531
+ a0 = int(u.semantic_action_to_action(*sa))
1532
+ # hindsight goal: roll forward a random downstream amount, take its phi
1533
+ ghoriz = int(rng.integers(20, 100))
1534
+ sa2 = sa
1535
+ d2 = 0
1536
+ gob, ginfo = ob, info
1537
+ while d2 < ghoriz:
1538
+ if u._action_step == 0:
1539
+ sa2 = pick_semantic(gob, ginfo)
1540
+ gob, _, gterm, gtrunc, ginfo = env.step(u.semantic_action_to_action(*sa2))
1541
+ if u._action_step == 0:
1542
+ d2 += 1
1543
+ if gterm or gtrunc:
1544
+ break
1545
+ g0 = pw_core.pw_phi_from_world(u._world[0, 0], elems=u._elems)
1546
+ WORLD.append(world0); ASTEP.append(astep0); OBS.append(obs0)
1547
+ ACT.append(a0); G.append(g0.astype(np.float32)); PHI0.append(phi0.astype(np.float32))
1548
+ env.close()
1549
+ return dict(world=WORLD, action_step=np.array(ASTEP, np.int64),
1550
+ obs=np.stack(OBS), a=np.array(ACT, np.int64),
1551
+ g=np.stack(G), phi0=np.stack(PHI0), num_elems=num_elems)
1552
+
1553
+
1554
+ # ----------------------------------------------------------------------------
1555
+ # which envs have a re-runnable fresh-rollout behaviour policy
1556
+ # ----------------------------------------------------------------------------
1557
+ SUPPORTS_FRESH_ROLLOUT = ("pointmaze", "antmaze", "humanoidmaze", "antsoccer",
1558
+ "cube", "scene", "puzzle", "powderworld")
1559
+
1560
+
1561
+ def supports_fresh_rollout(env_id):
1562
+ return any(k in env_id for k in SUPPORTS_FRESH_ROLLOUT)
1563
+
1564
+
1565
+ # ----------------------------------------------------------------------------
1566
+ # maze layout for figures (walls in xy coordinates)
1567
+ # ----------------------------------------------------------------------------
1568
+ def maze_wall_rects(env):
1569
+ """Return (rects, extent) for drawing the maze layout under xy scatter plots.
1570
+
1571
+ rects: list of (x0, y0, w, h) rectangles for wall cells (maze_map == 1), in the
1572
+ same xy coordinates as observations. extent: (xmin, xmax, ymin, ymax).
1573
+ Returns (None, None) if the env exposes no maze geometry.
1574
+ """
1575
+ import numpy as np
1576
+ u = env.unwrapped
1577
+ if not (hasattr(u, "maze_map") and hasattr(u, "ij_to_xy")):
1578
+ return None, None
1579
+ mm = np.asarray(u.maze_map)
1580
+ I, J = mm.shape
1581
+ # cell size from adjacent centers
1582
+ c00 = np.asarray(u.ij_to_xy((0, 0)), dtype=float)
1583
+ c01 = np.asarray(u.ij_to_xy((0, 1)), dtype=float)
1584
+ c10 = np.asarray(u.ij_to_xy((1, 0)), dtype=float)
1585
+ dx = abs(c01[0] - c00[0]) or 1.0
1586
+ dy = abs(c10[1] - c00[1]) or 1.0
1587
+ rects = []
1588
+ xs, ys = [], []
1589
+ for i in range(I):
1590
+ for j in range(J):
1591
+ cx, cy = u.ij_to_xy((i, j))
1592
+ xs += [cx - dx / 2, cx + dx / 2]
1593
+ ys += [cy - dy / 2, cy + dy / 2]
1594
+ if mm[i, j] == 1:
1595
+ rects.append((cx - dx / 2, cy - dy / 2, dx, dy))
1596
+ extent = (min(xs), max(xs), min(ys), max(ys))
1597
+ return rects, extent
1598
+
1599
+
1600
+ def draw_maze(ax, env, facecolor="0.6", edgecolor="0.4"):
1601
+ """Draw maze walls as filled rectangles behind a scatter, set equal aspect/extent.
1602
+ Returns True if a layout was drawn, False if no geometry (caller should flag)."""
1603
+ from matplotlib.patches import Rectangle
1604
+ rects, extent = maze_wall_rects(env)
1605
+ if rects is None:
1606
+ return False
1607
+ for (x0, y0, w, h) in rects:
1608
+ ax.add_patch(Rectangle((x0, y0), w, h, facecolor=facecolor,
1609
+ edgecolor=edgecolor, lw=0.5, zorder=0))
1610
+ ax.set_xlim(extent[0], extent[1]); ax.set_ylim(extent[2], extent[3])
1611
+ ax.set_aspect("equal")
1612
+ return True
gen_q_rsm/preliminary_analysis/genq.py ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Gen-Q: TD-free goal-conditioned policy evaluation via a learned occupancy model.
2
+
3
+ Math
4
+ ----
5
+ Gen-Q learns the discounted future-state occupancy of the (goal-conditioned)
6
+ behaviour policy as a conditional generative model
7
+
8
+ p_theta(x_{t+k} | s_t, a_t, g), k ~ Geom(1 - gamma),
9
+
10
+ so samples from p_theta are distributed as d^pi_gamma(. | s, a, g). The normalized
11
+ goal-conditioned value is then a plain expectation, estimated by sampling:
12
+
13
+ Q^pi(s, a, g) = E_{x ~ p_theta(. | s, a, g)} [ r(x; g) ]
14
+ ~= (1/N) sum_{i=1}^N r(x_i; g), x_i ~ p_theta(. | s, a, g).
15
+
16
+ Occupancy model: a **conditional denoising diffusion model** (DDPM cosine
17
+ alpha-bar schedule; DDIM deterministic sampling). Diffusion is chosen over a
18
+ Gaussian mixture density network because the discounted occupancy is strongly
19
+ multi-modal (futures branch around walls / object configurations) and diffusion
20
+ captures that without a fixed mode count. **Flow-matching** is an equally valid
21
+ choice and is available via ``--occ_model flow`` (``models.ConditionalFlowMatching``);
22
+ both share the interface ``.training_loss(c, y)`` / ``.sample(c, n) -> [B,n,D]``.
23
+
24
+ Training objective (epsilon-prediction MSE):
25
+ L = E_{(s,a,g), k~Geom, eps, t} || eps - eps_theta(sqrt(abar_t)x0 + sqrt(1-abar_t)eps, t, (s,a,g)) ||^2,
26
+ x0 = xy(s_{t+k}), g = hindsight goal downstream of t+k.
27
+
28
+ Pseudocode
29
+ ----------
30
+ train: minibatch (s, a, g, x=xy(s_{t+k})) ; minimize eps-prediction MSE
31
+ eval : for each anchor (s, a, g): draw N samples x_i ~ p_theta(.|s,a,g)
32
+ Q(s,a,g) <- mean_i r(x_i; g)
33
+ """
34
+ import time
35
+
36
+ import numpy as np
37
+
38
+ from _common import get_device, set_seed, q_metrics, init_wandb
39
+ import gc_core
40
+ from evaluate_policy import ground_truth_q, FreshRolloutUnsupported
41
+
42
+
43
+ def run(env_id, seed, cfg):
44
+ device = get_device()
45
+ set_seed(seed)
46
+ gamma = cfg["gamma"]
47
+ kind, sigma, eps = cfg["reward"], cfg["sigma"], cfg["epsilon"]
48
+ occ_model = cfg.get("occ_model", "diffusion")
49
+
50
+ # state_slice="full" gives raw N-D state occupancy (AntMaze 29-D); occupancy target
51
+ # stays xy (first pos dims). For manipspace the occupancy target is the privileged
52
+ # object position and pos_dim comes from the dataset loader.
53
+ state_slice = cfg.get("state_slice", "auto")
54
+ train_ds, val_ds, _, _ = gc_core.load_ogbench_gc(env_id, gamma, state_slice=state_slice)
55
+ pos = train_ds.get("pos_dim", cfg.get("pos_dim", 2))
56
+ cfg["pos_dim"] = pos
57
+
58
+ pack = gc_core.prepare_eval_anchors(env_id, val_ds, cfg, seed)
59
+ sigma, eps = cfg["sigma"], cfg["epsilon"] # prepare may set manipspace reward scale
60
+ s_a, a_a, g_a = pack["s"], pack["a"], pack["g"]
61
+ anchors = pack["anchor_idx"]
62
+ anchor_full = pack["anchor_full"]
63
+
64
+ run_obj, wlog, wfinish = init_wandb(
65
+ cfg.get("wandb_project", "genq-policy-eval"),
66
+ f"genq-{occ_model}-{env_id}-s{seed}",
67
+ {**cfg, "env": env_id, "seed": seed, "method": "genq"}, mode=cfg.get("wandb_mode"))
68
+ wandb_url = getattr(run_obj, "url", None)
69
+
70
+ cond_dim = train_ds["s_dim"] + train_ds["a_dim"] + pos
71
+ occ = gc_core.build_occupancy(occ_model, cond_dim, pos, cfg, device)
72
+
73
+ t0 = time.time()
74
+ losses = gc_core.train_gc_occupancy(occ, train_ds, gamma, cfg, device, seed, wandb_log=wlog)
75
+ train_wall = time.time() - t0
76
+
77
+ truth, truth_kind = ground_truth_q(env_id, val_ds, anchors, g_a, gamma,
78
+ kind=kind, sigma=sigma, eps=eps,
79
+ M=cfg.get("truth_M", 8), H=cfg.get("truth_H", 350),
80
+ seed=seed, anchor_full=anchor_full,
81
+ anchors_pack=pack["anchors_pack"])
82
+
83
+ # Sample-count sweep: Gen-Q's estimate (1/N) sum r(x_i) should improve with N.
84
+ gen_counts = cfg.get("gen_sample_counts", [1, 2, 4, 8, 16, 32, 64, 128, 256])
85
+ family = train_ds.get("family")
86
+ mse_by_n, corr_by_n, mse_curve = {}, {}, []
87
+ for N in gen_counts:
88
+ est_n = gc_core.occ_q(occ, s_a, a_a, g_a, N, sigma, device, kind, eps, family=family)
89
+ mn = q_metrics(est_n, truth)
90
+ mse_by_n[str(N)] = mn["mse"]; corr_by_n[str(N)] = mn["pearson"]
91
+ mse_curve.append(mn["mse"])
92
+ N_final = gen_counts[-1]
93
+ est = gc_core.occ_q(occ, s_a, a_a, g_a, N_final, sigma, device, kind, eps, family=family)
94
+ m = q_metrics(est, truth)
95
+
96
+ result = {
97
+ "method": "genq", "env": env_id, "seed": seed, "wandb_url": wandb_url,
98
+ "occ_model": occ_model, "reward": kind, "truth_kind": truth_kind,
99
+ "anchor_protocol": pack["anchor_protocol"],
100
+ "gen_sample_counts": gen_counts,
101
+ "train/loss": losses, "train/q_mse": [m["mse"]],
102
+ "eval/q_mse": m["mse"], "eval/q_mae": m["mae"],
103
+ "eval/q_corr": m["pearson"], "eval/q_spearman": m["spearman"],
104
+ "eval/q_mse_by_n": mse_by_n, "eval/q_corr_by_n": corr_by_n,
105
+ "eval/q_mse_vs_N": mse_curve, "eval/N_final": N_final,
106
+ "eval/truth_std": float(np.std(truth)),
107
+ "wall_clock_s": train_wall, "n_anchors": int(len(s_a)),
108
+ }
109
+ wlog({"eval/q_mse": m["mse"], "eval/q_corr": m["pearson"]})
110
+ wfinish()
111
+ return result
112
+
113
+
114
+ if __name__ == "__main__":
115
+ pass
gen_q_rsm/preliminary_analysis/genq_reward_latent.py ADDED
@@ -0,0 +1,202 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Gen-Q with a reward-predictive latent, for image / high-dim observations.
2
+
3
+ Why a latent?
4
+ -------------
5
+ When the state is an image (or otherwise high-dimensional), learning the occupancy
6
+ p_theta(x_{t+k} | s, a, g) directly over raw pixels is intractable: most pixel
7
+ variation is reward-irrelevant. The issue mandates that for image observations,
8
+ occupancy learning be performed in a **reward-predictive latent space** and used
9
+ (instead of raw pixels) for both occupancy estimation and Q^pi.
10
+
11
+ How the latent is learned
12
+ --------------------------
13
+ Train an encoder E_psi over the (future) state and a goal-conditioned reward
14
+ decoder R_psi so the latent keeps exactly the reward-relevant information:
15
+
16
+ z = E_psi(x), r_hat = R_psi(z, g),
17
+ L_latent(psi) = E_{x,g} [ ( R_psi(E_psi(x), g) - r(x; g) )^2 ] + lambda ||z||^2.
18
+
19
+ Then **freeze** E_psi, R_psi (so the occupancy target distribution does not drift).
20
+
21
+ Occupancy in latent space
22
+ -------------------------
23
+ z_{t+k} = stopgrad( E_psi(x_{t+k}) ), p_theta(z_{t+k} | s_t, a_t, g), k ~ Geom(1-gamma).
24
+
25
+ Q from latent occupancy
26
+ -----------------------
27
+ Q^pi(s, a, g) = E_{z ~ p_theta(.|s,a,g)} [ R_psi(z, g) ] ~= (1/N) sum_i R_psi(z_i, g).
28
+
29
+ For the low-dim Tier-1 envs this is run as an *ablation* of raw-state Gen-Q (the
30
+ latent encodes the position dims); for true image envs E_psi would be a CNN
31
+ (``models.ImageEncoder``). The recipe is identical.
32
+ """
33
+ import time
34
+
35
+ import numpy as np
36
+ import torch
37
+ import torch.nn as nn
38
+ import torch.nn.functional as F
39
+
40
+ from _common import get_device, set_seed, q_metrics, init_wandb
41
+ import gc_core
42
+ import models
43
+ from evaluate_policy import ground_truth_q
44
+
45
+
46
+ class GCRewardDecoder(nn.Module):
47
+ """R(z, g) -> scalar goal-reaching reward."""
48
+ def __init__(self, z_dim, g_dim, hidden=256, layers=2):
49
+ super().__init__()
50
+ self.net = models.mlp(z_dim + g_dim, 1, hidden, layers)
51
+
52
+ def forward(self, z, g):
53
+ return self.net(torch.cat([z, g], -1)).squeeze(-1)
54
+
55
+
56
+ def train_reward_latent(ds, gamma, z_dim, cfg, device, seed, wlog):
57
+ """Reward-aware encoder over (future) state + goal-conditioned reward decoder."""
58
+ pos = cfg.get("pos_dim", 2)
59
+ s_dim = ds["s_dim"]
60
+ enc = models.Encoder(s_dim, z_dim, cfg["hidden_dim"], cfg["num_layers"]).to(device)
61
+ dec = GCRewardDecoder(z_dim, pos, cfg["hidden_dim"], 2).to(device)
62
+ opt = torch.optim.Adam(list(enc.parameters()) + list(dec.parameters()), lr=cfg["lr"])
63
+ rng = np.random.default_rng(seed + 3)
64
+ obs, end = ds["obs"], ds["end"]
65
+ lam = cfg.get("latent_l2", 1e-4)
66
+ kind, sigma, eps = cfg["reward"], cfg["sigma"], cfg["epsilon"]
67
+ steps = cfg.get("latent_steps", 20000)
68
+ final = 0.0
69
+ for step in range(1, steps + 1):
70
+ x_idx = rng.integers(0, ds["N"], cfg["batch_size"])
71
+ g = obs[gc_core.sample_goal_after(x_idx, end, rng)][:, :pos]
72
+ d = np.linalg.norm(obs[x_idx][:, :pos] - g, axis=1)
73
+ r = gc_core.reward_of_dist(d, kind, sigma, eps).astype(np.float32)
74
+ x = torch.as_tensor(obs[x_idx], device=device)
75
+ gt = torch.as_tensor(g, dtype=torch.float32, device=device)
76
+ rt = torch.as_tensor(r, device=device)
77
+ z = enc(x)
78
+ loss = F.mse_loss(dec(z, gt), rt) + lam * (z ** 2).mean()
79
+ opt.zero_grad(); loss.backward(); opt.step()
80
+ if step % max(1, steps // 20) == 0 or step == 1:
81
+ final = float(loss.item())
82
+ wlog({"latent/loss": final}, step=step)
83
+ enc.eval(); dec.eval()
84
+ for p in enc.parameters(): p.requires_grad_(False)
85
+ for p in dec.parameters(): p.requires_grad_(False)
86
+ return enc, dec, final
87
+
88
+
89
+ def _encode_all(enc, obs, device, batch=8192):
90
+ out = []
91
+ with torch.no_grad():
92
+ for i in range(0, len(obs), batch):
93
+ out.append(enc(torch.as_tensor(obs[i:i+batch], dtype=torch.float32, device=device)).cpu().numpy())
94
+ return np.concatenate(out, 0)
95
+
96
+
97
+ def train_latent_occupancy(occ, ds, enc, gamma, cfg, device, seed, wlog):
98
+ pos = cfg.get("pos_dim", 2)
99
+ z_all = _encode_all(enc, ds["obs"], device)
100
+ obs, act, end = ds["obs"], ds["act"], ds["end"]
101
+ rng = np.random.default_rng(seed + 7)
102
+ t0 = rng.integers(0, ds["N"], 20000); j0 = gc_core.future_idx(t0, end, gamma, rng)
103
+ g0 = obs[gc_core.sample_goal_after(j0, end, rng)][:, :pos]
104
+ c0 = np.concatenate([obs[t0], act[t0], g0], 1)
105
+ occ.set_normalization(c0.mean(0), c0.std(0) + 1e-6, z_all.mean(0), z_all.std(0) + 1e-6)
106
+ z_t = torch.from_numpy(z_all.astype(np.float32))
107
+ opt = torch.optim.Adam(occ.parameters(), lr=cfg["lr"])
108
+ losses = []
109
+ log_every = max(1, cfg["steps"] // 50)
110
+ for step in range(1, cfg["steps"] + 1):
111
+ t = rng.integers(0, ds["N"], cfg["batch_size"])
112
+ j = gc_core.future_idx(t, end, gamma, rng)
113
+ g = obs[gc_core.sample_goal_after(j, end, rng)][:, :pos]
114
+ c = np.concatenate([obs[t], act[t], g], 1)
115
+ loss = occ.training_loss(torch.as_tensor(c, dtype=torch.float32, device=device),
116
+ z_t[j].to(device))
117
+ opt.zero_grad(); loss.backward()
118
+ gn = torch.nn.utils.clip_grad_norm_(occ.parameters(), 10.0); opt.step()
119
+ if step % log_every == 0 or step == 1:
120
+ losses.append(float(loss.item()))
121
+ wlog({"train/loss": float(loss.item()), "train/grad_norm": float(gn)}, step=step)
122
+ occ.eval()
123
+ return losses
124
+
125
+
126
+ @torch.no_grad()
127
+ def latent_occ_q(occ, dec, s, a, g, N, device, batch=256):
128
+ out = np.zeros(len(s))
129
+ for i in range(0, len(s), batch):
130
+ c = np.concatenate([s[i:i+batch], a[i:i+batch], g[i:i+batch]], 1)
131
+ ct = torch.as_tensor(c, dtype=torch.float32, device=device)
132
+ z = occ.sample(ct, N) # [b, N, z]
133
+ b, n, zd = z.shape
134
+ gt = torch.as_tensor(g[i:i+batch], dtype=torch.float32, device=device)
135
+ gt = gt.unsqueeze(1).expand(-1, n, -1).reshape(b * n, -1)
136
+ r = dec(z.reshape(b * n, zd), gt).reshape(b, n)
137
+ out[i:i+batch] = r.mean(1).cpu().numpy()
138
+ return out
139
+
140
+
141
+ def run(env_id, seed, cfg):
142
+ device = get_device()
143
+ set_seed(seed)
144
+ gamma = cfg["gamma"]
145
+ kind = cfg["reward"]
146
+ pos = cfg.get("pos_dim", 2); cfg["pos_dim"] = pos
147
+ occ_model = cfg.get("occ_model", "diffusion")
148
+ z_dim = cfg.get("z_dim", 8)
149
+
150
+ state_slice = cfg.get("state_slice", "auto")
151
+ train_ds, val_ds, _, _ = gc_core.load_ogbench_gc(env_id, gamma, state_slice=state_slice)
152
+ rng = np.random.default_rng(seed)
153
+ anchors = gc_core.anchors_with_min_horizon(val_ds, cfg["n_anchors"], cfg["min_horizon"], rng)
154
+ s_a = val_ds["obs"][anchors]; a_a = val_ds["act"][anchors]
155
+ g_a = val_ds["obs"][gc_core.sample_goal_idx(anchors, val_ds["end"], rng)][:, :pos]
156
+ anchor_full = s_a if (state_slice == "full" and "antmaze" in env_id) else None
157
+
158
+ run_obj, wlog, wfinish = init_wandb(
159
+ cfg.get("wandb_project", "genq-policy-eval"),
160
+ f"genqlatent-{occ_model}-z{z_dim}-{env_id}-s{seed}",
161
+ {**cfg, "env": env_id, "seed": seed, "method": "genq_reward_latent"}, mode=cfg.get("wandb_mode"))
162
+ wandb_url = getattr(run_obj, "url", None)
163
+
164
+ t0 = time.time()
165
+ enc, dec, latent_mse = train_reward_latent(train_ds, gamma, z_dim, cfg, device, seed, wlog)
166
+ cond_dim = train_ds["s_dim"] + train_ds["a_dim"] + pos
167
+ occ = gc_core.build_occupancy(occ_model, cond_dim, z_dim, cfg, device)
168
+ losses = train_latent_occupancy(occ, train_ds, enc, gamma, cfg, device, seed, wlog)
169
+ train_wall = time.time() - t0
170
+
171
+ truth, truth_kind = ground_truth_q(env_id, val_ds, anchors, g_a, gamma,
172
+ kind=kind, sigma=cfg["sigma"], eps=cfg["epsilon"],
173
+ M=cfg.get("truth_M", 8), H=cfg.get("truth_H", 350), seed=seed,
174
+ anchor_full=anchor_full)
175
+ gen_counts = cfg.get("gen_sample_counts", [1, 2, 4, 8, 16, 32, 64, 128, 256])
176
+ mse_by_n, corr_by_n, mse_curve = {}, {}, []
177
+ for N in gen_counts:
178
+ mn = q_metrics(latent_occ_q(occ, dec, s_a, a_a, g_a, N, device), truth)
179
+ mse_by_n[str(N)] = mn["mse"]; corr_by_n[str(N)] = mn["pearson"]; mse_curve.append(mn["mse"])
180
+ N_final = gen_counts[-1]
181
+ est = latent_occ_q(occ, dec, s_a, a_a, g_a, N_final, device)
182
+ m = q_metrics(est, truth)
183
+
184
+ result = {
185
+ "method": "genq_reward_latent", "env": env_id, "seed": seed, "wandb_url": wandb_url,
186
+ "occ_model": occ_model, "z_dim": z_dim, "reward": kind, "truth_kind": truth_kind,
187
+ "gen_sample_counts": gen_counts,
188
+ "train/loss": losses, "train/q_mse": [m["mse"]], "latent/reward_mse": latent_mse,
189
+ "eval/q_mse": m["mse"], "eval/q_mae": m["mae"],
190
+ "eval/q_corr": m["pearson"], "eval/q_spearman": m["spearman"],
191
+ "eval/q_mse_by_n": mse_by_n, "eval/q_corr_by_n": corr_by_n,
192
+ "eval/q_mse_vs_N": mse_curve, "eval/N_final": N_final,
193
+ "eval/truth_std": float(np.std(truth)),
194
+ "wall_clock_s": train_wall, "n_anchors": int(len(anchors)),
195
+ }
196
+ wlog({"eval/q_mse": m["mse"], "eval/q_corr": m["pearson"]})
197
+ wfinish()
198
+ return result
199
+
200
+
201
+ if __name__ == "__main__":
202
+ pass
gen_q_rsm/preliminary_analysis/genq_visual.py ADDED
@@ -0,0 +1,450 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Gen-Q policy evaluation for IMAGE observations (visual-antmaze-medium-navigate-v0).
2
+
3
+ Why this file exists
4
+ --------------------
5
+ For image states the occupancy p_theta(x_{t+k} | s, a, g) must be learned in a
6
+ REWARD-PREDICTIVE LATENT, never over raw pixels (CLAUDE.md "Image observations =>
7
+ reward-predictive latent occupancy"). The state ``genq_reward_latent.py`` uses an MLP
8
+ encoder over a flat state vector and slices the xy goal/reward out of ``obs[:, :2]``;
9
+ neither works for a 64x64x3 image. This driver swaps in ``models.ImageEncoder`` (CNN)
10
+ and reads the xy reward/goal signal from the dataset's auxiliary ``qpos`` array.
11
+
12
+ Recipe (reward-predictive latent, frozen, then diffusion occupancy)
13
+ -------------------------------------------------------------------
14
+ 1. Encoder z = E_psi(image) (models.ImageEncoder, CNN, [B,3,64,64] in [0,1])
15
+ Decoder r_hat = R_psi(z, g) (goal-conditioned, g = xy)
16
+ Loss E[(R_psi(E_psi(image), g) - r(xy; g))^2] + lambda||z||^2 ; FREEZE E,R.
17
+ The reward is goal-reaching on the ant xy = qpos[:, :2].
18
+ 2. Conditioning representation: we condition the occupancy on (z_now, a, g) where
19
+ z_now = E_psi(image_now). (Documented choice: the CNN latent of the current image
20
+ is the conditioning state; the action a (8-D ant torque) and goal g (xy) complete
21
+ the (s,a,g) input.)
22
+ 3. Occupancy p_theta(z' | z_now, a, g), z' = stopgrad(E_psi(image_{t+k})),
23
+ k ~ Geom(1-gamma). Conditional diffusion (NEVER a Gaussian MDN).
24
+ 4. Q^pi(s,a,g) = E_{z ~ p_theta}[ R_psi(z, g) ] ~= (1/N) sum_i R_psi(z_i, g).
25
+
26
+ Ground truth = FRESH ROLLOUTS only. The image obs cannot reset the sim, so we pass the
27
+ dataset's 29-D qpos+qvel full state as ``anchor_full`` to
28
+ ``evaluate_policy.ground_truth_q``; the shared lib rolls the SAC expert + oracle-subgoal
29
+ behaviour policy on ant dynamics from that exact state (the image-ness only changes the
30
+ OCCUPANCY model input, not the rollout).
31
+
32
+ mc / td baselines: run on the 29-D qpos+qvel STATE (the non-latent reference), since a
33
+ trained-MC / IQL-TD critic over the raw 64x64x3 image is a separate CNN-critic study;
34
+ the honest, comparable reference here is the same MC/TD recipe on the full ant state.
35
+ This is documented in each result JSON via ``"representation"``.
36
+ """
37
+ import os
38
+ import time
39
+
40
+ import numpy as np
41
+ import torch
42
+ import torch.nn as nn
43
+ import torch.nn.functional as F
44
+
45
+ from _common import get_device, set_seed, q_metrics, init_wandb
46
+ import gc_core
47
+ import models
48
+ from evaluate_policy import ground_truth_q
49
+ from genq_reward_latent import GCRewardDecoder
50
+
51
+ _HERE = os.path.dirname(os.path.abspath(__file__))
52
+ # data_ogbench/ physically lives at the SHARED proj root and is symlinked into the
53
+ # worktree as <repo_root>/data_ogbench. The symlink is untracked+gitignored and can
54
+ # be removed by `git clean -fdx` during worktree ops, so we resolve the symlink to
55
+ # its real absolute target and use that stable shared path directly. Override with
56
+ # GENQ_DATA_DIR if needed.
57
+ def _resolve_data_dir():
58
+ env = os.environ.get("GENQ_DATA_DIR")
59
+ if env:
60
+ return os.path.abspath(env)
61
+ cand = os.path.join(_HERE, "..", "data_ogbench") # repo-root data_ogbench (symlink)
62
+ # realpath follows the symlink to the shared /proj/.../gen_q/data_ogbench target,
63
+ # so reads keep working even if the worktree symlink is later cleaned.
64
+ return os.path.realpath(cand)
65
+ _DATA_DIR = _resolve_data_dir()
66
+
67
+
68
+ # ----------------------------------------------------------------------------
69
+ # visual dataset (images + qpos/qvel)
70
+ # ----------------------------------------------------------------------------
71
+ def load_visual_gc(env_id, split, n_traj=None):
72
+ """Load the visual-antmaze npz for `split` in {"train","val"}.
73
+
74
+ Returns a dataset dict with:
75
+ img : uint8 [N, 64, 64, 3] (observation; encoded by the CNN, never modeled raw)
76
+ xy : float32 [N, 2] (ant xy = qpos[:, :2]; reward/goal signal)
77
+ full : float32 [N, 29] (qpos[15] + qvel[14]; resets the sim for fresh truth)
78
+ act : float32 [N, 8]
79
+ end : int64 [N] (trajectory end index per step)
80
+ N, a_dim
81
+ """
82
+ fname = env_id if split == "train" else f"{env_id}-val"
83
+ path = os.path.join(_DATA_DIR, f"{fname}.npz")
84
+ if not os.path.exists(path):
85
+ raise FileNotFoundError(
86
+ f"visual dataset not found: {path} (expected data_ogbench/ symlink at repo root)")
87
+ d = np.load(path, mmap_mode="r")
88
+ term = np.asarray(d["terminals"], dtype=np.float32)
89
+ if n_traj is not None:
90
+ ends = np.where(term > 0.5)[0] + 1
91
+ N = int(ends[min(n_traj, len(ends)) - 1]) if len(ends) else len(term)
92
+ else:
93
+ N = len(term)
94
+ qpos = np.asarray(d["qpos"][:N], dtype=np.float32)
95
+ qvel = np.asarray(d["qvel"][:N], dtype=np.float32)
96
+ full = np.concatenate([qpos, qvel], axis=1) # [N, 29]
97
+ return dict(
98
+ img=d["observations"][:N], # keep as mmap'd uint8; index lazily
99
+ xy=qpos[:, :2].copy(),
100
+ full=full,
101
+ # `obs` alias = 29-D full state so evaluate_policy.ground_truth_q can index
102
+ # val_ds["obs"]/["act"] generically; for visual-antmaze the antmaze truth uses
103
+ # `anchor_full` for the sim reset and only needs `act` from here.
104
+ obs=full,
105
+ act=np.asarray(d["actions"][:N], dtype=np.float32),
106
+ end=gc_core.trajectory_bounds(term[:N]),
107
+ N=N, a_dim=int(d["actions"].shape[1]),
108
+ )
109
+
110
+
111
+ def _imgs_to_tensor(img_u8, device):
112
+ """uint8 [B,64,64,3] -> float [B,3,64,64] in [0,1]."""
113
+ x = torch.as_tensor(np.asarray(img_u8), dtype=torch.float32, device=device) / 255.0
114
+ return x.permute(0, 3, 1, 2).contiguous()
115
+
116
+
117
+ # ----------------------------------------------------------------------------
118
+ # reward-predictive CNN latent (encoder + goal-conditioned reward decoder)
119
+ # ----------------------------------------------------------------------------
120
+ def train_reward_latent_image(ds, z_dim, cfg, device, seed, wlog):
121
+ enc = models.ImageEncoder(z_dim, hidden_dim=cfg["hidden_dim"]).to(device)
122
+ dec = GCRewardDecoder(z_dim, 2, cfg["hidden_dim"], 2).to(device)
123
+ opt = torch.optim.Adam(list(enc.parameters()) + list(dec.parameters()), lr=cfg["lr"])
124
+ rng = np.random.default_rng(seed + 3)
125
+ xy, end = ds["xy"], ds["end"]
126
+ lam = cfg.get("latent_l2", 1e-4)
127
+ kind, sigma, eps = cfg["reward"], cfg["sigma"], cfg["epsilon"]
128
+ steps = cfg.get("latent_steps", 20000)
129
+ bs = cfg["batch_size"]
130
+ final = 0.0
131
+ for step in range(1, steps + 1):
132
+ x_idx = rng.integers(0, ds["N"], bs)
133
+ g = xy[gc_core.sample_goal_after(x_idx, end, rng)]
134
+ d = np.linalg.norm(xy[x_idx] - g, axis=1)
135
+ r = gc_core.reward_of_dist(d, kind, sigma, eps).astype(np.float32)
136
+ img = _imgs_to_tensor(ds["img"][x_idx], device)
137
+ gt = torch.as_tensor(g, dtype=torch.float32, device=device)
138
+ rt = torch.as_tensor(r, device=device)
139
+ z = enc(img)
140
+ loss = F.mse_loss(dec(z, gt), rt) + lam * (z ** 2).mean()
141
+ opt.zero_grad(); loss.backward(); opt.step()
142
+ if step % max(1, steps // 20) == 0 or step == 1:
143
+ final = float(loss.item())
144
+ wlog({"latent/loss": final}, step=step)
145
+ enc.eval(); dec.eval()
146
+ for p in enc.parameters(): p.requires_grad_(False)
147
+ for p in dec.parameters(): p.requires_grad_(False)
148
+ return enc, dec, final
149
+
150
+
151
+ @torch.no_grad()
152
+ def encode_images(enc, img_u8, device, batch=2048):
153
+ out = []
154
+ for i in range(0, len(img_u8), batch):
155
+ out.append(enc(_imgs_to_tensor(img_u8[i:i+batch], device)).cpu().numpy())
156
+ return np.concatenate(out, 0).astype(np.float32)
157
+
158
+
159
+ # ----------------------------------------------------------------------------
160
+ # latent occupancy p_theta(z' | z_now, a, g)
161
+ # ----------------------------------------------------------------------------
162
+ def train_latent_occupancy_image(occ, ds, z_all, gamma, cfg, device, seed, wlog):
163
+ """z_all: precomputed E_psi(image) for every step (conditioning AND target source)."""
164
+ act, end = ds["act"], ds["end"]
165
+ xy = ds["xy"]
166
+ rng = np.random.default_rng(seed + 7)
167
+ # normalization from a sample of (z_now, a, g) cond and z' target
168
+ t0 = rng.integers(0, ds["N"], 20000)
169
+ j0 = gc_core.future_idx(t0, end, gamma, rng)
170
+ g0 = xy[gc_core.sample_goal_after(j0, end, rng)]
171
+ c0 = np.concatenate([z_all[t0], act[t0], g0], 1)
172
+ occ.set_normalization(c0.mean(0), c0.std(0) + 1e-6, z_all[j0].mean(0), z_all[j0].std(0) + 1e-6)
173
+ z_t = torch.from_numpy(z_all)
174
+ opt = torch.optim.Adam(occ.parameters(), lr=cfg["lr"])
175
+ losses = []
176
+ log_every = max(1, cfg["steps"] // 50)
177
+ bs = cfg["batch_size"]
178
+ for step in range(1, cfg["steps"] + 1):
179
+ t = rng.integers(0, ds["N"], bs)
180
+ j = gc_core.future_idx(t, end, gamma, rng)
181
+ g = xy[gc_core.sample_goal_after(j, end, rng)]
182
+ c = np.concatenate([z_all[t], act[t], g], 1)
183
+ loss = occ.training_loss(torch.as_tensor(c, dtype=torch.float32, device=device),
184
+ z_t[j].to(device))
185
+ opt.zero_grad(); loss.backward()
186
+ gn = torch.nn.utils.clip_grad_norm_(occ.parameters(), 10.0); opt.step()
187
+ if step % log_every == 0 or step == 1:
188
+ losses.append(float(loss.item()))
189
+ wlog({"train/loss": float(loss.item()), "train/grad_norm": float(gn)}, step=step)
190
+ occ.eval()
191
+ return losses
192
+
193
+
194
+ @torch.no_grad()
195
+ def latent_occ_q(occ, dec, z_now, a, g, N, device, batch=256):
196
+ out = np.zeros(len(z_now))
197
+ for i in range(0, len(z_now), batch):
198
+ c = np.concatenate([z_now[i:i+batch], a[i:i+batch], g[i:i+batch]], 1)
199
+ ct = torch.as_tensor(c, dtype=torch.float32, device=device)
200
+ z = occ.sample(ct, N) # [b, N, z]
201
+ b, n, zd = z.shape
202
+ gt = torch.as_tensor(g[i:i+batch], dtype=torch.float32, device=device)
203
+ gt = gt.unsqueeze(1).expand(-1, n, -1).reshape(b * n, -1)
204
+ r = dec(z.reshape(b * n, zd), gt).reshape(b, n)
205
+ out[i:i+batch] = r.mean(1).cpu().numpy()
206
+ return out
207
+
208
+
209
+ # ----------------------------------------------------------------------------
210
+ # anchors + goals shared across methods (so mc/td/genq score the SAME (s,a,g))
211
+ # ----------------------------------------------------------------------------
212
+ def _make_anchors(val_ds, cfg, seed):
213
+ rng = np.random.default_rng(seed)
214
+ n = cfg["n_anchors"]; min_h = cfg["min_horizon"]
215
+ rem = val_ds["end"] - np.arange(val_ds["N"])
216
+ valid = np.where(rem >= min_h)[0]
217
+ if len(valid) == 0:
218
+ valid = np.arange(val_ds["N"])
219
+ anchors = valid[rng.integers(0, len(valid), size=n)]
220
+ g_idx = gc_core.sample_goal_idx(anchors, val_ds["end"], rng)
221
+ g_a = val_ds["xy"][g_idx]
222
+ return anchors, g_a
223
+
224
+
225
+ # ----------------------------------------------------------------------------
226
+ # genq (image reward-predictive latent occupancy)
227
+ # ----------------------------------------------------------------------------
228
+ def run(env_id, seed, cfg):
229
+ device = get_device()
230
+ set_seed(seed)
231
+ gamma = cfg["gamma"]
232
+ kind = cfg["reward"]
233
+ occ_model = cfg.get("occ_model", "diffusion")
234
+ z_dim = cfg.get("z_dim", 8)
235
+ n_traj_tr = cfg.get("vis_train_traj", None)
236
+ n_traj_val = cfg.get("vis_val_traj", None)
237
+
238
+ train_ds = load_visual_gc(env_id, "train", n_traj_tr)
239
+ val_ds = load_visual_gc(env_id, "val", n_traj_val)
240
+ anchors, g_a = _make_anchors(val_ds, cfg, seed)
241
+ s_img_a = val_ds["img"][anchors]
242
+ a_a = val_ds["act"][anchors]
243
+ anchor_full = val_ds["full"][anchors] # 29-D qpos+qvel for fresh rollout
244
+
245
+ run_obj, wlog, wfinish = init_wandb(
246
+ cfg.get("wandb_project", "genq-policy-eval"),
247
+ f"genqvisual-{occ_model}-z{z_dim}-{env_id}-s{seed}",
248
+ {**cfg, "env": env_id, "seed": seed, "method": "genq_reward_latent"},
249
+ mode=cfg.get("wandb_mode"))
250
+ wandb_url = getattr(run_obj, "url", None)
251
+
252
+ t0 = time.time()
253
+ enc, dec, latent_mse = train_reward_latent_image(train_ds, z_dim, cfg, device, seed, wlog)
254
+ z_train = encode_images(enc, train_ds["img"], device)
255
+ cond_dim = z_dim + train_ds["a_dim"] + 2 # (z_now, a, g_xy)
256
+ occ = gc_core.build_occupancy(occ_model, cond_dim, z_dim, cfg, device)
257
+ losses = train_latent_occupancy_image(occ, train_ds, z_train, gamma, cfg, device, seed, wlog)
258
+ train_wall = time.time() - t0
259
+
260
+ truth, truth_kind = ground_truth_q(env_id, val_ds, anchors, g_a, gamma,
261
+ kind=kind, sigma=cfg["sigma"], eps=cfg["epsilon"],
262
+ M=cfg.get("truth_M", 8), H=cfg.get("truth_H", 350),
263
+ seed=seed, anchor_full=anchor_full)
264
+ # encode anchor images to z_now for conditioning
265
+ z_now_a = encode_images(enc, s_img_a, device)
266
+
267
+ gen_counts = cfg.get("gen_sample_counts", [1, 2, 4, 8, 16, 32, 64, 128, 256])
268
+ mse_by_n, corr_by_n, mse_curve = {}, {}, []
269
+ for N in gen_counts:
270
+ mn = q_metrics(latent_occ_q(occ, dec, z_now_a, a_a, g_a, N, device), truth)
271
+ mse_by_n[str(N)] = mn["mse"]; corr_by_n[str(N)] = mn["pearson"]; mse_curve.append(mn["mse"])
272
+ N_final = gen_counts[-1]
273
+ est = latent_occ_q(occ, dec, z_now_a, a_a, g_a, N_final, device)
274
+ m = q_metrics(est, truth)
275
+
276
+ result = {
277
+ "method": "genq_reward_latent", "env": env_id, "seed": seed, "wandb_url": wandb_url,
278
+ "representation": "image_reward_predictive_latent",
279
+ "occ_model": occ_model, "z_dim": z_dim, "reward": kind, "truth_kind": truth_kind,
280
+ "gen_sample_counts": gen_counts,
281
+ "train/loss": losses, "train/q_mse": [m["mse"]], "latent/reward_mse": latent_mse,
282
+ "eval/q_mse": m["mse"], "eval/q_mae": m["mae"],
283
+ "eval/q_corr": m["pearson"], "eval/q_spearman": m["spearman"],
284
+ "eval/q_mse_by_n": mse_by_n, "eval/q_corr_by_n": corr_by_n,
285
+ "eval/q_mse_vs_N": mse_curve, "eval/N_final": N_final,
286
+ "eval/truth_std": float(np.std(truth)),
287
+ "wall_clock_s": train_wall, "n_anchors": int(len(anchors)),
288
+ }
289
+ wlog({"eval/q_mse": m["mse"], "eval/q_corr": m["pearson"]})
290
+ wfinish()
291
+ return result
292
+
293
+
294
+ # ----------------------------------------------------------------------------
295
+ # mc / td baselines on the 29-D ant STATE (non-latent reference, documented)
296
+ # ----------------------------------------------------------------------------
297
+ def _shared_state_setup(env_id, seed, cfg):
298
+ """Build (train_ds, val_ds, anchors, g_a, anchor_full) on the 29-D ant state."""
299
+ n_traj_tr = cfg.get("vis_train_traj", None)
300
+ n_traj_val = cfg.get("vis_val_traj", None)
301
+ train_v = load_visual_gc(env_id, "train", n_traj_tr)
302
+ val_v = load_visual_gc(env_id, "val", n_traj_val)
303
+ # state datasets: obs = full MuJoCo state (qpos+qvel); xy reward signal stays
304
+ # qpos[:, :2] (== full[:, :2]). s_dim is derived from the data so this works for
305
+ # both AntMaze (29-D) and the rendered visual-PointMaze (4-D qpos[2]+qvel[2]).
306
+ s_dim = int(train_v["full"].shape[1])
307
+ tr = dict(obs=train_v["full"], act=train_v["act"], end=train_v["end"],
308
+ N=train_v["N"], s_dim=s_dim, a_dim=train_v["a_dim"])
309
+ va = dict(obs=val_v["full"], act=val_v["act"], end=val_v["end"],
310
+ N=val_v["N"], s_dim=s_dim, a_dim=val_v["a_dim"])
311
+ anchors, g_a = _make_anchors(val_v, cfg, seed)
312
+ anchor_full = val_v["full"][anchors]
313
+ return tr, va, val_v, anchors, g_a, anchor_full
314
+
315
+
316
+ def run_mc(env_id, seed, cfg):
317
+ """Trained-MC critic Q_MC(s,a,g) on the 29-D ant state (non-latent reference)."""
318
+ import mc as mc_mod
319
+ device = get_device(); set_seed(seed)
320
+ gamma = cfg["gamma"]; kind, sigma, eps = cfg["reward"], cfg["sigma"], cfg["epsilon"]
321
+ pos = 2
322
+ tr, va, val_v, anchors, g_a, anchor_full = _shared_state_setup(env_id, seed, cfg)
323
+ s_a = va["obs"][anchors]; a_a = va["act"][anchors]
324
+
325
+ run_obj, wlog, wfinish = init_wandb(
326
+ cfg.get("wandb_project", "genq-policy-eval"),
327
+ f"mc-state29-{env_id}-s{seed}", {**cfg, "env": env_id, "seed": seed, "method": "mc"},
328
+ mode=cfg.get("wandb_mode"))
329
+ wandb_url = getattr(run_obj, "url", None)
330
+
331
+ rng = np.random.default_rng(seed)
332
+ cand = np.where((tr["end"] - np.arange(tr["N"])) >= 2)[0]
333
+ n_fit = min(cfg.get("mc_fit_anchors", 80000), len(cand))
334
+ fit_idx = cand[rng.integers(0, len(cand), size=n_fit)]
335
+ fit_g = tr["obs"][gc_core.sample_goal_idx(fit_idx, tr["end"], rng)][:, :pos]
336
+ fit_ret = mc_mod.gc_return(tr["obs"][:, :pos], tr["end"], fit_g, fit_idx, gamma, sigma, kind, eps)
337
+
338
+ net = mc_mod.QNet(tr["s_dim"], pos, tr["a_dim"], cfg["hidden_dim"], cfg["num_layers"]).to(device)
339
+ opt = torch.optim.Adam(net.parameters(), lr=cfg["lr"])
340
+ St = torch.as_tensor(tr["obs"][fit_idx], dtype=torch.float32)
341
+ Gt = torch.as_tensor(fit_g, dtype=torch.float32)
342
+ At = torch.as_tensor(tr["act"][fit_idx], dtype=torch.float32)
343
+ Rt = torch.as_tensor(fit_ret, dtype=torch.float32)
344
+ losses, qmse = [], []
345
+ log_every = max(1, cfg["steps"] // 50); t0 = time.time()
346
+ for step in range(1, cfg["steps"] + 1):
347
+ b = rng.integers(0, len(fit_idx), cfg["batch_size"])
348
+ loss = ((net(St[b].to(device), Gt[b].to(device), At[b].to(device)) - Rt[b].to(device)) ** 2).mean()
349
+ opt.zero_grad(); loss.backward(); opt.step()
350
+ if step % log_every == 0 or step == 1:
351
+ losses.append(float(loss.item())); qmse.append(float(loss.item()))
352
+ wlog({"train/loss": float(loss.item()), "train/q_mse": float(loss.item())}, step=step)
353
+ net.eval(); train_wall = time.time() - t0
354
+
355
+ truth, truth_kind = ground_truth_q(env_id, va, anchors, g_a, gamma, kind=kind, sigma=sigma,
356
+ eps=eps, M=cfg.get("truth_M", 8), H=cfg.get("truth_H", 350),
357
+ seed=seed, anchor_full=anchor_full)
358
+ with torch.no_grad():
359
+ est = net(torch.as_tensor(s_a, dtype=torch.float32, device=device),
360
+ torch.as_tensor(g_a, dtype=torch.float32, device=device),
361
+ torch.as_tensor(a_a, dtype=torch.float32, device=device)).cpu().numpy()
362
+ m = q_metrics(est, truth)
363
+ result = {"method": "mc", "env": env_id, "seed": seed, "wandb_url": wandb_url,
364
+ "representation": "ant_state_29d", "reward": kind, "truth_kind": truth_kind,
365
+ "train/loss": losses, "train/q_mse": qmse,
366
+ "eval/q_mse": m["mse"], "eval/q_mae": m["mae"],
367
+ "eval/q_corr": m["pearson"], "eval/q_spearman": m["spearman"],
368
+ "eval/truth_std": float(np.std(truth)), "wall_clock_s": train_wall,
369
+ "n_anchors": int(len(anchors))}
370
+ wlog({"eval/q_mse": m["mse"], "eval/q_corr": m["pearson"]}); wfinish()
371
+ return result
372
+
373
+
374
+ def run_td(env_id, seed, cfg):
375
+ """IQL-style TD critic Q(s,a,g) on the 29-D ant state (non-latent reference)."""
376
+ import mc as mc_mod
377
+ import td as td_mod
378
+ device = get_device(); set_seed(seed)
379
+ gamma = cfg["gamma"]; kind, sigma, eps = cfg["reward"], cfg["sigma"], cfg["epsilon"]
380
+ pos = 2
381
+ tr, va, val_v, anchors, g_a, anchor_full = _shared_state_setup(env_id, seed, cfg)
382
+ s_a = va["obs"][anchors]; a_a = va["act"][anchors]
383
+
384
+ run_obj, wlog, wfinish = init_wandb(
385
+ cfg.get("wandb_project", "genq-policy-eval"),
386
+ f"td-state29-{env_id}-s{seed}", {**cfg, "env": env_id, "seed": seed, "method": "td"},
387
+ mode=cfg.get("wandb_mode"))
388
+ wandb_url = getattr(run_obj, "url", None)
389
+
390
+ obs = tr["obs"]; act = tr["act"]; end = tr["end"]; N = tr["N"]
391
+ nxt = np.where((end - np.arange(N)) > 1)[0]
392
+ sd, ad = tr["s_dim"], tr["a_dim"]; Hd, L = cfg["hidden_dim"], cfg["num_layers"]
393
+ q = mc_mod.QNet(sd, pos, ad, Hd, L).to(device)
394
+ qt = mc_mod.QNet(sd, pos, ad, Hd, L).to(device); qt.load_state_dict(q.state_dict())
395
+ v = td_mod.VNet(sd, pos, Hd, L).to(device)
396
+ optq = torch.optim.Adam(q.parameters(), lr=cfg["lr"])
397
+ optv = torch.optim.Adam(v.parameters(), lr=cfg["lr"])
398
+ tau = cfg.get("iql_expectile", 0.5); polyak = cfg.get("polyak", 0.005)
399
+ rng = np.random.default_rng(seed)
400
+ losses, qmse = [], []; log_every = max(1, cfg["steps"] // 50); t0 = time.time()
401
+ for step in range(1, cfg["steps"] + 1):
402
+ idx = nxt[rng.integers(0, len(nxt), size=cfg["batch_size"])]
403
+ g = obs[gc_core.sample_goal_idx(idx, end, rng)][:, :pos]
404
+ d = np.linalg.norm(obs[idx][:, :pos] - g, axis=1)
405
+ r = gc_core.reward_of_dist(d, kind, sigma, eps).astype(np.float32)
406
+ s = torch.as_tensor(obs[idx], device=device)
407
+ a = torch.as_tensor(act[idx], device=device)
408
+ s2 = torch.as_tensor(obs[idx + 1], device=device)
409
+ gt = torch.as_tensor(g, dtype=torch.float32, device=device)
410
+ rt = torch.as_tensor(r, device=device)
411
+ with torch.no_grad():
412
+ qsa = qt(s, gt, a)
413
+ diff = qsa - v(s, gt)
414
+ w = torch.abs(tau - (diff < 0).float())
415
+ loss_v = (w * diff ** 2).mean()
416
+ optv.zero_grad(); loss_v.backward(); optv.step()
417
+ with torch.no_grad():
418
+ y = (1 - gamma) * rt + gamma * v(s2, gt)
419
+ loss_q = ((q(s, gt, a) - y) ** 2).mean()
420
+ optq.zero_grad(); loss_q.backward(); optq.step()
421
+ with torch.no_grad():
422
+ for p, ptg in zip(q.parameters(), qt.parameters()):
423
+ ptg.mul_(1 - polyak).add_(polyak * p)
424
+ if step % log_every == 0 or step == 1:
425
+ losses.append(float(loss_q.item())); qmse.append(float(loss_q.item()))
426
+ wlog({"train/loss": float(loss_q.item()), "train/q_mse": float(loss_q.item()),
427
+ "train/v_loss": float(loss_v.item())}, step=step)
428
+ q.eval(); train_wall = time.time() - t0
429
+
430
+ truth, truth_kind = ground_truth_q(env_id, va, anchors, g_a, gamma, kind=kind, sigma=sigma,
431
+ eps=eps, M=cfg.get("truth_M", 8), H=cfg.get("truth_H", 350),
432
+ seed=seed, anchor_full=anchor_full)
433
+ with torch.no_grad():
434
+ est = q(torch.as_tensor(s_a, dtype=torch.float32, device=device),
435
+ torch.as_tensor(g_a, dtype=torch.float32, device=device),
436
+ torch.as_tensor(a_a, dtype=torch.float32, device=device)).cpu().numpy()
437
+ m = q_metrics(est, truth)
438
+ result = {"method": "td", "env": env_id, "seed": seed, "wandb_url": wandb_url,
439
+ "representation": "ant_state_29d", "reward": kind, "truth_kind": truth_kind,
440
+ "train/loss": losses, "train/q_mse": qmse,
441
+ "eval/q_mse": m["mse"], "eval/q_mae": m["mae"],
442
+ "eval/q_corr": m["pearson"], "eval/q_spearman": m["spearman"],
443
+ "eval/truth_std": float(np.std(truth)), "wall_clock_s": train_wall,
444
+ "n_anchors": int(len(anchors))}
445
+ wlog({"eval/q_mse": m["mse"], "eval/q_corr": m["pearson"]}); wfinish()
446
+ return result
447
+
448
+
449
+ if __name__ == "__main__":
450
+ pass
gen_q_rsm/preliminary_analysis/genq_visual_cube.py ADDED
@@ -0,0 +1,409 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Gen-Q policy evaluation for IMAGE observations on a MANIPSPACE env
2
+ (visual-cube-single-play-v0).
3
+
4
+ This file combines two already-proven pieces (issue #35):
5
+
6
+ (a) image obs -> frozen REWARD-PREDICTIVE LATENT occupancy
7
+ (proven on visual-antmaze-medium-navigate-v0 via ``genq_visual.py``), and
8
+ (b) the FRESH-RESET manipspace ground truth
9
+ (proven on the STATE cube-single-play-v0, genq corr ~0.88, via
10
+ ``gc_core.fresh_reset_anchors`` + ``gc_core.gc_fresh_truth_manipspace``).
11
+
12
+ Why a dedicated driver (vs reusing ``genq_visual.py``)
13
+ ------------------------------------------------------
14
+ ``genq_visual.py`` was written for visual-ANTmaze, where (i) the reward/goal signal is
15
+ the 2-D ant xy = ``qpos[:, :2]`` and (ii) the ground truth uses the DATASET-anchor
16
+ protocol (the 29-D qpos+qvel slice resets the sim). visual-cube differs on BOTH axes:
17
+
18
+ * The reward/goal is the 3-D OBJECT (block) position, not an agent xy. For cube-single
19
+ the block_0 position lives at ``qpos[:, 14:17]`` (resolved LIVE from the state cube
20
+ env so nothing is hardcoded across env versions).
21
+ * The cube observation is a lossy projection -> the truth MUST use the FRESH-RESET
22
+ protocol (FRESH_RESET_SPEC.md Protocol B): each anchor is its own ``env.reset()``
23
+ start, the live CubeMarkovOracle is rolled from ``set_state`` for the truth, and the
24
+ SAME anchors are queried by the learned models.
25
+
26
+ The underlying sim for ``visual-cube-single-play-v0`` is the SAME cube env as the state
27
+ version; only the observation rendering differs. So ``fresh_reset_anchors`` /
28
+ ``gc_fresh_truth_manipspace`` work UNCHANGED when handed the visual env id — the only
29
+ difference is that the recorded anchor ``s`` is now a 64x64x3 IMAGE (used solely to
30
+ condition the CNN-latent occupancy), while the truth uses qpos/qvel/target/g from the
31
+ privileged ``info`` exactly as in the state cube.
32
+
33
+ Recipe (reward-predictive latent, frozen, then diffusion occupancy)
34
+ -------------------------------------------------------------------
35
+ 1. Encoder z = E_psi(image) (models.ImageEncoder, CNN, [B,3,64,64] in [0,1])
36
+ Decoder r_hat = R_psi(z, g) (goal-conditioned, g = 3-D block-goal position)
37
+ Loss E[(R_psi(E_psi(image), g) - r(block_pos; g))^2] + lambda||z||^2 ; FREEZE E,R.
38
+ The reward is OBJECT goal-reaching: r(x;g)=exp(-||x-g||^2/2 sigma^2), x=block_pos.
39
+ 2. Conditioning representation (s,a,g) = (z_now=E_psi(image_now), a (5-D), g (3-D)).
40
+ 3. Occupancy p_theta(z' | z_now, a, g), z' = stopgrad(E_psi(image_{t+k})),
41
+ k ~ Geom(1-gamma). Conditional diffusion (NEVER a Gaussian MDN).
42
+ 4. Q^pi(s,a,g) = E_{z ~ p_theta}[ R_psi(z, g) ] ~= (1/N) sum_i R_psi(z_i, g).
43
+
44
+ Ground truth = FRESH ROLLOUTS only (Protocol B, fresh_reset). NO in-dataset return-to-go,
45
+ NO synthetic fallback. ``anchor_protocol="fresh_reset"`` in every result JSON.
46
+
47
+ mc / td baselines run on the cube STATE (28-D obs) as the non-latent reference, against
48
+ the SAME fresh-reset anchors/truth — the honest comparable reference (a trained CNN
49
+ critic over raw pixels is a separate study). Documented via ``"representation"`` in each
50
+ result JSON.
51
+ """
52
+ import os
53
+ import time
54
+
55
+ import numpy as np
56
+ import torch
57
+ import torch.nn.functional as F
58
+
59
+ from _common import get_device, set_seed, q_metrics, init_wandb
60
+ import gc_core
61
+ import models
62
+ from genq_reward_latent import GCRewardDecoder
63
+
64
+ _HERE = os.path.dirname(os.path.abspath(__file__))
65
+
66
+
67
+ def _resolve_data_dir():
68
+ """Resolve the OGBench data dir robustly across login/compute nodes.
69
+
70
+ On the login node $HOME=/proj/inf-scaling/zwhong, but on a Blue Vela compute node
71
+ $HOME=/u/zwhong (a separate .ogbench without the prefetched data). Prefer an explicit
72
+ OGBENCH_DATA_DIR, then any candidate that actually contains the dataset, else the
73
+ expanduser default."""
74
+ cands = []
75
+ if os.environ.get("OGBENCH_DATA_DIR"):
76
+ cands.append(os.path.expanduser(os.environ["OGBENCH_DATA_DIR"]))
77
+ cands += [
78
+ os.path.expanduser("~/.ogbench/data"),
79
+ "/proj/inf-scaling/zwhong/.ogbench/data",
80
+ "/u/zwhong/.ogbench/data",
81
+ ]
82
+ for c in cands:
83
+ if os.path.isdir(c) and any(f.endswith(".npz") for f in os.listdir(c)):
84
+ return c
85
+ return os.path.expanduser("~/.ogbench/data")
86
+
87
+
88
+ _DATA_DIR = _resolve_data_dir()
89
+
90
+ # cube-single block_0 position qpos slice (resolved live below; this is the fallback /
91
+ # documented default verified on 2026-06-28: qpos[14:17]).
92
+ _CUBE_BLOCK_SLICE = (14, 17)
93
+
94
+
95
+ # ----------------------------------------------------------------------------
96
+ # block qpos slice (resolved live so we never hardcode across env versions)
97
+ # ----------------------------------------------------------------------------
98
+ def _resolve_cube_block_slice(env_id):
99
+ """Resolve the (lo, hi) qpos slice giving the cube block_0 3-D position, by
100
+ inspecting the STATE cube env (same sim, has privileged block keys). Falls back to
101
+ the verified default if the live probe fails."""
102
+ state_env_id = env_id.replace("visual-", "")
103
+ try:
104
+ import ogbench
105
+ env = ogbench.make_env_and_datasets(
106
+ state_env_id, env_only=True, terminate_at_goal=False,
107
+ mode="data_collection", max_episode_steps=1001, dataset_dir=_DATA_DIR)
108
+ sl = gc_core._manipspace_block_qpos_slices(env, "cube")
109
+ env.close()
110
+ # cube-single -> single (lo, hi)
111
+ return sl[0]
112
+ except Exception as e: # pragma: no cover - defensive
113
+ print(f"[visualcube] block-slice probe failed ({e}); using default {_CUBE_BLOCK_SLICE}",
114
+ flush=True)
115
+ return _CUBE_BLOCK_SLICE
116
+
117
+
118
+ # ----------------------------------------------------------------------------
119
+ # visual cube dataset (images + qpos -> block position reward signal)
120
+ # ----------------------------------------------------------------------------
121
+ def load_visual_cube(env_id, split, block_slice, n_traj=None):
122
+ """Load the visual-cube npz for `split` in {"train","val"}.
123
+
124
+ Returns a dataset dict with:
125
+ img : uint8 [N, 64, 64, 3] (observation; encoded by the CNN, never modeled raw)
126
+ obj : float32 [N, 3] (block_0 position = qpos[:, lo:hi]; reward/goal signal)
127
+ full : float32 [N, 41] (qpos[21] + qvel[20]; reference only)
128
+ act : float32 [N, 5]
129
+ end : int64 [N] (trajectory end index per step)
130
+ N, a_dim
131
+ """
132
+ fname = env_id if split == "train" else f"{env_id}-val"
133
+ path = os.path.join(_DATA_DIR, f"{fname}.npz")
134
+ if not os.path.exists(path):
135
+ raise FileNotFoundError(f"visual-cube dataset not found: {path}")
136
+ d = np.load(path, mmap_mode="r")
137
+ term = np.asarray(d["terminals"], dtype=np.float32)
138
+ if n_traj is not None:
139
+ ends = np.where(term > 0.5)[0] + 1
140
+ N = int(ends[min(n_traj, len(ends)) - 1]) if len(ends) else len(term)
141
+ else:
142
+ N = len(term)
143
+ qpos = np.asarray(d["qpos"][:N], dtype=np.float32)
144
+ qvel = np.asarray(d["qvel"][:N], dtype=np.float32)
145
+ lo, hi = block_slice
146
+ return dict(
147
+ img=d["observations"][:N], # mmap'd uint8; index lazily
148
+ obj=qpos[:, lo:hi].copy().astype(np.float32), # [N, 3] block position
149
+ full=np.concatenate([qpos, qvel], axis=1), # reference only
150
+ act=np.asarray(d["actions"][:N], dtype=np.float32),
151
+ end=gc_core.trajectory_bounds(term[:N]),
152
+ N=N, a_dim=int(d["actions"].shape[1]),
153
+ )
154
+
155
+
156
+ def _imgs_to_tensor(img_u8, device):
157
+ """uint8 [B,64,64,3] -> float [B,3,64,64] in [0,1]."""
158
+ x = torch.as_tensor(np.asarray(img_u8), dtype=torch.float32, device=device) / 255.0
159
+ return x.permute(0, 3, 1, 2).contiguous()
160
+
161
+
162
+ # ----------------------------------------------------------------------------
163
+ # reward-predictive CNN latent (encoder + goal-conditioned reward decoder)
164
+ # ----------------------------------------------------------------------------
165
+ def train_reward_latent_image(ds, z_dim, g_dim, cfg, device, seed, wlog):
166
+ """E_psi(image), R_psi(z, g) trained so z retains reward-relevant info; then frozen.
167
+ The reward is OBJECT goal-reaching on the 3-D block position (ds['obj'])."""
168
+ enc = models.ImageEncoder(z_dim, hidden_dim=cfg["hidden_dim"]).to(device)
169
+ dec = GCRewardDecoder(z_dim, g_dim, cfg["hidden_dim"], 2).to(device)
170
+ opt = torch.optim.Adam(list(enc.parameters()) + list(dec.parameters()), lr=cfg["lr"])
171
+ rng = np.random.default_rng(seed + 3)
172
+ obj, end = ds["obj"], ds["end"]
173
+ lam = cfg.get("latent_l2", 1e-4)
174
+ kind, sigma, eps = cfg["reward"], cfg["sigma"], cfg["epsilon"]
175
+ steps = cfg.get("latent_steps", 20000)
176
+ bs = cfg["batch_size"]
177
+ final = 0.0
178
+ for step in range(1, steps + 1):
179
+ x_idx = rng.integers(0, ds["N"], bs)
180
+ g = obj[gc_core.sample_goal_after(x_idx, end, rng)] # hindsight block goal
181
+ d = np.linalg.norm(obj[x_idx] - g, axis=1)
182
+ r = gc_core.reward_of_dist(d, kind, sigma, eps).astype(np.float32)
183
+ img = _imgs_to_tensor(ds["img"][x_idx], device)
184
+ gt = torch.as_tensor(g, dtype=torch.float32, device=device)
185
+ rt = torch.as_tensor(r, device=device)
186
+ z = enc(img)
187
+ loss = F.mse_loss(dec(z, gt), rt) + lam * (z ** 2).mean()
188
+ opt.zero_grad(); loss.backward(); opt.step()
189
+ if step % max(1, steps // 20) == 0 or step == 1:
190
+ final = float(loss.item())
191
+ wlog({"latent/loss": final}, step=step)
192
+ enc.eval(); dec.eval()
193
+ for p in enc.parameters(): p.requires_grad_(False)
194
+ for p in dec.parameters(): p.requires_grad_(False)
195
+ return enc, dec, final
196
+
197
+
198
+ @torch.no_grad()
199
+ def encode_images(enc, img_u8, device, batch=2048):
200
+ out = []
201
+ for i in range(0, len(img_u8), batch):
202
+ out.append(enc(_imgs_to_tensor(img_u8[i:i + batch], device)).cpu().numpy())
203
+ return np.concatenate(out, 0).astype(np.float32)
204
+
205
+
206
+ # ----------------------------------------------------------------------------
207
+ # latent occupancy p_theta(z' | z_now, a, g)
208
+ # ----------------------------------------------------------------------------
209
+ def train_latent_occupancy_image(occ, ds, z_all, gamma, cfg, device, seed, wlog):
210
+ """z_all: precomputed E_psi(image) for every step (conditioning AND target source).
211
+ Goal g = hindsight block-position goal (ds['obj'] downstream of the target)."""
212
+ act, end, obj = ds["act"], ds["end"], ds["obj"]
213
+ rng = np.random.default_rng(seed + 7)
214
+ t0 = rng.integers(0, ds["N"], 20000)
215
+ j0 = gc_core.future_idx(t0, end, gamma, rng)
216
+ g0 = obj[gc_core.sample_goal_after(j0, end, rng)]
217
+ c0 = np.concatenate([z_all[t0], act[t0], g0], 1)
218
+ occ.set_normalization(c0.mean(0), c0.std(0) + 1e-6,
219
+ z_all[j0].mean(0), z_all[j0].std(0) + 1e-6)
220
+ z_t = torch.from_numpy(z_all)
221
+ opt = torch.optim.Adam(occ.parameters(), lr=cfg["lr"])
222
+ losses = []
223
+ log_every = max(1, cfg["steps"] // 50)
224
+ bs = cfg["batch_size"]
225
+ for step in range(1, cfg["steps"] + 1):
226
+ t = rng.integers(0, ds["N"], bs)
227
+ j = gc_core.future_idx(t, end, gamma, rng)
228
+ g = obj[gc_core.sample_goal_after(j, end, rng)]
229
+ c = np.concatenate([z_all[t], act[t], g], 1)
230
+ loss = occ.training_loss(torch.as_tensor(c, dtype=torch.float32, device=device),
231
+ z_t[j].to(device))
232
+ opt.zero_grad(); loss.backward()
233
+ gn = torch.nn.utils.clip_grad_norm_(occ.parameters(), 10.0); opt.step()
234
+ if step % log_every == 0 or step == 1:
235
+ losses.append(float(loss.item()))
236
+ wlog({"train/loss": float(loss.item()), "train/grad_norm": float(gn)}, step=step)
237
+ occ.eval()
238
+ return losses
239
+
240
+
241
+ @torch.no_grad()
242
+ def latent_occ_q(occ, dec, z_now, a, g, N, device, batch=256):
243
+ out = np.zeros(len(z_now))
244
+ for i in range(0, len(z_now), batch):
245
+ c = np.concatenate([z_now[i:i + batch], a[i:i + batch], g[i:i + batch]], 1)
246
+ ct = torch.as_tensor(c, dtype=torch.float32, device=device)
247
+ z = occ.sample(ct, N) # [b, N, z]
248
+ b, n, zd = z.shape
249
+ gt = torch.as_tensor(g[i:i + batch], dtype=torch.float32, device=device)
250
+ gt = gt.unsqueeze(1).expand(-1, n, -1).reshape(b * n, -1)
251
+ r = dec(z.reshape(b * n, zd), gt).reshape(b, n)
252
+ out[i:i + batch] = r.mean(1).cpu().numpy()
253
+ return out
254
+
255
+
256
+ # ----------------------------------------------------------------------------
257
+ # fresh-reset anchors with IMAGE conditioning state
258
+ # ----------------------------------------------------------------------------
259
+ def _fresh_reset_image_anchors(env_id, n_anchors, seed):
260
+ """Protocol-B fresh-reset anchors for visual-cube. Identical to
261
+ ``gc_core.fresh_reset_anchors`` except the recorded conditioning state ``s`` is the
262
+ 64x64x3 IMAGE observation (the visual env reset returns an image obs while the
263
+ oracle/truth read everything from the privileged ``info``). Returns the same pack
264
+ dict (so ``gc_core.gc_fresh_truth_manipspace`` consumes it unchanged) with
265
+ ``s_img`` = [A,64,64,3] uint8 added."""
266
+ fam = gc_core.manipspace_family(env_id)
267
+ assert fam == "cube", f"expected cube family, got {fam} for {env_id}"
268
+ env = gc_core._make_manipspace_env(env_id, _DATA_DIR)
269
+ u = env.unwrapped
270
+ oracles = gc_core._make_manipspace_oracles(env, fam)
271
+ S_img, A, G, QP, QV, OBJ, TGT = [], [], [], [], [], [], []
272
+ for i in range(n_anchors):
273
+ np.random.seed(seed * 100003 + i)
274
+ ob, info = env.reset(seed=seed * 100003 + i)
275
+ oracle = oracles[info["privileged/target_task"]]
276
+ oracle.reset(ob, info)
277
+ a0 = np.clip(np.asarray(oracle.select_action(ob, info), dtype=np.float64), -1, 1)
278
+ S_img.append(np.asarray(ob, dtype=np.uint8)) # IMAGE obs
279
+ A.append(a0.astype(np.float32))
280
+ G.append(gc_core._manipspace_goal(info, fam).astype(np.float32)) # 3-D block goal
281
+ QP.append(np.asarray(info["qpos"], dtype=np.float64))
282
+ QV.append(np.asarray(info["qvel"], dtype=np.float64))
283
+ OBJ.append(gc_core._manipspace_object(info, fam).astype(np.float32))
284
+ TGT.append(gc_core._capture_manipspace_target(u, fam, info))
285
+ env.close()
286
+ return dict(family=fam, s_img=np.stack(S_img), a=np.stack(A), g=np.stack(G),
287
+ qpos=np.stack(QP), qvel=np.stack(QV), obj0=np.stack(OBJ), target=TGT,
288
+ # `s` placeholder so gc_fresh_truth_manipspace's len(anchors["s"]) works
289
+ s=np.stack(A))
290
+
291
+
292
+ # ----------------------------------------------------------------------------
293
+ # genq (image reward-predictive latent occupancy) + fresh-reset truth
294
+ # ----------------------------------------------------------------------------
295
+ def run(env_id, seed, cfg):
296
+ device = get_device()
297
+ set_seed(seed)
298
+ gamma = cfg["gamma"]
299
+ occ_model = cfg.get("occ_model", "diffusion")
300
+ z_dim = cfg.get("z_dim", 8)
301
+ n_traj_tr = cfg.get("vis_train_traj", None)
302
+ n_traj_val = cfg.get("vis_val_traj", None)
303
+
304
+ # manipulation reward scale (NOT maze sigma=5). Match state cube (0.05 / 0.04).
305
+ if abs(cfg.get("sigma", 5.0) - 5.0) < 1e-9:
306
+ cfg["sigma"] = 0.05
307
+ if abs(cfg.get("epsilon", 0.5) - 0.5) < 1e-9:
308
+ cfg["epsilon"] = 0.04
309
+ kind, sigma, eps = cfg["reward"], cfg["sigma"], cfg["epsilon"]
310
+
311
+ block_slice = _resolve_cube_block_slice(env_id)
312
+ g_dim = block_slice[1] - block_slice[0] # 3 for cube-single
313
+
314
+ train_ds = load_visual_cube(env_id, "train", block_slice, n_traj_tr)
315
+ # fresh-reset anchors (image s + privileged qpos/qvel/target for truth)
316
+ pack = _fresh_reset_image_anchors(env_id, cfg["n_anchors"], seed)
317
+ s_img_a = pack["s_img"]
318
+ a_a = pack["a"]
319
+ g_a = pack["g"] # [A, 3] block goal
320
+
321
+ run_obj, wlog, wfinish = init_wandb(
322
+ cfg.get("wandb_project", "genq-policy-eval"),
323
+ f"genqvisualcube-{occ_model}-z{z_dim}-{env_id}-s{seed}",
324
+ {**cfg, "env": env_id, "seed": seed, "method": "genq_reward_latent"},
325
+ mode=cfg.get("wandb_mode"))
326
+ wandb_url = getattr(run_obj, "url", None)
327
+
328
+ t0 = time.time()
329
+ enc, dec, latent_mse = train_reward_latent_image(train_ds, z_dim, g_dim, cfg,
330
+ device, seed, wlog)
331
+ z_train = encode_images(enc, train_ds["img"], device)
332
+ cond_dim = z_dim + train_ds["a_dim"] + g_dim # (z_now, a, g)
333
+ occ = gc_core.build_occupancy(occ_model, cond_dim, z_dim, cfg, device)
334
+ losses = train_latent_occupancy_image(occ, train_ds, z_train, gamma, cfg, device, seed, wlog)
335
+ train_wall = time.time() - t0
336
+
337
+ # FRESH-ROLLOUT truth (Protocol B) — CubeMarkovOracle rolled M x H from set_state.
338
+ truth = gc_core.gc_fresh_truth_manipspace(
339
+ env_id, pack, gamma, kind, sigma, eps,
340
+ M=cfg.get("truth_M", 8), H=cfg.get("truth_H", 350), seed=seed, verbose=True,
341
+ dataset_dir=_DATA_DIR)
342
+ truth_kind = "fresh_rollout"
343
+
344
+ z_now_a = encode_images(enc, s_img_a, device) # encode anchor images
345
+ gen_counts = cfg.get("gen_sample_counts", [1, 2, 4, 8, 16, 32, 64, 128, 256])
346
+ mse_by_n, corr_by_n, mse_curve = {}, {}, []
347
+ for N in gen_counts:
348
+ mn = q_metrics(latent_occ_q(occ, dec, z_now_a, a_a, g_a, N, device), truth)
349
+ mse_by_n[str(N)] = mn["mse"]; corr_by_n[str(N)] = mn["pearson"]; mse_curve.append(mn["mse"])
350
+ N_final = gen_counts[-1]
351
+ est = latent_occ_q(occ, dec, z_now_a, a_a, g_a, N_final, device)
352
+ m = q_metrics(est, truth)
353
+
354
+ result = {
355
+ "method": "genq", "env": env_id, "seed": seed, "wandb_url": wandb_url,
356
+ "representation": "image_reward_predictive_latent",
357
+ "anchor_protocol": "fresh_reset",
358
+ "occ_model": occ_model, "z_dim": z_dim, "reward": kind, "truth_kind": truth_kind,
359
+ "gen_sample_counts": gen_counts,
360
+ "train/loss": losses, "train/q_mse": [m["mse"]], "latent/reward_mse": latent_mse,
361
+ "eval/q_mse": m["mse"], "eval/q_mae": m["mae"],
362
+ "eval/q_corr": m["pearson"], "eval/q_spearman": m["spearman"],
363
+ "eval/q_mse_by_n": mse_by_n, "eval/q_corr_by_n": corr_by_n,
364
+ "eval/q_mse_vs_N": mse_curve, "eval/N_final": N_final,
365
+ "eval/truth_std": float(np.std(truth)),
366
+ "wall_clock_s": train_wall, "n_anchors": int(len(s_img_a)),
367
+ "block_slice": list(block_slice), "sigma": sigma, "epsilon": eps,
368
+ }
369
+ wlog({"eval/q_mse": m["mse"], "eval/q_corr": m["pearson"]})
370
+ wfinish()
371
+ return result
372
+
373
+
374
+ # ----------------------------------------------------------------------------
375
+ # mc / td baselines on the cube STATE (28-D obs) — non-latent reference
376
+ # ----------------------------------------------------------------------------
377
+ # A trained-MC / IQL-TD critic over RAW 64x64x3 pixels is a separate CNN-critic study.
378
+ # The honest, comparable reference here is the SAME mc/td recipe on the cube STATE, run
379
+ # against the IDENTICAL fresh-reset truth. The underlying sim for visual-cube IS the
380
+ # state cube (only the observation rendering differs), and ``mc.run`` / ``td.run`` already
381
+ # use ``gc_core.fresh_reset_anchors`` + ``gc_core.gc_fresh_truth_manipspace`` on the cube
382
+ # family with the SAME (seed, n_anchors, M, H, sigma, eps). So delegating to the proven
383
+ # state-cube mc/td and only relabeling ``env`` gives results scored against the same
384
+ # fresh-rollout truth as genq, with zero reimplementation risk. ``representation`` and
385
+ # ``state_env`` document the deviation in the JSON.
386
+ def _run_state_baseline(method, env_id, seed, cfg):
387
+ import mc as mc_mod
388
+ import td as td_mod
389
+ state_env_id = env_id.replace("visual-", "")
390
+ fn = mc_mod.run if method == "mc" else td_mod.run
391
+ result = fn(state_env_id, seed, cfg)
392
+ result["env"] = env_id
393
+ result["state_env"] = state_env_id
394
+ result["representation"] = "cube_state_28d_nonlatent_reference"
395
+ return result
396
+
397
+
398
+ def run_mc(env_id, seed, cfg):
399
+ """Trained-MC critic on the cube STATE (non-latent reference; same fresh-reset truth)."""
400
+ return _run_state_baseline("mc", env_id, seed, cfg)
401
+
402
+
403
+ def run_td(env_id, seed, cfg):
404
+ """IQL-TD critic on the cube STATE (non-latent reference; same fresh-reset truth)."""
405
+ return _run_state_baseline("td", env_id, seed, cfg)
406
+
407
+
408
+ if __name__ == "__main__":
409
+ pass
gen_q_rsm/preliminary_analysis/genq_visual_puzzle.py ADDED
@@ -0,0 +1,439 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Gen-Q policy evaluation for the IMAGE puzzle env (visual-puzzle-3x3-play-v0).
2
+
3
+ Why this file exists
4
+ --------------------
5
+ This is the IMAGE + COMBINATORIAL cell (issue #35). It marries two existing recipes:
6
+
7
+ * the image reward-predictive-latent occupancy of ``genq_visual.py`` (CNN encoder
8
+ over 64x64x3 frames, NEVER raw-pixel occupancy), and
9
+ * the puzzle button-state machinery of ``gc_core.py`` (the match-fraction reward and
10
+ the manipspace fresh-RESET fresh-rollout truth used by the STATE puzzle cell).
11
+
12
+ The puzzle reward / goal / occupancy TARGET are BINARY button-state vectors (9 bits for
13
+ 3x3), NOT object positions. The principled reward is the match-fraction
14
+ (``gc_core.puzzle_reward``, see issue #35) used IDENTICALLY by genq, mc, td and the
15
+ fresh-rollout truth.
16
+
17
+ Recipe (reward-predictive image latent, frozen, then latent occupancy)
18
+ ----------------------------------------------------------------------
19
+ 1. Encoder z = E_psi(image) (models.ImageEncoder, CNN, [B,3,64,64] in [0,1])
20
+ Decoder r_hat = R_psi(z, g) (g = 9-D goal button pattern)
21
+ Loss E[(R_psi(E_psi(image), g) - puzzle_reward(button_states; g))^2] + lam||z||^2 ;
22
+ FREEZE E,R.
23
+ 2. Conditioning: occupancy on (z_now, a, g), z_now = E_psi(image_now).
24
+ 3. Occupancy p_theta(z' | z_now, a, g), z' = stopgrad(E_psi(image_{t+k})),
25
+ k ~ Geom(1-gamma). Conditional diffusion (NEVER a Gaussian MDN).
26
+ 4. Q^pi(s,a,g) = E_{z ~ p_theta}[ R_psi(z, g) ] ~= (1/N) sum_i R_psi(z_i, g).
27
+
28
+ Ground truth = FRESH ROLLOUTS only (fresh-RESET Protocol B, identical to the STATE
29
+ puzzle). The live PuzzleEnv sim has all privileged info, so ``set_state(qpos,qvel,
30
+ button_states)`` + ButtonMarkovOracle rollouts produce the truth REGARDLESS of whether
31
+ the model's observation is an image or a state vector. The anchor pack is built ONCE
32
+ from a live env reset and SHARED by genq/mc/td so the three score the SAME (s,a,g).
33
+
34
+ mc / td baselines: trained-MC / IQL-TD critics over the 46-D [qpos|qvel] STATE (the
35
+ non-latent reference, documented via ``representation``), exactly mirroring the
36
+ genq_visual antmaze precedent where mc/td run on the 29-D ant state. The occupancy
37
+ TARGET / reward signal for mc/td is the button-state vector (match-fraction reward),
38
+ the same target genq's latent decoder predicts.
39
+
40
+ EXPECTED RESULT (honest negative, inherited from the STATE puzzle): the discrete
41
+ combinatorial button task yields near-degenerate fresh-rollout truth (the target
42
+ button is either pressed or not within the horizon; truth std ~ 0.01), so Q is
43
+ essentially unrankable and ALL THREE methods (mc/td/genq) land at ~0 correlation.
44
+ This driver runs the pipeline honestly and reports whatever it finds; it does NOT tune
45
+ toward a spurious positive. The image latent is one more transformation on top of the
46
+ same degenerate truth, so the image case is expected to CONFIRM the state negative.
47
+ """
48
+ import os
49
+ import time
50
+
51
+ import numpy as np
52
+ import torch
53
+ import torch.nn.functional as F
54
+
55
+ from _common import get_device, set_seed, q_metrics, init_wandb
56
+ import gc_core
57
+ import models
58
+ from genq_reward_latent import GCRewardDecoder
59
+
60
+ _HERE = os.path.dirname(os.path.abspath(__file__))
61
+ _DATA_DIR = os.path.expanduser(os.environ.get("OGBENCH_DATA_DIR", "~/.ogbench/data"))
62
+
63
+
64
+ # ----------------------------------------------------------------------------
65
+ # visual-puzzle dataset (images + button_states + qpos/qvel)
66
+ # ----------------------------------------------------------------------------
67
+ def load_visual_puzzle(env_id, split, n_traj=None):
68
+ """Load the visual-puzzle npz for `split` in {"train","val"}.
69
+
70
+ Returns a dataset dict with:
71
+ img : uint8 [N, 64, 64, 3] (observation; encoded by the CNN, never raw)
72
+ button : float32 [N, 9] (button-state vector; reward/goal/occ TARGET)
73
+ full : float32 [N, 46] (qpos[23]+qvel[23]; the mc/td STATE reference)
74
+ act : float32 [N, 5]
75
+ end : int64 [N] (trajectory end index per step)
76
+ N, a_dim
77
+
78
+ `n_traj` (optional) caps the number of trajectories loaded — used only for fast
79
+ CPU smoke tests; the real GPU runs use the full set.
80
+ """
81
+ fname = env_id if split == "train" else f"{env_id}-val"
82
+ path = os.path.join(_DATA_DIR, f"{fname}.npz")
83
+ if not os.path.exists(path):
84
+ raise FileNotFoundError(f"visual-puzzle dataset not found: {path}")
85
+ d = np.load(path, mmap_mode="r")
86
+ term = np.asarray(d["terminals"], dtype=np.float32)
87
+ if n_traj is not None:
88
+ ends = np.where(term > 0.5)[0] + 1
89
+ N = int(ends[min(n_traj, len(ends)) - 1]) if len(ends) else len(term)
90
+ else:
91
+ N = len(term)
92
+ qpos = np.asarray(d["qpos"][:N], dtype=np.float32)
93
+ qvel = np.asarray(d["qvel"][:N], dtype=np.float32)
94
+ full = np.concatenate([qpos, qvel], axis=1) # [N, 46]
95
+ button = np.asarray(d["button_states"][:N], dtype=np.float32)
96
+ return dict(
97
+ img=d["observations"][:N], # mmap'd uint8; index lazily
98
+ button=button,
99
+ full=full,
100
+ act=np.asarray(d["actions"][:N], dtype=np.float32),
101
+ end=gc_core.trajectory_bounds(term[:N]),
102
+ N=N, a_dim=int(d["actions"].shape[1]), pos_dim=int(button.shape[1]),
103
+ )
104
+
105
+
106
+ def _imgs_to_tensor(img_u8, device):
107
+ x = torch.as_tensor(np.asarray(img_u8), dtype=torch.float32, device=device) / 255.0
108
+ return x.permute(0, 3, 1, 2).contiguous()
109
+
110
+
111
+ # ----------------------------------------------------------------------------
112
+ # shared fresh-reset anchor pack (built ONCE; genq/mc/td all query the same (s,a,g))
113
+ # ----------------------------------------------------------------------------
114
+ def build_shared_anchors(env_id, cfg, seed):
115
+ """Fresh-RESET anchors for visual-puzzle. The live (image-obs) PuzzleEnv reset gives
116
+ the IMAGE obs (genq conditioning), the privileged button goal g, the behaviour
117
+ oracle action a, and qpos/qvel/button_states (for set_state + the mc/td state
118
+ reference). Identical protocol to the STATE puzzle, just with an image `s`."""
119
+ pack = gc_core.fresh_reset_anchors(env_id, cfg["n_anchors"], seed, dataset_dir=_DATA_DIR)
120
+ # pack["s"] is the image obs (the visual env returns 64x64x3). Add the 46-D state.
121
+ pack["state"] = np.concatenate([pack["qpos"], pack["qvel"]], axis=1).astype(np.float32)
122
+ return pack
123
+
124
+
125
+ # ----------------------------------------------------------------------------
126
+ # reward-predictive CNN latent (encoder + button-goal-conditioned reward decoder)
127
+ # ----------------------------------------------------------------------------
128
+ def train_reward_latent_image(ds, z_dim, cfg, device, seed, wlog):
129
+ """z = E_psi(image); r_hat = R_psi(z, g); fit to puzzle_reward(button; g), then freeze."""
130
+ pos = ds["pos_dim"]
131
+ enc = models.ImageEncoder(z_dim, hidden_dim=cfg["hidden_dim"]).to(device)
132
+ dec = GCRewardDecoder(z_dim, pos, cfg["hidden_dim"], 2).to(device)
133
+ opt = torch.optim.Adam(list(enc.parameters()) + list(dec.parameters()), lr=cfg["lr"])
134
+ rng = np.random.default_rng(seed + 3)
135
+ button, end = ds["button"], ds["end"]
136
+ lam = cfg.get("latent_l2", 1e-4)
137
+ kind = cfg["reward"]
138
+ steps = cfg.get("latent_steps", 20000)
139
+ bs = cfg["batch_size"]
140
+ final = 0.0
141
+ for step in range(1, steps + 1):
142
+ x_idx = rng.integers(0, ds["N"], bs)
143
+ g = button[gc_core.sample_goal_after(x_idx, end, rng)] # downstream button pattern
144
+ r = gc_core.puzzle_reward(button[x_idx], g, kind).astype(np.float32)
145
+ img = _imgs_to_tensor(ds["img"][x_idx], device)
146
+ gt = torch.as_tensor(g, dtype=torch.float32, device=device)
147
+ rt = torch.as_tensor(r, device=device)
148
+ z = enc(img)
149
+ loss = F.mse_loss(dec(z, gt), rt) + lam * (z ** 2).mean()
150
+ opt.zero_grad(); loss.backward(); opt.step()
151
+ if step % max(1, steps // 20) == 0 or step == 1:
152
+ final = float(loss.item())
153
+ wlog({"latent/loss": final}, step=step)
154
+ enc.eval(); dec.eval()
155
+ for p in enc.parameters(): p.requires_grad_(False)
156
+ for p in dec.parameters(): p.requires_grad_(False)
157
+ return enc, dec, final
158
+
159
+
160
+ @torch.no_grad()
161
+ def encode_images(enc, img_u8, device, batch=2048):
162
+ out = []
163
+ for i in range(0, len(img_u8), batch):
164
+ out.append(enc(_imgs_to_tensor(img_u8[i:i+batch], device)).cpu().numpy())
165
+ return np.concatenate(out, 0).astype(np.float32)
166
+
167
+
168
+ # ----------------------------------------------------------------------------
169
+ # latent occupancy p_theta(z' | z_now, a, g)
170
+ # ----------------------------------------------------------------------------
171
+ def train_latent_occupancy_image(occ, ds, z_all, gamma, cfg, device, seed, wlog):
172
+ act, end = ds["act"], ds["end"]
173
+ button = ds["button"]
174
+ rng = np.random.default_rng(seed + 7)
175
+ t0 = rng.integers(0, ds["N"], 20000)
176
+ j0 = gc_core.future_idx(t0, end, gamma, rng)
177
+ g0 = button[gc_core.sample_goal_after(j0, end, rng)]
178
+ c0 = np.concatenate([z_all[t0], act[t0], g0], 1)
179
+ occ.set_normalization(c0.mean(0), c0.std(0) + 1e-6, z_all[j0].mean(0), z_all[j0].std(0) + 1e-6)
180
+ z_t = torch.from_numpy(z_all)
181
+ opt = torch.optim.Adam(occ.parameters(), lr=cfg["lr"])
182
+ losses = []
183
+ log_every = max(1, cfg["steps"] // 50)
184
+ bs = cfg["batch_size"]
185
+ for step in range(1, cfg["steps"] + 1):
186
+ t = rng.integers(0, ds["N"], bs)
187
+ j = gc_core.future_idx(t, end, gamma, rng)
188
+ g = button[gc_core.sample_goal_after(j, end, rng)]
189
+ c = np.concatenate([z_all[t], act[t], g], 1)
190
+ loss = occ.training_loss(torch.as_tensor(c, dtype=torch.float32, device=device),
191
+ z_t[j].to(device))
192
+ opt.zero_grad(); loss.backward()
193
+ gn = torch.nn.utils.clip_grad_norm_(occ.parameters(), 10.0); opt.step()
194
+ if step % log_every == 0 or step == 1:
195
+ losses.append(float(loss.item()))
196
+ wlog({"train/loss": float(loss.item()), "train/grad_norm": float(gn)}, step=step)
197
+ occ.eval()
198
+ return losses
199
+
200
+
201
+ @torch.no_grad()
202
+ def latent_occ_q(occ, dec, z_now, a, g, N, device, batch=256):
203
+ out = np.zeros(len(z_now))
204
+ for i in range(0, len(z_now), batch):
205
+ c = np.concatenate([z_now[i:i+batch], a[i:i+batch], g[i:i+batch]], 1)
206
+ ct = torch.as_tensor(c, dtype=torch.float32, device=device)
207
+ z = occ.sample(ct, N) # [b, N, z]
208
+ b, n, zd = z.shape
209
+ gt = torch.as_tensor(g[i:i+batch], dtype=torch.float32, device=device)
210
+ gt = gt.unsqueeze(1).expand(-1, n, -1).reshape(b * n, -1)
211
+ r = dec(z.reshape(b * n, zd), gt).reshape(b, n)
212
+ out[i:i+batch] = r.mean(1).cpu().numpy()
213
+ return out
214
+
215
+
216
+ def _truth_for_pack(env_id, pack, cfg, seed):
217
+ """Fresh-rollout truth at the shared pack (identical to the STATE puzzle path)."""
218
+ return gc_core.gc_fresh_truth_manipspace(
219
+ env_id, pack, cfg["gamma"], cfg["reward"], cfg["sigma"], cfg["epsilon"],
220
+ M=cfg.get("truth_M", 8), H=cfg.get("truth_H", 200), seed=seed,
221
+ verbose=True, dataset_dir=_DATA_DIR)
222
+
223
+
224
+ # ----------------------------------------------------------------------------
225
+ # genq (image reward-predictive latent occupancy)
226
+ # ----------------------------------------------------------------------------
227
+ def run(env_id, seed, cfg, pack=None, truth=None):
228
+ device = get_device()
229
+ set_seed(seed)
230
+ gamma = cfg["gamma"]; kind = cfg["reward"]
231
+ occ_model = cfg.get("occ_model", "diffusion")
232
+ z_dim = cfg.get("z_dim", 8)
233
+
234
+ train_ds = load_visual_puzzle(env_id, "train", cfg.get("vis_train_traj"))
235
+ pos = train_ds["pos_dim"]
236
+
237
+ run_obj, wlog, wfinish = init_wandb(
238
+ cfg.get("wandb_project", "genq-policy-eval"),
239
+ f"genqvispuzzle-{occ_model}-z{z_dim}-{env_id}-s{seed}",
240
+ {**cfg, "env": env_id, "seed": seed, "method": "genq_reward_latent"},
241
+ mode=cfg.get("wandb_mode"))
242
+ wandb_url = getattr(run_obj, "url", None)
243
+
244
+ if pack is None:
245
+ pack = build_shared_anchors(env_id, cfg, seed)
246
+ a_a = pack["a"].astype(np.float32)
247
+ g_a = pack["g"].astype(np.float32) # 9-D goal button pattern
248
+ s_img_a = pack["s"] # image obs at each anchor
249
+
250
+ t0 = time.time()
251
+ enc, dec, latent_mse = train_reward_latent_image(train_ds, z_dim, cfg, device, seed, wlog)
252
+ z_train = encode_images(enc, train_ds["img"], device)
253
+ cond_dim = z_dim + train_ds["a_dim"] + pos # (z_now, a, g_button)
254
+ occ = gc_core.build_occupancy(occ_model, cond_dim, z_dim, cfg, device)
255
+ losses = train_latent_occupancy_image(occ, train_ds, z_train, gamma, cfg, device, seed, wlog)
256
+ train_wall = time.time() - t0
257
+
258
+ if truth is None:
259
+ truth = _truth_for_pack(env_id, pack, cfg, seed)
260
+ z_now_a = encode_images(enc, s_img_a, device)
261
+
262
+ gen_counts = cfg.get("gen_sample_counts", [1, 2, 4, 8, 16, 32, 64, 128, 256])
263
+ mse_by_n, corr_by_n, mse_curve = {}, {}, []
264
+ for N in gen_counts:
265
+ mn = q_metrics(latent_occ_q(occ, dec, z_now_a, a_a, g_a, N, device), truth)
266
+ mse_by_n[str(N)] = mn["mse"]; corr_by_n[str(N)] = mn["pearson"]; mse_curve.append(mn["mse"])
267
+ N_final = gen_counts[-1]
268
+ est = latent_occ_q(occ, dec, z_now_a, a_a, g_a, N_final, device)
269
+ m = q_metrics(est, truth)
270
+
271
+ result = {
272
+ "method": "genq_reward_latent", "env": env_id, "seed": seed, "wandb_url": wandb_url,
273
+ "representation": "image_reward_predictive_latent",
274
+ "occ_model": occ_model, "z_dim": z_dim, "reward": kind,
275
+ "truth_kind": "fresh_rollout", "anchor_protocol": "fresh_reset",
276
+ "gen_sample_counts": gen_counts,
277
+ "train/loss": losses, "train/q_mse": [m["mse"]], "latent/reward_mse": latent_mse,
278
+ "eval/q_mse": m["mse"], "eval/q_mae": m["mae"],
279
+ "eval/q_corr": m["pearson"], "eval/q_spearman": m["spearman"],
280
+ "eval/q_mse_by_n": mse_by_n, "eval/q_corr_by_n": corr_by_n,
281
+ "eval/q_mse_vs_N": mse_curve, "eval/N_final": N_final,
282
+ "eval/truth_std": float(np.std(truth)),
283
+ "wall_clock_s": train_wall, "n_anchors": int(len(a_a)),
284
+ }
285
+ wlog({"eval/q_mse": m["mse"], "eval/q_corr": m["pearson"]}); wfinish()
286
+ return result, pack, truth
287
+
288
+
289
+ # ----------------------------------------------------------------------------
290
+ # mc / td baselines on the 46-D [qpos|qvel] STATE (non-latent reference, documented)
291
+ # ----------------------------------------------------------------------------
292
+ def _state_setup(env_id, cfg):
293
+ """Train/val state datasets: obs = 46-D [qpos|qvel]; occupancy TARGET = button vec."""
294
+ tr_v = load_visual_puzzle(env_id, "train", cfg.get("vis_train_traj"))
295
+ tr = dict(obs=tr_v["full"], act=tr_v["act"], end=tr_v["end"], N=tr_v["N"],
296
+ s_dim=tr_v["full"].shape[1], a_dim=tr_v["a_dim"], pos_dim=tr_v["pos_dim"],
297
+ obj=tr_v["button"], manipspace=True, family="puzzle")
298
+ return tr
299
+
300
+
301
+ def run_mc(env_id, seed, cfg, pack=None, truth=None):
302
+ import mc as mc_mod
303
+ device = get_device(); set_seed(seed)
304
+ gamma = cfg["gamma"]; kind, sigma, eps = cfg["reward"], cfg["sigma"], cfg["epsilon"]
305
+ tr = _state_setup(env_id, cfg)
306
+ pos = tr["pos_dim"]
307
+
308
+ run_obj, wlog, wfinish = init_wandb(
309
+ cfg.get("wandb_project", "genq-policy-eval"),
310
+ f"mc-state46-{env_id}-s{seed}", {**cfg, "env": env_id, "seed": seed, "method": "mc"},
311
+ mode=cfg.get("wandb_mode"))
312
+ wandb_url = getattr(run_obj, "url", None)
313
+
314
+ if pack is None:
315
+ pack = build_shared_anchors(env_id, cfg, seed)
316
+ s_a = pack["state"]; a_a = pack["a"].astype(np.float32); g_a = pack["g"].astype(np.float32)
317
+
318
+ rng = np.random.default_rng(seed)
319
+ tgt = tr["obj"] # button states (occ target / reward signal)
320
+ cand = np.where((tr["end"] - np.arange(tr["N"])) >= 2)[0]
321
+ n_fit = min(cfg.get("mc_fit_anchors", 80000), len(cand))
322
+ fit_idx = cand[rng.integers(0, len(cand), size=n_fit)]
323
+ fit_g = tgt[gc_core.sample_goal_idx(fit_idx, tr["end"], rng)]
324
+ fit_ret = mc_mod.gc_return(tgt, tr["end"], fit_g, fit_idx, gamma, sigma, kind, eps,
325
+ family="puzzle")
326
+
327
+ net = mc_mod.QNet(tr["s_dim"], pos, tr["a_dim"], cfg["hidden_dim"], cfg["num_layers"]).to(device)
328
+ opt = torch.optim.Adam(net.parameters(), lr=cfg["lr"])
329
+ St = torch.as_tensor(tr["obs"][fit_idx], dtype=torch.float32)
330
+ Gt = torch.as_tensor(fit_g, dtype=torch.float32)
331
+ At = torch.as_tensor(tr["act"][fit_idx], dtype=torch.float32)
332
+ Rt = torch.as_tensor(fit_ret, dtype=torch.float32)
333
+ losses, qmse = [], []; log_every = max(1, cfg["steps"] // 50); t0 = time.time()
334
+ for step in range(1, cfg["steps"] + 1):
335
+ b = rng.integers(0, len(fit_idx), cfg["batch_size"])
336
+ loss = ((net(St[b].to(device), Gt[b].to(device), At[b].to(device)) - Rt[b].to(device)) ** 2).mean()
337
+ opt.zero_grad(); loss.backward(); opt.step()
338
+ if step % log_every == 0 or step == 1:
339
+ losses.append(float(loss.item())); qmse.append(float(loss.item()))
340
+ wlog({"train/loss": float(loss.item()), "train/q_mse": float(loss.item())}, step=step)
341
+ net.eval(); train_wall = time.time() - t0
342
+
343
+ if truth is None:
344
+ truth = _truth_for_pack(env_id, pack, cfg, seed)
345
+ with torch.no_grad():
346
+ est = net(torch.as_tensor(s_a, dtype=torch.float32, device=device),
347
+ torch.as_tensor(g_a, dtype=torch.float32, device=device),
348
+ torch.as_tensor(a_a, dtype=torch.float32, device=device)).cpu().numpy()
349
+ m = q_metrics(est, truth)
350
+ result = {"method": "mc", "env": env_id, "seed": seed, "wandb_url": wandb_url,
351
+ "representation": "puzzle_state_46d", "reward": kind,
352
+ "truth_kind": "fresh_rollout", "anchor_protocol": "fresh_reset",
353
+ "train/loss": losses, "train/q_mse": qmse,
354
+ "eval/q_mse": m["mse"], "eval/q_mae": m["mae"],
355
+ "eval/q_corr": m["pearson"], "eval/q_spearman": m["spearman"],
356
+ "eval/truth_std": float(np.std(truth)), "wall_clock_s": train_wall,
357
+ "n_anchors": int(len(a_a))}
358
+ wlog({"eval/q_mse": m["mse"], "eval/q_corr": m["pearson"]}); wfinish()
359
+ return result, pack, truth
360
+
361
+
362
+ def run_td(env_id, seed, cfg, pack=None, truth=None):
363
+ import mc as mc_mod
364
+ import td as td_mod
365
+ device = get_device(); set_seed(seed)
366
+ gamma = cfg["gamma"]; kind, sigma, eps = cfg["reward"], cfg["sigma"], cfg["epsilon"]
367
+ tr = _state_setup(env_id, cfg)
368
+ pos = tr["pos_dim"]
369
+
370
+ run_obj, wlog, wfinish = init_wandb(
371
+ cfg.get("wandb_project", "genq-policy-eval"),
372
+ f"td-state46-{env_id}-s{seed}", {**cfg, "env": env_id, "seed": seed, "method": "td"},
373
+ mode=cfg.get("wandb_mode"))
374
+ wandb_url = getattr(run_obj, "url", None)
375
+
376
+ if pack is None:
377
+ pack = build_shared_anchors(env_id, cfg, seed)
378
+ s_a = pack["state"]; a_a = pack["a"].astype(np.float32); g_a = pack["g"].astype(np.float32)
379
+
380
+ obs = tr["obs"]; act = tr["act"]; end = tr["end"]; N = tr["N"]; tgt = tr["obj"]
381
+ nxt = np.where((end - np.arange(N)) > 1)[0]
382
+ sd, ad = tr["s_dim"], tr["a_dim"]; Hd, L = cfg["hidden_dim"], cfg["num_layers"]
383
+ q = mc_mod.QNet(sd, pos, ad, Hd, L).to(device)
384
+ qt = mc_mod.QNet(sd, pos, ad, Hd, L).to(device); qt.load_state_dict(q.state_dict())
385
+ v = td_mod.VNet(sd, pos, Hd, L).to(device)
386
+ optq = torch.optim.Adam(q.parameters(), lr=cfg["lr"])
387
+ optv = torch.optim.Adam(v.parameters(), lr=cfg["lr"])
388
+ tau = cfg.get("iql_expectile", 0.5); polyak = cfg.get("polyak", 0.005)
389
+ rng = np.random.default_rng(seed)
390
+ losses, qmse = [], []; log_every = max(1, cfg["steps"] // 50); t0 = time.time()
391
+ for step in range(1, cfg["steps"] + 1):
392
+ idx = nxt[rng.integers(0, len(nxt), size=cfg["batch_size"])]
393
+ g = tgt[gc_core.sample_goal_idx(idx, end, rng)] # button-pattern goal
394
+ r = gc_core.puzzle_reward(tgt[idx], g, kind).astype(np.float32) # match-fraction reward
395
+ s = torch.as_tensor(obs[idx], device=device)
396
+ a = torch.as_tensor(act[idx], device=device)
397
+ s2 = torch.as_tensor(obs[idx + 1], device=device)
398
+ gt = torch.as_tensor(g, dtype=torch.float32, device=device)
399
+ rt = torch.as_tensor(r, device=device)
400
+ with torch.no_grad():
401
+ qsa = qt(s, gt, a)
402
+ diff = qsa - v(s, gt)
403
+ w = torch.abs(tau - (diff < 0).float())
404
+ loss_v = (w * diff ** 2).mean()
405
+ optv.zero_grad(); loss_v.backward(); optv.step()
406
+ with torch.no_grad():
407
+ y = (1 - gamma) * rt + gamma * v(s2, gt)
408
+ loss_q = ((q(s, gt, a) - y) ** 2).mean()
409
+ optq.zero_grad(); loss_q.backward(); optq.step()
410
+ with torch.no_grad():
411
+ for p, ptg in zip(q.parameters(), qt.parameters()):
412
+ ptg.mul_(1 - polyak).add_(polyak * p)
413
+ if step % log_every == 0 or step == 1:
414
+ losses.append(float(loss_q.item())); qmse.append(float(loss_q.item()))
415
+ wlog({"train/loss": float(loss_q.item()), "train/q_mse": float(loss_q.item()),
416
+ "train/v_loss": float(loss_v.item())}, step=step)
417
+ q.eval(); train_wall = time.time() - t0
418
+
419
+ if truth is None:
420
+ truth = _truth_for_pack(env_id, pack, cfg, seed)
421
+ with torch.no_grad():
422
+ est = q(torch.as_tensor(s_a, dtype=torch.float32, device=device),
423
+ torch.as_tensor(g_a, dtype=torch.float32, device=device),
424
+ torch.as_tensor(a_a, dtype=torch.float32, device=device)).cpu().numpy()
425
+ m = q_metrics(est, truth)
426
+ result = {"method": "td", "env": env_id, "seed": seed, "wandb_url": wandb_url,
427
+ "representation": "puzzle_state_46d", "reward": kind,
428
+ "truth_kind": "fresh_rollout", "anchor_protocol": "fresh_reset",
429
+ "train/loss": losses, "train/q_mse": qmse,
430
+ "eval/q_mse": m["mse"], "eval/q_mae": m["mae"],
431
+ "eval/q_corr": m["pearson"], "eval/q_spearman": m["spearman"],
432
+ "eval/truth_std": float(np.std(truth)), "wall_clock_s": train_wall,
433
+ "n_anchors": int(len(a_a))}
434
+ wlog({"eval/q_mse": m["mse"], "eval/q_corr": m["pearson"]}); wfinish()
435
+ return result, pack, truth
436
+
437
+
438
+ if __name__ == "__main__":
439
+ pass
gen_q_rsm/preliminary_analysis/illustration.py ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Animate how Gen-Q estimates the goal-conditioned Q^pi from the learned occupancy.
2
+
3
+ Trains a goal-conditioned diffusion occupancy on PointMaze, then renders a GIF
4
+ showing, for a query (s, a, g):
5
+ * left panel: the occupancy cloud forming over DDIM denoising steps, coloured by
6
+ goal-reaching reward, over the maze + reward field;
7
+ * right panel: the running estimate Q^pi(s,a,g) = mean_i r(x_i; g) converging as
8
+ the denoising sharpens.
9
+ """
10
+ import argparse
11
+ import os
12
+
13
+ import numpy as np
14
+ import torch
15
+ import matplotlib
16
+ matplotlib.use("Agg")
17
+ import matplotlib.pyplot as plt
18
+ from matplotlib import animation
19
+
20
+ from _common import get_device, set_seed
21
+ import gc_core
22
+ from config import make_cfg
23
+
24
+ _HERE = os.path.dirname(os.path.abspath(__file__))
25
+
26
+
27
+ def env_safe(env_id):
28
+ return env_id.replace("-", "_")
29
+
30
+
31
+ def make_gif(env_id="pointmaze-medium-navigate-v0", seed=0, steps=20000, n=400, out=None):
32
+ device = get_device()
33
+ set_seed(seed)
34
+ cfg = make_cfg(steps=steps, wandb_mode="disabled")
35
+ gamma = cfg["gamma"]; sigma = cfg["sigma"]; pos = 2; cfg["pos_dim"] = pos
36
+ kind, eps = "dense", cfg["epsilon"]
37
+ train_ds, val_ds, env, _ = gc_core.load_ogbench_gc(env_id, gamma)
38
+ env.reset()
39
+ # maze layout rectangles (drawn under the scatter so occupancy mass visibly
40
+ # respects the walls). If geometry can't be recovered, flag it.
41
+ wall_rects, wall_extent = gc_core.maze_wall_rects(env)
42
+ if wall_rects is None:
43
+ print(f"[illustration] WARNING: no maze geometry for {env_id}; background "
44
+ f"will be blank — FLAG this rather than trusting the layout.", flush=True)
45
+
46
+ cond_dim = train_ds["s_dim"] + train_ds["a_dim"] + pos
47
+ occ = gc_core.build_occupancy("diffusion", cond_dim, pos, cfg, device)
48
+ gc_core.train_gc_occupancy(occ, train_ds, gamma, cfg, device, seed)
49
+
50
+ rng = np.random.default_rng(seed)
51
+ idx = gc_core.anchors_with_min_horizon(val_ds, 1, cfg["min_horizon"], rng)[0]
52
+ s = val_ds["obs"][idx:idx + 1]; a = val_ds["act"][idx:idx + 1]
53
+ g = val_ds["obs"][gc_core.sample_goal_idx(np.array([idx]), val_ds["end"], rng)][:, :pos]
54
+ c = torch.as_tensor(np.concatenate([s, a, g], 1), dtype=torch.float32, device=device)
55
+ _, traj = occ.sample_trajectory(c, n_samples=n)
56
+
57
+ def rew(pts):
58
+ d = np.linalg.norm(pts - g[0][None], axis=1)
59
+ return gc_core.reward_of_dist(d, kind, sigma, eps)
60
+
61
+ from matplotlib.patches import Rectangle
62
+ running_q = [float(rew(cloud[0]).mean()) for cloud in traj]
63
+ fig, (axL, axR) = plt.subplots(1, 2, figsize=(11, 5))
64
+
65
+ def frame(i):
66
+ axL.clear(); axR.clear()
67
+ # real maze layout underneath: wall cells as filled gray rectangles in xy
68
+ if wall_rects is not None:
69
+ for (x0, y0, w, h) in wall_rects:
70
+ axL.add_patch(Rectangle((x0, y0), w, h, facecolor="0.6",
71
+ edgecolor="0.4", lw=0.5, zorder=0))
72
+ axL.set_xlim(wall_extent[0], wall_extent[1])
73
+ axL.set_ylim(wall_extent[2], wall_extent[3])
74
+ axL.set_aspect("equal")
75
+ pts = traj[i][0]
76
+ axL.scatter(pts[:, 0], pts[:, 1], c=rew(pts), cmap="viridis", s=10, alpha=0.8, zorder=2)
77
+ axL.scatter([s[0, 0]], [s[0, 1]], c="black", s=120, marker="*", label="query s", zorder=3)
78
+ axL.scatter([g[0, 0]], [g[0, 1]], c="red", s=120, marker="X", label="goal g", zorder=3)
79
+ axL.set_title(f"occupancy p_theta(.|s,a,g) over the maze — denoising step {i+1}/{len(traj)}")
80
+ axL.legend(loc="upper left", fontsize=8)
81
+ axR.plot(range(1, i + 2), running_q[:i + 1], "-o", color="tab:green")
82
+ axR.axhline(running_q[-1], ls="--", color="gray", alpha=0.6,
83
+ label=f"final Q={running_q[-1]:.3f}")
84
+ axR.set_xlim(1, len(traj)); axR.set_ylim(0, max(running_q) * 1.2 + 1e-6)
85
+ axR.set_xlabel("denoising step"); axR.set_ylabel("Q(s,a,g) = mean r(x;g)")
86
+ axR.set_title("Gen-Q estimate converging"); axR.legend(fontsize=8); axR.grid(alpha=0.3)
87
+
88
+ anim = animation.FuncAnimation(fig, frame, frames=len(traj), interval=200)
89
+ out = out or os.path.join(_HERE, "experiments", env_safe(env_id), "figures", "illustration.gif")
90
+ os.makedirs(os.path.dirname(out), exist_ok=True)
91
+ anim.save(out, writer=animation.PillowWriter(fps=5))
92
+ plt.close(fig)
93
+ print(f"[illustration] wrote {out} final Q={running_q[-1]:.4f}", flush=True)
94
+ return out
95
+
96
+
97
+ def main():
98
+ ap = argparse.ArgumentParser()
99
+ ap.add_argument("--env", default="pointmaze-medium-navigate-v0")
100
+ ap.add_argument("--seed", type=int, default=0)
101
+ ap.add_argument("--steps", type=int, default=20000)
102
+ ap.add_argument("--n", type=int, default=400)
103
+ ap.add_argument("--out", default=None,
104
+ help="explicit output path. visual-pointmaze has no live env, but the "
105
+ "occupancy->Q mechanism is identical on the underlying maze, so we "
106
+ "render the state-maze illustration into the visual env figures dir.")
107
+ args = ap.parse_args()
108
+ make_gif(args.env, args.seed, args.steps, args.n, out=args.out)
109
+
110
+
111
+ if __name__ == "__main__":
112
+ main()
gen_q_rsm/preliminary_analysis/mc.py ADDED
@@ -0,0 +1,150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Monte-Carlo goal-conditioned policy evaluation of Q^pi(s, a, g).
2
+
3
+ Math
4
+ ----
5
+ The goal-conditioned behaviour value is the discounted occupancy expectation of
6
+ the goal-reaching reward:
7
+
8
+ Q^pi(s, a, g) = (1-gamma) E[ sum_{k>=0} gamma^k r(s_{t+k}; g) | s,a,g ].
9
+
10
+ MC estimates this from logged trajectories: the renormalized discounted
11
+ return-to-go toward a hindsight goal g,
12
+
13
+ G_t(g) = ( sum_{j>=t} (1-gamma)gamma^{j-t} r(s_j; g) ) / ( sum_{j>=t} (1-gamma)gamma^{j-t} ),
14
+
15
+ is an unbiased (high-variance) sample of Q^pi(s_t, a_t, g). We fit a regressor
16
+ Q_MC(s, a, g) on these targets so the estimate generalizes and averages out
17
+ single-rollout variance (the strong "trained MC" baseline).
18
+
19
+ NOTE the in-trajectory return-to-go is the TRAINING TARGET for the MC regressor
20
+ only; the regressor's predictions are scored against FRESH on-policy rollouts
21
+ (``evaluate_policy.ground_truth_q``), exactly like Gen-Q and TD.
22
+
23
+ Pseudocode
24
+ ----------
25
+ for sampled transitions t with hindsight goal g_t: G_t(g_t) <- renorm return-to-go
26
+ train Q_MC(s, a, g) by regression onto {(s_t, a_t, g_t) -> G_t}
27
+ eval : Q_MC(s_anchor, a_anchor, g_anchor) ; score vs fresh-rollout truth
28
+ """
29
+ import time
30
+
31
+ import numpy as np
32
+ import torch
33
+ import torch.nn as nn
34
+
35
+ from _common import get_device, set_seed, q_metrics, init_wandb
36
+ import gc_core
37
+ import models
38
+ from evaluate_policy import ground_truth_q
39
+
40
+
41
+ class QNet(nn.Module):
42
+ """Q(s, g, a)."""
43
+ def __init__(self, s_dim, g_dim, a_dim, hidden=256, layers=3):
44
+ super().__init__()
45
+ self.net = models.mlp(s_dim + g_dim + a_dim, 1, hidden, layers)
46
+
47
+ def forward(self, s, g, a):
48
+ return self.net(torch.cat([s, g, a], -1)).squeeze(-1)
49
+
50
+
51
+ def gc_return(obs_xy, end, goal_xy, anchors, gamma, sigma, kind, eps, family=None):
52
+ """Renormalized discounted goal-reaching return along each anchor's trajectory.
53
+
54
+ For puzzle (family=="puzzle") obs_xy / goal_xy are binary button-state vectors and the
55
+ per-step reward is the match-fraction (``puzzle_reward``); else position-distance."""
56
+ out = np.zeros(len(anchors))
57
+ for i, t in enumerate(anchors):
58
+ e = end[t]; g = goal_xy[i]
59
+ idx = np.arange(t, e)
60
+ if family == "puzzle":
61
+ r = gc_core.puzzle_reward(obs_xy[idx], g[None, :], kind)
62
+ else:
63
+ d = np.linalg.norm(obs_xy[idx] - g, axis=1)
64
+ r = gc_core.reward_of_dist(d, kind, sigma, eps)
65
+ w = (1 - gamma) * gamma ** (idx - t)
66
+ out[i] = (w * r).sum() / max(w.sum(), 1e-12)
67
+ return out
68
+
69
+
70
+ def run(env_id, seed, cfg):
71
+ device = get_device()
72
+ set_seed(seed)
73
+ gamma = cfg["gamma"]
74
+ kind, sigma, eps = cfg["reward"], cfg["sigma"], cfg["epsilon"]
75
+ state_slice = cfg.get("state_slice", "auto")
76
+ train_ds, val_ds, _, _ = gc_core.load_ogbench_gc(env_id, gamma, state_slice=state_slice)
77
+ pos = train_ds.get("pos_dim", cfg.get("pos_dim", 2))
78
+ cfg["pos_dim"] = pos
79
+ rng = np.random.default_rng(seed)
80
+ pack = gc_core.prepare_eval_anchors(env_id, val_ds, cfg, seed)
81
+ sigma, eps = cfg["sigma"], cfg["epsilon"] # prepare may set manipspace reward scale
82
+ s_a, a_a, g_a = pack["s"], pack["a"], pack["g"]
83
+ anchors = pack["anchor_idx"]
84
+ anchor_full = pack["anchor_full"]
85
+
86
+ run_obj, wlog, wfinish = init_wandb(
87
+ cfg.get("wandb_project", "genq-policy-eval"),
88
+ f"mc-{env_id}-s{seed}", {**cfg, "env": env_id, "seed": seed, "method": "mc"},
89
+ mode=cfg.get("wandb_mode"))
90
+ wandb_url = getattr(run_obj, "url", None)
91
+
92
+ # training targets: hindsight-goal-conditioned return-to-go on the train set.
93
+ # The reward/goal POSITION is the privileged object pos for manipspace, else xy.
94
+ tr = train_ds
95
+ tgt_pos = gc_core._target_array(tr, cfg) # [N, pos]
96
+ cand = np.where((tr["end"] - np.arange(tr["N"])) >= 2)[0]
97
+ n_fit = min(cfg.get("mc_fit_anchors", 80000), len(cand))
98
+ fit_idx = cand[rng.integers(0, len(cand), size=n_fit)]
99
+ fit_g = tgt_pos[gc_core.sample_goal_idx(fit_idx, tr["end"], rng)]
100
+ family = tr.get("family")
101
+ fit_ret = gc_return(tgt_pos, tr["end"], fit_g, fit_idx, gamma, sigma, kind, eps,
102
+ family=family)
103
+
104
+ net = QNet(tr["s_dim"], pos, tr["a_dim"], cfg["hidden_dim"], cfg["num_layers"]).to(device)
105
+ opt = torch.optim.Adam(net.parameters(), lr=cfg["lr"])
106
+ St = torch.as_tensor(tr["obs"][fit_idx], dtype=torch.float32)
107
+ Gt = torch.as_tensor(fit_g, dtype=torch.float32)
108
+ At = torch.as_tensor(tr["act"][fit_idx], dtype=torch.float32)
109
+ Rt = torch.as_tensor(fit_ret, dtype=torch.float32)
110
+
111
+ losses, qmse = [], []
112
+ log_every = max(1, cfg["steps"] // 50)
113
+ t0 = time.time()
114
+ for step in range(1, cfg["steps"] + 1):
115
+ b = rng.integers(0, len(fit_idx), cfg["batch_size"])
116
+ loss = ((net(St[b].to(device), Gt[b].to(device), At[b].to(device)) - Rt[b].to(device)) ** 2).mean()
117
+ opt.zero_grad(); loss.backward(); opt.step()
118
+ if step % log_every == 0 or step == 1:
119
+ losses.append(float(loss.item())); qmse.append(float(loss.item()))
120
+ wlog({"train/loss": float(loss.item()), "train/q_mse": float(loss.item())}, step=step)
121
+ net.eval()
122
+ train_wall = time.time() - t0
123
+
124
+ truth, truth_kind = ground_truth_q(env_id, val_ds, anchors, g_a, gamma,
125
+ kind=kind, sigma=sigma, eps=eps,
126
+ M=cfg.get("truth_M", 8), H=cfg.get("truth_H", 350), seed=seed,
127
+ anchor_full=anchor_full, anchors_pack=pack["anchors_pack"])
128
+ with torch.no_grad():
129
+ est = net(torch.as_tensor(s_a, dtype=torch.float32, device=device),
130
+ torch.as_tensor(g_a, dtype=torch.float32, device=device),
131
+ torch.as_tensor(a_a, dtype=torch.float32, device=device)).cpu().numpy()
132
+ m = q_metrics(est, truth)
133
+
134
+ result = {
135
+ "method": "mc", "env": env_id, "seed": seed, "wandb_url": wandb_url,
136
+ "reward": kind, "truth_kind": truth_kind,
137
+ "anchor_protocol": pack["anchor_protocol"],
138
+ "train/loss": losses, "train/q_mse": qmse,
139
+ "eval/q_mse": m["mse"], "eval/q_mae": m["mae"],
140
+ "eval/q_corr": m["pearson"], "eval/q_spearman": m["spearman"],
141
+ "eval/truth_std": float(np.std(truth)),
142
+ "wall_clock_s": train_wall, "n_anchors": int(len(s_a)),
143
+ }
144
+ wlog({"eval/q_mse": m["mse"], "eval/q_corr": m["pearson"]})
145
+ wfinish()
146
+ return result
147
+
148
+
149
+ if __name__ == "__main__":
150
+ pass
gen_q_rsm/preliminary_analysis/models.py ADDED
@@ -0,0 +1,487 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Models: conditional Gaussian mixture density network, encoder/reward decoder,
2
+ one-step dynamics model, and proposal network. All in PyTorch."""
3
+ import math
4
+ import numpy as np
5
+ import torch
6
+ import torch.nn as nn
7
+ import torch.nn.functional as F
8
+
9
+ LOG_2PI = math.log(2 * math.pi)
10
+
11
+
12
+ def mlp(in_dim, out_dim, hidden_dim, num_layers, act=nn.ReLU):
13
+ layers = []
14
+ d = in_dim
15
+ for _ in range(num_layers):
16
+ layers += [nn.Linear(d, hidden_dim), act()]
17
+ d = hidden_dim
18
+ layers += [nn.Linear(d, out_dim)]
19
+ return nn.Sequential(*layers)
20
+
21
+
22
+ class ConditionalGMM(nn.Module):
23
+ """p(y | c) as a diagonal-covariance Gaussian mixture, c = conditioning input.
24
+
25
+ Outputs mixture logits [M], means [M, D], log_stds [M, D].
26
+ """
27
+
28
+ def __init__(self, cond_dim, y_dim, num_components=8, hidden_dim=256, num_layers=3,
29
+ log_std_min=-7.0, log_std_max=2.0):
30
+ super().__init__()
31
+ self.y_dim = y_dim
32
+ self.M = num_components
33
+ self.log_std_min = log_std_min
34
+ self.log_std_max = log_std_max
35
+ self.backbone = mlp(cond_dim, hidden_dim, hidden_dim, num_layers)
36
+ self.head_logits = nn.Linear(hidden_dim, num_components)
37
+ self.head_means = nn.Linear(hidden_dim, num_components * y_dim)
38
+ self.head_logstd = nn.Linear(hidden_dim, num_components * y_dim)
39
+
40
+ def forward(self, c):
41
+ h = F.relu(self.backbone(c))
42
+ B = c.shape[0]
43
+ logits = self.head_logits(h) # [B, M]
44
+ means = self.head_means(h).view(B, self.M, self.y_dim) # [B, M, D]
45
+ log_stds = self.head_logstd(h).view(B, self.M, self.y_dim)
46
+ log_stds = torch.clamp(log_stds, self.log_std_min, self.log_std_max)
47
+ return logits, means, log_stds
48
+
49
+ def training_loss(self, c, y):
50
+ return -self.log_prob(c, y).mean()
51
+
52
+ @torch.no_grad()
53
+ def eval_loss(self, c, y):
54
+ return float((-self.log_prob(c, y)).mean().item())
55
+
56
+ def log_prob(self, c, y):
57
+ """log p(y|c). y: [B, D]. Returns [B]."""
58
+ logits, means, log_stds = self.forward(c)
59
+ log_w = F.log_softmax(logits, dim=-1) # [B, M]
60
+ y = y.unsqueeze(1) # [B, 1, D]
61
+ var = torch.exp(2 * log_stds)
62
+ comp_logp = -0.5 * (((y - means) ** 2) / var + 2 * log_stds + LOG_2PI)
63
+ comp_logp = comp_logp.sum(-1) # [B, M]
64
+ return torch.logsumexp(log_w + comp_logp, dim=-1) # [B]
65
+
66
+ def log_prob_from_params(self, params, y):
67
+ logits, means, log_stds = params
68
+ log_w = F.log_softmax(logits, dim=-1)
69
+ y = y.unsqueeze(1)
70
+ var = torch.exp(2 * log_stds)
71
+ comp_logp = -0.5 * (((y - means) ** 2) / var + 2 * log_stds + LOG_2PI)
72
+ comp_logp = comp_logp.sum(-1)
73
+ return torch.logsumexp(log_w + comp_logp, dim=-1)
74
+
75
+ @torch.no_grad()
76
+ def sample(self, c, n_samples=1):
77
+ """Sample y ~ p(.|c). Returns [B, n_samples, D]."""
78
+ logits, means, log_stds = self.forward(c)
79
+ B = c.shape[0]
80
+ probs = F.softmax(logits, dim=-1) # [B, M]
81
+ comp = torch.multinomial(probs, n_samples, replacement=True) # [B, n_samples]
82
+ idx = comp.unsqueeze(-1).expand(-1, -1, self.y_dim) # [B, n, D]
83
+ mu = torch.gather(means, 1, idx)
84
+ ls = torch.gather(log_stds, 1, idx)
85
+ eps = torch.randn_like(mu)
86
+ return mu + eps * torch.exp(ls)
87
+
88
+ @torch.no_grad()
89
+ def sample_with_logprob(self, c, n_samples=1):
90
+ y = self.sample(c, n_samples) # [B, n, D]
91
+ B, n, D = y.shape
92
+ params = self.forward(c)
93
+ # broadcast log_prob over n samples
94
+ logits, means, log_stds = params
95
+ log_w = F.log_softmax(logits, dim=-1).unsqueeze(1) # [B,1,M]
96
+ var = torch.exp(2 * log_stds).unsqueeze(1) # [B,1,M,D]
97
+ mu = means.unsqueeze(1) # [B,1,M,D]
98
+ ls = log_stds.unsqueeze(1)
99
+ yy = y.unsqueeze(2) # [B,n,1,D]
100
+ comp_logp = -0.5 * (((yy - mu) ** 2) / var + 2 * ls + LOG_2PI).sum(-1) # [B,n,M]
101
+ logp = torch.logsumexp(log_w + comp_logp, dim=-1) # [B,n]
102
+ return y, logp
103
+
104
+
105
+ class SinusoidalEmbedding(nn.Module):
106
+ def __init__(self, dim):
107
+ super().__init__()
108
+ self.dim = dim
109
+
110
+ def forward(self, t):
111
+ # t: [B] float in [0,1]
112
+ device = t.device
113
+ half = self.dim // 2
114
+ freqs = torch.exp(-math.log(10000) * torch.arange(half, device=device) / max(half - 1, 1))
115
+ ang = t[:, None] * freqs[None] * 1000.0
116
+ return torch.cat([torch.sin(ang), torch.cos(ang)], dim=-1)
117
+
118
+
119
+ def _cosine_abar(T, s=0.008):
120
+ steps = torch.arange(T + 1, dtype=torch.float64)
121
+ f = torch.cos(((steps / T) + s) / (1 + s) * math.pi / 2) ** 2
122
+ abar = f / f[0]
123
+ return abar[1:].clamp(1e-6, 0.9999).float() # alpha_bar[t], t=1..T
124
+
125
+
126
+ class ConditionalDiffusion(nn.Module):
127
+ """Conditional DDPM for p(y | c). Predicts noise eps; samples via DDIM.
128
+
129
+ Same external interface as ConditionalGMM where possible: `.sample(c, n)` -> [B,n,D].
130
+ Densities (for importance weighting) come from the probability-flow ODE: `.log_prob`.
131
+ """
132
+
133
+ def __init__(self, cond_dim, y_dim, hidden_dim=256, num_layers=4, T=100,
134
+ time_dim=64, sample_steps=30):
135
+ super().__init__()
136
+ self.y_dim = y_dim
137
+ self.cond_dim = cond_dim
138
+ self.T = T
139
+ self.sample_steps = sample_steps
140
+ self.time_emb = nn.Sequential(SinusoidalEmbedding(time_dim),
141
+ nn.Linear(time_dim, time_dim), nn.SiLU(),
142
+ nn.Linear(time_dim, time_dim))
143
+ self.cond_emb = nn.Sequential(nn.Linear(cond_dim, hidden_dim), nn.SiLU())
144
+ self.x_emb = nn.Linear(y_dim, hidden_dim)
145
+ layers = []
146
+ d = hidden_dim + hidden_dim + time_dim
147
+ for _ in range(num_layers):
148
+ layers += [nn.Linear(d, hidden_dim), nn.SiLU()]
149
+ d = hidden_dim
150
+ self.trunk = nn.Sequential(*layers)
151
+ self.out = nn.Linear(hidden_dim, y_dim)
152
+ abar = _cosine_abar(T)
153
+ self.register_buffer("abar", abar) # [T], index t-1
154
+ self.register_buffer("abar_prev", torch.cat([torch.ones(1), abar[:-1]]))
155
+ # normalization buffers (identity until set_normalization called)
156
+ self.register_buffer("cond_mean", torch.zeros(cond_dim))
157
+ self.register_buffer("cond_std", torch.ones(cond_dim))
158
+ self.register_buffer("y_mean", torch.zeros(y_dim))
159
+ self.register_buffer("y_std", torch.ones(y_dim))
160
+
161
+ def set_normalization(self, cond_mean, cond_std, y_mean, y_std):
162
+ self.cond_mean.copy_(torch.as_tensor(cond_mean, dtype=torch.float32))
163
+ self.cond_std.copy_(torch.as_tensor(cond_std, dtype=torch.float32))
164
+ self.y_mean.copy_(torch.as_tensor(y_mean, dtype=torch.float32))
165
+ self.y_std.copy_(torch.as_tensor(y_std, dtype=torch.float32))
166
+
167
+ def _nc(self, c):
168
+ return (c - self.cond_mean) / self.cond_std
169
+
170
+ def _ny(self, y):
171
+ return (y - self.y_mean) / self.y_std
172
+
173
+ def _uny(self, yn):
174
+ return yn * self.y_std + self.y_mean
175
+
176
+ def eps_pred(self, x, t_frac, c):
177
+ """x:[B,D] normalized, t_frac:[B] in (0,1], c:[B,cond] normalized."""
178
+ te = self.time_emb(t_frac)
179
+ h = torch.cat([self.x_emb(x), self.cond_emb(c), te], dim=-1)
180
+ return self.out(self.trunk(h))
181
+
182
+ def training_loss(self, c, x0):
183
+ c = self._nc(c); x0 = self._ny(x0)
184
+ B = x0.shape[0]
185
+ t = torch.randint(1, self.T + 1, (B,), device=x0.device)
186
+ abar = self.abar[t - 1].unsqueeze(-1)
187
+ noise = torch.randn_like(x0)
188
+ xt = abar.sqrt() * x0 + (1 - abar).sqrt() * noise
189
+ pred = self.eps_pred(xt, t.float() / self.T, c)
190
+ return F.mse_loss(pred, noise)
191
+
192
+ @torch.no_grad()
193
+ def eval_loss(self, c, x0, n_t=8):
194
+ """Deterministic denoising-loss proxy averaged over a fixed t grid."""
195
+ c = self._nc(c); x0 = self._ny(x0)
196
+ B = x0.shape[0]
197
+ ts = torch.linspace(1, self.T, n_t, device=x0.device).long().clamp(1, self.T)
198
+ gen = torch.Generator(device=x0.device).manual_seed(0)
199
+ tot = 0.0
200
+ for t in ts:
201
+ abar = self.abar[t - 1]
202
+ noise = torch.randn(x0.shape, generator=gen, device=x0.device)
203
+ xt = abar.sqrt() * x0 + (1 - abar).sqrt() * noise
204
+ tf = torch.full((B,), float(t) / self.T, device=x0.device)
205
+ pred = self.eps_pred(xt, tf, c)
206
+ tot += F.mse_loss(pred, noise).item()
207
+ return tot / len(ts)
208
+
209
+ @torch.no_grad()
210
+ def sample(self, c, n_samples=1, steps=None, eta=0.0):
211
+ """DDIM sampling. Returns [B, n_samples, D] in raw (unnormalized) coordinates."""
212
+ steps = steps or self.sample_steps
213
+ c = self._nc(c)
214
+ B = c.shape[0]
215
+ cc = c.unsqueeze(1).expand(-1, n_samples, -1).reshape(B * n_samples, -1)
216
+ x = torch.randn(B * n_samples, self.y_dim, device=c.device)
217
+ ts = torch.linspace(self.T, 1, steps, device=c.device).long().clamp(1, self.T)
218
+ for i in range(steps):
219
+ t = ts[i]
220
+ abar_t = self.abar[t - 1]
221
+ tf = torch.full((B * n_samples,), float(t) / self.T, device=c.device)
222
+ eps = self.eps_pred(x, tf, cc)
223
+ x0 = (x - (1 - abar_t).sqrt() * eps) / abar_t.sqrt()
224
+ x0 = x0.clamp(-5.0, 5.0) # normalized data is ~unit std; clamp well outside support
225
+ if i < steps - 1:
226
+ t_next = ts[i + 1]
227
+ abar_n = self.abar[t_next - 1]
228
+ sigma = eta * ((1 - abar_n) / (1 - abar_t)).sqrt() * (1 - abar_t / abar_n).sqrt()
229
+ noise = torch.randn_like(x) if eta > 0 else 0.0
230
+ x = abar_n.sqrt() * x0 + (1 - abar_n - sigma ** 2).clamp(min=0).sqrt() * eps + sigma * noise
231
+ else:
232
+ x = x0
233
+ x = self._uny(x)
234
+ return x.view(B, n_samples, self.y_dim)
235
+
236
+ @torch.no_grad()
237
+ def sample_trajectory(self, c, n_samples=1, steps=None):
238
+ """Like sample(), but returns (final, traj) where traj is a list of the clean-estimate x0
239
+ (raw coords) at each DDIM step -- for animating how the occupancy cloud forms."""
240
+ steps = steps or self.sample_steps
241
+ c = self._nc(c); B = c.shape[0]
242
+ cc = c.unsqueeze(1).expand(-1, n_samples, -1).reshape(B * n_samples, -1)
243
+ x = torch.randn(B * n_samples, self.y_dim, device=c.device)
244
+ ts = torch.linspace(self.T, 1, steps, device=c.device).long().clamp(1, self.T)
245
+ traj = []
246
+ for i in range(steps):
247
+ t = ts[i]; abar_t = self.abar[t - 1]
248
+ tf = torch.full((B * n_samples,), float(t) / self.T, device=c.device)
249
+ eps = self.eps_pred(x, tf, cc)
250
+ x0 = ((x - (1 - abar_t).sqrt() * eps) / abar_t.sqrt()).clamp(-5.0, 5.0)
251
+ traj.append(self._uny(x0).view(B, n_samples, self.y_dim).cpu().numpy())
252
+ if i < steps - 1:
253
+ abar_n = self.abar[ts[i + 1] - 1]
254
+ x = abar_n.sqrt() * x0 + (1 - abar_n).clamp(min=0).sqrt() * eps
255
+ else:
256
+ x = x0
257
+ return self._uny(x).view(B, n_samples, self.y_dim), traj
258
+
259
+ def score(self, x, t_frac, c):
260
+ """score = grad_x log p_t(x) = -eps / sqrt(1-abar_t)."""
261
+ t = (t_frac * self.T).round().long().clamp(1, self.T)
262
+ abar = self.abar[t - 1].unsqueeze(-1)
263
+ eps = self.eps_pred(x, t_frac, c)
264
+ return -eps / (1 - abar).sqrt()
265
+
266
+ @torch.no_grad()
267
+ def log_prob(self, c, y, steps=None, n_hutch=4):
268
+ """Approximate log p(y|c) via the probability-flow ODE (continuous-time change of
269
+ variables). Uses Hutchinson trace estimation. Returns [B]."""
270
+ steps = steps or max(self.sample_steps, 40)
271
+ device = y.device
272
+ B = y.shape[0]
273
+ c = self._nc(c)
274
+ x = self._ny(y).clone()
275
+ jac_norm = -torch.log(self.y_std).sum() # change of vars for normalization
276
+ logdet = torch.zeros(B, device=device)
277
+ # integrate from t=eps_t -> t=1 (data -> noise) in continuous time s in (0,1]
278
+ s_grid = torch.linspace(1.0 / self.T, 1.0, steps, device=device)
279
+ eps_vecs = [torch.randint(0, 2, y.shape, device=device).float() * 2 - 1 for _ in range(n_hutch)]
280
+ for i in range(len(s_grid) - 1):
281
+ s0 = s_grid[i]; s1 = s_grid[i + 1]
282
+ ds = (s1 - s0)
283
+ sf = torch.full((B,), float(s0), device=device)
284
+ f = self._pf_drift(x, sf, c)
285
+ # divergence via Hutchinson
286
+ with torch.enable_grad():
287
+ xg = x.detach().requires_grad_(True)
288
+ ff = self._pf_drift(xg, sf, c)
289
+ div = torch.zeros(B, device=device)
290
+ for ev in eps_vecs:
291
+ g = torch.autograd.grad(ff, xg, grad_outputs=ev, create_graph=False, retain_graph=True)[0]
292
+ div += (g * ev).sum(-1)
293
+ div /= len(eps_vecs)
294
+ x = x + ds * f
295
+ logdet = logdet + ds * div
296
+ # log p_1(x) standard normal
297
+ log_pT = (-0.5 * (x ** 2).sum(-1) - 0.5 * self.y_dim * math.log(2 * math.pi))
298
+ return log_pT + logdet + jac_norm
299
+
300
+ def _pf_drift(self, x, s_frac, c):
301
+ """Probability-flow ODE drift in the variance-preserving 's in (0,1]' time where
302
+ we map continuous s to nearest discrete t. dx/ds = f(x,s). Uses a VP-SDE form."""
303
+ t = (s_frac * self.T).round().long().clamp(1, self.T)
304
+ abar = self.abar[t - 1].unsqueeze(-1)
305
+ abar_prev = self.abar_prev[t - 1].unsqueeze(-1)
306
+ # discrete beta_t approx
307
+ beta = (1 - abar / abar_prev).clamp(1e-6, 0.999)
308
+ eps = self.eps_pred(x, s_frac, c)
309
+ score = -eps / (1 - abar).sqrt()
310
+ # PF-ODE drift (VP): -0.5 beta x - 0.5 beta score, per unit discrete step; scale by T for s-time
311
+ return self.T * (-0.5 * beta * x - 0.5 * beta * score)
312
+
313
+
314
+ class ImageEncoder(nn.Module):
315
+ """z = E(image). Small CNN for 64x64x3 -> z. Input expected as [B,3,64,64] float in [0,1]."""
316
+
317
+ def __init__(self, z_dim, ch=32, hidden_dim=256):
318
+ super().__init__()
319
+ self.conv = nn.Sequential(
320
+ nn.Conv2d(3, ch, 4, 2, 1), nn.ReLU(), # 64 -> 32
321
+ nn.Conv2d(ch, ch * 2, 4, 2, 1), nn.ReLU(), # 32 -> 16
322
+ nn.Conv2d(ch * 2, ch * 2, 4, 2, 1), nn.ReLU(), # 16 -> 8
323
+ nn.Conv2d(ch * 2, ch * 2, 4, 2, 1), nn.ReLU(), # 8 -> 4
324
+ )
325
+ self.head = nn.Sequential(nn.Linear(ch * 2 * 4 * 4, hidden_dim), nn.ReLU(),
326
+ nn.Linear(hidden_dim, z_dim))
327
+
328
+ def forward(self, x):
329
+ h = self.conv(x).flatten(1)
330
+ return self.head(h)
331
+
332
+
333
+ class ImageDecoder(nn.Module):
334
+ """image_hat = D(z). Mirror of ImageEncoder, for the reward-agnostic autoencoder baseline."""
335
+
336
+ def __init__(self, z_dim, ch=32, hidden_dim=256):
337
+ super().__init__()
338
+ self.ch = ch
339
+ self.fc = nn.Sequential(nn.Linear(z_dim, hidden_dim), nn.ReLU(),
340
+ nn.Linear(hidden_dim, ch * 2 * 4 * 4), nn.ReLU())
341
+ self.deconv = nn.Sequential(
342
+ nn.ConvTranspose2d(ch * 2, ch * 2, 4, 2, 1), nn.ReLU(), # 4 -> 8
343
+ nn.ConvTranspose2d(ch * 2, ch * 2, 4, 2, 1), nn.ReLU(), # 8 -> 16
344
+ nn.ConvTranspose2d(ch * 2, ch, 4, 2, 1), nn.ReLU(), # 16 -> 32
345
+ nn.ConvTranspose2d(ch, 3, 4, 2, 1), nn.Sigmoid(), # 32 -> 64
346
+ )
347
+
348
+ def forward(self, z):
349
+ h = self.fc(z).view(-1, self.ch * 2, 4, 4)
350
+ return self.deconv(h)
351
+
352
+
353
+ class Encoder(nn.Module):
354
+ """z = E(s). Reward-aware or reward-agnostic latent encoder."""
355
+
356
+ def __init__(self, s_dim, z_dim, hidden_dim=256, num_layers=3):
357
+ super().__init__()
358
+ self.net = mlp(s_dim, z_dim, hidden_dim, num_layers)
359
+
360
+ def forward(self, s):
361
+ return self.net(s)
362
+
363
+
364
+ class RewardDecoder(nn.Module):
365
+ """r_hat = R(z)."""
366
+
367
+ def __init__(self, z_dim, hidden_dim=256, num_layers=2):
368
+ super().__init__()
369
+ self.net = mlp(z_dim, 1, hidden_dim, num_layers)
370
+
371
+ def forward(self, z):
372
+ return self.net(z).squeeze(-1)
373
+
374
+
375
+ class StateDecoder(nn.Module):
376
+ """s_hat = D(z), for reward-agnostic autoencoder baseline."""
377
+
378
+ def __init__(self, z_dim, s_dim, hidden_dim=256, num_layers=3):
379
+ super().__init__()
380
+ self.net = mlp(z_dim, s_dim, hidden_dim, num_layers)
381
+
382
+ def forward(self, z):
383
+ return self.net(z)
384
+
385
+
386
+ class ConditionalFlowMatching(nn.Module):
387
+ """Conditional Flow Matching for p(y | c). Learns a velocity field v_theta(y_t, t, c)
388
+ that transports N(0,I) to the target distribution via linear interpolation paths.
389
+
390
+ Same external interface as ConditionalDiffusion: .sample(c, n) -> [B,n,D].
391
+ """
392
+
393
+ def __init__(self, cond_dim, y_dim, hidden_dim=256, num_layers=4,
394
+ time_dim=64, sample_steps=30):
395
+ super().__init__()
396
+ self.y_dim = y_dim
397
+ self.cond_dim = cond_dim
398
+ self.sample_steps = sample_steps
399
+ self.time_emb = nn.Sequential(SinusoidalEmbedding(time_dim),
400
+ nn.Linear(time_dim, time_dim), nn.SiLU(),
401
+ nn.Linear(time_dim, time_dim))
402
+ self.cond_emb = nn.Sequential(nn.Linear(cond_dim, hidden_dim), nn.SiLU())
403
+ self.y_emb = nn.Linear(y_dim, hidden_dim)
404
+ layers = []
405
+ d = hidden_dim + hidden_dim + time_dim
406
+ for _ in range(num_layers):
407
+ layers += [nn.Linear(d, hidden_dim), nn.SiLU()]
408
+ d = hidden_dim
409
+ self.trunk = nn.Sequential(*layers)
410
+ self.out = nn.Linear(hidden_dim, y_dim)
411
+ # normalization buffers
412
+ self.register_buffer("cond_mean", torch.zeros(cond_dim))
413
+ self.register_buffer("cond_std", torch.ones(cond_dim))
414
+ self.register_buffer("y_mean", torch.zeros(y_dim))
415
+ self.register_buffer("y_std", torch.ones(y_dim))
416
+
417
+ def set_normalization(self, cond_mean, cond_std, y_mean, y_std):
418
+ self.cond_mean.copy_(torch.as_tensor(cond_mean, dtype=torch.float32))
419
+ self.cond_std.copy_(torch.as_tensor(cond_std, dtype=torch.float32))
420
+ self.y_mean.copy_(torch.as_tensor(y_mean, dtype=torch.float32))
421
+ self.y_std.copy_(torch.as_tensor(y_std, dtype=torch.float32))
422
+
423
+ def _nc(self, c): return (c - self.cond_mean) / self.cond_std
424
+ def _ny(self, y): return (y - self.y_mean) / self.y_std
425
+ def _uny(self, yn): return yn * self.y_std + self.y_mean
426
+
427
+ def velocity(self, yt, t_frac, c):
428
+ """v_theta(y_t, t, c). y_t: [B,D] normalized; t_frac: [B] in [0,1]; c: [B,cond] normalized."""
429
+ te = self.time_emb(t_frac)
430
+ h = torch.cat([self.y_emb(yt), self.cond_emb(c), te], dim=-1)
431
+ return self.out(self.trunk(h))
432
+
433
+ def training_loss(self, c, y1):
434
+ """CFM loss given pre-sampled target y1 (raw coords). Samples z0, t, forms path."""
435
+ c = self._nc(c); y1n = self._ny(y1)
436
+ z0 = torch.randn_like(y1n)
437
+ t = torch.rand(y1n.shape[0], device=y1n.device)
438
+ yt = (1 - t.unsqueeze(-1)) * z0 + t.unsqueeze(-1) * y1n # linear path
439
+ u_t = y1n - z0 # constant velocity
440
+ v = self.velocity(yt, t, c)
441
+ return F.mse_loss(v, u_t)
442
+
443
+ def training_loss_td(self, c, y1):
444
+ """Alias for training_loss — y1 may come from the TD mixture (external)."""
445
+ return self.training_loss(c, y1)
446
+
447
+ @torch.no_grad()
448
+ def eval_loss(self, c, y1):
449
+ c = self._nc(c); y1n = self._ny(y1)
450
+ z0 = torch.zeros_like(y1n) # deterministic for eval
451
+ t = torch.full((y1n.shape[0],), 0.5, device=y1n.device)
452
+ yt = 0.5 * z0 + 0.5 * y1n
453
+ u_t = y1n - z0
454
+ return F.mse_loss(self.velocity(yt, t, c), u_t).item()
455
+
456
+ @torch.no_grad()
457
+ def sample(self, c, n_samples=1, steps=None):
458
+ """Euler ODE integration from z0~N(0,I). Returns [B, n_samples, D] raw coords."""
459
+ steps = steps or self.sample_steps
460
+ c = self._nc(c); B = c.shape[0]
461
+ cc = c.unsqueeze(1).expand(-1, n_samples, -1).reshape(B * n_samples, -1)
462
+ z = torch.randn(B * n_samples, self.y_dim, device=c.device)
463
+ dt = 1.0 / steps
464
+ for i in range(steps):
465
+ t_frac = torch.full((B * n_samples,), i * dt, device=c.device)
466
+ v = self.velocity(z, t_frac, cc)
467
+ z = z + dt * v
468
+ return self._uny(z).view(B, n_samples, self.y_dim)
469
+
470
+
471
+ class OneStepModel(nn.Module):
472
+ """p(s_{t+1} | s_t, a_t) as a small conditional GMM over the *delta* s_{t+1}-s_t."""
473
+
474
+ def __init__(self, s_dim, a_dim, num_components=4, hidden_dim=256, num_layers=3):
475
+ super().__init__()
476
+ self.gmm = ConditionalGMM(s_dim + a_dim, s_dim, num_components, hidden_dim, num_layers)
477
+ self.s_dim = s_dim
478
+
479
+ def log_prob(self, s, a, s_next):
480
+ c = torch.cat([s, a], dim=-1)
481
+ return self.gmm.log_prob(c, s_next - s)
482
+
483
+ @torch.no_grad()
484
+ def step(self, s, a):
485
+ c = torch.cat([s, a], dim=-1)
486
+ delta = self.gmm.sample(c, 1).squeeze(1)
487
+ return s + delta