Skip to main content

pgeon (or pgeon-xai) is a Python package that produces explanations for opaque agents using Policy Graphs (PGs)

Project description

pgeon / pgeon-xai

Tormos, A., Abalos, V., Gnatyshak, D., & Alvarez-Napagao, S. (2023, October). Policy graphs in action: explaining single- and multi-agent behaviour using predicates. In XAI in Action: Past, Present, and Future Applications.

pgeon (pgeon-xai) is a Python package that produces explanations for opaque agents using Policy Graphs (PGs).

A Policy Graph is a means to obtain a representation of the behavior of an opaque agent, in the form of a directed graph. Discrete states are mapped to nodes and actions to edges.

Getting started

  • Install pgeon with pip: pip install pgeon-xai

or:

  1. Download the pgeon/ folder and move it into the root directory of your project.
  2. Install pgeon's requirements with pip install -r PATH_TO_PGEON_REQUIREMENTS.

Example usage

Generating a Policy Graph

Given a Gymnasium environment and a discretizer, you can generate a PG to describe an opaque agent's behavior with fit().

from pgeon import PolicyGraph

pg = PolicyGraph(environment, discretizer)
pg = pg.fit(agent, num_episodes=1000)

Creating and using a PG-based policy

There exist two PG-based policies. You can select one or the other with PGBasedPolicyMode.

from pgeon import PGBasedPolicy, PGBasedPolicyMode

greedy_policy = PGBasedPolicy(pg, mode=PGBasedPolicyMode.GREEDY)
stochastic_policy = PGBasedPolicy(pg, mode=PGBasedPolicyMode.STOCHASTIC)

# Passing the policy an observation to get an action
obs, _ = environment.reset()
action = greedy_policy.act(obs)

More examples

You can check examples/cartpole/demo.ipynb for a complete breakdown of pgeon's features.

To run the notebook yourself:

  1. Download the entire repository.
  2. Install pgeon's requirements with pip install -r requirements.txt.
  3. Install an extra dependency, rllib, with pip install "ray[rllib]".
  4. Open and execute examples/cartpole/demo.ipynb.

Citation

If you use the pgeon library, please cite:

@inproceedings{tormos2023policy,
  title={Policy graphs in action: explaining single-and multi-agent behaviour using predicates},
  author={Tormos, Adrian and Abalos, Victor and Gnatyshak, Dmitry and Alvarez-Napagao, Sergio},
  booktitle={XAI in Action: Past, Present, and Future Applications},
  year={2023},
  url={https://openreview.net/forum?id=QPqL9xsYOf}
}

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

pgeon_xai-1.0.1.tar.gz (3.5 MB view details)

Uploaded Source

Built Distribution

pgeon_xai-1.0.1-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

Details for the file pgeon_xai-1.0.1.tar.gz.

File metadata

  • Download URL: pgeon_xai-1.0.1.tar.gz
  • Upload date:
  • Size: 3.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.7

File hashes

Hashes for pgeon_xai-1.0.1.tar.gz
Algorithm Hash digest
SHA256 7c8d675f0ee264143740a434ea6c0e072ad1b4f607e6fd51f02ceab6442dd3c9
MD5 de7350c84f11f4c50749bc0a1b6a6a84
BLAKE2b-256 3cbab0b5cd960494d91396fe711bab4b4447b21733526f3ffcaa7849a8be81a6

See more details on using hashes here.

File details

Details for the file pgeon_xai-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: pgeon_xai-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 11.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.7

File hashes

Hashes for pgeon_xai-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3c8bfdb12920ef26a76fa20a622a697b1f393170db851cfafb611b7e27b69a46
MD5 9042bf39e8b7743262c12b023d60b752
BLAKE2b-256 e51f7bd9c95163b1edca1fb61ec8d3d3db334daf70ad5e889deb6fa044b682d6

See more details on using hashes here.

Supported by

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