gr-libs 0.1.7.post0__tar.gz → 0.1.8__tar.gz

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 (102) hide show
  1. {gr_libs-0.1.7.post0 → gr_libs-0.1.8}/PKG-INFO +1 -1
  2. gr_libs-0.1.8/evaluation/analyze_results_cross_alg_cross_domain.py +267 -0
  3. {gr_libs-0.1.7.post0 → gr_libs-0.1.8}/evaluation/create_minigrid_map_image.py +10 -6
  4. {gr_libs-0.1.7.post0 → gr_libs-0.1.8}/evaluation/file_system.py +16 -5
  5. gr_libs-0.1.8/evaluation/generate_experiments_results.py +141 -0
  6. gr_libs-0.1.8/evaluation/generate_experiments_results_new_ver1.py +238 -0
  7. gr_libs-0.1.8/evaluation/generate_experiments_results_new_ver2.py +331 -0
  8. gr_libs-0.1.8/evaluation/generate_task_specific_statistics_plots.py +500 -0
  9. gr_libs-0.1.8/evaluation/get_plans_images.py +62 -0
  10. gr_libs-0.1.8/evaluation/increasing_and_decreasing_.py +104 -0
  11. {gr_libs-0.1.7.post0 → gr_libs-0.1.8}/gr_libs/__init__.py +2 -1
  12. {gr_libs-0.1.7.post0 → gr_libs-0.1.8}/gr_libs/_version.py +2 -2
  13. gr_libs-0.1.8/gr_libs/environment/__init__.py +30 -0
  14. gr_libs-0.1.8/gr_libs/environment/environment.py +353 -0
  15. gr_libs-0.1.8/gr_libs/environment/utils/utils.py +27 -0
  16. gr_libs-0.1.8/gr_libs/metrics/__init__.py +5 -0
  17. {gr_libs-0.1.7.post0 → gr_libs-0.1.8}/gr_libs/metrics/metrics.py +76 -34
  18. {gr_libs-0.1.7.post0 → gr_libs-0.1.8}/gr_libs/ml/__init__.py +2 -0
  19. {gr_libs-0.1.7.post0 → gr_libs-0.1.8}/gr_libs/ml/agent.py +21 -6
  20. {gr_libs-0.1.7.post0 → gr_libs-0.1.8}/gr_libs/ml/base/__init__.py +1 -1
  21. {gr_libs-0.1.7.post0 → gr_libs-0.1.8}/gr_libs/ml/base/rl_agent.py +13 -10
  22. {gr_libs-0.1.7.post0 → gr_libs-0.1.8}/gr_libs/ml/consts.py +1 -1
  23. gr_libs-0.1.8/gr_libs/ml/neural/deep_rl_learner.py +474 -0
  24. {gr_libs-0.1.7.post0 → gr_libs-0.1.8}/gr_libs/ml/neural/utils/__init__.py +1 -1
  25. {gr_libs-0.1.7.post0 → gr_libs-0.1.8}/gr_libs/ml/neural/utils/dictlist.py +3 -3
  26. {gr_libs-0.1.7.post0 → gr_libs-0.1.8}/gr_libs/ml/neural/utils/penv.py +5 -2
  27. gr_libs-0.1.8/gr_libs/ml/planner/mcts/mcts_model.py +552 -0
  28. {gr_libs-0.1.7.post0 → gr_libs-0.1.8}/gr_libs/ml/planner/mcts/utils/__init__.py +1 -1
  29. {gr_libs-0.1.7.post0 → gr_libs-0.1.8}/gr_libs/ml/planner/mcts/utils/node.py +11 -7
  30. {gr_libs-0.1.7.post0 → gr_libs-0.1.8}/gr_libs/ml/planner/mcts/utils/tree.py +14 -10
  31. gr_libs-0.1.8/gr_libs/ml/sequential/__init__.py +1 -0
  32. gr_libs-0.1.8/gr_libs/ml/sequential/lstm_model.py +273 -0
  33. {gr_libs-0.1.7.post0 → gr_libs-0.1.8}/gr_libs/ml/tabular/state.py +7 -7
  34. {gr_libs-0.1.7.post0 → gr_libs-0.1.8}/gr_libs/ml/tabular/tabular_q_learner.py +123 -73
  35. {gr_libs-0.1.7.post0 → gr_libs-0.1.8}/gr_libs/ml/tabular/tabular_rl_agent.py +20 -19
  36. gr_libs-0.1.8/gr_libs/ml/utils/__init__.py +12 -0
  37. gr_libs-0.1.8/gr_libs/ml/utils/format.py +108 -0
  38. {gr_libs-0.1.7.post0 → gr_libs-0.1.8}/gr_libs/ml/utils/math.py +2 -1
  39. {gr_libs-0.1.7.post0 → gr_libs-0.1.8}/gr_libs/ml/utils/other.py +1 -1
  40. {gr_libs-0.1.7.post0 → gr_libs-0.1.8}/gr_libs/ml/utils/storage.py +88 -28
  41. gr_libs-0.1.8/gr_libs/problems/consts.py +1566 -0
  42. gr_libs-0.1.8/gr_libs/recognizer/gr_as_rl/gr_as_rl_recognizer.py +167 -0
  43. gr_libs-0.1.8/gr_libs/recognizer/graml/gr_dataset.py +233 -0
  44. gr_libs-0.1.8/gr_libs/recognizer/graml/graml_recognizer.py +465 -0
  45. gr_libs-0.1.8/gr_libs/recognizer/recognizer.py +56 -0
  46. gr_libs-0.1.8/gr_libs/recognizer/utils/__init__.py +1 -0
  47. {gr_libs-0.1.7.post0 → gr_libs-0.1.8}/gr_libs/recognizer/utils/format.py +8 -3
  48. {gr_libs-0.1.7.post0 → gr_libs-0.1.8}/gr_libs.egg-info/PKG-INFO +1 -1
  49. {gr_libs-0.1.7.post0 → gr_libs-0.1.8}/gr_libs.egg-info/SOURCES.txt +3 -0
  50. gr_libs-0.1.8/tests/test_gcdraco.py +10 -0
  51. {gr_libs-0.1.7.post0 → gr_libs-0.1.8}/tests/test_graml.py +8 -4
  52. {gr_libs-0.1.7.post0 → gr_libs-0.1.8}/tests/test_graql.py +2 -1
  53. gr_libs-0.1.8/tutorials/gcdraco_panda_tutorial.py +66 -0
  54. gr_libs-0.1.8/tutorials/gcdraco_parking_tutorial.py +61 -0
  55. gr_libs-0.1.8/tutorials/graml_minigrid_tutorial.py +64 -0
  56. {gr_libs-0.1.7.post0 → gr_libs-0.1.8}/tutorials/graml_panda_tutorial.py +35 -14
  57. gr_libs-0.1.8/tutorials/graml_parking_tutorial.py +56 -0
  58. gr_libs-0.1.8/tutorials/graml_point_maze_tutorial.py +59 -0
  59. gr_libs-0.1.8/tutorials/graql_minigrid_tutorial.py +50 -0
  60. gr_libs-0.1.7.post0/evaluation/analyze_results_cross_alg_cross_domain.py +0 -277
  61. gr_libs-0.1.7.post0/evaluation/generate_experiments_results.py +0 -92
  62. gr_libs-0.1.7.post0/evaluation/generate_experiments_results_new_ver1.py +0 -254
  63. gr_libs-0.1.7.post0/evaluation/generate_experiments_results_new_ver2.py +0 -331
  64. gr_libs-0.1.7.post0/evaluation/generate_task_specific_statistics_plots.py +0 -272
  65. gr_libs-0.1.7.post0/evaluation/get_plans_images.py +0 -47
  66. gr_libs-0.1.7.post0/evaluation/increasing_and_decreasing_.py +0 -63
  67. gr_libs-0.1.7.post0/gr_libs/environment/__init__.py +0 -22
  68. gr_libs-0.1.7.post0/gr_libs/environment/environment.py +0 -225
  69. gr_libs-0.1.7.post0/gr_libs/environment/utils/utils.py +0 -17
  70. gr_libs-0.1.7.post0/gr_libs/ml/neural/deep_rl_learner.py +0 -393
  71. gr_libs-0.1.7.post0/gr_libs/ml/planner/mcts/mcts_model.py +0 -330
  72. gr_libs-0.1.7.post0/gr_libs/ml/sequential/__init__.py +0 -1
  73. gr_libs-0.1.7.post0/gr_libs/ml/sequential/lstm_model.py +0 -192
  74. gr_libs-0.1.7.post0/gr_libs/ml/utils/__init__.py +0 -6
  75. gr_libs-0.1.7.post0/gr_libs/ml/utils/format.py +0 -100
  76. gr_libs-0.1.7.post0/gr_libs/problems/consts.py +0 -1244
  77. gr_libs-0.1.7.post0/gr_libs/recognizer/gr_as_rl/gr_as_rl_recognizer.py +0 -102
  78. gr_libs-0.1.7.post0/gr_libs/recognizer/graml/__init__.py +0 -0
  79. gr_libs-0.1.7.post0/gr_libs/recognizer/graml/gr_dataset.py +0 -134
  80. gr_libs-0.1.7.post0/gr_libs/recognizer/graml/graml_recognizer.py +0 -274
  81. gr_libs-0.1.7.post0/gr_libs/recognizer/recognizer.py +0 -45
  82. gr_libs-0.1.7.post0/gr_libs/recognizer/utils/__init__.py +0 -1
  83. gr_libs-0.1.7.post0/tutorials/graml_minigrid_tutorial.py +0 -34
  84. gr_libs-0.1.7.post0/tutorials/graml_parking_tutorial.py +0 -39
  85. gr_libs-0.1.7.post0/tutorials/graml_point_maze_tutorial.py +0 -39
  86. gr_libs-0.1.7.post0/tutorials/graql_minigrid_tutorial.py +0 -34
  87. {gr_libs-0.1.7.post0 → gr_libs-0.1.8}/README.md +0 -0
  88. {gr_libs-0.1.7.post0 → gr_libs-0.1.8}/gr_libs/environment/utils/__init__.py +0 -0
  89. {gr_libs-0.1.7.post0 → gr_libs-0.1.8}/gr_libs/ml/neural/__init__.py +0 -0
  90. {gr_libs-0.1.7.post0/gr_libs/metrics → gr_libs-0.1.8/gr_libs/ml/planner}/__init__.py +0 -0
  91. {gr_libs-0.1.7.post0/gr_libs/ml/planner → gr_libs-0.1.8/gr_libs/ml/planner/mcts}/__init__.py +0 -0
  92. {gr_libs-0.1.7.post0 → gr_libs-0.1.8}/gr_libs/ml/tabular/__init__.py +0 -0
  93. {gr_libs-0.1.7.post0 → gr_libs-0.1.8}/gr_libs/ml/utils/env.py +0 -0
  94. {gr_libs-0.1.7.post0/gr_libs/ml/planner/mcts → gr_libs-0.1.8/gr_libs/problems}/__init__.py +0 -0
  95. {gr_libs-0.1.7.post0/gr_libs/problems → gr_libs-0.1.8/gr_libs/recognizer}/__init__.py +0 -0
  96. {gr_libs-0.1.7.post0/gr_libs/recognizer → gr_libs-0.1.8/gr_libs/recognizer/gr_as_rl}/__init__.py +0 -0
  97. {gr_libs-0.1.7.post0/gr_libs/recognizer/gr_as_rl → gr_libs-0.1.8/gr_libs/recognizer/graml}/__init__.py +0 -0
  98. {gr_libs-0.1.7.post0 → gr_libs-0.1.8}/gr_libs.egg-info/dependency_links.txt +0 -0
  99. {gr_libs-0.1.7.post0 → gr_libs-0.1.8}/gr_libs.egg-info/requires.txt +0 -0
  100. {gr_libs-0.1.7.post0 → gr_libs-0.1.8}/gr_libs.egg-info/top_level.txt +0 -0
  101. {gr_libs-0.1.7.post0 → gr_libs-0.1.8}/pyproject.toml +0 -0
  102. {gr_libs-0.1.7.post0 → gr_libs-0.1.8}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gr_libs
