Created
May 31, 2017 16:20
-
-
Save nzw0301/392367c176dff673e1f220c4985b214d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"from matplotlib import rc\n", | |
"%matplotlib inline\n", | |
"import daft\n", | |
"\n", | |
"rc(\"font\", family=\"Ricty\", size=15)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"pgm = daft.PGM(shape=[7, 5])\n", | |
"\n", | |
"pgm.add_node(daft.Node(\"alpha\", r\"$\\alpha$\", 1, 2.5))\n", | |
"pgm.add_node(daft.Node(\"theta\", r\"$\\theta$\", 2, 2.5))\n", | |
"pgm.add_node(daft.Node(\"z\", r\"$z_i$\", 3, 2.5))\n", | |
"pgm.add_node(daft.Node(\"w\", r\"$w_i$\", 4, 2.5, observed=True))\n", | |
"\n", | |
"pgm.add_node(daft.Node(\"phi\", r\"$\\beta$\", 5, 2.5))\n", | |
"pgm.add_node(daft.Node(\"beta\", r\"$\\eta$\", 6, 2.5))\n", | |
"\n", | |
"# Edges.\n", | |
"pgm.add_edge(\"alpha\", \"theta\")\n", | |
"pgm.add_edge(\"theta\", \"z\")\n", | |
"pgm.add_edge(\"z\", \"w\")\n", | |
"pgm.add_edge(\"beta\", \"phi\")\n", | |
"pgm.add_edge(\"phi\", \"w\")\n", | |
"\n", | |
"# And a plate.\n", | |
"pgm.add_plate(daft.Plate([1.6, 2.0, 2.9, 1.0], label=r\"$D$\", shift=-0.1))\n", | |
"pgm.add_plate(daft.Plate([2.5, 2.1, 1.8, 0.8], label=r\"$N$\", shift=-0.1))\n", | |
"pgm.add_plate(daft.Plate([4.7, 2.0, 0.6, 1.0], label=r\"$K$\", shift=-0.1))\n", | |
"\n", | |
"pgm.render()\n", | |
"pgm.figure.savefig(\"lda.pdf\")" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"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.6.1" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment