SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
InverseGaussianMSHGen.java
1/*
2 * Class: InverseGaussianMSHGen
3 * Description: inverse gaussian random variate generators
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
41 private NormalGen genN;
42
48 public InverseGaussianMSHGen(RandomStream s, NormalGen sn, double mu, double lambda) {
49 super(s, null);
50 setParams(mu, lambda, sn);
51 }
52
58 super(s, dist);
59 if (dist != null)
60 setParams(dist.getMu(), dist.getLambda(), sn);
61 }
62
68 public static double nextDouble(RandomStream s, NormalGen sn, double mu, double lambda) {
69 return mhs(s, sn, mu, lambda);
70 }
71
72 public double nextDouble() {
73 return mhs(stream, genN, mu, lambda);
74 }
75
76//>>>>>>>>>>>>>>>>>>>> P R I V A T E M E T H O D S <<<<<<<<<<<<<<<<<<<<
77
78 private static double mhs(RandomStream stream, NormalGen genN, double mu, double lambda) {
79 if (lambda <= 0.0)
80 throw new IllegalArgumentException("lambda <= 0");
81 if (mu <= 0.0)
82 throw new IllegalArgumentException("mu <= 0");
83
84 double z = genN.nextDouble();
85 double ymu = mu * z * z;
86 double x1 = mu + 0.5 * mu * ymu / lambda - 0.5 * mu / lambda * Math.sqrt(4.0 * ymu * lambda + ymu * ymu);
87 double u = stream.nextDouble();
88 if (u <= mu / (mu + x1))
89 return x1;
90 return mu * mu / x1;
91 }
92
93 protected void setParams(double mu, double lambda, NormalGen sn) {
94 setParams(mu, lambda);
95 this.genN = sn;
96 }
97
98}
Extends the class ContinuousDistribution for the inverse Gaussian distribution with location paramete...
InverseGaussianGen(RandomStream s, double mu, double lambda)
Creates an inverse Gaussian random variate generator with parameters mu and lambda,...
double nextDouble()
Generates a random number from the continuous distribution contained in this object.
static double nextDouble(RandomStream s, NormalGen sn, double mu, double lambda)
Generates a new variate from the inverse gaussian distribution with parameters mu and lambda,...
InverseGaussianMSHGen(RandomStream s, NormalGen sn, double mu, double lambda)
Creates an inverse gaussian random variate generator with parameters mu and lambda,...
InverseGaussianMSHGen(RandomStream s, NormalGen sn, InverseGaussianDist dist)
Creates a new generator for the distribution dist using streams s and sn.
This class implements methods for generating random variates from the normal distribution .
static double nextDouble(RandomStream s, double mu, double sigma)
Generates a variate from the normal distribution 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,...