{ "info": { "author": "Darryl Reeves and Jaakko Luttinen", "author_email": "", "bugtrack_url": null, "classifiers": [ "Development Status :: 2 - Pre-Alpha", "Environment :: Console", "Intended Audience :: Developers", "Intended Audience :: Science/Research", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3 :: Only", "Topic :: Scientific/Engineering", "Topic :: Scientific/Engineering :: Information Analysis" ], "description": "# junction-tree\nImplementation of discrete factor graph inference utilizing the Junction Tree algorithm\n\nRequirements:\n-------------\n\n* NumPy (>= 1.12)\n\nFactor graphs:\n--------------\n\nA factor graph is given as a list of keys that tell which variables are in the\nfactor. (A key corresponds to a variable.)\n\n```[keys1, ..., keysN] # a list of N factors```\n\nThe index in the list can be used as an ID for the factor, that is, the first\nfactor in the list has ID 0 and the last factor has ID N-1.\n\nA companion list (of numpy arrays) of the same length as the factor list is\nprovided as a representation for the factor values\n\n```[values1, ..., valuesN]```\n\nAlso, the size of each of the M variables is given as a dictionary:\n\n```\n{\n key1: size1,\n ...\n keyM: sizeM\n}\n```\n\nHere, size is an integer representing the size of the variable. It is the same as\nthe length of the corresponding axis in the numeric array.\n\n\nGeneric trees (recursive definition):\n-------------------------------------\n\n```\n[index, keys, child_tree1, ..., child_treeN]\n```\n\n\nJunction trees:\n---------------\n\n```\ntree structure (composed of node indices found in node list):\n[\n index,\n (\n separator1_index,\n child_tree1\n ),\n ...,\n (\n separatorN_index,\n child_treeN\n )\n]\nnode list (elements are list of keys which define node):\n[node0_keys, node1_keys,...,nodeN_keys]\n\nmaxcliques and separators are both types of nodes\n```\n\nPotentials in (junction) trees:\n-------------------------------\n\nA list of arrays. The node IDs in the tree graphs map\nto the arrays in this data structure in order to get the numeric\narrays in the execution phase. The numeric arrays are not needed\nin the compilation phase.\n\n\n\n\n## Usage:\n\n### Junction Tree construction\n\nStarting with the definition of a factor graph\n\n(Example taken from http://mensxmachina.org/files/software/demos/jtreedemo.html)\n```\nimport junctiontree.beliefpropagation as bp\nimport junctiontree.junctiontree as jt\nimport numpy as np\n\nkey_sizes = {\n \"cloudy\": 2,\n \"sprinkler\": 2,\n \"rain\": 2,\n \"wet_grass\": 2\n }\n\nfactors = [\n [\"cloudy\"],\n [\"cloudy\", \"sprinkler\"],\n [\"cloudy\", \"rain\"],\n [\"rain\", \"sprinkler\", \"wet_grass\"]\n]\n\nvalues = [\n np.array([0.5,0.5]),\n np.array(\n [\n [0.5,0.5],\n [0.9,0.1]\n ]\n ),\n np.array(\n [\n [0.8,0.2],\n [0.2,0.8]\n ]\n ),\n np.array(\n [\n [\n [1,0],\n [0.1,0.9]\n ],\n [\n [0.1,0.9],\n [0.01,0.99]\n ]\n ]\n )\n]\n\ntree = jt.create_junction_tree(factors, key_sizes)\n\n```\n\n\n### Global Propagation\n\nThe initial clique potentials are inconsistent. The potentials are made consistent through global propagation on the junction tree\n\n```\nprop_values = tree.propagate(values)\n```\n\n### Observing Data\n\nAlternatively, clique potentials can be made consistent after observing data for the variables in the junction tree\n\n```\n# Update the size of observed variable\ncond_sizes = key_sizes.copy()\ncond_sizes[\"wet_grass\"] = 1\ncond_tree = jt.create_junction_tree(factors, cond_sizes)\n\n# Then, also similarly the values:\ncond_values = values.copy()\n# remove axis corresponding to \"wet_grass\" == 0\ncond_values[3] = cond_values[3][:,:,1:2]\n\n# Perform global propagation using conditioned values\nprop_values = tree.propagate(cond_values)\n```\n\n### Marginalization\n\nFrom a collection of consistent clique potentials, the marginal value of variables of interest can be calculated\n\n```\n# Pr(sprinkler|wet_grass = 1)\nmarginal = np.sum(prop_values[1], axis=0)\n\n# The probabilities are unnormalized but we can calculate the normalized values:\nnorm_marginal = marginal/np.sum(marginal)\n```\n\n\nReferences:\n\nS. M. Aji and R. J. McEliece, \"The generalized distributive law,\" in IEEE Transactions on Information Theory, vol. 46, no. 2, pp. 325-343, Mar 2000. doi: 10.1109/18.825794\n\nCecil Huang, Adnan Darwiche, Inference in belief networks: A procedural guide, International Journal of Approximate Reasoning, Volume 15, Issue 3, 1996, Pages 225-263, ISSN 0888-613X, http://dx.doi.org/10.1016/S0888-613X(96)00069-2.\n\nF. R. Kschischang, B. J. Frey and H. A. Loeliger, \"Factor graphs and the sum-product algorithm,\" in IEEE Transactions on Information Theory, vol. 47, no. 2, pp. 498-519, Feb 2001. doi: 10.1109/18.910572\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/jluttine/junction-tree", "keywords": "probabilistic programming", "license": "", "maintainer": "", "maintainer_email": "", "name": "junctiontree", "package_url": "https://pypi.org/project/junctiontree/", "platform": "", "project_url": "https://pypi.org/project/junctiontree/", "project_urls": { "Homepage": "https://github.com/jluttine/junction-tree" }, "release_url": "https://pypi.org/project/junctiontree/0.1.2/", "requires_dist": null, "requires_python": "", "summary": "Junction tree and belief propagation algorithms", "version": "0.1.2" }, "last_serial": 4274440, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "77e2bbaa1ea67f8ed8b866d41ba6c6cb", "sha256": "87668006c90e00d51ff2e476eebfbbb3f17e87d08541cd65b44e9137ddfe5229" }, "downloads": -1, "filename": "junctiontree-0.1.0.tar.gz", "has_sig": false, "md5_digest": "77e2bbaa1ea67f8ed8b866d41ba6c6cb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 31846, "upload_time": "2018-02-11T17:26:05", "url": "https://files.pythonhosted.org/packages/1c/a8/6ad70007707fb2a77aad1995ce1a9013d81150dd58dda2d23d6dd1441038/junctiontree-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "472e7727d7838664981db53d4b9476d4", "sha256": "e037265532b3717e1427d08f41d2a410b4c46611104267389760a3a07e99b8e3" }, "downloads": -1, "filename": "junctiontree-0.1.1.tar.gz", "has_sig": false, "md5_digest": "472e7727d7838664981db53d4b9476d4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 31979, "upload_time": "2018-02-12T18:14:08", "url": "https://files.pythonhosted.org/packages/ab/60/5da0bd6a71282349a04d68579567f9974c23e636738f5071419d76515f2e/junctiontree-0.1.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "c0e6b7e1bbfcf9866c6f77819fe6dffd", "sha256": "06974cfe70599426e3e3b9fb7c0d2b1bf5935d8bf98d9f8e81d4c031b18a495e" }, "downloads": -1, "filename": "junctiontree-0.1.2.tar.gz", "has_sig": false, "md5_digest": "c0e6b7e1bbfcf9866c6f77819fe6dffd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 32060, "upload_time": "2018-09-15T06:07:10", "url": "https://files.pythonhosted.org/packages/3d/ae/1b226a51c9660ed959f2a869e83bafabefe67f88ea7e37d3c9ec47db5a25/junctiontree-0.1.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "c0e6b7e1bbfcf9866c6f77819fe6dffd", "sha256": "06974cfe70599426e3e3b9fb7c0d2b1bf5935d8bf98d9f8e81d4c031b18a495e" }, "downloads": -1, "filename": "junctiontree-0.1.2.tar.gz", "has_sig": false, "md5_digest": "c0e6b7e1bbfcf9866c6f77819fe6dffd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 32060, "upload_time": "2018-09-15T06:07:10", "url": "https://files.pythonhosted.org/packages/3d/ae/1b226a51c9660ed959f2a869e83bafabefe67f88ea7e37d3c9ec47db5a25/junctiontree-0.1.2.tar.gz" } ] }