SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
NegativeBinomialGen.java
1/*
2 * Class: NegativeBinomialGen
3 * Description: random variate generators for the negative binomial distribution
4 * Environment: Java
5 * Software: SSJ
6 * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal
7 * Organization: DIRO, Universite de Montreal
8 * @author
9 * @since
10 *
11 *
12 * Licensed under the Apache License, Version 2.0 (the "License");
13 * you may not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
15 *
16 * http://www.apache.org/licenses/LICENSE-2.0
17 *
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
23 *
24 */
25package umontreal.ssj.randvar;
26
27import umontreal.ssj.rng.*;
28import umontreal.ssj.probdist.*;
29
46public class NegativeBinomialGen extends RandomVariateGenInt {
47 protected double gamma;
48 protected double p;
49
55 public NegativeBinomialGen(RandomStream s, double gamma, double p) {
56 super(s, new NegativeBinomialDist(gamma, p));
57 setParams(gamma, p);
58 }
59
64 super(s, dist);
65 if (dist != null)
66 setParams(dist.getGamma(), dist.getP());
67 }
68
75 public static int nextInt(RandomStream s, double gamma, double p) {
76 return NegativeBinomialDist.inverseF(gamma, p, s.nextDouble());
77 }
78
82 public double getGamma() {
83 return gamma;
84 }
85
89 public double getP() {
90 return p;
91 }
92
96 protected void setParams(double gamma, double p) {
97 if (p < 0.0 || p > 1.0)
98 throw new IllegalArgumentException("p not in [0, 1]");
99 if (gamma <= 0.0)
100 throw new IllegalArgumentException("gamma <= 0");
101 this.p = p;
102 this.gamma = gamma;
103 }
104}
Extends the class DiscreteDistributionInt for the negative binomial distribution slaw00a  (page 324) ...
static int inverseF(double n, double p, double u)
Computes the inverse function without precomputing tables.
double getP()
Returns the parameter of this object.
void setParams(double gamma, double p)
Sets the parameter and of this object.
NegativeBinomialGen(RandomStream s, double gamma, double p)
Creates a negative binomial random variate generator with parameters.
double getGamma()
Returns the parameter of this object.
static int nextInt(RandomStream s, double gamma, double p)
Generates a new variate from the negative binomial distribution, with parameters &#160;gamma and &#160;p,...
NegativeBinomialGen(RandomStream s, NegativeBinomialDist dist)
Creates a new generator for the distribution dist, using stream s.
This interface defines the basic structures to handle multiple streams of uniform (pseudo)random numb...
double nextDouble()
Returns a (pseudo)random number from the uniform distribution over the interval , using this stream,...