All Downloads are FREE. Search and download functionalities are using the official Maven repository.

umontreal.iro.lecuyer.randvar.HypergeometricGen Maven / Gradle / Ivy

Go to download

SSJ is a Java library for stochastic simulation, developed under the direction of Pierre L'Ecuyer, in the Département d'Informatique et de Recherche Opérationnelle (DIRO), at the Université de Montréal. It provides facilities for generating uniform and nonuniform random variates, computing different measures related to probability distributions, performing goodness-of-fit tests, applying quasi-Monte Carlo methods, collecting (elementary) statistics, and programming discrete-event simulations with both events and processes.

The newest version!


/*
 * Class:        HypergeometricGen
 * Description:  random variate generators for the hypergeometric distribution
 * Environment:  Java
 * Software:     SSJ 
 * Copyright (C) 2001  Pierre L'Ecuyer and Université de Montréal
 * Organization: DIRO, Université de Montréal
 * @author       
 * @since

 * SSJ is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License (GPL) as published by the
 * Free Software Foundation, either version 3 of the License, or
 * any later version.

 * SSJ is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * A copy of the GNU General Public License is available at
   GPL licence site.
 */

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


/**
 * This class implements random variate generators for the 
 * hypergeometric distribution. Its mass function is
 * 
 * 

*
* p(x) = nCr(m, x)nCr(l - m, k - x)/nCr(l, k)        for x = max(0, k - l + m),..., min(k, m) *

* where nCr(n, x) is the number of possible combinations when choosing * x elements among a set of n elements, * m, l and k are integers that satisfy 0 < m <= l and * 0 < k <= l. * *

* The generation method is inversion using the chop-down algorithm * */ public class HypergeometricGen extends RandomVariateGenInt { private int m; private int l; private int k; /** * Creates a hypergeometric generator with * parameters m = m, l = l and k = k, * using stream s. * */ public HypergeometricGen (RandomStream s, int m, int l, int k) { super (s, new HypergeometricDist (m, l, k)); setParams (m, l, k); } /** * Creates a new generator for distribution dist, * using stream s. * */ public HypergeometricGen (RandomStream s, HypergeometricDist dist) { super (s, dist); if (dist != null) setParams (dist.getM(), dist.getL(), dist.getK()); } /** * Generates a new variate from the hypergeometric distribution with * parameters m = m, l = l and k = k, * using stream s. * */ public static int nextInt (RandomStream s, int m, int l, int k) { return HypergeometricDist.inverseF (m, l, k, s.nextDouble()); } /** * Returns the m associated with this object. * */ public int getM() { return m; } /** * Returns the l associated with this object. * */ public int getL() { return l; } /** * Returns the k associated with this object. * * */ public int getK() { return k; } /** * Sets the parameter n and p of this object. * */ protected void setParams (int m, int l, int k) { if (l <= 0) throw new IllegalArgumentException ("l must be greater than 0"); if (m <= 0 || m > l) throw new IllegalArgumentException ("m is invalid: 1<=m l) throw new IllegalArgumentException ("k is invalid: 1<=k





© 2015 - 2024 Weber Informatics LLC | Privacy Policy