gr-libs 0.1.8__py3-none-any.whl → 0.2.5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. gr_libs/__init__.py +3 -1
  2. gr_libs/_version.py +2 -2
  3. gr_libs/all_experiments.py +260 -0
  4. gr_libs/environment/__init__.py +14 -1
  5. gr_libs/environment/_utils/__init__.py +0 -0
  6. gr_libs/environment/{utils → _utils}/utils.py +1 -1
  7. gr_libs/environment/environment.py +278 -23
  8. gr_libs/evaluation/__init__.py +1 -0
  9. gr_libs/evaluation/generate_experiments_results.py +100 -0
  10. gr_libs/metrics/__init__.py +2 -0
  11. gr_libs/metrics/metrics.py +166 -31
  12. gr_libs/ml/__init__.py +1 -6
  13. gr_libs/ml/base/__init__.py +3 -1
  14. gr_libs/ml/base/rl_agent.py +68 -3
  15. gr_libs/ml/neural/__init__.py +1 -3
  16. gr_libs/ml/neural/deep_rl_learner.py +241 -84
  17. gr_libs/ml/neural/utils/__init__.py +1 -2
  18. gr_libs/ml/planner/mcts/{utils → _utils}/tree.py +1 -1
  19. gr_libs/ml/planner/mcts/mcts_model.py +71 -34
  20. gr_libs/ml/sequential/__init__.py +0 -1
  21. gr_libs/ml/sequential/{lstm_model.py → _lstm_model.py} +11 -14
  22. gr_libs/ml/tabular/__init__.py +1 -3
  23. gr_libs/ml/tabular/tabular_q_learner.py +27 -9
  24. gr_libs/ml/tabular/tabular_rl_agent.py +22 -9
  25. gr_libs/ml/utils/__init__.py +2 -9
  26. gr_libs/ml/utils/format.py +13 -90
  27. gr_libs/ml/utils/math.py +3 -2
  28. gr_libs/ml/utils/other.py +2 -2
  29. gr_libs/ml/utils/storage.py +41 -94
  30. gr_libs/odgr_executor.py +263 -0
  31. gr_libs/problems/consts.py +570 -292
  32. gr_libs/recognizer/{utils → _utils}/format.py +2 -2
  33. gr_libs/recognizer/gr_as_rl/gr_as_rl_recognizer.py +127 -36
  34. gr_libs/recognizer/graml/{gr_dataset.py → _gr_dataset.py} +11 -11
  35. gr_libs/recognizer/graml/graml_recognizer.py +186 -35
  36. gr_libs/recognizer/recognizer.py +59 -10
  37. gr_libs/tutorials/draco_panda_tutorial.py +58 -0
  38. gr_libs/tutorials/draco_parking_tutorial.py +56 -0
  39. {tutorials → gr_libs/tutorials}/gcdraco_panda_tutorial.py +11 -11
  40. {tutorials → gr_libs/tutorials}/gcdraco_parking_tutorial.py +6 -8
  41. {tutorials → gr_libs/tutorials}/graml_minigrid_tutorial.py +18 -14
  42. {tutorials → gr_libs/tutorials}/graml_panda_tutorial.py +11 -12
  43. {tutorials → gr_libs/tutorials}/graml_parking_tutorial.py +8 -10
  44. {tutorials → gr_libs/tutorials}/graml_point_maze_tutorial.py +17 -3
  45. {tutorials → gr_libs/tutorials}/graql_minigrid_tutorial.py +2 -2
  46. {gr_libs-0.1.8.dist-info → gr_libs-0.2.5.dist-info}/METADATA +95 -29
  47. gr_libs-0.2.5.dist-info/RECORD +72 -0
  48. {gr_libs-0.1.8.dist-info → gr_libs-0.2.5.dist-info}/WHEEL +1 -1
  49. gr_libs-0.2.5.dist-info/top_level.txt +2 -0
  50. tests/test_draco.py +14 -0
  51. tests/test_gcdraco.py +2 -2
  52. tests/test_graml.py +4 -4
  53. tests/test_graql.py +1 -1
  54. tests/test_odgr_executor_expertbasedgraml.py +14 -0
  55. tests/test_odgr_executor_gcdraco.py +14 -0
  56. tests/test_odgr_executor_gcgraml.py +14 -0
  57. tests/test_odgr_executor_graql.py +14 -0
  58. evaluation/analyze_results_cross_alg_cross_domain.py +0 -267
  59. evaluation/create_minigrid_map_image.py +0 -38
  60. evaluation/file_system.py +0 -53
  61. evaluation/generate_experiments_results.py +0 -141
  62. evaluation/generate_experiments_results_new_ver1.py +0 -238
  63. evaluation/generate_experiments_results_new_ver2.py +0 -331
  64. evaluation/generate_task_specific_statistics_plots.py +0 -500
  65. evaluation/get_plans_images.py +0 -62
  66. evaluation/increasing_and_decreasing_.py +0 -104
  67. gr_libs/ml/neural/utils/penv.py +0 -60
  68. gr_libs-0.1.8.dist-info/RECORD +0 -70
  69. gr_libs-0.1.8.dist-info/top_level.txt +0 -4
  70. /gr_libs/{environment/utils/__init__.py → _evaluation/_generate_experiments_results.py} +0 -0
  71. /gr_libs/ml/planner/mcts/{utils → _utils}/__init__.py +0 -0
  72. /gr_libs/ml/planner/mcts/{utils → _utils}/node.py +0 -0
  73. /gr_libs/recognizer/{utils → _utils}/__init__.py +0 -0