3
- Version: 0.1.7.post0
3
+ Version: 0.1.8
4
4
  Summary: Package with goal recognition frameworks baselines
5
5
  Author: Ben Nageris
6
6
  Author-email: Matan Shamir <matan.shamir@live.biu.ac.il>, Osher Elhadad <osher.elhadad@live.biu.ac.il>
@@ -0,0 +1,267 @@
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)
@@ -2,21 +2,25 @@ from minigrid.wrappers import RGBImgPartialObsWrapper, ImgObsWrapper
2
2
  import numpy as np
3
3
  import gr_libs.ml as ml
4
4
  from minigrid.core.world_object import Wall
5
- #from q_table_plot import save_q_table_plot_image
5
+
6
+ # from q_table_plot import save_q_table_plot_image
6
7
  from gymnasium.envs.registration import register
7
8
 
8
9
  env_name = "MiniGrid-SimpleCrossingS13N4-DynamicGoal-5x9-v0"
9
10
  # create an agent and train it (if it is already trained, it will get q-table from cache)
10
- agent = ml.TabularQLearner(env_name='MiniGrid-Walls-13x13-v0',problem_name = "MiniGrid-SimpleCrossingS13N4-DynamicGoal-5x9-v0")
11
+ agent = ml.TabularQLearner(
12
+ env_name="MiniGrid-Walls-13x13-v0",
13
+ problem_name="MiniGrid-SimpleCrossingS13N4-DynamicGoal-5x9-v0",
14
+ )
11
15
  # agent.learn()
