SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
TriangularGen.java
1/*
2 * Class: TriangularGen
3 * Description: random variate generators for the triangular distribution
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
47public class TriangularGen extends RandomVariateGen {
48 private double a;
49 private double b;
50 private double m;
51
56 public TriangularGen(RandomStream s, double a, double b, double m) {
57 super(s, new TriangularDist(a, b, m));
58 setParams(a, b, m);
59 }
60
65 public TriangularGen(RandomStream s, double m) {
66 this(s, 0.0, 1.0, m);
67 }
68
74 super(s, dist);
75 if (dist != null)
76 setParams(dist.getA(), dist.getB(), dist.getM());
77 }
78
85 public static double nextDouble(RandomStream s, double a, double b, double m) {
86 // the code is taken and adapted from unuran
87 // file /distributions/c_triangular_gen.c
88 return TriangularDist.inverseF(a, b, m, s.nextDouble());
89 }
90
94 public double getA() {
95 return a;
96 }
97
101 public double getB() {
102 return b;
103 }
104
108 public double getM() {
109 return m;
110 }
111
116 private void setParams(double a, double b, double m) {
117 if ((a == 0.0 && b == 1.0) && (m < 0 || m > 1))
118 throw new IllegalArgumentException("m is not in [0,1]");
119 else if (a >= b)
120 throw new IllegalArgumentException("a >= b");
121 else if (m < a || m > b)
122 throw new IllegalArgumentException("m is not in [a,b]");
123 this.a = a;
124 this.b = b;
125 this.m = m;
126 }
127}
Extends the class ContinuousDistribution for the triangular distribution (see tjoh95b  (page 297) and...
double inverseF(double u)
Returns the inverse distribution function .
double getM()
Returns the value of for this object.
TriangularGen(RandomStream s, double a, double b, double m)
Creates a triangular random variate generator over the interval (a, b), with parameter m,...
TriangularGen(RandomStream s, TriangularDist dist)
Creates a new generator for the triangular distribution dist and stream s.
TriangularGen(RandomStream s, double m)
Creates a triangular random variate generator over the interval , with parameter m,...
double getA()
Returns the value of for this object.
double getB()
Returns the value of for this object.
static double nextDouble(RandomStream s, double a, double b, double m)
Generates a new variate from the triangular distribution with parameters &#160;a, &#160;b and &#160;m and stre...
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,...