lintsampler


Namelintsampler JSON
Version 0.3.0 PyPI version JSON
download
home_pageNone
SummaryEfficient random sampling via linear interpolation.
upload_time2024-06-14 10:22:11
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseNone
keywords python statistics numpy sampling random
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # lintsampler
![Animation showing 'lintsampler' rendered in points.](docs/source/_static/lintsampler.gif)

**Efficient random sampling via linear interpolation.**

[![Test](https://github.com/aneeshnaik/lintsampler/actions/workflows/test.yaml/badge.svg)](https://github.com/aneeshnaik/lintsampler/actions/workflows/test.yaml)
[![Coverage Status](https://coveralls.io/repos/github/aneeshnaik/lintsampler/badge.svg?branch=main&kill_cache=1)](https://coveralls.io/github/aneeshnaik/lintsampler?branch=main)
[![Documentation Status](https://readthedocs.org/projects/lintsampler/badge/?version=latest)](https://lintsampler.readthedocs.io/en/latest/?badge=latest)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/aneeshnaik/lintsampler/blob/main/LICENSE)

When you have a density function, but you would like to create a set of sample points from that density function, you can use _linear interpolate sampling_. Using the evaluation of the density at the two endpoints of 1D interval, or the four corners of a 2D rectangle, or generally the $2^k$ vertices of a $k$-dimensional hyperbox (or a series of such hyperboxes, e.g., the cells of a $k$-dimensional grid), linear interpolant sampling is a technique to draw random samples within the hyperbox. `lintsampler` provides a Python implementation of this.

See the [documentation](https://lintsampler.readthedocs.io/) or our [paper](https://github.com/aneeshnaik/lintsampler/blob/main/paper/paper.pdf) for further details. 

## Installation

Three ways of installing `lintsampler`:

- `pip`:
```
pip install lintsampler
```

- `conda`:
```
conda install -c conda-forge lintsampler
```

- Simply cloning this repository.

## Quickstart Example

If you have a density function, such as this multi-modal 1d pdf with the bulk of the density between -7 and 7,

```python
import numpy as np

def gmm_pdf(x):
    mu = np.array([-3.0, 0.5, 2.5])
    sig = np.array([1.0, 0.25, 0.75])
    w = np.array([0.4, 0.25, 0.35])
    return np.sum([w[i] * norm.pdf(x, mu[i], sig[i]) for i in range(3)], axis=0)
```

`lintsampler` can efficiently draw samples from it on some defined interval (here a 100-point grid between -7 and 7):

```python
from lintsampler import LintSampler

grid = np.linspace(-7,7,100)
samples = LintSampler(grid,pdf=gmm_pdf).sample(N=10000)
```

Making a histogram of the resulting samples and comparing to the input density function shows good agreement -- and we can do even better by increasing the resolution.
![Example 1d pdf with comparative histogram of sampled points.](docs/source/assets/example1.png)

See [this page of the documentation](https://lintsampler.readthedocs.io/en/latest/examples/1_gmm.html) for a more detailed explanation of this example.

## Documentation

Complete documentation, including more example notebooks, is available at [lintsampler.readthedocs.io/](https://lintsampler.readthedocs.io/).

## Attribution

If using `lintsampler` for a research publication, please cite our [paper](https://github.com/aneeshnaik/lintsampler/blob/main/paper/paper.pdf).

## License

`lintsampler` is available under the MIT license. See the LICENSE file for specifics.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "lintsampler",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "python, statistics, numpy, sampling, random",
    "author": null,
    "author_email": "\"Aneesh P. Naik\" <aneesh.naik@roe.ac.uk>, \"Michael S. Petersen\" <michael.petersen@roe.ac.uk>",
    "download_url": "https://files.pythonhosted.org/packages/25/13/3b9e60c45968cc4930917cf6992f8db76492c62915bf913f1b8b928ae94f/lintsampler-0.3.0.tar.gz",
    "platform": null,
    "description": "# lintsampler\n![Animation showing 'lintsampler' rendered in points.](docs/source/_static/lintsampler.gif)\n\n**Efficient random sampling via linear interpolation.**\n\n[![Test](https://github.com/aneeshnaik/lintsampler/actions/workflows/test.yaml/badge.svg)](https://github.com/aneeshnaik/lintsampler/actions/workflows/test.yaml)\n[![Coverage Status](https://coveralls.io/repos/github/aneeshnaik/lintsampler/badge.svg?branch=main&kill_cache=1)](https://coveralls.io/github/aneeshnaik/lintsampler?branch=main)\n[![Documentation Status](https://readthedocs.org/projects/lintsampler/badge/?version=latest)](https://lintsampler.readthedocs.io/en/latest/?badge=latest)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/aneeshnaik/lintsampler/blob/main/LICENSE)\n\nWhen you have a density function, but you would like to create a set of sample points from that density function, you can use _linear interpolate sampling_. Using the evaluation of the density at the two endpoints of 1D interval, or the four corners of a 2D rectangle, or generally the $2^k$ vertices of a $k$-dimensional hyperbox (or a series of such hyperboxes, e.g., the cells of a $k$-dimensional grid), linear interpolant sampling is a technique to draw random samples within the hyperbox. `lintsampler` provides a Python implementation of this.\n\nSee the [documentation](https://lintsampler.readthedocs.io/) or our [paper](https://github.com/aneeshnaik/lintsampler/blob/main/paper/paper.pdf) for further details. \n\n## Installation\n\nThree ways of installing `lintsampler`:\n\n- `pip`:\n```\npip install lintsampler\n```\n\n- `conda`:\n```\nconda install -c conda-forge lintsampler\n```\n\n- Simply cloning this repository.\n\n## Quickstart Example\n\nIf you have a density function, such as this multi-modal 1d pdf with the bulk of the density between -7 and 7,\n\n```python\nimport numpy as np\n\ndef gmm_pdf(x):\n    mu = np.array([-3.0, 0.5, 2.5])\n    sig = np.array([1.0, 0.25, 0.75])\n    w = np.array([0.4, 0.25, 0.35])\n    return np.sum([w[i] * norm.pdf(x, mu[i], sig[i]) for i in range(3)], axis=0)\n```\n\n`lintsampler` can efficiently draw samples from it on some defined interval (here a 100-point grid between -7 and 7):\n\n```python\nfrom lintsampler import LintSampler\n\ngrid = np.linspace(-7,7,100)\nsamples = LintSampler(grid,pdf=gmm_pdf).sample(N=10000)\n```\n\nMaking a histogram of the resulting samples and comparing to the input density function shows good agreement -- and we can do even better by increasing the resolution.\n![Example 1d pdf with comparative histogram of sampled points.](docs/source/assets/example1.png)\n\nSee [this page of the documentation](https://lintsampler.readthedocs.io/en/latest/examples/1_gmm.html) for a more detailed explanation of this example.\n\n## Documentation\n\nComplete documentation, including more example notebooks, is available at [lintsampler.readthedocs.io/](https://lintsampler.readthedocs.io/).\n\n## Attribution\n\nIf using `lintsampler` for a research publication, please cite our [paper](https://github.com/aneeshnaik/lintsampler/blob/main/paper/paper.pdf).\n\n## License\n\n`lintsampler` is available under the MIT license. See the LICENSE file for specifics.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Efficient random sampling via linear interpolation.",
    "version": "0.3.0",
    "project_urls": {
        "Documentation": "https://lintsampler.readthedocs.io",
        "Homepage": "https://github.com/aneeshnaik/lintsampler"
    },
    "split_keywords": [
        "python",
        " statistics",
        " numpy",
        " sampling",
        " random"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "734ba1aea1d52948bed44718b82775fc01abf76112f84b438246029f787c05c6",
                "md5": "c575d8a5b995056eb60a11ad4056e653",
                "sha256": "db6fd54a327b135a1f8f932fca2d498c7c6ac5f484ff2ca7bb9cfdb07b549e1f"
            },
            "downloads": -1,
            "filename": "lintsampler-0.3.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c575d8a5b995056eb60a11ad4056e653",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 30467,
            "upload_time": "2024-06-14T10:22:09",
            "upload_time_iso_8601": "2024-06-14T10:22:09.163079Z",
            "url": "https://files.pythonhosted.org/packages/73/4b/a1aea1d52948bed44718b82775fc01abf76112f84b438246029f787c05c6/lintsampler-0.3.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "25133b9e60c45968cc4930917cf6992f8db76492c62915bf913f1b8b928ae94f",
                "md5": "9674dafa85aadabf4475d95a97b2fd4c",
                "sha256": "dc8ab38e183bac59988a4be2b479385fae1fff55904aeb54024c27bcfc24e532"
            },
            "downloads": -1,
            "filename": "lintsampler-0.3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "9674dafa85aadabf4475d95a97b2fd4c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 13676309,
            "upload_time": "2024-06-14T10:22:11",
            "upload_time_iso_8601": "2024-06-14T10:22:11.858681Z",
            "url": "https://files.pythonhosted.org/packages/25/13/3b9e60c45968cc4930917cf6992f8db76492c62915bf913f1b8b928ae94f/lintsampler-0.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-14 10:22:11",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "aneeshnaik",
    "github_project": "lintsampler",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "test_requirements": [],
    "lcname": "lintsampler"
}
        
Elapsed time: 1.40824s