SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
StudentPolarGen.java
1/*
2 * Class: StudentPolarGen
3 * Description: Student-t random variate generators using the polar 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
44public class StudentPolarGen extends StudentGen {
45
46 private boolean available = false;
47 private double[] variates = new double[2];
48 private static double[] staticVariates = new double[2];
49 // Used by the polar method.
50
55 public StudentPolarGen(RandomStream s, int n) {
56 super(s, null);
57 setN(n);
58 }
59
64 super(s, dist);
65 if (dist != null)
66 setN(dist.getN());
67 }
68
69 public double nextDouble() {
70 if (available) {
71 available = false;
72 return variates[1];
73 } else {
74 polar(stream, n, variates);
75 available = true;
76 return variates[0];
77 }
78 }
79
85 public static double nextDouble(RandomStream s, int n) {
86 polar(s, n, staticVariates);
87 return staticVariates[0];
88 }
89//>>>>>>>>>>>>>>>>>>>> P R I V A T E S M E T H O D S <<<<<<<<<<<<<<<<<<<<
90
91 /*****************************************************************************
92 * * Student's t Distribution: Polar Method * *
93 *****************************************************************************
94 * * FUNCTION: - samples a random number from Student's t distribution with *
95 * parameters n > 0. * * REFERENCE: - R.W. Bailey (1994): Polar generation of
96 * random variates * with the t-distribution, * Mathematics of Computation 62,
97 * 779-781. * * Implemented by F. Niederl, 1994 *
98 *****************************************************************************
99 * * The polar method of Box/Muller for generating Normal variates is adapted *
100 * to the Student-t distribution. The two generated variates are not *
101 * independent and the expected no. of uniforms per variate is 2.5464. * *
102 *****************************************************************************
103 * WinRand (c) 1995 Ernst Stadlober, Institut fuer Statistitk, TU Graz *
104 *****************************************************************************
105 * UNURAN (c) 2000 W. Hoermann & J. Leydold, Institut f. Statistik, WU Wien *
106 ****************************************************************************/
107
108 private static void polar(RandomStream stream, int n, double[] variates) {
109 double u, v, w;
110 do {
111 u = 2. * stream.nextDouble() - 1.;
112 v = 2. * stream.nextDouble() - 1.;
113 w = u * u + v * v;
114 } while (w > 1.);
115
116 double temp = Math.sqrt(n * (Math.exp(-2. / n * Math.log(w)) - 1.) / w);
117 variates[0] = u * temp;
118 variates[1] = v * temp;
119 }
120
121}
Extends the class ContinuousDistribution for the Student.
StudentGen(RandomStream s, int n)
Creates a Student random variate generator with degrees of freedom, using stream s.
StudentPolarGen(RandomStream s, int n)
Creates a Student random variate generator with degrees of freedom, using stream s.
StudentPolarGen(RandomStream s, StudentDist dist)
Creates a new generator for the Student distribution dist and stream s.
double nextDouble()
Generates a random number from the continuous distribution contained in this object.
static double nextDouble(RandomStream s, int n)
Generates a new variate from the Student distribution with &#160;n degrees of freedom,...
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,...