SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
BetaSymmetricalBestGen.java
1/*
2 * Class: BetaSymmetricalBestGen
3 * Description: symmetrical beta random variate generators using
4 Devroye's one-liner 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
52 private RandomStream stream2;
53 private RandomStream stream3;
54 private double afactor; // = 1/alpha
55 private static final double TWOPI = 2.0 * Math.PI; // = 2 Pi
56
67 super(s1, null);
68 stream2 = s2;
69 stream3 = s3;
70 afactor = 1.0 / alpha;
71 setParams(alpha, alpha, 0.0, 1.0);
72 }
73
82 public BetaSymmetricalBestGen(RandomStream s1, double alpha) {
83 this(s1, s1, s1, alpha);
84 }
85
93 super(s1, dist);
94 stream2 = s2;
95 stream3 = s3;
96 afactor = 1.0 / dist.getAlpha();
97 if (dist != null)
98 setParams(dist.getAlpha(), dist.getAlpha(), dist.getA(), dist.getB());
99 }
100
106 this(s1, s1, s1, dist);
107 }
108
113 public static double nextDouble(RandomStream s1, RandomStream s2, RandomStream s3, double alpha) {
114 double cos, temp, v, S;
115 cos = Math.cos(TWOPI * s2.nextDouble());
116 temp = 1.0 / Math.pow(s1.nextDouble(), 1.0 / alpha) - 1.0;
117 v = Math.sqrt(1.0 + 1.0 / (temp * cos * cos));
118 S = s3.nextDouble();
119 if (S < 0.5)
120 return 0.5 - 0.5 / v;
121 else
122 return 0.5 + 0.5 / v;
123 }
124
129 public static double nextDouble(RandomStream s, double alpha) {
130 return nextDouble(s, s, s, alpha);
131 }
132
133 public double nextDouble() {
134 // Generates a random number using Devroye's one liner method
135 double cos, temp, v, S;
136 cos = Math.cos(TWOPI * stream2.nextDouble());
137 temp = 1.0 / Math.pow(stream.nextDouble(), afactor) - 1.0;
138 v = Math.sqrt(1.0 + 1.0 / (temp * cos * cos));
139 S = stream3.nextDouble();
140 if (S < 0.5)
141 return 0.5 - 0.5 / v;
142 else
143 return 0.5 + 0.5 / v;
144 }
145
150 return stream2;
151 }
152
157 return stream3;
158 }
159
160}
Specializes the class BetaDist to the case of a symmetrical beta distribution over the interval ,...
static double nextDouble(RandomStream s1, RandomStream s2, RandomStream s3, double alpha)
Generates a random number using Devroye’s one-liner method.
static double nextDouble(RandomStream s, double alpha)
Generates a random number using Devroye’s one-liner method with only one stream s.
BetaSymmetricalBestGen(RandomStream s1, BetaSymmetricalDist dist)
Creates a new generator for the distribution dist, using only one stream s1.
BetaSymmetricalBestGen(RandomStream s1, RandomStream s2, RandomStream s3, BetaSymmetricalDist dist)
Creates a new generator for the distribution dist, using stream s1 to generate , stream s2 to generat...
RandomStream getStream2()
Returns stream s2 associated with this object.
RandomStream getStream3()
Returns stream s3 associated with this object.
BetaSymmetricalBestGen(RandomStream s1, RandomStream s2, RandomStream s3, double alpha)
Creates a symmetrical beta random variate generator with parameter.
double nextDouble()
Generates a random number from the continuous distribution contained in this object.
BetaSymmetricalBestGen(RandomStream s1, double alpha)
Creates a symmetrical beta random variate generator with parameter.
BetaSymmetricalGen(RandomStream s, double alpha)
Creates a new symmetrical beta generator with parameters.
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,...