12
16
 
13
17
  # save_q_table_plot_image(agent.q_table, 15, 15, (10,7))
14
18
 
15
19
  # add to the steps list the step the trained agent would take on the env in every state according to the q_table
16
20
  env = agent.env
17
- env = RGBImgPartialObsWrapper(env) # Get pixel observations
18
- env = ImgObsWrapper(env) # Get rid of the 'mission' field
19
- obs, _ = env.reset() # This now produces an RGB tensor only
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
20
24
 
21
25
  img = env.get_frame()
22
26
 
@@ -24,7 +28,7 @@ img = env.get_frame()
24
28
  from PIL import Image
25
29
  import numpy as np
26
30
 
27
- image_pil = Image.fromarray(np.uint8(img)).convert('RGB')
31
+ image_pil = Image.fromarray(np.uint8(img)).convert("RGB")
28
32
  image_pil.save(r"{}.png".format(env_name))
29
33
 
30
34
  # ####### show image
@@ -4,26 +4,36 @@ import random
4
4
  import hashlib
5
5
  from typing import List
6
6
 
7
+
7
8
  def get_observations_path(env_name: str):
8
9
  return f"dataset/{env_name}/observations"
9
10
 
11
+
10
12
  def get_observations_paths(path: str):
11
13
  return [os.path.join(path, file_name) for file_name in os.listdir(path)]
