SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
BetaSymmetricalPolarGen.java
1/*
2 * Class: BetaSymmetricalPolarGen
3 * Description: symmetrical beta random variate generators using
4 Ulrich's polar method
5 * Environment: Java
6 * Software: SSJ
7 * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal
8 * Organization: DIRO, Universite de Montreal
9 * @author Richard Simard
10 * @since
11 *
12 *
13 * Licensed under the Apache License, Version 2.0 (the "License");
14 * you may not use this file except in compliance with the License.
15 * You may obtain a copy of the License at
16 *
17 * http://www.apache.org/licenses/LICENSE-2.0
18 *
19 * Unless required by applicable law or agreed to in writing, software
20 * distributed under the License is distributed on an "AS IS" BASIS,
21 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 * See the License for the specific language governing permissions and
23 * limitations under the License.
24 *
25 */
26package umontreal.ssj.randvar;
27
28import umontreal.ssj.rng.*;
29import umontreal.ssj.probdist.BetaSymmetricalDist;
30
48 private double afactor; // = 2/(2*alpha - 1)
49 private RandomStream stream2;
50
59 public BetaSymmetricalPolarGen(RandomStream s1, RandomStream s2, double alpha) {
60 super(s1, null);
61 stream2 = s2;
62 if (alpha <= 0.5)
63 throw new IllegalArgumentException(" must have alpha > 1/2");
64 afactor = 2.0 / (2.0 * alpha - 1.0);
65 setParams(alpha, alpha, 0.0, 1.0);
66 }
67
75 public BetaSymmetricalPolarGen(RandomStream s1, double alpha) {
76 this(s1, s1, alpha);
77 }
78
86 super(s1, dist);
87 stream2 = s2;
88 double alp = dist.getAlpha();
89 if (alp <= 0.5)
90 throw new IllegalArgumentException(" must have alpha > 1/2");
91 afactor = 2.0 / (2.0 * dist.getAlpha() - 1.0);
92 setParams(alp, alp, 0.0, 1.0);
93 }
94
100 this(s1, s1, dist);
101 }
102
109 public static double nextDouble(RandomStream s1, RandomStream s2, double alpha) {
110 double u, v, S;
111 do {
112 u = s1.nextDouble();
113 v = -1.0 + 2.0 * s2.nextDouble();
114 S = u * u + v * v;
115 } while (S > 1.0);
116 return 0.5 + u * v / S * Math.sqrt(1.0 - Math.pow(S, 2.0 / (2.0 * alpha - 1.0)));
117 }
118
123 public static double nextDouble(RandomStream s, double alpha) {
124 return nextDouble(s, s, alpha);
125 }
126
127 public double nextDouble() {
128 // Generates a random number using Ulrich's polar method.
129 double u, v, S;
130 do {
131 u = stream.nextDouble();
132 v = -1.0 + 2.0 * stream2.nextDouble();
133 S = u * u + v * v;
134 } while (S > 1.0);
135 return 0.5 + u * v / S * Math.sqrt(1.0 - Math.pow(S, afactor));
136 }
137
142 return stream2;
143 }
144
145}
Specializes the class BetaDist to the case of a symmetrical beta distribution over the interval ,...
BetaSymmetricalGen(RandomStream s, double alpha)
Creates a new symmetrical beta generator with parameters.
BetaSymmetricalPolarGen(RandomStream s1, RandomStream s2, double alpha)
Creates a symmetrical beta random variate generator with parameter.
BetaSymmetricalPolarGen(RandomStream s1, double alpha)
Creates a symmetrical beta random variate generator with parameter.
static double nextDouble(RandomStream s, double alpha)
Generates a random number by Ulrich’s polar method using stream s.
RandomStream getStream2()
Returns stream s2 associated with this object.
BetaSymmetricalPolarGen(RandomStream s1, RandomStream s2, BetaSymmetricalDist dist)
Creates a new generator for the distribution dist, using stream s1 to generate and stream s2 to gene...
static double nextDouble(RandomStream s1, RandomStream s2, double alpha)
Generates a random number using Ulrich’s polar method.
BetaSymmetricalPolarGen(RandomStream s1, BetaSymmetricalDist dist)
Creates a new generator for the distribution dist, using only one stream s1.
double nextDouble()
Generates a random number from the continuous distribution contained in 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,...