pykda

Python package for the Kemeny Decomposition Algorithm (KDA) together with some Markov chain tooling.

https://github.com/joostberkhout/pykda

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 2 DOI reference(s) in README
  • Academic publication links
  • Committers with academic emails
    1 of 1 committers (100.0%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (12.1%) to scientific vocabulary

Keywords

kda kemeny-constant kemeny-decomposition-algorithm markov-chain
Last synced: 6 months ago · JSON representation ·

Repository

Python package for the Kemeny Decomposition Algorithm (KDA) together with some Markov chain tooling.

Basic Info
Statistics
  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • Open Issues: 0
  • Releases: 10
Topics
kda kemeny-constant kemeny-decomposition-algorithm markov-chain
Created about 2 years ago · Last pushed over 1 year ago
Metadata Files
Readme License Citation

README.md

PyPI version ALNS codecov

pykda (you say "pie-k-d-a") is a Python package for the Kemeny Decomposition Algorithm (KDA) which allows to decompose a Markov chain into clusters of states, where states within a cluster are relatively more connected to each other than states outside the cluster. This is useful for analyzing influence graphs, such as social networks and internet networks. KDA was developed in the paper from Berkhout and Heidergott (2019) and uses the Kemeny constant as a connectivity measure.

Installing pykda

Package pykda depends on numpy, tarjan and pyvis. Use the package manager pip to install PyKDA bash pip install pykda

Getting started

The first step is to load a Markov chain as a MarkovChain object using a transition matrix P. ```python from pykda.Markov_chain import MarkovChain

P = [[0, 0.3, 0.7, 0, 0], [0.7, 0.2, 0.09, 0, 0.01], [0.5, 0.25, 0.25, 0, 0], [0, 0, 0, 0.5, 0.5], [0.01, 0, 0, 0.74, 0.25]] # artificial transition matrix MC = MarkovChain(P) We can study some properties of the Markov chain, such as the stationary distribution: python print(MC.stationarydistribution.flatten().round(3)) This gives `[0.226 0.156 0.23 0.232 0.156]`. We can also plot the Markov chain: python MC.plot(filename="An artificial Markov chain") ```

Now, let us decompose the Markov chain into clusters using KDA. We start by initializing a KDA object using the Markov chain and the KDA settings (such as the number of clusters). For more details about setting choices, see the KDA documentation or Berkhout and Heidergott (2019). Here, we apply the default settings, which is to cut all edges with a negative Kemeny constant derivative and normalizing the transition matrix afterward. python kda = KDA( original_MC=MC, CO_A="CO_A_1(1)", CO_B="CO_B_3(0)", symmetric_cut=False ) Now, let us run the KDA algorithm and visualize the results. python kda.run() kda.plot(file_name="An artificial Markov chain after KDA_A1_1_B3_0")

We can study the resulting Markov chain in more detail via the current Markov chain attribute MC of the KDA object. python print(kda.MC) This gives the following output: python MC with 5 states. Ergodic classes: [[2, 0], [3]]. Transient classes: [[1], [4]]. So KDA led to a Markov multi-chain with two ergodic classes and two transient classes. We can also study the edges that KDA cut via the log attribute of the KDA object. python print(kda.log['edges cut']) This gives the following output: [[None], [(4, 0), (1, 4), (2, 1), (0, 1), (3, 4)]] We can also study the Markov chains that KDA found in each (outer) iteration via kda.log['Markov chains'])`.

As another KDA application example, let us apply KDA until we find two ergodic classes explicitly. We will also ensure that the Kemeny constant derivatives are recalculated after each cut (and normalize the cut transition matrix to ensure it is a stochastic matrix again). To that end, we use: python kda2 = KDA( original_MC=MC, CO_A="CO_A_2(2)", CO_B="CO_B_1(1)", symmetric_cut=False ) kda2.run() kda2.plot(file_name="An artificial Markov chain after KDA_A2_2_B1_1") which gives (edges (4, 0) and (1, 4) are cut in two iterations):

How to learn more about pykda?

To learn more about pykda have a look at the documentation. There, you can also find links to interactive Google Colab notebooks in examples. If you have any questions, feel free to open an issue here on Github Issues.

How to cite pykda?

If you use pykda in your research, please consider citing the following paper:

Joost Berkhout, Bernd F. Heidergott (2019). Analysis of Markov influence graphs. Operations Research, 67(3):892-904. https://doi.org/10.1287/opre.2018.1813

Or, using the following BibTeX entry:

bibtex @article{Berkhout_Heidergott_2019, title = {Analysis of {Markov} influence graphs}, volume = {67}, number = {3}, journal = {Operations Research}, author = {Berkhout, J. and Heidergott, B. F.}, year = {2019}, pages = {892--904}, }

Owner

  • Name: Joost Berkhout
  • Login: JoostBerkhout
  • Kind: user
  • Location: Amsterdam
  • Company: Vrije Universiteit Amsterdam

Assistant professor in the field of operations research.

Citation (CITATION.cff)

cff-version: 1.2.0
message: "If you use this software, please cite it using the following metadata."
authors:
  - family-names: "Berkhout"
    given-names: "Joost"
    orcid: "https://orcid.org/0000-0001-5883-9683"
  - family-names: "Heidergott"
    given-names: "Bernd"
    orcid: "https://orcid.org/0000-0002-3389-2311"
title: "PyKDA"
url: "https://github.com/JoostBerkhout/PyKDA"
preferred-citation:
  type: article
  authors:
  - family-names: "Berkhout"
    given-names: "Joost"
    orcid: "https://orcid.org/0000-0001-5883-9683"
  - family-names: "Heidergott"
    given-names: "Bernd"
    orcid: "https://orcid.org/0000-0002-3389-2311"
  title: "Analysis of Markov influence graphs"
  journal: "Operations Research"
  volume: 67
  issue: 3
  year: 2019
  doi: "https://doi.org/10.1287/opre.2018.1813"

GitHub Events

Total
Last Year

Committers

Last synced: 8 months ago

All Time
  • Total Commits: 62
  • Total Committers: 1
  • Avg Commits per committer: 62.0
  • Development Distribution Score (DDS): 0.0
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Joost Berkhout j****t@v****l 62
Committer Domains (Top 20 + Academic)
vu.nl: 1

Issues and Pull Requests

Last synced: 8 months ago

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 64 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 7
  • Total maintainers: 1
pypi.org: pykda

Python package for the Kemeny Decomposition Algorithm (KDA) together with some Markov chain tooling.

  • Versions: 7
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 64 Last month
Rankings
Dependent packages count: 9.8%
Average: 37.2%
Dependent repos count: 64.7%
Maintainers (1)
Last synced: 7 months ago