{ "info": { "author": "Luke Zoltan Kelley", "author_email": "lzkelley@northwestern.edu", "bugtrack_url": null, "classifiers": [], "description": "# kalepy: Kernel Density Estimation and Sampling\n\n[![Build Status](https://travis-ci.org/lzkelley/kalepy.svg?branch=master)](https://travis-ci.org/lzkelley/kalepy)\n[![codecov](https://codecov.io/gh/lzkelley/kalepy/branch/master/graph/badge.svg)](https://codecov.io/gh/lzkelley/kalepy)\n\ndev: [![Build Status](https://travis-ci.org/lzkelley/kalepy.svg?branch=dev)](https://travis-ci.org/lzkelley/kalepy)\n\nThis package performs KDE operations on multidimensional data to: **1) calculate estimated PDFs** (probability distribution functions), and **2) to resample new data** from those PDFs.\n\n## Installation\n\n#### from pypi (i.e. via pip)\n\n```bash\npip install kalepy\n```\n\n#### from source (e.g. for development)\n\n```bash\ngit clone https://github.com/lzkelley/kalepy.git\npip install -e kalepy/\n```\n\nIn this case the package can easily be updated be changing into the source directory, pulling, and rebuilding:\n\n```bash\ncd kalepy\ngit pull\npip install -e .\n# Optional: run unit tests (using the `nosetests` package)\nnosetests\n```\n\n\n## Examples\n\n### Use 'reflecting' boundary conditions to improve PDF reconstruction at boundaries\n\nWithout reflection, the KDE (red line) noticeably underestimates the edges of this uniform distribution (grey histogram). When resampling from the KDE, the new samples (red carpet and histogram) are drawn outside of the original distribution edges. Reflecting boundary conditions better estimate the PDF, and constrain new samples to be within bounds.\n\n```python\nimport kalepy as kale\n# here `data` has shape (N,) for N data points\nkde = kale.KDE(data)\ngrid = np.linspace(-0.5, 2.5, 1000)\n# choose reflection boundaries\nboundaries = [0.0, 2.0]\npdf = kde.pdf(grid, reflect=boundaries)\nsamples = kde.resample(100, reflect=boundaries)\n```\n\n\n\n![1D Samples with Reflection](https://raw.githubusercontent.com/lzkelley/kalepy/master/docs/media/kde_1d_reflect.png)\n\nThis also works in multiple dimensions. In each dimension, reflecting boundaries can be applied either on both sides (e.g. x-axis), or only on one side (e.g. y-axis).\n\n```python\nimport kalepy as kale\n# here `data` has shape (2,N) 2-parameters and N data points\nkde = kale.KDE(data)\nxc, yc = np.meshgrid([np.linspace(-0.5, 2.5, 100), np.linspace(-3.0, 2.5, 200)])\ngrid = np.vstack([xc.ravel(), yc.ravel()])\n# choose reflection boundaries in each parameter\nboundaries = [[0.0, 2.0], [None, 2.0]]\npdf = kde.pdf(grid, reflect=boundaries)\nsamples = kde.resample(1000, reflect=boundaries)\n```\n\n![2D Samples with Reflection](https://raw.githubusercontent.com/lzkelley/kalepy/master/docs/media/kde_2d_reflect.png)\n\n\n\n### Comparison of Different Histogram Parameters and Different Kernel\n\nThe choice in bin-widths and bin-origins makes a significant difference in how a histogram appears. In general, both parameters are chosen arbitrarily. KDE also have freedom in what kernel is used, and the bandwidth (amount of smoothing), but there are heuristics for optimizing these parameters. In particular, for general data, the Parabola/\"Epanechnikov\" kernel is optimal in reducing bias, and the bandwidth can be estimated using Scott's method.\n\n![Different Histograms and Kernels](https://raw.githubusercontent.com/lzkelley/kalepy/master/docs/media/kde_motivation.png)\n\n\n\n### Calculate projected / marginalized PDF across target parameters\n\n```python\n# 2-parameter data, shaped (2,N) for N data-points\nkde = kale.KDE(data)\n# Create bins in each dimension\nedges = [np.linspace(-7.5, 10.5, 100), np.linspace(-3, 9, 100)]\nxe, ye = np.meshgrid(*edges)\n# Grid of test points\ngrid = np.vstack([xe.ravel(), ye.ravel()])\n# Calculate 2D PDF\npdf_2d = kde.pdf(grid)\n# Calculate each 1D PDF\npdf_x = kde.pdf(edges[0], param=0)\npdf_y = kde.pdf(edges[1], param=1)\n```\n\n![2D PDF with projections](https://raw.githubusercontent.com/lzkelley/kalepy/master/docs/media/2d_pdf_projection.png)\n\n\n\n### KDE Refinement with increasing data points\n\n![2D PDF with projections](https://raw.githubusercontent.com/lzkelley/kalepy/master/docs/media/movie.gif)\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "https://github.com/lzkelley/kalepy/archive/v0.2.1.tar.gz", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/lzkelley/kalepy/", "keywords": "utilities,physics,astronomy,cosmology,astrophysics,statistics,kernel density estimation,kernel density estimate", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "kalepy", "package_url": "https://pypi.org/project/kalepy/", "platform": "", "project_url": "https://pypi.org/project/kalepy/", "project_urls": { "Download": "https://github.com/lzkelley/kalepy/archive/v0.2.1.tar.gz", "Homepage": "https://github.com/lzkelley/kalepy/" }, "release_url": "https://pypi.org/project/kalepy/0.2.1/", "requires_dist": [ "numpy", "scipy", "codecov", "six", "future", "nose", "sphinx", "jupyter", "nbconvert", "corner", "matplotlib" ], "requires_python": "", "summary": "Kernel density estimation and sampling.", "version": "0.2.1" }, "last_serial": 5378246, "releases": { "0.1.3": [ { "comment_text": "", "digests": { "md5": "b2eadf25d62abb4fc5064d0e2456b655", "sha256": "df6c060b2a365ebd535292200d73855b62107673f55fe4d2f06d52f853ad2f10" }, "downloads": -1, "filename": "kalepy-0.1.3-py3-none-any.whl", "has_sig": false, "md5_digest": "b2eadf25d62abb4fc5064d0e2456b655", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 21562, "upload_time": "2019-05-25T16:06:49", "url": "https://files.pythonhosted.org/packages/f3/e8/ba2eb3c6dd6d5fa3cb85fbbfa9c7ffcbee008299bd218e1518f28cb170fa/kalepy-0.1.3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "ef3d0981bdd38e86b2c34c0f4e4c6112", "sha256": "3ddf76b0ac1e1932093a5c141aa386630e9630958c1c3e36a90f1e80214a3d56" }, "downloads": -1, "filename": "kalepy-0.1.3.tar.gz", "has_sig": false, "md5_digest": "ef3d0981bdd38e86b2c34c0f4e4c6112", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8899426, "upload_time": "2019-05-25T16:06:57", "url": "https://files.pythonhosted.org/packages/9c/19/356d3d6a62df9422d36d187a66ff0b03b15e02728e09d4c71164402bfd1a/kalepy-0.1.3.tar.gz" } ], "0.1.4": [ { "comment_text": "", "digests": { "md5": "66b160f1a290f4f973d3d81f003ac7e7", "sha256": "a0d2db63264dd46a130cea13abf3ca8276060de8e81e2a1f1b0de202e49680f9" }, "downloads": -1, "filename": "kalepy-0.1.4-py3-none-any.whl", "has_sig": false, "md5_digest": "66b160f1a290f4f973d3d81f003ac7e7", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 21617, "upload_time": "2019-05-25T16:57:41", "url": "https://files.pythonhosted.org/packages/55/0d/10b090a6e92df92e508d923872f1a6613fc57962d3634d5ccbd7e0ae8b6d/kalepy-0.1.4-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "7480e1ed60b29f58445947ced6d8d9b8", "sha256": "cbe22b21dd29c9402c859f622a49acd60260b1afc3bf39b3bc506b9ec3c56f30" }, "downloads": -1, "filename": "kalepy-0.1.4.tar.gz", "has_sig": false, "md5_digest": "7480e1ed60b29f58445947ced6d8d9b8", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8899628, "upload_time": "2019-05-25T16:57:50", "url": "https://files.pythonhosted.org/packages/1d/e0/a8ea2b50215b0fd186e9b58dfbbb5698c90b01d6ba8bda6530798629894b/kalepy-0.1.4.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "2793b981804f4dd0bf7e24b907d17efb", "sha256": "2e47ee76faa43d9434c96a3ca15f5f73c9861cc7d12d1edaf2ab76dbf9ec0168" }, "downloads": -1, "filename": "kalepy-0.2.0-py3-none-any.whl", "has_sig": false, "md5_digest": "2793b981804f4dd0bf7e24b907d17efb", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 27463, "upload_time": "2019-06-03T19:02:24", "url": "https://files.pythonhosted.org/packages/2a/7d/92218b03385f6a4bff91689b4c5377d140e67de6ff8304816101c4c29425/kalepy-0.2.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "191b1eac4aaf8abd3373a4615a6e65a9", "sha256": "9369ee53569e771093dcc58ca2e413696624b9a0eccfa9cc68dad115ad39357c" }, "downloads": -1, "filename": "kalepy-0.2.0.tar.gz", "has_sig": false, "md5_digest": "191b1eac4aaf8abd3373a4615a6e65a9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 16093404, "upload_time": "2019-06-03T19:02:49", "url": "https://files.pythonhosted.org/packages/8b/92/12d3e5202bbbfa9208f312dc27aad42ca25e470d8832dea569000e2de0e8/kalepy-0.2.0.tar.gz" } ], "0.2.1": [ { "comment_text": "", "digests": { "md5": "5afd9834f638900966aee36fbc471e9c", "sha256": "566c8e3b68303ccaa87233d0f71a29ed6fa739e6a0c9d57c8b55412320467a1a" }, "downloads": -1, "filename": "kalepy-0.2.1-py3-none-any.whl", "has_sig": false, "md5_digest": "5afd9834f638900966aee36fbc471e9c", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 32442, "upload_time": "2019-06-09T17:18:13", "url": "https://files.pythonhosted.org/packages/62/86/3b4dbaf91c24010fba5c3b3fde206a2694e34b3e740ec209a034337fc51b/kalepy-0.2.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "9717a6871b8e5e877b7859419645808a", "sha256": "c071bb459723d321e4bf8b6a59dda9c56dbd279929abfb431df5d0edf4555943" }, "downloads": -1, "filename": "kalepy-0.2.1.tar.gz", "has_sig": false, "md5_digest": "9717a6871b8e5e877b7859419645808a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 21878061, "upload_time": "2019-06-09T17:18:18", "url": "https://files.pythonhosted.org/packages/4a/02/4657eb8ac82b144db9a187e411f745df9616f75042eed48a4d89c25f9ce1/kalepy-0.2.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "5afd9834f638900966aee36fbc471e9c", "sha256": "566c8e3b68303ccaa87233d0f71a29ed6fa739e6a0c9d57c8b55412320467a1a" }, "downloads": -1, "filename": "kalepy-0.2.1-py3-none-any.whl", "has_sig": false, "md5_digest": "5afd9834f638900966aee36fbc471e9c", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 32442, "upload_time": "2019-06-09T17:18:13", "url": "https://files.pythonhosted.org/packages/62/86/3b4dbaf91c24010fba5c3b3fde206a2694e34b3e740ec209a034337fc51b/kalepy-0.2.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "9717a6871b8e5e877b7859419645808a", "sha256": "c071bb459723d321e4bf8b6a59dda9c56dbd279929abfb431df5d0edf4555943" }, "downloads": -1, "filename": "kalepy-0.2.1.tar.gz", "has_sig": false, "md5_digest": "9717a6871b8e5e877b7859419645808a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 21878061, "upload_time": "2019-06-09T17:18:18", "url": "https://files.pythonhosted.org/packages/4a/02/4657eb8ac82b144db9a187e411f745df9616f75042eed48a4d89c25f9ce1/kalepy-0.2.1.tar.gz" } ] }