Skip to main content

Package with goal recognition frameworks baselines

Project description

GRLib

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.

Setup

Note: If you are using Windows, use Git Bash for the following commands. Otherwise, any terminal or shell will work.

gr_libs depends on gr_envs, which registers a set of Gym environments. Ensure your Python environment is set up with Python >= 3.11.

Setting Up a Python Environment (if needed)

Using Pip

  1. Find Your Python Installation:
    To locate your Python 3.12 executable, run:
    py -3.12 -c "import sys; print(sys.executable)"
    
  2. Create a New Virtual Environment:
    Using the path found above, create a new empty venv:
    C:/Users/path/to/Programs/Python/Python312/python.exe -m venv test_env
    
  3. Activate the Virtual Environment:
    source test_env/Scripts/activate
    
  4. Verify the Active Environment:
    Since there is no direct equivalent to conda env list, you can check your active environment via:
    echo $VIRTUAL_ENV
    

Using Conda

If you prefer using Conda, follow these steps:

  1. Create a New Conda Environment:
    Replace 3.12 with your desired Python version if necessary.
    conda create -n new_env python=3.12
    
  2. Activate the Environment:
    conda activate new_env
    

Upgrade Basic Package Management Modules:

Run the following command (replace /path/to/python.exe with the actual path):

/path/to/python.exe -m pip install --upgrade pip setuptools wheel versioneer

Install the GoalRecognitionLibs Package:

The extras install the custom environments defined in gr_envs. (For editable installation, add the -e flag by cloning the repo and cd'ing to it https://github.com/MatanShamir1/GRLib.git)

  • Minigrid Environment:
    pip install gr_libs[minigrid]
    
  • Highway Environment (Parking):
    pip install gr_libs[highway]
    
  • Maze Environment (Point-Maze):
    pip install gr_libs[maze]
    
  • Panda Environment:
    pip install gr_libs[panda]
    

(For editable installation, add the -e flag.)

cd /path/to/clone/of/GoalRecognitionLibs
pip install -e .

Issues & Troubleshooting

For any issues or troubleshooting, please refer to the repository's issue tracker.

Usage Guide

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.

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.

Method 1: Writing a Custom Script

  1. Create a recognizer

    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.

    recognizer = Graql(
        domain_name="minigrid",
        env_name="MiniGrid-SimpleCrossingS13N4"
    )
    
  2. Domain Learning Phase (For GRAQL)

    GRAQL does not accumulate information about the domain or engage in learning activities during this phase. 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.

  3. Goal Adaptation Phase

    The recognizer receives new goals and corresponding training configurations. GRAQL trains goal-directed agents and stores their policies for inference.

    recognizer.goals_adaptation_phase(
        dynamic_goals=[(11,1), (11,11), (1,11)],
        dynamic_train_configs=[(QLEARNING, 100000) for _ in range(3)]  # For expert sequence generation
    )
    
  4. Inference Phase

    This phase generates a partial sequence from a trained agent, simulating suboptimal behavior with Gaussian noise.

    actor = TabularQLearner(
        domain_name="minigrid",
        problem_name="MiniGrid-SimpleCrossingS13N4-DynamicGoal-11x1-v0",
        algorithm=QLEARNING,
        num_timesteps=100000
    )
    actor.learn()
    full_sequence = actor.generate_observation(
        action_selection_method=stochastic_amplified_selection,
        random_optimalism=True  # Adds noise to action values
    )
    partial_sequence = random_subset_with_order(full_sequence, int(0.5 * len(full_sequence)), is_consecutive=False)
    closest_goal = recognizer.inference_phase(partial_sequence, (11,1), 0.5)
    
  5. Evaluate the result

    print(f"Closest goal returned by Graql: {closest_goal}\nActual goal actor aimed towards: (11, 1)")
    

Method 2: Using a Configuration File

The consts.py file contains predefined ODGR problem configurations. You can use existing configurations or define new ones.

To execute a single task using the configuration file:

python odgr_executor.py --recognizer MCTSBasedGraml --domain minigrid --task L1 --minigrid_env MinigridSimple

Supported Algorithms

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).

Algorithm Supervised Reinforcement Learning Discrete States Continuous States Discrete Actions Continuous Actions Model-Based Model-Free Action-Only
GRAQL
DRACO (GC)
GRAML (GC, BG)

Supported Domains

Domain Action Space State Space
Minigrid Discrete Discrete
PointMaze Continuous Continuous
Parking Continuous Continuous
Panda Continuous Continuous

Running Experiments

The repository provides benchmark domains and scripts for analyzing experimental results. The scripts directory contains tools for processing and visualizing results.

  1. analyze_results_cross_alg_cross_domain.py

    • Runs without arguments.
    • Reads data from get_experiment_results_path (e.g., dataset/graml/minigrid/continuing/.../experiment_results.pkl).
    • Generates plots comparing algorithm performance across domains.
  2. generate_task_specific_statistics_plots.py

    • Produces task-specific accuracy and confidence plots.
    • Generates a confusion matrix displaying confidence levels.
    • Example output paths:
      • figures/point_maze/obstacles/graql_point_maze_obstacles_fragmented_stats.png
      • figures/point_maze/obstacles/graml_point_maze_obstacles_conf_mat.png

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gr_libs-0.1.5.tar.gz (69.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gr_libs-0.1.5-py3-none-any.whl (78.1 kB view details)

Uploaded Python 3

File details

Details for the file gr_libs-0.1.5.tar.gz.

File metadata

  • Download URL: gr_libs-0.1.5.tar.gz
  • Upload date:
  • Size: 69.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for gr_libs-0.1.5.tar.gz
Algorithm Hash digest
SHA256 430fda46c16ccc7c26e081e3887f53cc8de034fe8df5416745c1edfb062bb95c
MD5 283aed7d8d772c9a6fccd46d156e4a17
BLAKE2b-256 a78fc0f02026725c703664d345669ef692b364997e743e462ee515a7a0838346

See more details on using hashes here.

File details

Details for the file gr_libs-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: gr_libs-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 78.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for gr_libs-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 169b443c067f58f39dbeab2c19d37bbb1af5dd53861584398b8c08ddc85808f5
MD5 b81259c78de39edbd5ab79effc7a8efd
BLAKE2b-256 bc1a06a66d2f4ce1c37770646122d5204ab19ac5dd887192810f1258e051c939

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page