From ef3bff9b66a4158180e71c7308b766b5e4fb1536 Mon Sep 17 00:00:00 2001 From: Du Phan Date: Thu, 15 Feb 2024 14:35:04 -0500 Subject: [PATCH] remove further causalgraphicalmodel code --- ...y_variables_and_the_spurious_waffles.ipynb | 25 ++++++------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/notebooks/05_the_many_variables_and_the_spurious_waffles.ipynb b/notebooks/05_the_many_variables_and_the_spurious_waffles.ipynb index 6ec678e..ae41608 100644 --- a/notebooks/05_the_many_variables_and_the_spurious_waffles.ipynb +++ b/notebooks/05_the_many_variables_and_the_spurious_waffles.ipynb @@ -1690,28 +1690,19 @@ "metadata": {}, "outputs": [], "source": [ - "dag5_7 = CausalGraphicalModel(\n", - " nodes=[\"M\", \"K\", \"N\"], edges=[(\"M\", \"K\"), (\"N\", \"K\"), (\"M\", \"N\")]\n", - ")\n", + "dag5_7 = nx.DiGraph()\n", + "dag5_7.add_edges_from([(\"M\", \"K\"), (\"N\", \"K\"), (\"M\", \"N\")])\n", "coordinates = {\"M\": (0, 0.5), \"K\": (1, 1), \"N\": (2, 0.5)}\n", - "nodes = list(dag5_7.dag.nodes.keys())\n", - "edges = list(dag5_7.dag.edges.keys())\n", "MElist = []\n", "for i in range(2):\n", " for j in range(2):\n", " for k in range(2):\n", - " try:\n", - " new_dag = CausalGraphicalModel(\n", - " nodes=nodes,\n", - " edges=[\n", - " edges[0] if i == 0 else edges[0][::-1],\n", - " edges[1] if j == 0 else edges[1][::-1],\n", - " edges[2] if k == 0 else edges[2][::-1],\n", - " ],\n", - " )\n", - " MElist.append(new_dag)\n", - " except:\n", - " pass" + " new_dag = nx.DiGraph()\n", + " new_dag.add_edges_from(\n", + " [edge[::-1] if flip else edge for edge, flip in zip(dag5_7.edges, (i, j, k))]\n", + " )\n", + " if not list(nx.simple_cycles(new_dag)):\n", + " MElist.append(new_dag)" ] }, {