gr-libs 0.1.3__py3-none-any.whl → 0.1.4__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.
- gr_libs/recognizer/recognizer_doc.md +61 -0
- gr_libs-0.1.4.dist-info/METADATA +211 -0
- {gr_libs-0.1.3.dist-info → gr_libs-0.1.4.dist-info}/RECORD +5 -4
- {gr_libs-0.1.3.dist-info → gr_libs-0.1.4.dist-info}/WHEEL +1 -1
- gr_libs-0.1.3.dist-info/METADATA +0 -197
- {gr_libs-0.1.3.dist-info → gr_libs-0.1.4.dist-info}/top_level.txt +0 -0
@@ -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.
|
@@ -0,0 +1,211 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: gr_libs
|
3
|
+
Version: 0.1.4
|
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`
|
@@ -44,6 +44,7 @@ gr_libs/ml/utils/other.py,sha256=HKUfeLBbd4DgJxSTs3ya9KQ85Acx4TjycRrtGD9WQ3s,505
|
|
44
44
|
gr_libs/ml/utils/storage.py,sha256=oCdvL_ypCglnSJsyyXzNyV_UJASTfioa3yJhFlFso64,4277
|
45
45
|
gr_libs/recognizer/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
46
46
|
gr_libs/recognizer/recognizer.py,sha256=ysJYOGe5OlERMAeMwclKpwqw2tQvbSvGnLZrq4qP0xk,1895
|
47
|
+
gr_libs/recognizer/recognizer_doc.md,sha256=RnTvbZhl2opvU7-QT4pULCV5HCdJTw2dsu8WQOOiR3E,2521
|
47
48
|
gr_libs/recognizer/gr_as_rl/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
48
49
|
gr_libs/recognizer/gr_as_rl/gr_as_rl_recognizer.py,sha256=84GdfohC2dZoNH_QEo7GpSt8nZWdfqSRKCTY99X_iME,5215
|
49
50
|
gr_libs/recognizer/graml/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -56,7 +57,7 @@ tutorials/graml_panda_tutorial.py,sha256=DuHVDLe49qwgWouLxwalqdT1P4dlNOOMdgDc3oc
|
|
56
57
|
tutorials/graml_parking_tutorial.py,sha256=sQ496DNuAo9GZ_0iUZ_6Hqe5zFxIYZ_pBIHQscQvR4o,2501
|
57
58
|
tutorials/graml_point_maze_tutorial.py,sha256=TnLT9FdDj6AF8lm0lDIZum4ouPE5rye4RBH8z4Exj2Y,2713
|
58
59
|
tutorials/graql_minigrid_tutorial.py,sha256=VoXbEgL_hjQLfau6WohXxPK8rrv1VLA874F8PZ7ZtPk,1421
|
59
|
-
gr_libs-0.1.
|
60
|
-
gr_libs-0.1.
|
61
|
-
gr_libs-0.1.
|
62
|
-
gr_libs-0.1.
|
60
|
+
gr_libs-0.1.4.dist-info/METADATA,sha256=wH7aEvKh4kRTXBs75uPSBW87s23dgcsKRqgkVSwKDQc,8905
|
61
|
+
gr_libs-0.1.4.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
62
|
+
gr_libs-0.1.4.dist-info/top_level.txt,sha256=k7_l789QSJEr9JrtvsRMxNoTIDwNduq8mhIN-YoPJUM,29
|
63
|
+
gr_libs-0.1.4.dist-info/RECORD,,
|
gr_libs-0.1.3.dist-info/METADATA
DELETED
@@ -1,197 +0,0 @@
|
|
1
|
-
Metadata-Version: 2.4
|
2
|
-
Name: gr_libs
|
3
|
-
Version: 0.1.3
|
4
|
-
Summary: Package with goal recognition frameworks baselines
|
5
|
-
Author: Osher Elhadad, Ben Nageris
|
6
|
-
Author-email: Matan Shamir <matan.shamir@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
|
-
|
16
|
-
# GRLib
|
17
|
-
GRLib is a python package containing implementations of Goal Recognition (GR) algorithms which use MDPs to represent the decision making process. All agents in those algorithms interact with an environment that's registered in gym API.
|
18
|
-
## Setup:
|
19
|
-
If you're on linux, great, If on windows, use git bash for the next commands to work.
|
20
|
-
1. Find where your python is installed. If you want to find where's your python3.12, you can run:
|
21
|
-
```sh
|
22
|
-
py -3.12 -c "import sys; print(sys.executable)"
|
23
|
-
```
|
24
|
-
2. Create a new empty venv from that python venv module:
|
25
|
-
```sh
|
26
|
-
C:/Users/path/to/Programs/Python/Python312/python.exe -m venv test_env
|
27
|
-
```
|
28
|
-
3. Activate the environment:
|
29
|
-
```sh
|
30
|
-
source test_env/Scripts/activate
|
31
|
-
```
|
32
|
-
4. There's no equivalent to conda env list to check the global virtual environments status, so you can verify the active one via:
|
33
|
-
```sh
|
34
|
-
echo $VIRTUAL_ENV
|
35
|
-
```
|
36
|
-
5. Install and upgrade basic package management modules:
|
37
|
-
```sh
|
38
|
-
/path/to/python.exe -m pip install --upgrade pip setuptools wheel versioneer
|
39
|
-
```
|
40
|
-
6. Install the gr_libss package (can add -e for editable mode):
|
41
|
-
```sh
|
42
|
-
cd /path/to/clone/of/GoalRecognitionLibs
|
43
|
-
pip install -e .
|
44
|
-
```
|
45
|
-
7. Install gr_libs package (can add -e for editable mode):
|
46
|
-
```sh
|
47
|
-
cd /path/to/clone/of/Grlib
|
48
|
-
pip install -e .
|
49
|
-
```
|
50
|
-
|
51
|
-
|
52
|
-
<!-- 1. Ensure you have python 3.11 installed.
|
53
|
-
If you have root permissions, simply use:
|
54
|
-
```sh
|
55
|
-
mkdir -p ~/.local/python3.11
|
56
|
-
dnf install python3.11 --prefix ~/.local/python3.11
|
57
|
-
echo 'export PATH=$HOME/.local/python3.11/bin:$PATH' >> ~/.bashrc
|
58
|
-
source ~/.bashrc
|
59
|
-
```
|
60
|
-
Else, use pyenv:
|
61
|
-
```sh
|
62
|
-
pyenv install 3.11.0
|
63
|
-
```
|
64
|
-
2. Create a new venv or use an existing 3.11 venv, and activate it. To create a new venv:
|
65
|
-
```sh
|
66
|
-
~/.pyenv/versions/3.11.0/bin/python -m venv graml_env
|
67
|
-
./Python-3.11.0/graml_env/bin/activate
|
68
|
-
```
|
69
|
-
If you're not a sudo, and you have problems with building python getting such warnings:
|
70
|
-
```sh
|
71
|
-
WARNING: The Python ctypes extension was not compiled. Missing the libffi lib?
|
72
|
-
```
|
73
|
-
That means you don't have the necesarry libraries for building python, and you probably can't change that since you're not a sudoer.
|
74
|
-
An alternative solution can be using a conda env:
|
75
|
-
```sh
|
76
|
-
conda create -n graml_env python=3.11
|
77
|
-
conda activate graml_env
|
78
|
-
```
|
79
|
-
3. Install GoalRecognitionLibs to get all needed dependencies:
|
80
|
-
```sh
|
81
|
-
git clone [GoalRecognitionLibs address]
|
82
|
-
cd GoalRecognitionLibs
|
83
|
-
pip install -e . # using the conda's pip of course
|
84
|
-
``` -->
|
85
|
-
|
86
|
-
### Issues & Problems ###
|
87
|
-
If you're not a sudo, and you have problems with building python getting such warnings:
|
88
|
-
```sh
|
89
|
-
WARNING: The Python ctypes extension was not compiled. Missing the libffi lib?
|
90
|
-
```
|
91
|
-
That means you don't have the necesarry libraries for building python.
|
92
|
-
|
93
|
-
### How to use Grlib ###
|
94
|
-
Now that you've installed the package, you have additional custom gym environments and you can start creating an ODGR scenario with the algorithm you wish to test.
|
95
|
-
The tutorial at tutorials/tutorial.py follows a simple ODGR scnenario. We guide through the initialization and deployment process following an example where GRAML is expected to adapt to new emerging goals in the point_maze gym environment.
|
96
|
-
|
97
|
-
#### Method 1: write your own script
|
98
|
-
1. create the recognizer: we need to state the base problems on which the recognizer train.
|
99
|
-
we also need the env_name for the sake of storing the trained models.
|
100
|
-
Other notable parameters include the parameters for the training of the model: For example, Graml's LSTM needs to accept input sizes the size of the concatenation of the state space with the action space.
|
101
|
-
|
102
|
-
```python
|
103
|
-
recognizer = Graml(
|
104
|
-
env_name="point_maze", # TODO change to macros which are importable from some info or env module of enums.
|
105
|
-
problems=[("PointMaze-FourRoomsEnvDense-11x11-Goal-9x1"),
|
106
|
-
("PointMaze-FourRoomsEnv-11x11-Goal-9x9"), # this one doesn't work with dense rewards because of encountering local minima
|
107
|
-
("PointMaze-FourRoomsEnvDense-11x11-Goal-1x9"),
|
108
|
-
("PointMaze-FourRoomsEnvDense-11x11-Goal-3x3"),
|
109
|
-
("PointMaze-FourRoomsEnvDense-11x11-Goal-3x4"),
|
110
|
-
("PointMaze-FourRoomsEnvDense-11x11-Goal-8x2"),
|
111
|
-
("PointMaze-FourRoomsEnvDense-11x11-Goal-3x7"),
|
112
|
-
("PointMaze-FourRoomsEnvDense-11x11-Goal-2x8")],
|
113
|
-
task_str_to_goal=maze_str_to_goal,
|
114
|
-
method=DeepRLAgent,
|
115
|
-
collect_statistics=False,
|
116
|
-
train_configs=[(SAC, 200000) for i in range(8)],
|
117
|
-
partial_obs_type="fragmented",
|
118
|
-
batch_size=32,
|
119
|
-
input_size=6,
|
120
|
-
hidden_size=8,
|
121
|
-
num_samples=20000,
|
122
|
-
problem_list_to_str_tuple=lambda problems: "_".join([f"[{s.split('-')[-1]}]" for s in problems]),
|
123
|
-
is_learn_same_length_sequences=False,
|
124
|
-
goals_adaptation_sequence_generation_method=AGENT_BASED # take expert samples in goals adaptation phase
|
125
|
-
)
|
126
|
-
```
|
127
|
-
|
128
|
-
2. The domain learning phase: In GRAML's case, the recognizer generates a dataset by training agents towards the base goals and trains an metric model combined of an LSTM on traces generated by those agents.
|
129
|
-
|
130
|
-
```python
|
131
|
-
recognizer.domain_learning_phase()
|
132
|
-
```
|
133
|
-
3. The goals adaptation phase: The recognizer receives new goals, along with configurations to the training of those agents - since the sequence generation method in this case is from an expert.
|
134
|
-
```python
|
135
|
-
recognizer.goals_adaptation_phase(
|
136
|
-
dynamic_goals_problems = ["PointMaze-FourRoomsEnvDense-11x11-Goal-4x4",
|
137
|
-
"PointMaze-FourRoomsEnvDense-11x11-Goal-7x3",
|
138
|
-
"PointMaze-FourRoomsEnvDense-11x11-Goal-3x7"],
|
139
|
-
dynamic_train_configs=[(SAC, 200000) for i in range(3)] # for expert sequence generation
|
140
|
-
)
|
141
|
-
```
|
142
|
-
4. Inference phase - this snippet generates a partial sequence by an agent trained towards one of the goals of the inference phase. Note how the trace is generated using a different agent from the recognizer's inner agents or expert (TD3 rather than SAC), and with noise added to every action to simulate suboptimal behavior.
|
143
|
-
```python
|
144
|
-
actor = DeepRLAgent(env_name="point_maze", problem_name="PointMaze-FourRoomsEnvDense-11x11-Goal-4x4", algorithm=TD3, num_timesteps=200000)
|
145
|
-
actor.learn()
|
146
|
-
full_sequence = actor.generate_observation(
|
147
|
-
action_selection_method=stochastic_amplified_selection,
|
148
|
-
random_optimalism=True, # the noise that's added to the actions
|
149
|
-
)
|
150
|
-
partial_sequence = random_subset_with_order(full_sequence, (int)(0.5 * len(full_sequence)), is_fragmented="fragmented")
|
151
|
-
closest_goal = recognizer.inference_phase(partial_sequence, maze_str_to_goal("PointMaze-FourRoomsEnvDense-11x11-Goal-4x4"), 0.5)
|
152
|
-
```
|
153
|
-
5. check the result returned by GRAML and print whether it was right or not.
|
154
|
-
```python
|
155
|
-
print(f"closest_goal returned by GRAML: {closest_goal}\nactual goal actor aimed towards: (4, 4)")
|
156
|
-
```
|
157
|
-
|
158
|
-
#### Method 2: use a configuration file
|
159
|
-
The configuraiton file consts.py holds configurations of ODGR problems.
|
160
|
-
You can either use existing ones or add new ones.
|
161
|
-
Note that using the config file, despite being easier on a large scale, some inputs to the ODGR problem are not as flexible as they would be using method 1.
|
162
|
-
For example, the sequence generation will be performed by trained agents and is non configurable. The sequences will either be completely consecutive or randomly sampled from the trace.
|
163
|
-
Example for a problem:
|
164
|
-
|
165
|
-
You can use odgr_executor.py to execute a single task:
|
166
|
-
```sh
|
167
|
-
python odgr_executor.py --recognizer MCTSBasedGraml --domain minigrid --task L1 --minigrid_env MinigridSimple
|
168
|
-
```
|
169
|
-
|
170
|
-
|
171
|
-
## Supported Algorithms
|
172
|
-
|
173
|
-
| **Name** | **Supervised** | **RL** | **Discrete** | **Continuous** | **Model-Based** | **Model-Free** | **Actions Only** |
|
174
|
-
| ------------------- | ------------------ | ------------------ | ------------------ | ------------------- | ------------------ | --------------------------------- |
|
175
|
-
| GRAQL | :x: | :heavy_check_mark: | :heavy_check_mark: | :x: | :x: | :heavy_check_mark: | :x: |
|
176
|
-
| DRACO | :x: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :x: | :heavy_check_mark: | :x: |
|
177
|
-
| GRAML | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :x: | :heavy_check_mark: | :heavy_check_mark: |
|
178
|
-
|
179
|
-
## Supported Domains
|
180
|
-
|
181
|
-
| **Name** | **Action** | **State** |
|
182
|
-
| ------------------- | ------------------ | ------------------ |
|
183
|
-
| Minigrid | Discrete | Discrete |
|
184
|
-
| PointMaze | Continuous | Continuous |
|
185
|
-
| Parking | Continuous | Continuous |
|
186
|
-
| Panda | Continuous | Continuous |
|
187
|
-
|
188
|
-
### Experiments
|
189
|
-
Given here is a guide for executing the experiments. There are benchmark domains suggested in the repository, and the 'scripts' directory suggests a series of tools to analyze them. They are defaultly set on the domains used for GRAML and GRAQL analysis during the writing of GRAML paper, but can easily be adjusted for new domains and algorithms.
|
190
|
-
1. analyze_results_cross_alg_cross_domain.py: this script runs with no arguments. it injects information from get_experiment_results_path (for example: dataset\graml\minigrid\continuing\inference_same_seq_len\learn_diff_seq_len\experiment_results\obstacles\L111\experiment_results.pkl), and produces a plot with 4 figures showing the accuracy trend of algorithms on the domains checked one against the other. Currently GRAML is checked against GRAQL or DRACO but it can easily be adjusted from within the script.
|
191
|
-
2. generate_task_specific_statistics_plots.py - this script produces, for a specific task execution (results of execution of experiments.py), a summary combined of a figure with sticks with the accuracies and confidence levels of an algorithm on the task on the varying percentages. figures\point_maze\obstacles\graql_point_maze_obstacles_fragmented_stats.png is an example of a path at which the output is dumped. Another product of this script is a confusion matrix with the confidence levels - visualizing the same data, and the output file resides in this path: figures\point_maze\obstacles\graml_point_maze_obstacles_fragmented_inference_same_seq_len_learn_diff_seq_len_goals_conf_mat.png.
|
192
|
-
|
193
|
-
### How to add a new environment
|
194
|
-
1. bla
|
195
|
-
2. blalba
|
196
|
-
|
197
|
-
### How to add a new Learner
|
File without changes
|