12
14
 
15
+
13
16
  def create_partial_observabilities_files(env_name: str, observabilities: List[float]):
14
- with open(r"dataset/{env_name}/observations/obs1.0.pkl".format(env_name=env_name), "rb") as f:
17
+ with open(
18
+ r"dataset/{env_name}/observations/obs1.0.pkl".format(env_name=env_name), "rb"
19
+ ) as f:
15
20
  step_1_0 = dill.load(f)
16
21
 
17
- number_of_items_to_randomize = [int(observability * len(step_1_0)) for observability in observabilities]
22
+ number_of_items_to_randomize = [
23
+ int(observability * len(step_1_0)) for observability in observabilities
24
+ ]
18
25
  obs = []
19
26
  for items_to_randomize in number_of_items_to_randomize:
20
27
  obs.append(random.sample(step_1_0, items_to_randomize))
21
28
  for index, observability in enumerate(observabilities):
22
29
  partial_steps = obs[index]
23
- file_path = r"dataset/{env_name}/observations/obs{obs}.pkl".format(env_name=env_name, obs=observability)
30
+ file_path = r"dataset/{env_name}/observations/obs{obs}.pkl".format(
31
+ env_name=env_name, obs=observability
32
+ )
24
33
  with open(file_path, "wb+") as f:
