pycid

Library for graphical models of decision making, based on pgmpy and networkx

https://github.com/causalincentives/pycid

Science Score: 67.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 1 DOI reference(s) in README
  • Academic publication links
  • Committers with academic emails
    3 of 11 committers (27.3%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (13.0%) to scientific vocabulary

Keywords

bayesian-networks causality influence-diagrams
Last synced: 6 months ago · JSON representation ·

Repository

Library for graphical models of decision making, based on pgmpy and networkx

Basic Info
  • Host: GitHub
  • Owner: causalincentives
  • License: apache-2.0
  • Language: Jupyter Notebook
  • Default Branch: master
  • Homepage:
  • Size: 5.63 MB
Statistics
  • Stars: 109
  • Watchers: 6
  • Forks: 17
  • Open Issues: 14
  • Releases: 14
Topics
bayesian-networks causality influence-diagrams
Created about 6 years ago · Last pushed over 2 years ago
Metadata Files
Readme License Citation

README.md

PyCID: Causal Influence Diagrams library

This package implements causal influence diagrams and methods to analyze them, and is part of the Causal Incentives project.

Building on pgmpy and NetworkX, pycid provides methods for defining CBNs, CIDs and MACIDs, computing optimal policies in CIDs, pure and mixed Nash equilibria in multi-agent CIDs, studying the effects of interventions, and checking graphical criteria for various types of incentives.

News

Version 0.8 breaks backwards compatibility by removing the getallpurene, getallpureneinsg, and getallpurespe class methods from the MACID class. This is because pure variants of NE and SPE can now be found by simply selecting the "enumpure" solver as an argument in the new getne, getneinsg, and getspe MACID class methods.

Version 0.7 breaks backwards compatibility by requiring CPD arguments to match the case of the parent nodes. To update your code to the latest version, simply change the case of the arguments, as illustrated here. Alternatively, stick to version 0.2.8.

Install

Create and activate a python virtual environment or a conda environment. Then install using: shell python3 -m pip install pycid

PyCID requires python version 3.8 or greater.

Basic usage

```python

Import

import pycid

Specify the nodes and edges of a simple CID

cid = pycid.CID([ ('S', 'D'), # add nodes S and D, and a link S -> D ('S', 'U'), # add node U, and a link S -> U ('D', 'U'), # add a link D -> U ], decisions=['D'], # D is a decision node utilities=['U']) # U is a utility node

specify the causal relationships with CPDs using keyword arguments

cid.addcpds(S = pycid.discreteuniform([-1, 1]), # S is -1 or 1 with equal probability D=[-1, 1], # the permitted action choices for D are -1 and 1 U=lambda S, D: S * D) # U is the product of S and D (argument names match parent names)

Draw the result

cid.draw() ```

image

The notebooks provide many more examples, including: * CBN Tutorial shows how to specify the structure and (causal) relationships between nodes, and ask simple queries. * CID tutorial adds special decision and utility nodes for one agent, and how to compute optimal policies. * MACID tutorial covers methods for handling multiple agents, including finding subgames and Nash equilibria. * Incentive Analysis tutorial illustrates various methods for analyzing the incentives of agents.

The above notebooks links all open in Colab, and can be run directly in the browser with no further setup or installation required.

Code overview

The code is structured into the following folders: * pycid/core contains methods and classes for specifying CBN, CID and MACID models, for finding and characterising types of paths in these models' graphs, and for computing optimal policies and Nash equilibria. * pycid/analyze has methods for analyzing different types of effects and interventions as well as incentives in single-decision CIDs and reasoning patterns in MACIDs. * pycid/random has methods for generating random CIDs. * pycid/examples has a range of pre-specified CBNs, CIDs and MACIDs. * notebooks has iPython notebooks illustrating the use of key methods. * tests has unit tests for all public methods.

Contributing

The project is developed at https://github.com/causalincentives/pycid.

Install

First create and activate a python virtual environment or a conda environment. shell git clone https://github.com/causalincentives/pycid # download the code cd pycid python3 -m pip install --editable .[test] python3 -m pytest # check that everything works

Making Commits

Fast checks are set up as git pre-commit hooks. To enable them, run: shell pip3 install pre-commit pre-commit install They will run on every commit or can be run manually with pre-commit run.

Before committing to the master branch, please ensure that: * The script tests/check-code.sh completes without error (you can add it as a pre-commit hook) * Any new requirements are added to setup.cfg. * Your functions have docstrings and types, and a unit test verifying that they work * For notebooks, you have done "restart kernel and run all cells" before saving and committing * Any documentation (such as this file) is up-to-date

Citing

Please use the following BibTeX entry for citing PyCID in your research:

@InProceedings{ james_fox-proc-scipy-2021, author = { {J}ames {F}ox and {T}om {E}veritt and {R}yan {C}arey and {E}ric {L}anglois and {A}lessandro {A}bate and {M}ichael {W}ooldridge }, title = { {P}y{C}{I}{D}: {A} {P}ython {L}ibrary for {C}ausal {I}nfluence {D}iagrams }, booktitle = { {P}roceedings of the 20th {P}ython in {S}cience {C}onference }, pages = { 43 - 51 }, year = { 2021 }, editor = { {M}eghann {A}garwal and {C}hris {C}alloway and {D}illon {N}iederhut and {D}avid {S}hupe }, doi = {10.25080/majora-1b6fd038-008} }

Owner

  • Name: Causal Incentives Working Group
  • Login: causalincentives
  • Kind: organization

We develop causal models to analyse agents' incentives

Citation (CITATION.cff)

cff-version: 1.2.0
message: "If you use PyCID in your work, please cite it as below."
authors:
- family-names: "Fox"
  given-names: "James"
- family-names: "Everitt"
  given-names: "Tom"
- family-names: "Carey"
  given-names: "Ryan"
- family-names: "Langlois"
  given-names: "Eric"

title: "PyCID"
version: 0.7.0
date-released: 2021-12-21
url: "https://github.com/causalincentives/pycid"
preferred-citation:
  type: conference-paper
  authors:
  - family-names: "Fox"
    given-names: "James"
  - family-names: "Everitt"
    given-names: "Tom"
  - family-names: "Carey"
    given-names: "Ryan"
  - family-names: "Langlois"
    given-names: "Eric"
  - family-names: "Abate"
    given-names: "Alessandro"
  - family-names: "Wooldridge"
    given-names: "Michael"
  doi: "10.25080/majora-1b6fd038-008"
  title: "PyCID: A Python Library for Causal Influence Diagrams"
  conference:
    name: "Python in Science Conference"
  collection-title: "Proceedings of the 20th Python in Science Conference"
  editors:
  - family-names: "Agarwal"
    given-names: "Meghann"
  - family-names: "Calloway"
    given-names: "Chris"
  - family-names: "Niederhut"
    given-names: "Dillon"
  - family-names: "Shupe"
    given-names: "David"
  start: 43 # First page number
  end: 51 # Last page number
  year: 2021

GitHub Events

Total
  • Issues event: 4
  • Watch event: 10
  • Issue comment event: 5
  • Fork event: 4
Last Year
  • Issues event: 4
  • Watch event: 10
  • Issue comment event: 5
  • Fork event: 4

Committers

Last synced: almost 3 years ago

All Time
  • Total Commits: 611
  • Total Committers: 11
  • Avg Commits per committer: 55.545
  • Development Distribution Score (DDS): 0.655
Top Committers
Name Email Commits
Tom Everitt t****t@g****m 211
James Fox j****x@k****k 193
Eric Langlois e****c@l****z 68
RyanCarey r****f@g****m 52
s-a-malik s****k@y****k 45
James Fox j****x@c****k 28
Eric Langlois e****l@c****u 8
Ryan Carey R****y@u****m 3
Xiaohu Zhu x****u@g****m 1
Sebastian Benthall sb@u****e 1
James Fox 5****1@u****m 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 62
  • Total pull requests: 20
  • Average time to close issues: 2 months
  • Average time to close pull requests: about 2 months
  • Total issue authors: 14
  • Total pull request authors: 9
  • Average comments per issue: 1.55
  • Average comments per pull request: 1.15
  • Merged pull requests: 17
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 3
  • Pull requests: 0
  • Average time to close issues: 6 days
  • Average time to close pull requests: N/A
  • Issue authors: 3
  • Pull request authors: 0
  • Average comments per issue: 1.0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • edlanglois (21)
  • tom4everitt (21)
  • Jamesfox1 (5)
  • sbenthall (4)
  • RyanCarey (2)
  • luoruisichuan (1)
  • atcrank (1)
  • JoaoPaulo-Ferreira (1)
  • kuuotto (1)
  • gabosantos (1)
  • kholtman (1)
  • bbkjunior (1)
  • MaartenCVonk (1)
  • yfflood (1)
Pull Request Authors
  • Jamesfox1 (8)
  • cool-RR (3)
  • s-a-malik (2)
  • edlanglois (2)
  • sbenthall (1)
  • tigerneil (1)
  • RyanCarey (1)
  • Rysias (1)
  • mattmacdermott1 (1)
Top Labels
Issue Labels
enhancement (13) bug (1)
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 41 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 1
  • Total versions: 14
  • Total maintainers: 1
pypi.org: pycid

Causal Influence Diagram library

  • Versions: 14
  • Dependent Packages: 0
  • Dependent Repositories: 1
  • Downloads: 41 Last month
Rankings
Stargazers count: 7.9%
Dependent packages count: 10.0%
Forks count: 10.2%
Average: 13.9%
Downloads: 19.9%
Dependent repos count: 21.7%
Maintainers (1)
Last synced: 6 months ago

Dependencies

.github/workflows/code-check.yaml actions
  • actions/checkout v2 composite
  • actions/setup-python v2 composite
.github/workflows/publish.yaml actions
  • actions/checkout master composite
  • actions/setup-python v1 composite
  • pypa/gh-action-pypi-publish master composite
pyproject.toml pypi
setup.py pypi