gr-libs 0.1.3__tar.gz → 0.1.5__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 (80) hide show
  1. gr_libs-0.1.5/PKG-INFO +211 -0
  2. gr_libs-0.1.5/README.md +183 -0
  3. gr_libs-0.1.5/gr_libs/environment/__init__.py +22 -0
  4. {gr_libs-0.1.3 → gr_libs-0.1.5}/gr_libs/environment/environment.py +0 -2
  5. {gr_libs-0.1.3 → gr_libs-0.1.5}/gr_libs/ml/neural/deep_rl_learner.py +10 -12
  6. {gr_libs-0.1.3 → gr_libs-0.1.5}/gr_libs/recognizer/graml/graml_recognizer.py +1 -2
  7. {gr_libs-0.1.3 → gr_libs-0.1.5}/gr_libs/recognizer/recognizer.py +3 -3
  8. gr_libs-0.1.5/gr_libs/recognizer/recognizer_doc.md +61 -0
  9. gr_libs-0.1.5/gr_libs.egg-info/PKG-INFO +211 -0
  10. {gr_libs-0.1.3 → gr_libs-0.1.5}/gr_libs.egg-info/SOURCES.txt +1 -0
  11. gr_libs-0.1.5/gr_libs.egg-info/requires.txt +20 -0
  12. {gr_libs-0.1.3 → gr_libs-0.1.5}/pyproject.toml +14 -2
  13. {gr_libs-0.1.3 → gr_libs-0.1.5}/tutorials/graml_minigrid_tutorial.py +2 -2
  14. {gr_libs-0.1.3 → gr_libs-0.1.5}/tutorials/graml_panda_tutorial.py +9 -4
  15. gr_libs-0.1.5/tutorials/graml_parking_tutorial.py +34 -0
  16. gr_libs-0.1.5/tutorials/graml_point_maze_tutorial.py +35 -0
  17. gr_libs-0.1.3/PKG-INFO +0 -197
  18. gr_libs-0.1.3/README.md +0 -182
  19. gr_libs-0.1.3/gr_libs/recognizer/graml/__init__.py +0 -0
  20. gr_libs-0.1.3/gr_libs.egg-info/PKG-INFO +0 -197
  21. gr_libs-0.1.3/gr_libs.egg-info/requires.txt +0 -3
  22. gr_libs-0.1.3/tutorials/graml_parking_tutorial.py +0 -38
  23. gr_libs-0.1.3/tutorials/graml_point_maze_tutorial.py +0 -43
  24. {gr_libs-0.1.3 → gr_libs-0.1.5}/.github/workflows/release.yml +0 -0
  25. {gr_libs-0.1.3 → gr_libs-0.1.5}/.gitignore +0 -0
  26. {gr_libs-0.1.3 → gr_libs-0.1.5}/all_experiments.py +0 -0
  27. {gr_libs-0.1.3 → gr_libs-0.1.5}/consts.py +0 -0
  28. {gr_libs-0.1.3 → gr_libs-0.1.5}/evaluation/analyze_results_cross_alg_cross_domain.py +0 -0
  29. {gr_libs-0.1.3 → gr_libs-0.1.5}/evaluation/create_minigrid_map_image.py +0 -0
  30. {gr_libs-0.1.3 → gr_libs-0.1.5}/evaluation/file_system.py +0 -0
  31. {gr_libs-0.1.3 → gr_libs-0.1.5}/evaluation/generate_experiments_results.py +0 -0
  32. {gr_libs-0.1.3 → gr_libs-0.1.5}/evaluation/generate_experiments_results_new_ver1.py +0 -0
  33. {gr_libs-0.1.3 → gr_libs-0.1.5}/evaluation/generate_experiments_results_new_ver2.py +0 -0
  34. {gr_libs-0.1.3 → gr_libs-0.1.5}/evaluation/generate_task_specific_statistics_plots.py +0 -0
  35. {gr_libs-0.1.3 → gr_libs-0.1.5}/evaluation/get_plans_images.py +0 -0
  36. {gr_libs-0.1.3 → gr_libs-0.1.5}/evaluation/increasing_and_decreasing_.py +0 -0
  37. {gr_libs-0.1.3 → gr_libs-0.1.5}/gr_libs/__init__.py +0 -0
  38. {gr_libs-0.1.3/gr_libs/environment → gr_libs-0.1.5/gr_libs/environment/utils}/__init__.py +0 -0
  39. {gr_libs-0.1.3 → gr_libs-0.1.5}/gr_libs/environment/utils/utils.py +0 -0
  40. {gr_libs-0.1.3/gr_libs/environment/utils → gr_libs-0.1.5/gr_libs/metrics}/__init__.py +0 -0
  41. {gr_libs-0.1.3 → gr_libs-0.1.5}/gr_libs/metrics/metrics.py +0 -0
  42. {gr_libs-0.1.3 → gr_libs-0.1.5}/gr_libs/ml/__init__.py +0 -0
  43. {gr_libs-0.1.3 → gr_libs-0.1.5}/gr_libs/ml/agent.py +0 -0
  44. {gr_libs-0.1.3 → gr_libs-0.1.5}/gr_libs/ml/base/__init__.py +0 -0
  45. {gr_libs-0.1.3 → gr_libs-0.1.5}/gr_libs/ml/base/rl_agent.py +0 -0
  46. {gr_libs-0.1.3 → gr_libs-0.1.5}/gr_libs/ml/consts.py +0 -0
  47. {gr_libs-0.1.3 → gr_libs-0.1.5}/gr_libs/ml/neural/__init__.py +0 -0
  48. {gr_libs-0.1.3 → gr_libs-0.1.5}/gr_libs/ml/neural/utils/__init__.py +0 -0
  49. {gr_libs-0.1.3 → gr_libs-0.1.5}/gr_libs/ml/neural/utils/dictlist.py +0 -0
  50. {gr_libs-0.1.3 → gr_libs-0.1.5}/gr_libs/ml/neural/utils/penv.py +0 -0
  51. {gr_libs-0.1.3/gr_libs/metrics → gr_libs-0.1.5/gr_libs/ml/planner}/__init__.py +0 -0
  52. {gr_libs-0.1.3/gr_libs/ml/planner → gr_libs-0.1.5/gr_libs/ml/planner/mcts}/__init__.py +0 -0
  53. {gr_libs-0.1.3 → gr_libs-0.1.5}/gr_libs/ml/planner/mcts/mcts_model.py +0 -0
  54. {gr_libs-0.1.3 → gr_libs-0.1.5}/gr_libs/ml/planner/mcts/utils/__init__.py +0 -0
  55. {gr_libs-0.1.3 → gr_libs-0.1.5}/gr_libs/ml/planner/mcts/utils/node.py +0 -0
  56. {gr_libs-0.1.3 → gr_libs-0.1.5}/gr_libs/ml/planner/mcts/utils/tree.py +0 -0
  57. {gr_libs-0.1.3 → gr_libs-0.1.5}/gr_libs/ml/sequential/__init__.py +0 -0
  58. {gr_libs-0.1.3 → gr_libs-0.1.5}/gr_libs/ml/sequential/lstm_model.py +0 -0
  59. {gr_libs-0.1.3 → gr_libs-0.1.5}/gr_libs/ml/tabular/__init__.py +0 -0
  60. {gr_libs-0.1.3 → gr_libs-0.1.5}/gr_libs/ml/tabular/state.py +0 -0
  61. {gr_libs-0.1.3 → gr_libs-0.1.5}/gr_libs/ml/tabular/tabular_q_learner.py +0 -0
  62. {gr_libs-0.1.3 → gr_libs-0.1.5}/gr_libs/ml/tabular/tabular_rl_agent.py +0 -0
  63. {gr_libs-0.1.3 → gr_libs-0.1.5}/gr_libs/ml/utils/__init__.py +0 -0
  64. {gr_libs-0.1.3 → gr_libs-0.1.5}/gr_libs/ml/utils/env.py +0 -0
  65. {gr_libs-0.1.3 → gr_libs-0.1.5}/gr_libs/ml/utils/format.py +0 -0
  66. {gr_libs-0.1.3 → gr_libs-0.1.5}/gr_libs/ml/utils/math.py +0 -0
  67. {gr_libs-0.1.3 → gr_libs-0.1.5}/gr_libs/ml/utils/other.py +0 -0
  68. {gr_libs-0.1.3 → gr_libs-0.1.5}/gr_libs/ml/utils/storage.py +0 -0
  69. {gr_libs-0.1.3/gr_libs/ml/planner/mcts → gr_libs-0.1.5/gr_libs/recognizer}/__init__.py +0 -0
  70. {gr_libs-0.1.3/gr_libs/recognizer → gr_libs-0.1.5/gr_libs/recognizer/gr_as_rl}/__init__.py +0 -0
  71. {gr_libs-0.1.3 → gr_libs-0.1.5}/gr_libs/recognizer/gr_as_rl/gr_as_rl_recognizer.py +0 -0
  72. {gr_libs-0.1.3/gr_libs/recognizer/gr_as_rl → gr_libs-0.1.5/gr_libs/recognizer/graml}/__init__.py +0 -0
  73. {gr_libs-0.1.3 → gr_libs-0.1.5}/gr_libs/recognizer/graml/gr_dataset.py +0 -0
  74. {gr_libs-0.1.3 → gr_libs-0.1.5}/gr_libs/recognizer/utils/__init__.py +0 -0
  75. {gr_libs-0.1.3 → gr_libs-0.1.5}/gr_libs/recognizer/utils/format.py +0 -0
  76. {gr_libs-0.1.3 → gr_libs-0.1.5}/gr_libs.egg-info/dependency_links.txt +0 -0
  77. {gr_libs-0.1.3 → gr_libs-0.1.5}/gr_libs.egg-info/top_level.txt +0 -0
  78. {gr_libs-0.1.3 → gr_libs-0.1.5}/odgr_executor.py +0 -0
  79. {gr_libs-0.1.3 → gr_libs-0.1.5}/setup.cfg +0 -0
  80. {gr_libs-0.1.3 → gr_libs-0.1.5}/tutorials/graql_minigrid_tutorial.py +0 -0
