SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
PascalConvolutionGen.java
1/*
2 * Class: PascalConvolutionGen
3 * Description: Pascal random variate generators using the convolution method
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
41public class PascalConvolutionGen extends PascalGen {
42
47 public PascalConvolutionGen(RandomStream s, int n, double p) {
48 super(s, null);
49 setParams(n, p);
50 }
51
56 super(s, dist);
57 }
58
59 public int nextInt() {
60 int x = 0;
61 for (int i = 0; i < n; i++)
62 x += GeometricDist.inverseF(p, stream.nextDouble());
63 return x;
64
65 }
66
72 public static int nextInt(RandomStream s, int n, double p) {
73 return convolution(s, n, p);
74 }
75
76 private static int convolution(RandomStream stream, int n, double p) {
77 int x = 0;
78 for (int i = 0; i < n; i++)
79 x += GeometricDist.inverseF(p, stream.nextDouble());
80 return x;
81 }
82}
Extends the class DiscreteDistributionInt for the geometric distribution slaw00a  (page 322) with par...
static int inverseF(double p, double u)
Computes the inverse of the geometric distribution, given by ( FInvgeom ).
The Pascal distribution is a special case of the negative binomial distribution slaw00a  (page 324) w...
PascalConvolutionGen(RandomStream s, PascalDist dist)
Creates a new generator for the distribution dist, using stream s.
PascalConvolutionGen(RandomStream s, int n, double p)
Creates a Pascal random variate generator with parameters and , using stream s.
static int nextInt(RandomStream s, int n, double p)
Generates a new variate from the Pascal distribution, with parameters.
int nextInt()
Generates a random number (an integer) from the discrete distribution contained in this object.
PascalGen(RandomStream s, int n, double p)
Creates a Pascal random variate generator with parameters and , using stream s.
void setParams(int n, double p)
Sets the parameter and of this object.
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,...