Skip to main content

Counting and Sampling Markov Equivalent DAGs

Project description

Python wrapper

You can install the cliquepicking module with pip install cliquepicking.

The module provides the functions

  • mec_size(G), which outputs the number of DAGs in the MEC represented by CPDAG G
  • mec_sample_dags(G, k), which returns k uniformly sampled DAGs from the MEC represented by CPDAG G
  • mec_sample_orders(G, k) which returns topological orders of k uniformly sampled DAGs from the MEC represented by CPDAG G

Be aware that mec_sample_dags(G, k) holds (and returns) k DAGs in memory. (For large graphs) to avoid large memory usage, generate DAGs in smaller batches or use mec_sample_orders(G, k), which only returns the often much smaller topological order.

In all cases, G should be given as a edge list (vertices should be represented by zero indexed integers), which includes (a, b) and (b, a) for undirected edges $$a - b$$ and only (a, b) for directed edges $$a \rightarrow b$$. E.g.

import cliquepicking as cp

edges = [(0, 1), (1, 0), (1, 2), (2, 1), (0, 3), (2, 3)]
print(cp.mec_size(edges))

computes the MEC size for the graph with edges $0 - 1 - 2$ and $0 \rightarrow 3 \leftarrow 2$ and hence the code should print out 3.

For a more involved example (Example 3 from the AAAI paper), which illustrates use with networkx, see:

import cliquepicking as cp
import networkx as nx

G = nx.DiGraph()
G.add_edge(0, 1)
G.add_edge(1, 0)
G.add_edge(0, 2)
G.add_edge(2, 0)
G.add_edge(1, 2)
G.add_edge(2, 1)
G.add_edge(1, 3)
G.add_edge(3, 1)
G.add_edge(1, 4)
G.add_edge(4, 1)
G.add_edge(1, 5)
G.add_edge(5, 1)
G.add_edge(2, 3)
G.add_edge(3, 2)
G.add_edge(2, 4)
G.add_edge(4, 2)
G.add_edge(2, 5)
G.add_edge(5, 2)
G.add_edge(3, 4)
G.add_edge(4, 3)
G.add_edge(4, 5)
G.add_edge(5, 4)
print(cp.mec_size(list(G.edges)))
sample_dags = cp.mec_sample_dags(list(G.edges), 5)
for dag in sample_dags:
    print(nx.DiGraph(dag))
sample_orders = cp.mec_sample_orders(list(G.edges), 5)
for order in sample_orders:
    print(order)

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

cliquepicking-0.1.2.tar.gz (3.2 MB view details)

Uploaded Source

Built Distribution

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

cliquepicking-0.1.2-cp312-cp312-manylinux_2_34_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

File details

Details for the file cliquepicking-0.1.2.tar.gz.

File metadata

  • Download URL: cliquepicking-0.1.2.tar.gz
  • Upload date:
  • Size: 3.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.7.4

File hashes

Hashes for cliquepicking-0.1.2.tar.gz
Algorithm Hash digest
SHA256 b316273ed5270a8e6daaea5b5c4ba033620eaf34803b3bd83e7b4f4952a8c3ca
MD5 635dfbfbbb91fc373532cd05ad55cfb6
BLAKE2b-256 018b00bb8c2d129f95b937901e82226aac61b37e811b0970f84d8d4268451029

See more details on using hashes here.

File details

Details for the file cliquepicking-0.1.2-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for cliquepicking-0.1.2-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 825e52c38bca231d6da3ffaed584b1ed1048bde17458627844c7c0945fadb929
MD5 c7fe53094473dcb55365ef28eac17b2d
BLAKE2b-256 be58bae0d7fd136581b7c6fa6693c7b10c471b031a8f7108818e0a67423e946b

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