{ "info": { "author": "asmith26", "author_email": "", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Science/Research", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.6" ], "description": "# Vose-Alias-Method\nPython implementation of Vose's alias method, an efficient algorithm for sampling from a discrete probability distribution (a good explanation of which can be found at http://www.keithschwarz.com/darts-dice-coins/).\n\nFor example, this code can be used for creating and efficiently sampling from a probability distribution representing rolling a weighted die (i.e where side j has probability P(j) of being rolled). Alternatively, it could be used for creating a simple [unigram language model](https://en.wikipedia.org/wiki/Language_model#Unigram_models) (see [example below](#unigram-usage))\n\nAny suggestions/contributions very welcome.\n\n## Installation\n`$ pip install Vose-Alias-Method`\n\n\n## Depends on:\n- The Python Standard Library, https://docs.python.org/2/library/, https://docs.python.org/3/library/\n- Python versions 2.7, 3.6 (and probably much more - tested on Python 2.7.11, 3.6.6)\n\n## Example Usage\nIn a python shell:\n\n```\n>>> from vose_sampler import VoseAlias\n>>> # Create the required probability distribution (here we use the example of a weighted coin with probability H:=Heads=0.2 and T:=Tail=0.8)\n>>> dist = {\"H\":0.2, \"T\":0.8}\n>>> # Create probability and alias tables from the probability distribution, for sampling via Vose's alias method\n>>> VA = VoseAlias(dist)\n>>> # Generate n random outcomes (here n=10)\n>>> VA.sample_n(size=10)\n['T', 'T', 'H', 'T', 'T', 'T', 'T', 'H', 'T', 'T']\n```\n\n### Unigram language model example\nTo create a [unigram language model](https://en.wikipedia.org/wiki/Language_model#Unigram_models) for [Alice in Wonderland](http://www.gutenberg.org/cache/epub/11/pg11.txt) and sample 10 words from this, run the main script from the command line with options:\n\n```\n$ vose-sampler -p data/Alice.txt -n 10 # or: python vose_sampler/vose_sampler.py -p data/Alice.txt -n 10\n\nGenerating 10 random samples:\n\nthe\nmore\nshe\nRabbit,\nsay\nsuddenly\nat\nsoon\nthing\nsolemn\n```\n\n[Note, this is intended to illustrate how Vose's alias method could be used. Thus I have not included any preprocessing steps that would make the language model more realistic; for example, we could add handling of upper vs. lower case words (so that e.g. \"The\" and \"the\" are not considered distinct), as well as handling of punctuation (e.g. so \"the\" and \"the.\" are considered the same).\n\nLikewise, should the text(s) you wish to sample from be particularly large, you may wish to integrate my [Hadoop MapReduce job for counting the word frequencies of text file(s)](https://github.com/asmith26/python-mapreduce-examples/tree/master/word_frequencies).]\n\n\n## Tests\nRun via: `$ python setup.py test` (or `$ python tests/tests.py`)\n\n## Build\n- `$ python setup.py sdist bdist_wheel`\n- `$ twine upload dist/* -r testpypi --skip-existing` assuming twine is installed and *~/.pypirc* exists with something like:\n```\n[distutils]\nindex-servers=\n testpypi\n pypi\n\n[testpypi]\nrepository = https://test.pypi.org/legacy/\nusername = asmith26\npassword = some_password\n\n[pypi]\nrepository = https://upload.pypi.org/legacy/\nusername = asmith26\npassword = some_harder_password\n```\n\n- Assuming everything looks good `$ twine upload dist/*`\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/asmith26/Vose-Alias-Method.git", "keywords": "", "license": "Apache-2.0", "maintainer": "", "maintainer_email": "", "name": "Vose-Alias-Method", "package_url": "https://pypi.org/project/Vose-Alias-Method/", "platform": "", "project_url": "https://pypi.org/project/Vose-Alias-Method/", "project_urls": { "Homepage": "https://github.com/asmith26/Vose-Alias-Method.git" }, "release_url": "https://pypi.org/project/Vose-Alias-Method/1.1.1/", "requires_dist": null, "requires_python": "", "summary": "Python implementation of Vose's alias method, an efficient algorithm for sampling from a discrete probability distribution.", "version": "1.1.1" }, "last_serial": 5781325, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "847cc0bc9b9b4870b8d8d97bcfe60d3d", "sha256": "d3bd3ab0fd2e3e7bb4909518bb0634d15d6438d282ea5a34ffad6161fa852c56" }, "downloads": -1, "filename": "Vose_Alias_Method-1.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "847cc0bc9b9b4870b8d8d97bcfe60d3d", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 5377, "upload_time": "2018-08-08T16:41:28", "url": "https://files.pythonhosted.org/packages/4b/e9/db7b01d398e75a960f24309171c8437ea1968e80d91a813fc54dd349dda0/Vose_Alias_Method-1.0.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "e3ebdd0f29188b687f8d35083de13f50", "sha256": "9a45256a0d7a9f12869061357427eeaf3f467b986eea972b051123bf4910e79e" }, "downloads": -1, "filename": "Vose-Alias-Method-1.0.0.tar.gz", "has_sig": false, "md5_digest": "e3ebdd0f29188b687f8d35083de13f50", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4853, "upload_time": "2018-08-08T16:41:30", "url": "https://files.pythonhosted.org/packages/47/a9/c2d62d7fe30613147a75fbfd89beaf5c2d6cde98c3040dea465ebd8dca9f/Vose-Alias-Method-1.0.0.tar.gz" } ], "1.1.0": [ { "comment_text": "", "digests": { "md5": "8901df9c8bf799a581996cbee55b16fa", "sha256": "a929d1ccc2b96bf5b7a08e8326bac2d87186349e65ac1d3ad9272aa79553333c" }, "downloads": -1, "filename": "Vose_Alias_Method-1.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "8901df9c8bf799a581996cbee55b16fa", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 9521, "upload_time": "2018-11-02T23:49:47", "url": "https://files.pythonhosted.org/packages/71/49/0f15b676c96d319da11d45a8ee3cd0f257d5070e08943229a59ffe717962/Vose_Alias_Method-1.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "f36ffb97a6648b2a15ad2d5be657124a", "sha256": "6ddc19008b917cbe46f3b2251ea0a5588f2261ad7b6f4f827285b47f9e099040" }, "downloads": -1, "filename": "Vose-Alias-Method-1.1.0.tar.gz", "has_sig": false, "md5_digest": "f36ffb97a6648b2a15ad2d5be657124a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4870, "upload_time": "2018-11-02T23:49:48", "url": "https://files.pythonhosted.org/packages/d3/fd/3c8cb0f5e408e8fdc9afe1e6f1c9097888815cf3284fbb3ca1264937e013/Vose-Alias-Method-1.1.0.tar.gz" } ], "1.1.1": [ { "comment_text": "", "digests": { "md5": "ebc5f57cc1ec066b22b6458050d6d631", "sha256": "5fc08d66693c24b3e4dc73669c09316e2e1d8ab7defdf6c82d3f1b33465b7bf5" }, "downloads": -1, "filename": "Vose_Alias_Method-1.1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "ebc5f57cc1ec066b22b6458050d6d631", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 13693, "upload_time": "2019-09-04T13:47:32", "url": "https://files.pythonhosted.org/packages/ca/41/41773550bab6a403e065e1e90d8074fe7e90a5d32481f17cd4c87fe82943/Vose_Alias_Method-1.1.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "12cd7ce940651e30f628346a66a58b01", "sha256": "aad5889d11852b0dd4cac75c6de9a431770a1822cdea87ec638d47357a3173a3" }, "downloads": -1, "filename": "Vose-Alias-Method-1.1.1.tar.gz", "has_sig": false, "md5_digest": "12cd7ce940651e30f628346a66a58b01", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8848, "upload_time": "2019-09-04T13:47:35", "url": "https://files.pythonhosted.org/packages/9e/89/7031a0665efb6dc2499429eb66168d750aecf27f6f9d4b554b0fadc4ebdc/Vose-Alias-Method-1.1.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "ebc5f57cc1ec066b22b6458050d6d631", "sha256": "5fc08d66693c24b3e4dc73669c09316e2e1d8ab7defdf6c82d3f1b33465b7bf5" }, "downloads": -1, "filename": "Vose_Alias_Method-1.1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "ebc5f57cc1ec066b22b6458050d6d631", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 13693, "upload_time": "2019-09-04T13:47:32", "url": "https://files.pythonhosted.org/packages/ca/41/41773550bab6a403e065e1e90d8074fe7e90a5d32481f17cd4c87fe82943/Vose_Alias_Method-1.1.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "12cd7ce940651e30f628346a66a58b01", "sha256": "aad5889d11852b0dd4cac75c6de9a431770a1822cdea87ec638d47357a3173a3" }, "downloads": -1, "filename": "Vose-Alias-Method-1.1.1.tar.gz", "has_sig": false, "md5_digest": "12cd7ce940651e30f628346a66a58b01", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8848, "upload_time": "2019-09-04T13:47:35", "url": "https://files.pythonhosted.org/packages/9e/89/7031a0665efb6dc2499429eb66168d750aecf27f6f9d4b554b0fadc4ebdc/Vose-Alias-Method-1.1.1.tar.gz" } ] }