diff options
author | jarrodmillman <jarrod.millman@gmail.com> | 2022-12-14 17:21:13 +0000 |
---|---|---|
committer | jarrodmillman <jarrod.millman@gmail.com> | 2022-12-14 17:21:13 +0000 |
commit | 832c558e3507e5cb667a622b5372f91384ab026f (patch) | |
tree | 74481f14ab9cfb5c6984ab59b378cdc857a8180d /_downloads/e0067247ba27f59d84e7f2e24e041fc1/plot_decomposition.ipynb | |
parent | 71985f91c82bf85657dce6a74669e93ec8d29e11 (diff) | |
download | networkx-832c558e3507e5cb667a622b5372f91384ab026f.tar.gz |
Deploying to gh-pages from @ networkx/networkx@6be702047b1bb596a8010cf80911bb6ea939b1d1 🚀
Diffstat (limited to '_downloads/e0067247ba27f59d84e7f2e24e041fc1/plot_decomposition.ipynb')
-rw-r--r-- | _downloads/e0067247ba27f59d84e7f2e24e041fc1/plot_decomposition.ipynb | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/_downloads/e0067247ba27f59d84e7f2e24e041fc1/plot_decomposition.ipynb b/_downloads/e0067247ba27f59d84e7f2e24e041fc1/plot_decomposition.ipynb new file mode 100644 index 00000000..8938015d --- /dev/null +++ b/_downloads/e0067247ba27f59d84e7f2e24e041fc1/plot_decomposition.ipynb @@ -0,0 +1,54 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "%matplotlib inline" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n# Decomposition\n\nExample of creating a junction tree from a directed graph.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "import matplotlib.pyplot as plt\nimport networkx as nx\n\nB = nx.DiGraph()\nB.add_nodes_from([\"A\", \"B\", \"C\", \"D\", \"E\", \"F\"])\nB.add_edges_from(\n [(\"A\", \"B\"), (\"A\", \"C\"), (\"B\", \"D\"), (\"B\", \"F\"), (\"C\", \"E\"), (\"E\", \"F\")]\n)\n\noptions = {\"with_labels\": True, \"node_color\": \"white\", \"edgecolors\": \"blue\"}\n\nfig = plt.figure(figsize=(6, 9))\naxgrid = fig.add_gridspec(3, 2)\n\nax1 = fig.add_subplot(axgrid[0, 0])\nax1.set_title(\"Bayesian Network\")\npos = nx.nx_agraph.graphviz_layout(B, prog=\"neato\")\nnx.draw_networkx(B, pos=pos, **options)\n\nmg = nx.moral_graph(B)\nax2 = fig.add_subplot(axgrid[0, 1], sharex=ax1, sharey=ax1)\nax2.set_title(\"Moralized Graph\")\nnx.draw_networkx(mg, pos=pos, **options)\n\njt = nx.junction_tree(B)\nax3 = fig.add_subplot(axgrid[1:, :])\nax3.set_title(\"Junction Tree\")\nax3.margins(0.15, 0.25)\nnsize = [2000 * len(n) for n in list(jt.nodes())]\npos = nx.nx_agraph.graphviz_layout(jt, prog=\"neato\")\nnx.draw_networkx(jt, pos=pos, node_size=nsize, **options)\n\nplt.tight_layout()\nplt.show()" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.15" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +}
\ No newline at end of file |