Skip to main content

# 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:
  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.

Metadata

Release files for SamplePairsGaussian 1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for SamplePairsGaussian 1.1
File Size Uploaded Provenance Actions
SamplePairsGaussian-1.1.tar.gz 12.1 kB Without provenance Details for SamplePairsGaussian-1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for SamplePairsGaussian 1.1
File Interpreter ABI Platform Actions
SamplePairsGaussian-1.1-py3.7.egg Legacy Egg format - - Details for SamplePairsGaussian-1.1-py3.7.egg

Total release size: 57.8 kB

Release files / SamplePairsGaussian-1.1.tar.gz

Download URL SamplePairsGaussian-1.1.tar.gz
Size 12.1 kB
Tags Source
SHA-256 checksum
How to use checksums
669440f2a15dc5c2f7b7abb95a12c01b86fbb045f4636cbcc3c749b4799b78b8
BLAKE2b-256 checksum
How to use checksums
e1bb1c60747ad4d15c39793ad2f09e1d79e85c242c605bc6873d340fa67e87e4
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / SamplePairsGaussian-1.1-py3.7.egg

Download URL SamplePairsGaussian-1.1-py3.7.egg
Size 45.8 kB
Tags Egg
SHA-256 checksum
How to use checksums
d825c4569fb9b0d0d3a1a3248ad6f05b3c6515b72f6a26900582868b9e928720
BLAKE2b-256 checksum
How to use checksums
5085c6bdff06b238f1931cc56d2e6d07435e2022443f43438054f219d951475f
Upload date
Uploaded using Trusted Publishing?
What is 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

Security for SamplePairsGaussian 1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page