Skip to content

Commit

Permalink
Fix notebook and update docs for CI
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Li <adam2392@gmail.com>
  • Loading branch information
adam2392 committed Jan 3, 2023
1 parent f52f1f3 commit 45eeb1a
Show file tree
Hide file tree
Showing 6 changed files with 516 additions and 92 deletions.
2 changes: 1 addition & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@
}

# prevent jupyter notebooks from being run even if empty cell
nbsphinx_execute = "never"
# nbsphinx_execute = "never"
nbsphinx_allow_errors = True

# Custom sidebar templates, maps document names to template names.
Expand Down
548 changes: 486 additions & 62 deletions doc/tutorials/markovian/example-pc-algo.ipynb

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions doc/whats_new/_contributors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@

.. _Adam Li: https://adam2392.github.io
.. _Chris Trevino: https://py-why.github.io
.. _Robert Osazuwa Ness: https://py-why.github.io
3 changes: 2 additions & 1 deletion doc/whats_new/v0.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Changelog
- |Feature| Implement FCI algorithm, :class:`dodiscover.constraint.FCI` for learning causal structure from observational data with latent confounders under the ``dodiscover.constraint`` submodule, by `Adam Li`_ (:pr:`52`)
- |Feature| Implement Structural Hamming Distance metric to compare directed graphs, :func:`dodiscover.metrics.structure_hamming_dist`, by `Adam Li`_ (:pr:`55`)
- |Fix| Update dependency on networkx, which removes a PR branch dependency with pywhy-graphs having the MixedEdgeGraph class that was causing a dependency conflict, by `Adam Li`_ (:pr:`74`)
- |Chore| Add tutorial for PC algorithm with Asia data, by `Robert Osazuwa Ness`_ (:pr:`67`)
- |Enhancement| Add tutorial for PC algorithm with Asia data, by `Robert Osazuwa Ness`_ (:pr:`67`)

Code and Documentation Contributors
-----------------------------------
Expand All @@ -47,3 +47,4 @@ the project since version inception, including:

* `Adam Li`_
* `Chris Trevino`_
* `Robert Osazuwa Ness`_
51 changes: 25 additions & 26 deletions dodiscover/constraint/pcalg.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
from itertools import combinations, permutations
from itertools import combinations
from typing import Optional

import networkx as nx
Expand Down Expand Up @@ -134,37 +134,36 @@ def orient_edges(self, graph: EquivalenceClass) -> None:
A skeleton graph. If ``None``, then will initialize PC using a
complete graph. By default None.
"""
node_ids = graph.nodes

# For all the combination of nodes i and j, apply the following
# rules.
idx = 0
finished = False
while idx < self.max_iter and not finished: # type: ignore
change_flag = False
for (i, j) in permutations(node_ids, 2):
if i == j:
continue
# Rule 1: Orient i-j into i->j whenever there is an arrow k->i
# such that k and j are nonadjacent.
r1_add = self._apply_meek_rule1(graph, i, j)

# Rule 2: Orient i-j into i->j whenever there is a chain
# i->k->j.
r2_add = self._apply_meek_rule2(graph, i, j)

# Rule 3: Orient i-j into i->j whenever there are two chains
# i-k->j and i-l->j such that k and l are nonadjacent.
r3_add = self._apply_meek_rule3(graph, i, j)

# Rule 4: Orient i-j into i->j whenever there are two chains
# i-k->l and k->l->j such that k and j are nonadjacent.
#
# However, this rule is not necessary when the PC-algorithm
# is used to estimate a DAG.

if any([r1_add, r2_add, r3_add]) and not change_flag:
change_flag = True
for i in graph.nodes:
for j in graph.neighbors(i):
if i == j:
continue
# Rule 1: Orient i-j into i->j whenever there is an arrow k->i
# such that k and j are nonadjacent.
r1_add = self._apply_meek_rule1(graph, i, j)

# Rule 2: Orient i-j into i->j whenever there is a chain
# i->k->j.
r2_add = self._apply_meek_rule2(graph, i, j)

# Rule 3: Orient i-j into i->j whenever there are two chains
# i-k->j and i-l->j such that k and l are nonadjacent.
r3_add = self._apply_meek_rule3(graph, i, j)

# Rule 4: Orient i-j into i->j whenever there are two chains
# i-k->l and k->l->j such that k and j are nonadjacent.
#
# However, this rule is not necessary when the PC-algorithm
# is used to estimate a DAG.

if any([r1_add, r2_add, r3_add]) and not change_flag:
change_flag = True
if not change_flag:
finished = True
logger.info(f"Finished applying R1-3, with {idx} iterations")
Expand Down
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ importlib-resources = { version = "*", python = "<3.9" }
networkx = "^2.8.8"
pywhy-graphs = { git = "https://github.com/py-why/pywhy-graphs.git", branch = 'main', optional = true }
pygraphviz = { version = "*", optional = true }
bnlearn = { git = "https://github.com/erdogant/bnlearn.git", branch = 'master', optional = true }

[tool.poetry.group.style]
optional = true
Expand Down Expand Up @@ -89,6 +88,7 @@ sphinx_rtd_theme = { version = "^1.0.0" }
graphviz = { version = "^0.20.1" }
ipython = { version = "^7.4.0" }
nbsphinx = { version = "^0.8" }
bnlearn = { git = "https://github.com/erdogant/bnlearn.git", branch = 'master', optional = true }
dowhy = { version = "^0.8" }
typing-extensions = { version = "*" } # needed in dowhy's package
joblib = { version = "^1.1.0" } # needed in dowhy's package
Expand All @@ -97,7 +97,6 @@ tqdm = { version = "^4.64.0" } # needed in dowhy's package
[tool.poetry.extras]
graph_func = ['pywhy-graphs']
viz = ['pygraphviz']
data = ['bnlearn']

[tool.portray]
output_dir = ['site']
Expand Down

0 comments on commit 45eeb1a

Please sign in to comment.