pgeon-xai is a Python package that produces explanations for opaque agents using Policy Graphs (PGs)
Project description
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-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
- Download the
pgeon_xai/
folder and move it into the root directory of your project. - Install pgeon-xai'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_xai 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_xai 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-xai's features.
To run the notebook yourself:
- Download the entire repository.
- Install pgeon-xai's requirements with
pip install -r requirements.txt
. - Install an extra dependency, rllib, with
pip install "ray[rllib]"
. - Open and execute
examples/cartpole/demo.ipynb
.
Citation
If you use the pgeon-xai 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pgeon_xai-1.0.tar.gz
.
File metadata
- Download URL: pgeon_xai-1.0.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
Algorithm | Hash digest | |
---|---|---|
SHA256 | f723e44ce4132ccec8dc1837a6f531d49156e1fd80edb09fbb960752fbaf61ce |
|
MD5 | 3cfed9126d0fd991cac09ed994c37f4e |
|
BLAKE2b-256 | 8093e466ce6ebb832d99e4eecc2162f3520c0667c3b5756e48ae6a2806bd85af |
File details
Details for the file pgeon_xai-1.0-py3-none-any.whl
.
File metadata
- Download URL: pgeon_xai-1.0-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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22dc5183ec00ced25e081fd4feb7be2e37f0edd577bb139a1c1a2528111d1d7b |
|
MD5 | fe7c5804fea82f72f20191977ab7a5ba |
|
BLAKE2b-256 | ad3c46d4e92d710b3d3cffffe2e917e9d89db4ed439aeeb2ed4bc99f0052d5ed |