Sample pairs of particles according to a discrete Gaussian distrbution
Project description
# Sample pairs of particles according to a discrete Gaussian Python code to sample pairs of a given set of particles in n dims, where the probability for each pair is Gaussian
<img src=”examples/figures/sample_2d_counts.png” width=”500”>
## Requirements
Python 3 & Numpy.
## Installation and usage
Use pip: ` pip install samplePairsGaussian ` or manually: ` python setup.py install ` and in your code: ` from samplePairsGaussian import * ` See also the [examples](examples) folder.
## Idea
Given a set of n particles with positions in d-dimensional space denoted by x_i for i=0,1,…,n.
We want to sample a pair of particles i,j where i =/= j, where the probability for sampling this pair is given by: ` p(i,j) ~ exp( - |x_i - x_j|^2 / 2 sigma^2 ) ` where we use |x| to denote the L_2 norm, and sigma is some chosen standard deviation.
This problem is easy to write down, but difficult to implement for large numbers of particles since it requires computing N^2 distances.
- A further problem is that we may want to:
Add a particle.
Remove a particle.
Move a particle.
In this case, not all distances are affected - these operations should be of order N. However, if we sample the discrete distribution by forming the CDF, we will need to recalculate it, which is expensive. Alternatively, if we use rejection sampling, we must have a good candidate (envelope) distribution such that the acceptance ratio is high.
This library attempts to come up with the most efficient way to perform these operations in Python.
A key way this library reduces computational cost is by introducing a cutoff for particle distances, where pairs of particles separated by a distance greater than the cutoff are not considered for sampling. It is natural to let this be some chosen multiple of the std. dev., i.e. m*sigma for some m. If we use rejection sampling where candidates are drawn from a uniform distribution, the acceptance ratio should be approximately ( sqrt(2 * pi) * sigma ) / ( 2 * m * sigma ) = 1.253 / m. (in the first equation: the area of the Gaussian is 1, divided by the area of the uniform distribution of width 2 * m * sigma and height 1 / (sqrt(2 * pi) * sigma )).
In general, we avoid all use of for loops, and rely extensively on array operations using numpy.
### Multiple species
Multiple species are also supported, where we have multiple species but want to draw two particles of the same species (two particles of any species can be done by simply ignoring the species labels).
Specifically, the classes ProbCalculatorMultiSpecies and SamplerMultiSpecies implement this.
## Examples
See the [examples](examples) folder.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file SamplePairsGaussian-1.1.tar.gz
.
File metadata
- Download URL: SamplePairsGaussian-1.1.tar.gz
- Upload date:
- Size: 12.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 669440f2a15dc5c2f7b7abb95a12c01b86fbb045f4636cbcc3c749b4799b78b8 |
|
MD5 | d5757327420e9a7b4fd8973b1814275e |
|
BLAKE2b-256 | e1bb1c60747ad4d15c39793ad2f09e1d79e85c242c605bc6873d340fa67e87e4 |
File details
Details for the file SamplePairsGaussian-1.1-py3.7.egg
.
File metadata
- Download URL: SamplePairsGaussian-1.1-py3.7.egg
- Upload date:
- Size: 45.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d825c4569fb9b0d0d3a1a3248ad6f05b3c6515b72f6a26900582868b9e928720 |
|
MD5 | d0153a9fbc8a0e3200a9c4cb19440569 |
|
BLAKE2b-256 | 5085c6bdff06b238f1931cc56d2e6d07435e2022443f43438054f219d951475f |