Skip to main content

Sampling from a Maximum-Likelihood fitted Multi-Gaussian distribution in TensorFlow 2.1

Project description

Multi-Gaussian Sampling

The parametrization of conditional probability density function plays a crucial role in the simulations used to produce quickly large samples of data emulating real-life datasets.

A very simple technique is based on the explicit modelling of the probability density function of the target dataset as a function of the conditions through the sum of kernel functions.

The packagemultigaussampler offers a simple Python3 implementation of this simple algorithm. The model of the pdf is obtained through a maximum likelihood fit of a probability density function obtained as sum of Gaussians, optimized using the TensorFlow implementation of the Adam optimizer.

The sampling of the pdf is also implemented in TensorFlow to provide efficient sampling on both CPU and GPU infrastructures.

Example code

The code snippet below trains a sampler on a random dataset and generates a random sample of y variables on top of the same X variables used for training.

import numpy as np

## Generate a random dataset as an example
nSamples = 1000 
X = np.random.uniform ( -20, 10,  (nSamples,4)).astype (np.float32) 
y = np.random.uniform ( 0, 1,     (nSamples,2)).astype (np.float32) 

#from multigaussampler import MGSampler
## Creates and configure the MGSampler object
gp = MGSampler(X,y) 

## Train the MGSampler on the training dataset
from tqdm import trange
progress_bar = trange ( 100 )
for iEpoch in progress_bar:
  l = gp.train ( X,y ) 
  progress_bar.set_description ( "Loss: %.1f " % l ) 

## Sample the obtained parametrization
gp.sample (X) 

Author

Lucio Anderlini (Istituto Nazionale di Fisica Nucleare)

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

multigaussampler-0.1.1-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file multigaussampler-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: multigaussampler-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/39.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.8

File hashes

Hashes for multigaussampler-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 36c49b55629d269539a1413bdf28ff4532ce68a38e2118c3fa2acb4a60e3403a
MD5 542add0f1cc300cd6a470be5b73131c8
BLAKE2b-256 fb72819ffefa7683d32c61908fed7b6af4778e007dba1479665376fd878a0019

See more details on using hashes here.

Supported by

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