# 测试结果转换工具 这个工具可以将PPO训练过程中保存的测试结果从one-hot向量格式转换为更直观的10x10字母矩阵格式,方便LLM分析。 ## 功能 - 将observation中的one-hot编码转换回字母(A-E, X) - 重建10x10的网格地图 - 将归一化的位置坐标转换回实际坐标 - 在网格中标记agent的当前位置(用@表示) - 保留所有原始的统计信息和轨迹数据 ## 使用方法 ### 1. 转换单个文件 ```bash python convert_test_results.py /path/to/test_iter_732.json ``` 这会在同一目录下生成 `test_iter_732_readable.json` ### 2. 指定输出文件 ```bash python convert_test_results.py /path/to/test_iter_732.json -o /path/to/output.json ``` ### 3. 批量转换目录中的所有测试文件 ```bash python convert_test_results.py /path/to/runs/directory -a ``` 这会递归查找所有 `test_iter_*.json` 文件并转换它们。 ### 4. 自定义批量转换的文件模式 ```bash python convert_test_results.py /path/to/runs/directory -a -p "test_*.json" ``` ## 示例 ### 转换EASY难度的所有测试结果 ```bash python convert_test_results.py runs/Ultrahorizon-v0__ppo_ultrahorizon__1_EASY__1761810199 -a ``` ### 转换特定的测试文件 ```bash python convert_test_results.py runs/Ultrahorizon-v0__ppo_ultrahorizon__1_EASY__1761810199/test_iter_732.json ``` ## 输出格式 转换后的JSON文件包含: ```json { "iteration": 732, "global_step": 1497088, "training_progress": 0.1, "test_results": { "episode_returns": [...], "episode_lengths": [...], "final_scores": [...], "mean_return": 123.45, "trajectories": [ { "actions": [0, 1, 2, ...], "rewards": [1.0, -0.5, ...], "dones": [false, false, ...], "observations": [ { "step": 0, "position": {"x": 5, "y": 3}, "energy": 20.0, "score": 0.0, "steps": 0.0, "grid": [ ["A", "B", "C", ...], ["D", "E", "X", ...], ... ], "grid_string": " 0 1 2 3 4 5 6 7 8 9\n -------------------\n0|A B C D E X A B C D \n1|E X A B C D E X A B \n...", "action": "right", "reward": 1.0 }, ... ] } ] } } ``` ## 网格可视化 每个observation都包含 `grid_string` 字段,显示10x10的网格: ``` 0 1 2 3 4 5 6 7 8 9 ------------------- 0|A B C D E X A B C D 1|E X A B C D E X A B 2|C D E X A B C D E X 3|A B C D E @ A B C D <- @ 表示agent位置 4|E X A B C D E X A B 5|C D E X A B C D E X 6|A B C D E X A B C D 7|E X A B C D E X A B 8|C D E X A B C D E X 9|A B C D E X A B C D ``` ## 观察向量结构 原始observation是605维向量: - **位置 (2维)**: x, y 坐标,归一化到 [0, 1] - **能量 (1维)**: 归一化到 [0, 1],原始范围约为 [0, 20] - **分数 (1维)**: 当前累积分数 - **步数 (1维)**: 归一化到 [0, 1],原始范围为 [0, 30] - **网格状态 (600维)**: 10x10网格,每个格子6维one-hot编码(A, B, C, D, E, X) ## 动作映射 - 0: up (向上) - 1: down (向下) - 2: left (向左) - 3: right (向右) ## 注意事项 1. 转换后的文件会比原始文件大,因为包含了可读的字符串表示 2. 网格坐标系:y=0在顶部,y=9在底部 3. agent位置用 `@` 标记在grid_string中 4. 所有原始数据(actions, rewards, dones)都会保留