Skip to main content

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

The usual: ` 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:
  1. Add a particle.

  2. Remove a particle.

  3. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

SamplePairsGaussian-1.0.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

SamplePairsGaussian-1.0-py3.7.egg (34.4 kB view details)

Uploaded Egg

File details

Details for the file SamplePairsGaussian-1.0.tar.gz.

File metadata

  • Download URL: SamplePairsGaussian-1.0.tar.gz
  • Upload date:
  • Size: 10.0 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

Hashes for SamplePairsGaussian-1.0.tar.gz
Algorithm Hash digest
SHA256 c7cf60565dca2a3ea7794b04ed0a60e80e84a1557de129793b1f1ba199c06e01
MD5 9db583605f4535039789ed8be4eac257
BLAKE2b-256 fc5e60d5dad65579ba93f65c05a57d4d2e1d4b7453ef67340ebddafb803060be

See more details on using hashes here.

File details

Details for the file SamplePairsGaussian-1.0-py3.7.egg.

File metadata

  • Download URL: SamplePairsGaussian-1.0-py3.7.egg
  • Upload date:
  • Size: 34.4 kB
  • Tags: Egg
  • 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

Hashes for SamplePairsGaussian-1.0-py3.7.egg
Algorithm Hash digest
SHA256 cc56578c770c26d21ff8dbe1536a747b812ead4ebd71e61576b39102980c5268
MD5 410977af6a9ae8dd2c9464ee2f4a1034
BLAKE2b-256 11beec570e809623f5a362d09565dc7009513188c53bf644584ae83f26e7ea51

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page