@@ -0,0 +1,72 @@
1
+ gr_libs/__init__.py,sha256=XGx0_nWGgy-1zEQUXHRBs3TTb13jX9yOxVvSaavCkBk,376
2
+ gr_libs/_version.py,sha256=N3oBwJUFmS-AwCjqOcSlRW4GvSq-uJJMaBvoGfv1-hM,511
3
+ gr_libs/all_experiments.py,sha256=OTTMx5ddy7z3kJbElQcR5nwEtshPsoehNPwDuMzojcc,10006
4
+ gr_libs/odgr_executor.py,sha256=ttfEjeEBjr_YusegCX2zx11NBMfeXUwyKJjryYS6QaY,10685
5
+ gr_libs/_evaluation/_generate_experiments_results.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ gr_libs/environment/__init__.py,sha256=xCCzTFDrj_ijdLoZ-PzGyyYDeU2aoW19X1da76_x9iM,1458
7
+ gr_libs/environment/environment.py,sha256=fAjkM5XyfFBlP6U3yjMyGj_WDI2c4fM2Ac-e7-kSKuM,16940
8
+ gr_libs/environment/_utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
+ gr_libs/environment/_utils/utils.py,sha256=dKuWoUpyuGSJL6qHQfvvJnFf4g-Rh1t2ykuRNrsIvP8,614
10
+ gr_libs/evaluation/__init__.py,sha256=trZ-4PyOhzEEK_TvQLfbnNFcqYuN6SdRjDkkAdW6MW8,78
11
+ gr_libs/evaluation/generate_experiments_results.py,sha256=mXsGlOJKqRwtTDxuIVlsZhwgLyHAKb3zmK6jAVE7G7o,3420
12
+ gr_libs/metrics/__init__.py,sha256=dQo4cMqrOB2-VLDxTIGryCm14mUnmEXs4F8jqcgNsY4,145
13
+ gr_libs/metrics/metrics.py,sha256=tpjr4hKt5AGft5H2YxkbF0O8La5JZQaOmnkyjptD2M8,13430
14
+ gr_libs/ml/__init__.py,sha256=xX9InKnWhYm8e0Lhsnnm0H68yBPTNEfq756w95xv-98,83
15
+ gr_libs/ml/agent.py,sha256=ea1yRltKX0LSpRMnpAQLRKvvKoLMQz9MgMeWBPhQISw,2095
16
+ gr_libs/ml/consts.py,sha256=vsEB1nk5V_qP3FjNlv4vBKeTTFngV3RNaNp6fWnmEz0,366
17
+ gr_libs/ml/base/__init__.py,sha256=f63VN3Lv4tQp3dAZjtT78PGV5XuOD8WlU4svy43LZrU,123
18
+ gr_libs/ml/base/rl_agent.py,sha256=Ewqu583gUkgRmeGWCJgkyDBKxTqQnN4qa2vxq0-ydoE,3843
19
+ gr_libs/ml/neural/__init__.py,sha256=vGdjx1KzlB9UxNRwkAeYBEoYdVtRdhj0M4mtWuzqvU8,55
20
+ gr_libs/ml/neural/deep_rl_learner.py,sha256=fq5n78RelIi794nNIl9x-W8ZnO5kXmD0LYv2q_2xMs8,26690
21
+ gr_libs/ml/neural/utils/__init__.py,sha256=Av5wB2eSHR7spHqZFdgau_9EJV0FmijaYqXeyGMwktQ,69
22
+ gr_libs/ml/neural/utils/dictlist.py,sha256=ORFez_KmaCzraStF97hxdgCAAALP4Er8u3e9RcqlvhM,1030
23
+ gr_libs/ml/planner/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
24
+ gr_libs/ml/planner/mcts/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
25
+ gr_libs/ml/planner/mcts/mcts_model.py,sha256=Cv9hDrxTSK5tiaqPqp6-oO68EbETWlvRFweVRfwfjgg,27827
26
+ gr_libs/ml/planner/mcts/_utils/__init__.py,sha256=0ccEf23-6VIenUSrlVFCq0VNVDkCHHNzBw7jR09UiO4,46
27
+ gr_libs/ml/planner/mcts/_utils/node.py,sha256=LcbBjzURMDF4v_Lvz24dyhhW5xb1xQKWdPkue-2lNLM,1056
28
+ gr_libs/ml/planner/mcts/_utils/tree.py,sha256=ua_7pN00K7ECm6fk0TdRpDTe-z4J4iC6f84GCC0ceKc,3399
29
+ gr_libs/ml/sequential/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
30
+ gr_libs/ml/sequential/_lstm_model.py,sha256=3fXduJt1BkA2dPzA_jKInmZvUd1UpThHE8kqNCDCul0,10693
31
+ gr_libs/ml/tabular/__init__.py,sha256=yzHIPrn1lqVEDJbLbSz7RzNSr8IjU4TBdP0pqzQSFGU,32
32
+ gr_libs/ml/tabular/state.py,sha256=ImpIrYWF80PB-4EeQ2Q9nO7jMZ2s0hGbgsir1ZtsO88,700
33
+ gr_libs/ml/tabular/tabular_q_learner.py,sha256=eZ4Db-YgzQd4DIpFl4DvO7zVM-w2mHGFNk18-5ZmB4c,20122
34
+ gr_libs/ml/tabular/tabular_rl_agent.py,sha256=bL8Rk4dMY5HmeyVVmo986ZOizISfArskxLjf5DL87Uk,4205
35
+ gr_libs/ml/utils/__init__.py,sha256=-shnIzZCGBxZfcpep39bIoBKYED-SIN8I_HFUkVjay0,164
36
+ gr_libs/ml/utils/env.py,sha256=AWVN0OXYmFU-J3FUiwvEAIY93Suf1oL6VNcxtyWJraM,171
37
+ gr_libs/ml/utils/format.py,sha256=Vn2l7zmfqZ9Hq2pk2nlzQuVElmVyXr6nME6GsVNvVPE,1068
38
+ gr_libs/ml/utils/math.py,sha256=7Au9L-FHE7eB1ygLbbuR6AhZK6kq8D_9srVtu4iDMPk,429
39
+ gr_libs/ml/utils/other.py,sha256=93oaveiHUzWt_rCDVqybrpHdAfI3UBPCto31Nm5yT0Y,506
40
+ gr_libs/ml/utils/storage.py,sha256=CgZHWcC3GovKe-U3Cvwz0s5qCbBrYHY6w_CV-LnTquc,3791
41
+ gr_libs/problems/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
42
+ gr_libs/problems/consts.py,sha256=FQk2TaKAFHdZiISubGXeYleBaOXpk8ZC749NtP5RqWs,68520
43
+ gr_libs/recognizer/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
44
+ gr_libs/recognizer/recognizer.py,sha256=gtUttI1473co5ZHgO7-wQ7HL-aYJp0S4X6goqVYyT24,3091
45
+ gr_libs/recognizer/_utils/__init__.py,sha256=MvXPRyr30W5C_n-Dul3aheE_9SWy2aIMGINKWj36mfM,42
46
+ gr_libs/recognizer/_utils/format.py,sha256=eCoqEwv7YdLrF5nb-xAbDXxQ-ogvq_DHf9I2uwdfv-0,512
47
+ gr_libs/recognizer/gr_as_rl/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
48
+ gr_libs/recognizer/gr_as_rl/gr_as_rl_recognizer.py,sha256=asjsjg52f43vlFPw1iT7PK8oOopa-u0UN7XBgiuufAY,10158
49
+ gr_libs/recognizer/graml/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
50
+ gr_libs/recognizer/graml/_gr_dataset.py,sha256=JChqXOh7TP8yu-zQPCQ34ghw7iJFnAzd2FkeOyndvFk,10038
51
+ gr_libs/recognizer/graml/graml_recognizer.py,sha256=BVV-qn46AffkALRudBydHU24BGwMnvGFB1WSkIOAcWs,26292
52
+ gr_libs/tutorials/draco_panda_tutorial.py,sha256=9_scjcyMjkjw8l6g9E-GKOrFTxsIIndW_J1WKjE6-wo,2146
53
+ gr_libs/tutorials/draco_parking_tutorial.py,sha256=jjbNzSv5l4EvjydwslNYh51xHoIkNmcjPbi0YL6WAeA,1896
54
+ gr_libs/tutorials/gcdraco_panda_tutorial.py,sha256=HzGKqZR--rcTYj3RQMuQCzTVll2Q-Z_RQbmGpcZPovg,2301
55
+ gr_libs/tutorials/gcdraco_parking_tutorial.py,sha256=kd7xRsjGPCHohwhbJEK5XAsD3R9k8rcd0qz8IZIgjN4,2103
56
+ gr_libs/tutorials/graml_minigrid_tutorial.py,sha256=bEsi21-9-AiOw4-H98Fr3YaCrp8_uSXOiiGahaCO4mg,2356
57
+ gr_libs/tutorials/graml_panda_tutorial.py,sha256=e2pm62Hj6wyzKO-RvSz_qnDxLZoqKqnzc8B_ylVoGVM,2208
58
+ gr_libs/tutorials/graml_parking_tutorial.py,sha256=vRvcbrbM8N7npt7W_0g-CbUhALkXVqUejoVWlPMuj04,1991
59
+ gr_libs/tutorials/graml_point_maze_tutorial.py,sha256=KA28__CNKslxq3p6O5htjJFDKOXXbiA1bOX-oPJxjmI,2463
60
+ gr_libs/tutorials/graql_minigrid_tutorial.py,sha256=HT8kCFNbZXAraIau9wtgC_aW8xg-QNRZB2lcpGm3yWk,1941
61
+ tests/test_draco.py,sha256=oIeTDgn6pt3RfTC-RPX3Bw5cG4BThxRGH3z8en3TX0M,385
62
+ tests/test_gcdraco.py,sha256=vV6rp7PkJJk_WpAfRekb197QiMHjXXApqrBiLG9RTwo,308
63
+ tests/test_graml.py,sha256=amSikMWrGS9BNVSXGNKc1n5tfRl-FfgCsyHYsJtduD4,608
64
+ tests/test_graql.py,sha256=KxVKx6rcSCbN-PjxR2DFoKcILRUmMDz0dTM5SvJZMXg,154
65
+ tests/test_odgr_executor_expertbasedgraml.py,sha256=UQh1pzaqAy9kRN1O--x1tQLGWkRXuYnz5ujB2H1XMas,558
66
+ tests/test_odgr_executor_gcdraco.py,sha256=VUmnO33tuMVlNYz7Fh08VUW4jfUXhhUsJu7oPiLF2iU,506
67
+ tests/test_odgr_executor_gcgraml.py,sha256=MmyadmboVxFwfRigqe9jondZopqUjhbQ3gXjCbK4yAs,506
68
+ tests/test_odgr_executor_graql.py,sha256=06p_kPAUn2OQrL-nBik58C22UPbTDC4CwDaB7MUk61o,514
69
+ gr_libs-0.2.5.dist-info/METADATA,sha256=TYD_l_WXrcWoyi8fb4RkGjamcfdbcOeiPfrxypb-sQs,14421
70
+ gr_libs-0.2.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
71
+ gr_libs-0.2.5.dist-info/top_level.txt,sha256=Yzc_VSW3gzbVM7ZtlV4r6VXmfAC8WXqGVUgK1r6JcLs,14
72
+ gr_libs-0.2.5.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.3.0)
2
+ Generator: setuptools (80.9.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -0,0 +1,2 @@
1
+ gr_libs
2
+ tests
tests/test_draco.py ADDED
@@ -0,0 +1,14 @@
1
+ from gr_libs.tutorials.draco_panda_tutorial import run_draco_panda_tutorial
2
+ from gr_libs.tutorials.draco_parking_tutorial import run_draco_parking_tutorial
3
+
4
+
5
+ def test_draco_panda_tutorial():
6
+ run_draco_panda_tutorial()
7
+
8
+
9
+ def test_draco_parking_tutorial():
10
+ run_draco_parking_tutorial()
11
+
12
+ if __name__ == "__main__":
13
+ test_draco_panda_tutorial()
14
+ test_draco_parking_tutorial()
tests/test_gcdraco.py CHANGED
@@ -1,5 +1,5 @@
1
- from tutorials.gcdraco_panda_tutorial import run_gcdraco_panda_tutorial
2
- from tutorials.gcdraco_parking_tutorial import run_gcdraco_parking_tutorial
1
+ from gr_libs.tutorials.gcdraco_panda_tutorial import run_gcdraco_panda_tutorial
2
+ from gr_libs.tutorials.gcdraco_parking_tutorial import run_gcdraco_parking_tutorial
3
3
 
4
4
 
5
5
  def test_gcdraco_panda_tutorial():
tests/test_graml.py CHANGED
@@ -1,7 +1,7 @@
1
- from tutorials.graml_minigrid_tutorial import run_graml_minigrid_tutorial
2
- from tutorials.graml_panda_tutorial import run_graml_panda_tutorial
3
- from tutorials.graml_parking_tutorial import run_graml_parking_tutorial
4
- from tutorials.graml_point_maze_tutorial import run_graml_point_maze_tutorial
1
+ from gr_libs.tutorials.graml_minigrid_tutorial import run_graml_minigrid_tutorial
2
+ from gr_libs.tutorials.graml_panda_tutorial import run_graml_panda_tutorial
3
+ from gr_libs.tutorials.graml_parking_tutorial import run_graml_parking_tutorial
4
+ from gr_libs.tutorials.graml_point_maze_tutorial import run_graml_point_maze_tutorial
5
5
 
6
6
 
7
7
  def test_graml_minigrid_tutorial():
tests/test_graql.py CHANGED
@@ -1,4 +1,4 @@
1
- from tutorials.graql_minigrid_tutorial import run_graql_minigrid_tutorial
1
+ from gr_libs.tutorials.graql_minigrid_tutorial import run_graql_minigrid_tutorial
2
2
 
3
3
 
4
4
  def test_graql_minigrid_tutorial():
@@ -0,0 +1,14 @@
1
+ import subprocess
2
+ import sys
3
+
4
+ def test_odgr_executor_expertbasedgraml_minigrid():
5
+ """Test odgr_executor.py with ExpertBasedGraml on minigrid, L1, easiest env."""
6
+ result = subprocess.run([
7
+ sys.executable, "gr_libs/odgr_executor.py",
8
+ "--domain", "minigrid",
9
+ "--env_name", "MiniGrid-SimpleCrossingS13N4",
10
+ "--recognizer", "ExpertBasedGraml",
11
+ "--task", "L1",
12
+ "--collect_stats"
13
+ ], capture_output=True, text=True)
14
+ assert result.returncode == 0, f"ExpertBasedGraml minigrid L1 failed: {result.stderr}"
@@ -0,0 +1,14 @@
1
+ import subprocess
2
+ import sys
3
+
4
+ def test_odgr_executor_gcdraco_parking():
5
+ """Test odgr_executor.py with GCDraco on parking, L1, easiest env."""
6
+ result = subprocess.run([
7
+ sys.executable, "gr_libs/odgr_executor.py",
8
+ "--domain", "parking",
9
+ "--env_name", "Parking-S-14-PC-",
10
+ "--recognizer", "GCDraco",
11
+ "--task", "L1",
12
+ "--collect_stats"
13
+ ], capture_output=True, text=True)
14
+ assert result.returncode == 0, f"GCDraco parking L1 failed: {result.stderr}"
@@ -0,0 +1,14 @@
1
+ import subprocess
2
+ import sys
3
+
4
+ def test_odgr_executor_gcgraml_parking():
5
+ """Test odgr_executor.py with GCGraml on parking, L1, easiest env."""
6
+ result = subprocess.run([
7
+ sys.executable, "gr_libs/odgr_executor.py",
8
+ "--domain", "parking",
9
+ "--env_name", "Parking-S-14-PC-",
10
+ "--recognizer", "GCGraml",
11
+ "--task", "L1",
12
+ "--collect_stats"
13
+ ], capture_output=True, text=True)
14
+ assert result.returncode == 0, f"GCGraml parking L1 failed: {result.stderr}"
@@ -0,0 +1,14 @@
1
+ import subprocess
2
+ import sys
3
+
4
+ def test_odgr_executor_graql_minigrid():
5
+ """Test odgr_executor.py with Graql on minigrid, L1, easiest env."""
6
+ result = subprocess.run([
7
+ sys.executable, "gr_libs/odgr_executor.py",
8
+ "--domain", "minigrid",
9
+ "--env_name", "MiniGrid-SimpleCrossingS13N4",
10
+ "--recognizer", "Graql",
11
+ "--task", "L1",
12
+ "--collect_stats"
13
+ ], capture_output=True, text=True)
14
+ assert result.returncode == 0, f"Graql minigrid L1 failed: {result.stderr}"
@@ -1,267 +0,0 @@
1
- import copy
2
- import sys
3
- import matplotlib.pyplot as plt
4
- import numpy as np
5
- import os
6
- import dill
7
- from scipy.interpolate import make_interp_spline
8
- from scipy.ndimage import gaussian_filter1d
9
- from gr_libs.ml.utils.storage import (
10
- get_experiment_results_path,
11
- set_global_storage_configs,
12
- )
13
- from scripts.generate_task_specific_statistics_plots import get_figures_dir_path
14
-
15
-
16
- def smooth_line(x, y, num_points=300):
17
- x_smooth = np.linspace(np.min(x), np.max(x), num_points)
18
- spline = make_interp_spline(x, y, k=3) # Cubic spline
19
- y_smooth = spline(x_smooth)
20
- return x_smooth, y_smooth
21
-
22
-
23
- if __name__ == "__main__":
24
-
25
- fragmented_accuracies = {
26
- "graml": {
27
- "panda": {
28
- "gd_agent": {
29
- "0.3": [], # every list here should have number of tasks accuracies in it, since we done experiments for L111-L555. remember each accuracy is an average of #goals different tasks.
30
- "0.5": [],
31
- "0.7": [],
32
- "0.9": [],
33
- "1": [],
34
- },
35
- "gc_agent": {"0.3": [], "0.5": [], "0.7": [], "0.9": [], "1": []},
36
- },
37
- "minigrid": {
38
- "obstacles": {"0.3": [], "0.5": [], "0.7": [], "0.9": [], "1": []},
39
- "lava_crossing": {"0.3": [], "0.5": [], "0.7": [], "0.9": [], "1": []},
40
- },
41
- "point_maze": {
42
- "obstacles": {"0.3": [], "0.5": [], "0.7": [], "0.9": [], "1": []},
43
- "four_rooms": {"0.3": [], "0.5": [], "0.7": [], "0.9": [], "1": []},
44
- },
45
- "parking": {
46
- "gd_agent": {"0.3": [], "0.5": [], "0.7": [], "0.9": [], "1": []},
47
- "gc_agent": {"0.3": [], "0.5": [], "0.7": [], "0.9": [], "1": []},
48
- },
49
- },
50
- "graql": {
51
- "panda": {
52
- "gd_agent": {"0.3": [], "0.5": [], "0.7": [], "0.9": [], "1": []},
53
- "gc_agent": {"0.3": [], "0.5": [], "0.7": [], "0.9": [], "1": []},
54
- },
55
- "minigrid": {
56
- "obstacles": {"0.3": [], "0.5": [], "0.7": [], "0.9": [], "1": []},
57
- "lava_crossing": {"0.3": [], "0.5": [], "0.7": [], "0.9": [], "1": []},
58
- },
59
- "point_maze": {
60
- "obstacles": {"0.3": [], "0.5": [], "0.7": [], "0.9": [], "1": []},
61
- "four_rooms": {"0.3": [], "0.5": [], "0.7": [], "0.9": [], "1": []},
62
- },
63
- "parking": {
64
- "gd_agent": {"0.3": [], "0.5": [], "0.7": [], "0.9": [], "1": []},
65
- "gc_agent": {"0.3": [], "0.5": [], "0.7": [], "0.9": [], "1": []},
66
- },
67
- },
68
- }
69
-
70
- continuing_accuracies = copy.deepcopy(fragmented_accuracies)
71
-
72
- # domains = ['panda', 'minigrid', 'point_maze', 'parking']
73
- domains = ["minigrid", "point_maze", "parking"]
74
- tasks = ["L111", "L222", "L333", "L444", "L555"]
75
- percentages = ["0.3", "0.5", "1"]
76
-
77
- for partial_obs_type, accuracies, is_same_learn in zip(
78
- ["fragmented", "continuing"],
79
- [fragmented_accuracies, continuing_accuracies],
80
- [False, True],
81
- ):
82
- for domain in domains:
83
- for env in accuracies["graml"][domain].keys():
84
- for task in tasks:
85
- set_global_storage_configs(
86
- recognizer_str="graml",
87
- is_fragmented=partial_obs_type,
88
- is_inference_same_length_sequences=True,
89
- is_learn_same_length_sequences=is_same_learn,
90
- )
91
- graml_res_file_path = (
92
- f"{get_experiment_results_path(domain, env, task)}.pkl"
93
- )
94
- set_global_storage_configs(
95
- recognizer_str="graql", is_fragmented=partial_obs_type
96
- )
97
- graql_res_file_path = (
98
- f"{get_experiment_results_path(domain, env, task)}.pkl"
99
- )
100
- if os.path.exists(graml_res_file_path):
101
- with open(graml_res_file_path, "rb") as results_file:
102
- results = dill.load(results_file)
103
- for percentage in accuracies["graml"][domain][env].keys():
104
- accuracies["graml"][domain][env][percentage].append(
105
- results[percentage]["accuracy"]
106
- )
107
- else:
108
- assert (False, f"no file for {graml_res_file_path}")
109
- if os.path.exists(graql_res_file_path):
110
- with open(graql_res_file_path, "rb") as results_file:
111
- results = dill.load(results_file)
112
- for percentage in accuracies["graml"][domain][env].keys():
113
- accuracies["graql"][domain][env][percentage].append(
114
- results[percentage]["accuracy"]
115
- )
116
- else:
117
- assert (False, f"no file for {graql_res_file_path}")
118
-
119
- plot_styles = {
120
- ("graml", "fragmented", 0.3): "g--o", # Green dashed line with circle markers
121
- ("graml", "fragmented", 0.5): "g--s", # Green dashed line with square markers
122
- (
123
- "graml",
124
- "fragmented",
125
- 0.7,
126
- ): "g--^", # Green dashed line with triangle-up markers
127
- ("graml", "fragmented", 0.9): "g--d", # Green dashed line with diamond markers
128
- ("graml", "fragmented", 1.0): "g--*", # Green dashed line with star markers
129
- ("graml", "continuing", 0.3): "g-o", # Green solid line with circle markers
130
- ("graml", "continuing", 0.5): "g-s", # Green solid line with square markers
131
- (
132
- "graml",
133
- "continuing",
134
- 0.7,
135
- ): "g-^", # Green solid line with triangle-up markers
136
- ("graml", "continuing", 0.9): "g-d", # Green solid line with diamond markers
137
- ("graml", "continuing", 1.0): "g-*", # Green solid line with star markers
138
- ("graql", "fragmented", 0.3): "b--o", # Blue dashed line with circle markers
139
- ("graql", "fragmented", 0.5): "b--s", # Blue dashed line with square markers
140
- (
141
- "graql",
142
- "fragmented",
143
- 0.7,
144
- ): "b--^", # Blue dashed line with triangle-up markers
145
- ("graql", "fragmented", 0.9): "b--d", # Blue dashed line with diamond markers
146
- ("graql", "fragmented", 1.0): "b--*", # Blue dashed line with star markers
147
- ("graql", "continuing", 0.3): "b-o", # Blue solid line with circle markers
148
- ("graql", "continuing", 0.5): "b-s", # Blue solid line with square markers
149
- ("graql", "continuing", 0.7): "b-^", # Blue solid line with triangle-up markers
150
- ("graql", "continuing", 0.9): "b-d", # Blue solid line with diamond markers
151
- ("graql", "continuing", 1.0): "b-*", # Blue solid line with star markers
152
- }
153
-
154
- def average_accuracies(accuracies, domain):
155
- avg_acc = {
156
- algo: {perc: [] for perc in percentages} for algo in ["graml", "graql"]
157
- }
158
-
159
- for algo in avg_acc.keys():
160
- for perc in percentages:
161
- for env in accuracies[algo][domain].keys():
162
- env_acc = accuracies[algo][domain][env][
163
- perc
164
- ] # list of 5, averages for L111 to L555.
165
- if env_acc:
166
- avg_acc[algo][perc].append(np.array(env_acc))
167
-
168
- for algo in avg_acc.keys():
169
- for perc in percentages:
170
- if avg_acc[algo][perc]:
171
- avg_acc[algo][perc] = np.mean(np.array(avg_acc[algo][perc]), axis=0)
172
-
173
- return avg_acc
174
-
175
- def plot_domain_accuracies(
176
- ax,
177
- fragmented_accuracies,
178
- continuing_accuracies,
179
- domain,
180
- sigma=1,
181
- line_width=1.5,
182
- ):
183
- fragmented_avg_acc = average_accuracies(fragmented_accuracies, domain)
184
- continuing_avg_acc = average_accuracies(continuing_accuracies, domain)
185
-
186
- x_vals = np.arange(1, 6) # Number of goals
187
-
188
- # Create "waves" (shaded regions) for each algorithm
189
- for algo in ["graml", "graql"]:
190
- fragmented_y_vals_by_percentage = []
191
- continuing_y_vals_by_percentage = []
192
-
193
- for perc in percentages:
194
- fragmented_y_vals = np.array(fragmented_avg_acc[algo][perc])
195
- continuing_y_vals = np.array(continuing_avg_acc[algo][perc])
196
-
197
- # Smooth the trends using Gaussian filtering
198
- fragmented_y_smoothed = gaussian_filter1d(
199
- fragmented_y_vals, sigma=sigma
200
- )
201
- continuing_y_smoothed = gaussian_filter1d(
202
- continuing_y_vals, sigma=sigma
203
- )
204
-
205
- fragmented_y_vals_by_percentage.append(fragmented_y_smoothed)
206
- continuing_y_vals_by_percentage.append(continuing_y_smoothed)
207
-
208
- ax.plot(
209
- x_vals,
210
- fragmented_y_smoothed,
211
- plot_styles[(algo, "fragmented", float(perc))],
212
- label=f"{algo}, non-consecutive, {perc}",
213
- linewidth=0.5, # Control line thickness here
214
- )
215
- ax.plot(
216
- x_vals,
217
- continuing_y_smoothed,
218
- plot_styles[(algo, "continuing", float(perc))],
219
- label=f"{algo}, consecutive, {perc}",
220
- linewidth=0.5, # Control line thickness here
221
- )
222
-
223
- ax.set_xticks(x_vals)
224
- ax.set_yticks(np.linspace(0, 1, 6))
225
- ax.set_ylim([0, 1])
226
- ax.set_title(f"{domain.capitalize()} Domain", fontsize=16)
227
- ax.grid(True)
228
-
229
- fig, axes = plt.subplots(
230
- 1, 4, figsize=(24, 6)
231
- ) # Increase the figure size for better spacing (width 24, height 6)
232
-
233
- # Generate each plot in a subplot, including both fragmented and continuing accuracies
234
- for i, domain in enumerate(domains):
235
- plot_domain_accuracies(
236
- axes[i], fragmented_accuracies, continuing_accuracies, domain
237
- )
238
-
239
- # Set a single x-axis and y-axis label for the entire figure
240
- fig.text(
241
- 0.5, 0.04, "Number of Goals", ha="center", fontsize=20
242
- ) # Centered x-axis label
243
- fig.text(
244
- 0.04, 0.5, "Accuracy", va="center", rotation="vertical", fontsize=20
245
- ) # Reduced spacing for y-axis label
246
-
247
- # Adjust subplot layout to avoid overlap
248
- plt.subplots_adjust(
249
- left=0.09, right=0.91, top=0.79, bottom=0.21, wspace=0.3
250
- ) # More space on top (top=0.82)
251
-
252
- # Place the legend above the plots with more space between legend and plots
253
- handles, labels = axes[0].get_legend_handles_labels()
254
- fig.legend(
255
- handles,
256
- labels,
257
- loc="upper center",
258
- ncol=4,
259
- bbox_to_anchor=(0.5, 1.05),
260
- fontsize=12,
261
- ) # Moved above with bbox_to_anchor
262
-
263
- # Save the figure and show it
264
- save_dir = os.path.join("figures", "all_domains_accuracy_plots")
265
- if not os.path.exists(save_dir):
266
- os.makedirs(save_dir)
267
- plt.savefig(os.path.join(save_dir, "accuracy_plots_smooth.png"), dpi=300)
@@ -1,38 +0,0 @@
1
- from minigrid.wrappers import RGBImgPartialObsWrapper, ImgObsWrapper
2
- import numpy as np
3
- import gr_libs.ml as ml
4
- from minigrid.core.world_object import Wall
5
-
6
- # from q_table_plot import save_q_table_plot_image
7
- from gymnasium.envs.registration import register
8
-
9
- env_name = "MiniGrid-SimpleCrossingS13N4-DynamicGoal-5x9-v0"
10
- # create an agent and train it (if it is already trained, it will get q-table from cache)
11
- agent = ml.TabularQLearner(
12
- env_name="MiniGrid-Walls-13x13-v0",
13
- problem_name="MiniGrid-SimpleCrossingS13N4-DynamicGoal-5x9-v0",
14
- )
15
- # agent.learn()
16
-
17
- # save_q_table_plot_image(agent.q_table, 15, 15, (10,7))
18
-
19
- # add to the steps list the step the trained agent would take on the env in every state according to the q_table
20
- env = agent.env
21
- env = RGBImgPartialObsWrapper(env) # Get pixel observations
22
- env = ImgObsWrapper(env) # Get rid of the 'mission' field
23
- obs, _ = env.reset() # This now produces an RGB tensor only
24
-
25
- img = env.get_frame()
26
-
27
- ####### save image to file
28
- from PIL import Image
29
- import numpy as np
30
-
31
- image_pil = Image.fromarray(np.uint8(img)).convert("RGB")
32
- image_pil.save(r"{}.png".format(env_name))
33
-
34
- # ####### show image
35
- # from gym_minigrid.window import Window
36
- # window = Window(r"z")
37
- # window.show_img(img=img)
38
- # window.close()
evaluation/file_system.py DELETED
@@ -1,53 +0,0 @@
1
- import os
2
- import dill
3
- import random
4
- import hashlib
5
- from typing import List
6
-
7
-
8
- def get_observations_path(env_name: str):
9
- return f"dataset/{env_name}/observations"
10
-
11
-
12
- def get_observations_paths(path: str):
13
- return [os.path.join(path, file_name) for file_name in os.listdir(path)]
14
-
15
-
16
- def create_partial_observabilities_files(env_name: str, observabilities: List[float]):
17
- with open(
18
- r"dataset/{env_name}/observations/obs1.0.pkl".format(env_name=env_name), "rb"
19
- ) as f:
20
- step_1_0 = dill.load(f)
21
-
22
- number_of_items_to_randomize = [
23
- int(observability * len(step_1_0)) for observability in observabilities
24
- ]
25
- obs = []
26
- for items_to_randomize in number_of_items_to_randomize:
27
- obs.append(random.sample(step_1_0, items_to_randomize))
28
- for index, observability in enumerate(observabilities):
29
- partial_steps = obs[index]
30
- file_path = r"dataset/{env_name}/observations/obs{obs}.pkl".format(
31
- env_name=env_name, obs=observability
32
- )
33
- with open(file_path, "wb+") as f:
34
- dill.dump(partial_steps, f)
35
-
36
-
37
- def md5(file_path: str):
38
- hash_md5 = hashlib.md5()
39
- with open(file_path, "rb") as f:
40
- for chunk in iter(lambda: f.read(4096), b""):
41
- hash_md5.update(chunk)
42
- return hash_md5.hexdigest()
43
-
44
-
45
- def get_md5(file_path_list: List[str]):
46
- return [(file_path, md5(file_path=file_path)) for file_path in file_path_list]
47
-
48
-
49
- def print_md5(file_path_list: List[str]):
50
- md5_of_observations = get_md5(file_path_list=file_path_list)
51
- for file_name, file_md5 in md5_of_observations:
52
- print(f"{file_name}:{file_md5}")
53
- print("")