package umontreal.iro.lecuyer.randvar;
import umontreal.iro.lecuyer.rng.*;
import umontreal.iro.lecuyer.probdist.*;


/**
 * This class implements random variate generators for the Erlang 
 * distribution with parameters k > 0 and 
 * λ > 0.
 * This Erlang random variable is the sum of k exponentials with 
 * parameter λ and has mean k/λ.
 * 
 * 

* The (non-static) nextDouble method simply calls inverseF on the * distribution. * */ public class ErlangGen extends GammaGen { protected int k = -1; /** * Creates an Erlang random variate generator with parameters * k and λ = lambda, * using stream s. * */ public ErlangGen (RandomStream s, int k, double lambda) { super (s, new ErlangDist(k, lambda)); setParams (k, lambda); } /** * Creates an Erlang random variate generator with parameters * k and * λ = 1, using stream s. * */ public ErlangGen (RandomStream s, int k) { this (s, k, 1.0); } /** * Creates a new generator for the distribution dist * and stream s. * */ public ErlangGen (RandomStream s, ErlangDist dist) { super (s, dist); if (dist != null) setParams (dist.getK(), dist.getLambda()); } /** * Generates a new variate from the Erlang distribution with * parameters k = k and λ = lambda, * using stream s. * */ public static double nextDouble (RandomStream s, int k, double lambda) { return ErlangDist.inverseF (k, lambda, 15, s.nextDouble()); } /** * Returns the parameter k of this object. * * */ public int getK() { return k; } /** * Sets the parameter k and λ of this object. * */ protected void setParams (int k, double lambda) { if (lambda <= 0.0) throw new IllegalArgumentException ("lambda <= 0"); if (k <= 0) throw new IllegalArgumentException ("k <= 0"); this.lambda = lambda; this.k = k; } }

Ads help maintain this website.