25
34
  dill.dump(partial_steps, f)
26
-
35
+
36
+
27
37
  def md5(file_path: str):
28
38
  hash_md5 = hashlib.md5()
29
39
  with open(file_path, "rb") as f:
@@ -31,6 +41,7 @@ def md5(file_path: str):
31
41
  hash_md5.update(chunk)
32
42
  return hash_md5.hexdigest()
33
43
 
44
+
34
45
  def get_md5(file_path_list: List[str]):
35
46
  return [(file_path, md5(file_path=file_path)) for file_path in file_path_list]
36
47
 
@@ -39,4 +50,4 @@ def print_md5(file_path_list: List[str]):
39
50
  md5_of_observations = get_md5(file_path_list=file_path_list)
40
51
  for file_name, file_md5 in md5_of_observations:
41
52
  print(f"{file_name}:{file_md5}")
42
- print("")
53
+ print("")
@@ -0,0 +1,141 @@
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 gr_libs.ml.utils.storage import (
8
+ get_experiment_results_path,
9
+ set_global_storage_configs,
10
+ )
11
+ from scripts.generate_task_specific_statistics_plots import get_figures_dir_path
12
+
13
+
14
+ def gen_graph(
15
+ graph_name,
16
+ x_label_str,
17
+ tasks,
18
+ panda_env,
19
+ minigrid_env,
20
+ parking_env,
21
+ maze_env,
22
+ percentage,
23
+ ):
24
+
25
+ fragmented_accuracies = {
26
+ "graml": {
27
+ #'panda': [],
28
+ #'minigrid': [],
29
+ #'point_maze': [],
30
+ "parking": []
31
+ },
32
+ "graql": {
33
+ #'panda': [],
34
+ #'minigrid': [],
35
+ #'point_maze': [],
36
+ "parking": []
37
+ },
38
+ }
39
+
40
+ continuing_accuracies = copy.deepcopy(fragmented_accuracies)
41
+
42
+ # domains_envs = [('minigrid', minigrid_env), ('point_maze', maze_env), ('parking', parking_env)]
43
+ domains_envs = [("parking", parking_env)]
44
+
45
+ for partial_obs_type, accuracies, is_same_learn in zip(
46
+ ["fragmented", "continuing"],
47
+ [fragmented_accuracies, continuing_accuracies],
48
+ [False, True],
49
+ ):
50
+ for domain, env in domains_envs:
51
+ for task in tasks:
52
+ set_global_storage_configs(
53
+ recognizer_str="graml",
54
+ is_fragmented=partial_obs_type,
55
+ is_inference_same_length_sequences=True,
56
+ is_learn_same_length_sequences=is_same_learn,
57
+ )
58
+ graml_res_file_path = (
59
+ f"{get_experiment_results_path(domain, env, task)}.pkl"
60
+ )
61
+ set_global_storage_configs(
62
+ recognizer_str="graql", is_fragmented=partial_obs_type
63
+ )
64
+ graql_res_file_path = (
65
+ f"{get_experiment_results_path(domain, env, task)}.pkl"
66
+ )
67
+ if os.path.exists(graml_res_file_path):
68
+ with open(graml_res_file_path, "rb") as results_file:
69
+ results = dill.load(results_file)
70
+ accuracies["graml"][domain].append(
71
+ results[percentage]["accuracy"]
72
+ )
73
+ else:
74
+ assert (False, f"no file for {graml_res_file_path}")
75
+ if os.path.exists(graql_res_file_path):
76
+ with open(graql_res_file_path, "rb") as results_file:
77
+ results = dill.load(results_file)
78
+ accuracies["graql"][domain].append(
79
+ results[percentage]["accuracy"]
80
+ )
81
+ else:
82
+ assert (False, f"no file for {graql_res_file_path}")
83
+
84
+ def plot_accuracies(accuracies, partial_obs_type):
85
+ plt.figure(figsize=(10, 6))
86
+ colors = plt.cm.get_cmap(
87
+ "tab10", len(accuracies["graml"]) * len(accuracies["graml"]["parking"])
88
+ )
89
+
90
+ # Define different line styles for each algorithm
91
+ line_styles = {"graml": "-", "graql": "--"}
92
+ x_vals = np.arange(3, 8)
93
+ plt.xticks(x_vals)
94
+ plt.yticks(np.linspace(0, 1, 6))
95
+ plt.ylim([0, 1])
96
+ # Plot each domain-env pair's accuracies with different line styles for each algorithm
97
+ for alg in ["graml", "graql"]:
98
+ for idx, (domain, acc_values) in enumerate(accuracies[alg].items()):
99
+ if acc_values and len(acc_values) > 0: # Only plot if there are values
100
+ x_values = np.arange(3, len(acc_values) + 3)
101
+ plt.plot(
102
+ x_values,
103
+ acc_values,
104
+ marker="o",
105
+ linestyle=line_styles[alg],
106
+ color=colors(idx),
107
+ label=f"{alg}-{domain}-{partial_obs_type}-{percentage}",
108
+ )
109
+
110
+ # Set labels, title, and grid
111
+ plt.xlabel(x_label_str)
112
+ plt.ylabel("Accuracy")
113
+ plt.grid(True)
114
+
115
+ # Add legend to differentiate between domain-env pairs
116
+ plt.legend()
117
+
118
+ # Save the figure
119
+ fig_path = os.path.join(f"{graph_name}_{partial_obs_type}.png")
120
+ plt.savefig(fig_path)
121
+ print(f"Accuracies figure saved at: {fig_path}")
122
+
123
+ print(f"fragmented_accuracies: {fragmented_accuracies}")
124
+ plot_accuracies(fragmented_accuracies, "fragmented")
125
+ print(f"continuing_accuracies: {continuing_accuracies}")
126
+ plot_accuracies(continuing_accuracies, "continuing")
127
+
128
+
129
+ if __name__ == "__main__":
130
+ # gen_graph("increasing_base_goals", "Number of base goals", ['L1', 'L2', 'L3', 'L4', 'L5'], panda_env='gd_agent', minigrid_env='obstacles', parking_env='gd_agent', maze_env='obstacles')
131
+ # gen_graph("increasing_dynamic_goals", "Number of dynamic goals", ['L1', 'L2', 'L3', 'L4', 'L5'], panda_env='gc_agent', minigrid_env='lava_crossing', parking_env='gc_agent', maze_env='four_rooms')
132
+ gen_graph(
133
+ "base_problems",
134
+ "Number of goals",
135
+ ["L111", "L222", "L333", "L444", "L555"],
136
+ panda_env="gd_agent",
137
+ minigrid_env="obstacles",
138
+ parking_env="gc_agent",
139
+ maze_env="obstacles",
140
+ percentage="0.7",
141
+ )