vec_math
Class PoissonRandom

java.lang.Object
  extended by java.util.Random
      extended by vec_math.PoissonRandom
All Implemented Interfaces:
Serializable

public class PoissonRandom
extends Random

Extends the random function to include Poisson-distributed random variable Uses algorithm of Ahrean & Dieter, 'Computer Methods for Sampling from Gamma, Beta, Poisson and Binominal Distributions', Computing 12, p223ff 1974. Currently, only the gamma method is implemented, which have a cost of order of ln(μ).

For other distributions, either use the inverse transform sampling theorem, which says that an cdf (cumulative distribution function cdf(x) = ∫_-&inf;^x pdf(x')dx', integral of the probability distribution function pdf), that is invertible (cdf*) produces random numbers r distributed according to pdf(x) out of uniform random numbers u with r=cdf*(u). If cdf is not known analytically, it might be worth the effort to use the rejection method, Num. Rec. p.290ff

See Also:
Serialized Form

Nested Class Summary
static class PoissonRandom.MedianGauss
          Class to take a normal-distributed variable, sort them, print the mean and the sigma.
static class PoissonRandom.Poisson
          Class to produce poisson distributed variable with the faster poisson method.
static class PoissonRandom.SimulFits
          Class to simulate a purely photon and/or shot-noise dominated fits image.
static class PoissonRandom.TestGamma
          Class to test the slow gammaSplit(a) method against the faster gamma method.
static class PoissonRandom.TestPoisson
          Class to test the slow poissonMM(a) method against the faster poisson method.
 
Field Summary
private static double ASPLIT
          Use the splitting mechanism for gamma values lower than this.
private static double BETA
          Maximum of H/(G+H), p230.
private static int C
          Cut-off point.
private static double D
          Convenience convergence factor.
private static double[] em
          The numbers exp(-m).
private static int L
          Maximum order in qm.
private static double LNPIBETA
          Some constant involving beta and pi.
private static int M
          Maximum order for the propabilities pi.
private static double[] pi
          Probabilities pi = 1/e*sum(1/j!), j=0 to i.
private static double[] qm
          Center probabilities qm for m>= 9.
private static double SQRT6
          Square root from 6.
private static double SQRT83
          Square root from 8/3.
 
Constructor Summary
PoissonRandom()
          Creates a new Poisson Random class with no special seed.
PoissonRandom(long seed)
          Creates a new Poisson Random class with special seed.
 
Method Summary
 int binominal(double p, int n)
          Returns binominal distribution with bernoulli process.
 double gamma(double a)
          Returns a gamma-distributed value.
private  double gammaFrac(double a)
          Returns a gamma for a fraction smaller one.
private  double gammaInt(int a)
          Returns gamma from an integer.
 double gammaSplit(double a)
          Split a in an integer and a fractional part, calculate the two gammas separately and return sum.
 double poisson(double mu)
          Creates a pseudo-poisson distributed value around the expectation value mu.
static double poissonMM(double mu)
          A simple method for poisson calculation, linear in mu
 
Methods inherited from class java.util.Random
next, nextBoolean, nextBytes, nextDouble, nextFloat, nextGaussian, nextInt, nextInt, nextLong, setSeed
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

em

private static double[] em
The numbers exp(-m).


qm

private static double[] qm
Center probabilities qm for m>= 9.


pi

private static double[] pi
Probabilities pi = 1/e*sum(1/j!), j=0 to i.


L

private static final int L
Maximum order in qm.

See Also:
Constant Field Values

M

private static final int M
Maximum order for the propabilities pi.

See Also:
Constant Field Values

C

private static final int C
Cut-off point.

See Also:
Constant Field Values

D

private static final double D
Convenience convergence factor.

See Also:
Constant Field Values

SQRT83

private static final double SQRT83
Square root from 8/3.


SQRT6

private static final double SQRT6
Square root from 6.


ASPLIT

private static final double ASPLIT
Use the splitting mechanism for gamma values lower than this.

See Also:
Constant Field Values

BETA

private static final double BETA
Maximum of H/(G+H), p230.

See Also:
Constant Field Values

LNPIBETA

private static final double LNPIBETA
Some constant involving beta and pi.

See Also:
Constant Field Values
Constructor Detail

PoissonRandom

public PoissonRandom()
Creates a new Poisson Random class with no special seed. Calls init after construct.


PoissonRandom

public PoissonRandom(long seed)
Creates a new Poisson Random class with special seed. Calls init after construct.

Method Detail

poisson

public double poisson(double mu)
Creates a pseudo-poisson distributed value around the expectation value mu. The value returned is always an integer.

Parameters:
mu - The expected value.
Returns:
A discrete realisation, always int.

binominal

public int binominal(double p,
                     int n)
Returns binominal distribution with bernoulli process.


gammaSplit

public double gammaSplit(double a)
Split a in an integer and a fractional part, calculate the two gammas separately and return sum.


gammaInt

private double gammaInt(int a)
Returns gamma from an integer.


gammaFrac

private double gammaFrac(double a)
Returns a gamma for a fraction smaller one.


gamma

public double gamma(double a)
Returns a gamma-distributed value.


poissonMM

public static double poissonMM(double mu)
A simple method for poisson calculation, linear in mu