lintsampler
Efficient random sampling via linear interpolation.
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 for further details.
This package was also reviewed for the Journal of Open Source Software (JOSS). See the paper here and the review thread here.
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,
import numpy as np
from scipy.stats import norm
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):
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.
See this page of the documentation for a more detailed explanation of this example.
Documentation
Complete documentation, including more example notebooks, is available at lintsampler.readthedocs.io/.
Contributing
The lintsampler maintainers welcome contributions to software, examples, and documentation. The maintainers are actively monitoring pull requests and would be happy to collaborate on contributions or ideas. If you have any requests for additional information or find any bugs, please open an issue directly.
Attribution
If using lintsampler for a research publication, please cite our paper.
License
lintsampler is available under the MIT license. See the LICENSE file for specifics.
Metadata
Release files for lintsampler 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| lintsampler-1.0.1.tar.gz | 13.8 MB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| lintsampler-1.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.8 MB
Release files / lintsampler-1.0.1.tar.gz
| Download URL | lintsampler-1.0.1.tar.gz |
|---|---|
| Size | 13.8 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2c4ecc9599a50279d41023eb72dd447af91dfac4f1083d5fe5ce23bd54a8baa9
|
|
BLAKE2b-256 checksum How to use checksums |
30dfab4419491db249bfc6dee6b2ce4d5b146867f74d798d26a8d714a0174873
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.14
|
Release files / lintsampler-1.0.1-py3-none-any.whl
| Download URL | lintsampler-1.0.1-py3-none-any.whl |
|---|---|
| Size | 30.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fb0477ba437ba1906b0ab09bedb0c25170e3ef9889a558dc50d3ae65c70466a4
|
|
BLAKE2b-256 checksum How to use checksums |
b51168bf4c146c573d4d4155de09b3fe747c1bea3d46f8d7bbd32f399c9108d1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.14
|