gr_libs-0.1.5/PKG-INFO ADDED
@@ -0,0 +1,211 @@
1
+ Metadata-Version: 2.4
2
+ Name: gr_libs
3
+ Version: 0.1.5
4
+ Summary: Package with goal recognition frameworks baselines
5
+ Author: Ben Nageris
6
+ Author-email: Matan Shamir <matan.shamir@live.biu.ac.il>, Osher Elhadad <osher.elhadad@live.biu.ac.il>
7
+ License-Expression: MIT
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Operating System :: OS Independent
10
+ Requires-Python: >=3.11
11
+ Description-Content-Type: text/markdown
12
+ Requires-Dist: gr_envs
13
+ Requires-Dist: dill
14
+ Requires-Dist: opencv-python
15
+ Requires-Dist: tensorboardX
16
+ Requires-Dist: torchvision
17
+ Requires-Dist: rl_zoo3
18
+ Requires-Dist: stable_baselines3[extra]
19
+ Requires-Dist: sb3_contrib
20
+ Provides-Extra: minigrid
21
+ Requires-Dist: gr_envs[minigrid]; extra == "minigrid"
22
+ Provides-Extra: highway
23
+ Requires-Dist: gr_envs[highway]; extra == "highway"
24
+ Provides-Extra: maze
25
+ Requires-Dist: gr_envs[maze]; extra == "maze"
26
+ Provides-Extra: panda
27
+ Requires-Dist: gr_envs[panda]; extra == "panda"
28
+
29
+ # GRLib
30
+ GRLib is a Python package that implements Goal Recognition (GR) algorithms using Markov Decision Processes (MDPs) to model decision-making processes. These implementations adhere to the Gymnasium API. All agents in these algorithms interact with environments registered to the Gym API as part of the initialization process of the `gr_envs` package, on which GRLib depends. More details on `gr_envs` can be found at: [GR Envs Repository](https://github.com/MatanShamir1/GREnvs).
31
+
32
+ ## Setup
33
+
34
+ **Note:** If you are using Windows, use Git Bash for the following commands. Otherwise, any terminal or shell will work.
35
+
36
+ `gr_libs` depends on `gr_envs`, which registers a set of Gym environments. Ensure your Python environment is set up with Python >= 3.11.
37
+
38
+ ### Setting Up a Python Environment (if needed)
39
+ #### Using Pip
40
+ 1. **Find Your Python Installation:**
41
+ To locate your Python 3.12 executable, run:
42
+ ```sh
43
+ py -3.12 -c "import sys; print(sys.executable)"
44
+ ```
45
+ 2. **Create a New Virtual Environment:**
46
+ Using the path found above, create a new empty venv:
47
+ ```sh
48
+ C:/Users/path/to/Programs/Python/Python312/python.exe -m venv test_env
49
+ ```
50
+ 3. **Activate the Virtual Environment:**
51
+ ```sh
52
+ source test_env/Scripts/activate
53
+ ```
54
+ 4. **Verify the Active Environment:**
55
+ Since there is no direct equivalent to `conda env list`, you can check your active environment via:
56
+ ```sh
57
+ echo $VIRTUAL_ENV
58
+ ```
59
+
60
+ #### Using Conda
61
+ If you prefer using Conda, follow these steps:
62
+
63
+ 1. **Create a New Conda Environment:**
64
+ Replace `3.12` with your desired Python version if necessary.
65
+ ```sh
66
+ conda create -n new_env python=3.12
67
+ ```
68
+ 2. **Activate the Environment:**
69
+ ```sh
70
+ conda activate new_env
71
+ ```
72
+
73
+
74
+ ### Upgrade Basic Package Management Modules:
75
+ Run the following command (replace `/path/to/python.exe` with the actual path):
76
+ ```sh
77
+ /path/to/python.exe -m pip install --upgrade pip setuptools wheel versioneer
78
+ ```
79
+ ### Install the `GoalRecognitionLibs` Package:
80
+ The extras install the custom environments defined in `gr_envs`.
81
+ (For editable installation, add the `-e` flag by cloning the repo and cd'ing to it https://github.com/MatanShamir1/GRLib.git)
82
+ - **Minigrid Environment:**
83
+ ```sh
84
+ pip install gr_libs[minigrid]
85
+ ```
86
+ - **Highway Environment (Parking):**
87
+ ```sh
88
+ pip install gr_libs[highway]
89
+ ```
90
+ - **Maze Environment (Point-Maze):**
91
+ ```sh
92
+ pip install gr_libs[maze]
93
+ ```
94
+ - **Panda Environment:**
95
+ ```sh
96
+ pip install gr_libs[panda]
97
+ ```
98
+ (For editable installation, add the `-e` flag.)
99
+ ```sh
100
+ cd /path/to/clone/of/GoalRecognitionLibs
101
+ pip install -e .
102
+ ```
103
+
104
+ ## Issues & Troubleshooting
105
+
106
+ For any issues or troubleshooting, please refer to the repository's issue tracker.
107
+
108
+ ## Usage Guide
109
+
110
+ After installing GRLib, you will have access to custom Gym environments, allowing you to set up and execute an Online Dynamic Goal Recognition (ODGR) scenario with the algorithm of your choice.
111
+
112
+ Tutorials demonstrating basic ODGR scenarios is available in the sub-package `tutorials`. These tutorials walk through the initialization and deployment process, showcasing how different GR algorithms adapt to emerging goals in various Gym environments.
113
+
114
+ ### Method 1: Writing a Custom Script
115
+
116
+ 1. **Create a recognizer**
117
+
118
+ Specify the domain name and specific environment for the recognizer, effectively telling it the domain theory - the collection of states and actions in the environment.
119
+
120
+ ```python
121
+ recognizer = Graql(
122
+ domain_name="minigrid",
123
+ env_name="MiniGrid-SimpleCrossingS13N4"
124
+ )
125
+ ```
126
+
127
+ 2. **Domain Learning Phase** (For GRAQL)
128
+
129
+ GRAQL does not accumulate information about the domain or engage in learning activities during this phase.
130
+ Other algorithms don't require any data for the phase and simply use what's provided in their intialization: the domain and environment specifics, excluding the possible goals.
131
+
132
+ 3. **Goal Adaptation Phase**
133
+
134
+ The recognizer receives new goals and corresponding training configurations. GRAQL trains goal-directed agents and stores their policies for inference.
135
+
136
+ ```python
137
+ recognizer.goals_adaptation_phase(
138
+ dynamic_goals=[(11,1), (11,11), (1,11)],
139
+ dynamic_train_configs=[(QLEARNING, 100000) for _ in range(3)] # For expert sequence generation
140
+ )
141
+ ```
142
+
143
+ 4. **Inference Phase**
144
+
145
+ This phase generates a partial sequence from a trained agent, simulating suboptimal behavior with Gaussian noise.
146
+
147
+ ```python
148
+ actor = TabularQLearner(
149
+ domain_name="minigrid",
150
+ problem_name="MiniGrid-SimpleCrossingS13N4-DynamicGoal-11x1-v0",
151
+ algorithm=QLEARNING,
152
+ num_timesteps=100000
153
+ )
154
+ actor.learn()
155
+ full_sequence = actor.generate_observation(
156
+ action_selection_method=stochastic_amplified_selection,
157
+ random_optimalism=True # Adds noise to action values
158
+ )
159
+ partial_sequence = random_subset_with_order(full_sequence, int(0.5 * len(full_sequence)), is_consecutive=False)
160
+ closest_goal = recognizer.inference_phase(partial_sequence, (11,1), 0.5)
161
+ ```
162
+
163
+ 5. **Evaluate the result**
164
+
165
+ ```python
166
+ print(f"Closest goal returned by Graql: {closest_goal}\nActual goal actor aimed towards: (11, 1)")
167
+ ```
168
+
169
+ ### Method 2: Using a Configuration File
170
+
171
+ The `consts.py` file contains predefined ODGR problem configurations. You can use existing configurations or define new ones.
172
+
173
+ To execute a single task using the configuration file:
174
+ ```sh
175
+ python odgr_executor.py --recognizer MCTSBasedGraml --domain minigrid --task L1 --minigrid_env MinigridSimple
176
+ ```
177
+
178
+ ## Supported Algorithms
179
+
180
+ Successors of algorithms that don't differ in their specifics are added in parentheses after the algorithm name. For example, since GC-DRACO and DRACO share the same column values, they're written on one line as DRACO (GC).
181
+
182
+ | **Algorithm** | **Supervised** | **Reinforcement Learning** | **Discrete States** | **Continuous States** | **Discrete Actions** | **Continuous Actions** | **Model-Based** | **Model-Free** | **Action-Only** |
183
+ |--------------|--------------|------------------------|------------------|------------------|--------------|--------------|--------------|--------------|--------------|
184
+ | GRAQL | ❌ | ✅ | ✅ | ❌ | ✅ | ❌ | ❌ | ✅ | ❌ |
185
+ | DRACO (GC) | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ | ❌ |
186
+ | GRAML (GC, BG) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ |
187
+
188
+ ## Supported Domains
189
+
190
+ | **Domain** | **Action Space** | **State Space** |
191
+ |------------|----------------|----------------|
192
+ | Minigrid | Discrete | Discrete |
193
+ | PointMaze | Continuous | Continuous |
194
+ | Parking | Continuous | Continuous |
195
+ | Panda | Continuous | Continuous |
196
+
197
+ ## Running Experiments
198
+
199
+ The repository provides benchmark domains and scripts for analyzing experimental results. The `scripts` directory contains tools for processing and visualizing results.
200
+
201
+ 1. **`analyze_results_cross_alg_cross_domain.py`**
202
+ - Runs without arguments.
203
+ - Reads data from `get_experiment_results_path` (e.g., `dataset/graml/minigrid/continuing/.../experiment_results.pkl`).
204
+ - Generates plots comparing algorithm performance across domains.
205
+
206
+ 2. **`generate_task_specific_statistics_plots.py`**
207
+ - Produces task-specific accuracy and confidence plots.
208
+ - Generates a confusion matrix displaying confidence levels.
209
+ - Example output paths:
210
+ - `figures/point_maze/obstacles/graql_point_maze_obstacles_fragmented_stats.png`
211
+ - `figures/point_maze/obstacles/graml_point_maze_obstacles_conf_mat.png`
@@ -0,0 +1,183 @@
1
+ # GRLib
2
+ GRLib is a Python package that implements Goal Recognition (GR) algorithms using Markov Decision Processes (MDPs) to model decision-making processes. These implementations adhere to the Gymnasium API. All agents in these algorithms interact with environments registered to the Gym API as part of the initialization process of the `gr_envs` package, on which GRLib depends. More details on `gr_envs` can be found at: [GR Envs Repository](https://github.com/MatanShamir1/GREnvs).
3
+
4
+ ## Setup
5
+
6
+ **Note:** If you are using Windows, use Git Bash for the following commands. Otherwise, any terminal or shell will work.
7
+
8
+ `gr_libs` depends on `gr_envs`, which registers a set of Gym environments. Ensure your Python environment is set up with Python >= 3.11.
9
+
10
+ ### Setting Up a Python Environment (if needed)
11
+ #### Using Pip
12
+ 1. **Find Your Python Installation:**
13
+ To locate your Python 3.12 executable, run:
14
+ ```sh
15
+ py -3.12 -c "import sys; print(sys.executable)"
16
+ ```
17
+ 2. **Create a New Virtual Environment:**
18
+ Using the path found above, create a new empty venv:
19
+ ```sh
20
+ C:/Users/path/to/Programs/Python/Python312/python.exe -m venv test_env
21
+ ```
22
+ 3. **Activate the Virtual Environment:**
23
+ ```sh
24
+ source test_env/Scripts/activate
25
+ ```
26
+ 4. **Verify the Active Environment:**
27
+ Since there is no direct equivalent to `conda env list`, you can check your active environment via:
28
+ ```sh
29
+ echo $VIRTUAL_ENV
30
+ ```
31
+
32
+ #### Using Conda
33
+ If you prefer using Conda, follow these steps:
34
+
35
+ 1. **Create a New Conda Environment:**
36
+ Replace `3.12` with your desired Python version if necessary.
37
+ ```sh
38
+ conda create -n new_env python=3.12
39
+ ```
40
+ 2. **Activate the Environment:**
41
+ ```sh
42
+ conda activate new_env
43
+ ```
44
+
45
+
46
+ ### Upgrade Basic Package Management Modules:
47
+ Run the following command (replace `/path/to/python.exe` with the actual path):
48
+ ```sh
49
+ /path/to/python.exe -m pip install --upgrade pip setuptools wheel versioneer
50
+ ```
51
+ ### Install the `GoalRecognitionLibs` Package:
52
+ The extras install the custom environments defined in `gr_envs`.
53
+ (For editable installation, add the `-e` flag by cloning the repo and cd'ing to it https://github.com/MatanShamir1/GRLib.git)
54
+ - **Minigrid Environment:**
55
+ ```sh
56
+ pip install gr_libs[minigrid]
57
+ ```
58
+ - **Highway Environment (Parking):**
59
+ ```sh
60
+ pip install gr_libs[highway]
61
+ ```
62
+ - **Maze Environment (Point-Maze):**
63
+ ```sh
64
+ pip install gr_libs[maze]
65
+ ```
66
+ - **Panda Environment:**
67
+ ```sh
68
+ pip install gr_libs[panda]
69
+ ```
70
+ (For editable installation, add the `-e` flag.)
71
+ ```sh
72
+ cd /path/to/clone/of/GoalRecognitionLibs
73
+ pip install -e .
74
+ ```
75
+
76
+ ## Issues & Troubleshooting
77
+
78
+ For any issues or troubleshooting, please refer to the repository's issue tracker.
79
+
80
+ ## Usage Guide
81
+
82
+ After installing GRLib, you will have access to custom Gym environments, allowing you to set up and execute an Online Dynamic Goal Recognition (ODGR) scenario with the algorithm of your choice.
83
+
84
+ Tutorials demonstrating basic ODGR scenarios is available in the sub-package `tutorials`. These tutorials walk through the initialization and deployment process, showcasing how different GR algorithms adapt to emerging goals in various Gym environments.
85
+
86
+ ### Method 1: Writing a Custom Script
87
+
88
+ 1. **Create a recognizer**
89
+
90
+ Specify the domain name and specific environment for the recognizer, effectively telling it the domain theory - the collection of states and actions in the environment.
91
+
92
+ ```python
93
+ recognizer = Graql(
94
+ domain_name="minigrid",
95
+ env_name="MiniGrid-SimpleCrossingS13N4"
96
+ )
97
+ ```
98
+
99
+ 2. **Domain Learning Phase** (For GRAQL)
100
+
101
+ GRAQL does not accumulate information about the domain or engage in learning activities during this phase.
102
+ Other algorithms don't require any data for the phase and simply use what's provided in their intialization: the domain and environment specifics, excluding the possible goals.
103
+
104
+ 3. **Goal Adaptation Phase**
105
+
106
+ The recognizer receives new goals and corresponding training configurations. GRAQL trains goal-directed agents and stores their policies for inference.
107
+
108
+ ```python
109
+ recognizer.goals_adaptation_phase(
110
+ dynamic_goals=[(11,1), (11,11), (1,11)],
111
+ dynamic_train_configs=[(QLEARNING, 100000) for _ in range(3)] # For expert sequence generation
112
+ )
113
+ ```
114
+
115
+ 4. **Inference Phase**
116
+
117
+ This phase generates a partial sequence from a trained agent, simulating suboptimal behavior with Gaussian noise.
118
+
119
+ ```python
120
+ actor = TabularQLearner(
121
+ domain_name="minigrid",
122
+ problem_name="MiniGrid-SimpleCrossingS13N4-DynamicGoal-11x1-v0",
123
+ algorithm=QLEARNING,
124
+ num_timesteps=100000
125
+ )
126
+ actor.learn()
127
+ full_sequence = actor.generate_observation(
128
+ action_selection_method=stochastic_amplified_selection,
129
+ random_optimalism=True # Adds noise to action values
130
+ )
131
+ partial_sequence = random_subset_with_order(full_sequence, int(0.5 * len(full_sequence)), is_consecutive=False)
132
+ closest_goal = recognizer.inference_phase(partial_sequence, (11,1), 0.5)
133
+ ```
134
+
135
+ 5. **Evaluate the result**
136
+
137
+ ```python
138
+ print(f"Closest goal returned by Graql: {closest_goal}\nActual goal actor aimed towards: (11, 1)")
139
+ ```
140
+
141
+ ### Method 2: Using a Configuration File
142
+
143
+ The `consts.py` file contains predefined ODGR problem configurations. You can use existing configurations or define new ones.
144
+
145
+ To execute a single task using the configuration file:
146
+ ```sh
147
+ python odgr_executor.py --recognizer MCTSBasedGraml --domain minigrid --task L1 --minigrid_env MinigridSimple
148
+ ```
149
+
150
+ ## Supported Algorithms
151
+
152
+ Successors of algorithms that don't differ in their specifics are added in parentheses after the algorithm name. For example, since GC-DRACO and DRACO share the same column values, they're written on one line as DRACO (GC).
153
+
154
+ | **Algorithm** | **Supervised** | **Reinforcement Learning** | **Discrete States** | **Continuous States** | **Discrete Actions** | **Continuous Actions** | **Model-Based** | **Model-Free** | **Action-Only** |
155
+ |--------------|--------------|------------------------|------------------|------------------|--------------|--------------|--------------|--------------|--------------|
156
+ | GRAQL | ❌ | ✅ | ✅ | ❌ | ✅ | ❌ | ❌ | ✅ | ❌ |
157
+ | DRACO (GC) | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ | ❌ |
158
+ | GRAML (GC, BG) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ |
159
+
160
+ ## Supported Domains
161
+
162
+ | **Domain** | **Action Space** | **State Space** |
163
+ |------------|----------------|----------------|
164
+ | Minigrid | Discrete | Discrete |
165
+ | PointMaze | Continuous | Continuous |
166
+ | Parking | Continuous | Continuous |
167
+ | Panda | Continuous | Continuous |
168
+
169
+ ## Running Experiments
170
+
171
+ The repository provides benchmark domains and scripts for analyzing experimental results. The `scripts` directory contains tools for processing and visualizing results.
172
+
173
+ 1. **`analyze_results_cross_alg_cross_domain.py`**
174
+ - Runs without arguments.
175
+ - Reads data from `get_experiment_results_path` (e.g., `dataset/graml/minigrid/continuing/.../experiment_results.pkl`).
176
+ - Generates plots comparing algorithm performance across domains.
177
+
178
+ 2. **`generate_task_specific_statistics_plots.py`**
179
+ - Produces task-specific accuracy and confidence plots.
180
+ - Generates a confusion matrix displaying confidence levels.
181
+ - Example output paths:
182
+ - `figures/point_maze/obstacles/graql_point_maze_obstacles_fragmented_stats.png`
183
+ - `figures/point_maze/obstacles/graml_point_maze_obstacles_conf_mat.png`
@@ -0,0 +1,22 @@
1
+ import importlib.metadata
2
+ import warnings
3
+
4
+ def is_extra_installed(package: str, extra: str) -> bool:
5
+ """Check if an extra was installed for a given package."""
6
+ try:
7
+ # Get metadata for the installed package
8
+ dist = importlib.metadata.metadata(package)
9
+ requires = dist.get_all("Requires-Dist", []) # Dependencies listed in the package metadata
10
+ return any(extra in req for req in requires)
11
+ except importlib.metadata.PackageNotFoundError:
12
+ return False # The package is not installed
13
+
14
+ # Check if `gr_libs[minigrid]` was installed
15
+ for env in ["minigrid", "panda", "parking", "point_maze"]:
16
+ if is_extra_installed("gr_libs", f"gr_envs[{env}]"):
17
+ try:
18
+ importlib.import_module(f"gr_envs.{env}_scripts.envs")
19
+ except ImportError:
20
+ raise ImportError(f"gr_libs[{env}] was not installed, but gr_libs[{env}] requires it! if you messed with gr_libs installation, you can reinstall gr_libs.")
21
+ else:
22
+ warnings.warn(f"gr_libs[{env}] was not installed, skipping {env} imports.", RuntimeWarning)
@@ -168,8 +168,6 @@ class PandaProperty(GCEnvProperty):
168
168
 
169
169
 
170
170
  class ParkingProperty(GCEnvProperty):
171
- # def str_to_goal(self): # TODO not use it, goal is not a part of the env property anymore.
172
- # return self.name.split("-")[-2]
173
171
 
174
172
  def __init__(self, name):
175
173
  super().__init__(name)
@@ -13,11 +13,6 @@ if __name__ != "__main__":
13
13
  from gr_libs.ml.utils.format import random_subset_with_order
14
14
  from stable_baselines3 import SAC, PPO
15
15
  from stable_baselines3.common.vec_env import DummyVecEnv
16
- from gr_envs.custom_env_wrappers.flat_obs_wrapper import CombineAchievedGoalAndObservationWrapper
17
-
18
- # important for registration of envs! do not remove lad
19
- import gr_envs.maze_scripts.envs.maze
20
- import gr_envs.highway_env_scripts.envs.parking_env
21
16
  from gr_libs.ml.utils import device
22
17
 
23
18
  # built-in python modules
@@ -32,13 +27,15 @@ def create_vec_env(kwargs):
32
27
  return DummyVecEnv([lambda: env])
33
28
 
34
29
  def change_goal_to_specific_desired(obs, desired):
35
- try:
36
- if desired!=None: obs['desired_goal'] = desired
37
- except Exception as e:
38
- try:
39
- if all(desired!=None): obs['desired_goal'] = desired
40
- except Exception as e:
41
- if all([desiredy!=None for desiredish in desired for desiredy in desiredish]): obs['desired_goal'] = desired
30
+ if desired is not None:
31
+ obs['desired_goal'] = desired
32
+ # try:
33
+ # if desired!=None: obs['desired_goal'] = desired
34
+ # except Exception as e:
35
+ # try:
36
+ # if all(desired!=None): obs['desired_goal'] = desired
37
+ # except Exception as e:
38
+ # if all([desiredy!=None for desiredish in desired for desiredy in desiredish]): obs['desired_goal'] = desired
42
39
 
43
40
 
44
41
  NETWORK_SETUP = {
@@ -265,6 +262,7 @@ class DeepRLAgent():
265
262
  assert fig_path == None, "You can't specify a vid path when you don't even save the figure."
266
263
  else:
267
264
  assert fig_path != None, "You need to specify a vid path when you save the figure."
265
+ # The try-except is a bug fix for the env not being reset properly in panda. If someone wants to check why and provide a robust solution they're welcome.
268
266
  try:
269
267
  obs = self.env.reset()
270
268
  change_goal_to_specific_desired(obs, desired)
@@ -103,7 +103,6 @@ class Graml(LearningRecognizer):
103
103
  self.plans_dict[f"{true_goal}_true"] = true_sequence
104
104
 
105
105
  with open(embeddings_path + f'/{true_goal}_{percentage}_plans_dict.pkl', 'wb') as plans_file:
106
- # TODO erase AGENT_BASED macros
107
106
  to_dump = {}
108
107
  for goal, obss in self.plans_dict.items():
109
108
  if goal == f"{true_goal}_true":
@@ -243,7 +242,7 @@ class GCGraml(Graml, GaAdaptingRecognizer):
243
242
  if num_timesteps != None: kwargs["num_timesteps"] = num_timesteps
244
243
  gc_agent = self.rl_agent_type(**kwargs)
245
244
  gc_agent.learn()
246
- self.agents.append(ContextualAgent(problem_name=self.env_prop.name, problem_goal="general", agent=gc_agent)) # TODO change
245
+ self.agents.append(ContextualAgent(problem_name=self.env_prop.name, problem_goal="general", agent=gc_agent))
247
246
 
248
247
  def generate_sequences_library(self, goal: str) -> List[List[Tuple[np.ndarray, np.ndarray]]]:
249
248
  problem_name = self.env_prop.goal_to_problem_str(goal)
@@ -18,7 +18,7 @@ class Recognizer(ABC):
18
18
  def inference_phase(self, inf_sequence, true_goal, percentage) -> str:
19
19
  pass
20
20
 
21
- class LearningRecognizer(Recognizer): # TODO add a class diagram with the inheritance of all calsses
21
+ class LearningRecognizer(Recognizer):
22
22
  def __init__(self, *args, **kwargs):
23
23
  super().__init__(*args, **kwargs)
24
24
 
@@ -26,7 +26,7 @@ class LearningRecognizer(Recognizer): # TODO add a class diagram with the inheri
26
26
  self.original_train_configs = train_configs
27
27
 
28
28
  # a recognizer that needs to train agents for every new goal as part of the goal adaptation phase (that's why it needs dynamic train configs)
29
- class GaAgentTrainerRecognizer(Recognizer): # TODO add a class diagram with the inheritance of all calsses
29
+ class GaAgentTrainerRecognizer(Recognizer):
30
30
  def __init__(self, *args, **kwargs):
31
31
  super().__init__(*args, **kwargs)
32
32
 
@@ -37,7 +37,7 @@ class GaAgentTrainerRecognizer(Recognizer): # TODO add a class diagram with the
37
37
  def domain_learning_phase(self, base_goals: List[str], train_configs: List):
38
38
  super().domain_learning_phase(base_goals, train_configs)
39
39
 
40
- class GaAdaptingRecognizer(Recognizer): # TODO add a class diagram with the inheritance of all calsses
40
+ class GaAdaptingRecognizer(Recognizer):
41
41
  def __init__(self, *args, **kwargs):
42
42
  super().__init__(*args, **kwargs)
43
43
 
@@ -0,0 +1,61 @@
1
+ # Recognizer Module Documentation
2
+
3
+ This document provides an overview of the recognizer module, including its class hierarchy and instructions for adding a new class of recognizer.
4
+
5
+ ## Class Hierarchy
6
+
7
+ The recognizer module consists of an abstract base class `Recognizer` and several derived classes, each implementing specific behaviors. The main classes are:
8
+
9
+ 1. **Recognizer (Abstract Base Class)**
10
+ - `inference_phase()` (abstract method)
11
+
12
+ 2. **LearningRecognizer (Extends Recognizer)**
13
+ - `domain_learning_phase()`
14
+
15
+ 3. **GaAgentTrainerRecognizer (Extends Recognizer)**
16
+ - `goals_adaptation_phase()` (abstract method)
17
+ - `domain_learning_phase()`
18
+
19
+ 4. **GaAdaptingRecognizer (Extends Recognizer)**
20
+ - `goals_adaptation_phase()` (abstract method)
21
+
22
+ 5. **GRAsRL (Extends Recognizer)**
23
+ - Implements `goals_adaptation_phase()`
24
+ - Implements `inference_phase()`
25
+
26
+ 6. **Specific Implementations:**
27
+ - `Graql (Extends GRAsRL, GaAgentTrainerRecognizer)`
28
+ - `Draco (Extends GRAsRL, GaAgentTrainerRecognizer)`
29
+ - `GCDraco (Extends GRAsRL, LearningRecognizer, GaAdaptingRecognizer)`
30
+ - `Graml (Extends LearningRecognizer)`
31
+
32
+ ## How to Add a New Recognizer Class
33
+
34
+ To add a new class of recognizer, follow these steps:
35
+
36
+ 1. **Determine the Type of Recognizer:**
37
+ - Will it require learning? Extend `LearningRecognizer`.
38
+ - Will it adapt goals dynamically? Extend `GaAdaptingRecognizer`.
39
+ - Will it train agents for new goals? Extend `GaAgentTrainerRecognizer`.
40
+ - Will it involve RL-based recognition? Extend `GRAsRL`.
41
+
42
+ 2. **Define the Class:**
43
+ - Create a new class that extends the appropriate base class(es).
44
+ - Implement the required abstract methods (`inference_phase()`, `goals_adaptation_phase()`, etc.).
45
+
46
+ 3. **Initialize the Recognizer:**
47
+ - Ensure proper initialization by calling `super().__init__(*args, **kwargs)`.
48
+ - Set up any necessary agent storage or evaluation functions.
49
+
50
+ 4. **Implement Core Methods:**
51
+ - Define how the recognizer processes inference sequences.
52
+ - Implement learning or goal adaptation logic if applicable.
53
+
54
+ 5. **Register the Recognizer:**
55
+ - Ensure it integrates properly with the existing system by using the correct `domain_to_env_property()`.
56
+
57
+ 6. **Test the New Recognizer:**
58
+ - Run experiments to validate its behavior.
59
+ - Compare results against existing recognizers to ensure correctness.
60
+
61
+ By following these steps, you can seamlessly integrate a new recognizer into the framework while maintaining compatibility with the existing structure.