{ "info": { "author": "Edward Newell", "author_email": "edward.newell@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 2.7", "Topic :: Software Development :: Build Tools" ], "description": "Categorical Sampler\n-----\n\nInstall from pip: `pip install categorical-sampler`\n\nLet’s generate a probability distribution to get us started. First, sample a bunch of random numbers to determine probability “scores”.\n\n\n >>> from random import random\n >>> k = 10**6\n >>> scores = [random() for i in range(k)]\n >>> total = sum(scores)\n >>> probabilities = [s / total for s in scores]\n\n\nWe've normalized the scores to sum to 1, i.e. make\nthem into proper probabilities, but actually the categorical sampler will do that for us, so it’s not necessary:\n\n >>> from categorical import Categorical as C\n >>> my_sampler = C(scores)\n >>> print my_sampler.sample()\n 487702\n\nComparing to numpy, assuming we draw 1000 individual samples *individually*:\n\n\n >>> from numpy.random import choice\n >>> import time\n >>> \n >>> def time_numpy():\n >>> start = time.time()\n >>> for i in range(1000):\n >>> choice(k, p=probabilities)\n >>> print time.time() - start\n >>> \n >>> def time_my_alias():\n >>> start = time.time()\n >>> for i in range(1000):\n >>> my_sampler.sample()\n >>> print time.time() - start\n >>> \n >>> time_numpy()\n 31.0555009842\n >>> time_my_alias()\n 0.0127031803131\n\nGet the actual probability of a given outcome:\n\n >>> my_sampler.get_probability(487702)\n 1.0911282101090306e-06", "description_content_type": null, "docs_url": null, "download_url": null, "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/enewe101/categorical", "keywords": "sample sampler sampling categorical multinomial discrete distribution statistics probability random", "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "categorical", "package_url": "https://pypi.org/project/categorical/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/categorical/", "project_urls": { "Homepage": "https://github.com/enewe101/categorical" }, "release_url": "https://pypi.org/project/categorical/0.1.4/", "requires_dist": null, "requires_python": null, "summary": "Fast on-demand sampling from categorical distributions", "version": "0.1.4" }, "last_serial": 2221583, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "28319e571ee13b7ca818c19c17877e7d", "sha256": "29c98b74012f0a7644a65428bd349449515daf6ca99a12a007bcea1fb1a6e5b7" }, "downloads": -1, "filename": "categorical-0.1.0.tar.gz", "has_sig": false, "md5_digest": "28319e571ee13b7ca818c19c17877e7d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3266, "upload_time": "2016-04-28T17:04:04", "url": "https://files.pythonhosted.org/packages/c3/62/fdeaa044a4add36fbbff52c5f0375b7766f2a2e47f615bc21eb989943916/categorical-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "11e4df9ae64e4e6e1075b5cd389723a3", "sha256": "50bd543f18827fccdf0a83be23d7162ff06764ebff0d24c87f144bd03db14051" }, "downloads": -1, "filename": "categorical-0.1.1.tar.gz", "has_sig": false, "md5_digest": "11e4df9ae64e4e6e1075b5cd389723a3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3353, "upload_time": "2016-04-28T17:11:19", "url": "https://files.pythonhosted.org/packages/c1/de/79402f34a595111f3ef77837b4b06096e44a31f868ea52db722f30756354/categorical-0.1.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "6171830bad2d914f6bebff92cd3df444", "sha256": "9248533be0d0dcdbe096940f6eac2dba5375312861dff7a688639507127f8d60" }, "downloads": -1, "filename": "categorical-0.1.2.tar.gz", "has_sig": false, "md5_digest": "6171830bad2d914f6bebff92cd3df444", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3487, "upload_time": "2016-04-28T17:17:47", "url": "https://files.pythonhosted.org/packages/35/d6/50b2d93184cbbb9865df09741d95bafe9049b1b1e150e0051c4332310360/categorical-0.1.2.tar.gz" } ], "0.1.3": [ { "comment_text": "", "digests": { "md5": "28ffce55710a63fc1f94d3e04245a935", "sha256": "b2bdd287795b5c9df8850940193f4dc06c7f1e19679ee63289a6d187b9ee4162" }, "downloads": -1, "filename": "categorical-0.1.3.tar.gz", "has_sig": false, "md5_digest": "28ffce55710a63fc1f94d3e04245a935", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3498, "upload_time": "2016-04-28T17:19:07", "url": "https://files.pythonhosted.org/packages/ec/e6/e8310999b1dc255e13fb4506a9b11a34a3d7e769410c6a68d2ab4fe88fb9/categorical-0.1.3.tar.gz" } ], "0.1.4": [ { "comment_text": "", "digests": { "md5": "50b309d8d0187d275e211ac73075cb9c", "sha256": "e6b532baa2561284557ed9b4c41c17a579ef372951ea5dffa739fce0d04df6b2" }, "downloads": -1, "filename": "categorical-0.1.4.tar.gz", "has_sig": false, "md5_digest": "50b309d8d0187d275e211ac73075cb9c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4365, "upload_time": "2016-07-14T18:16:35", "url": "https://files.pythonhosted.org/packages/1c/82/2373e9f91656dbc2c1b90052ba7541cf9629bf021eef665419115d1dd9bf/categorical-0.1.4.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "50b309d8d0187d275e211ac73075cb9c", "sha256": "e6b532baa2561284557ed9b4c41c17a579ef372951ea5dffa739fce0d04df6b2" }, "downloads": -1, "filename": "categorical-0.1.4.tar.gz", "has_sig": false, "md5_digest": "50b309d8d0187d275e211ac73075cb9c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4365, "upload_time": "2016-07-14T18:16:35", "url": "https://files.pythonhosted.org/packages/1c/82/2373e9f91656dbc2c1b90052ba7541cf9629bf021eef665419115d1dd9bf/categorical-0.1.4.tar.gz" } ] }