SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
AntitheticStream.java
1/*
2 * Class: AntitheticStream
3 * Description: container class allows the user to force any RandomStream
4 to return antithetic variates
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
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.rng;
27
39public class AntitheticStream implements RandomStream {
40
41 // The base stream.
42 private RandomStream st;
43
49 this.st = stream;
50 }
51
52 public void resetStartStream() {
53 st.resetStartStream();
54 }
55
56 public void resetStartSubstream() {
57 st.resetStartSubstream();
58 }
59
60 public void resetNextSubstream() {
61 st.resetNextSubstream();
62 }
63
68 public String toString() {
69 return "Antithetic of " + st.toString();
70 }
71
75 public double nextDouble() {
76 return 1.0 - st.nextDouble();
77 }
78
82 public int nextInt(int i, int j) {
83 // pas (j - st.nextInt(0,j-i)), au cas ou le resultat varie.
84 return j - i - st.nextInt(i, j);
85 }
86
95 public void nextArrayOfDouble(double[] u, int start, int n) {
96 st.nextArrayOfDouble(u, start, n);
97 for (int ii = start; ii < start + n; ii++)
98 u[ii] = 1.0 - u[ii];
99 }
100
111 public void nextArrayOfInt(int i, int j, int[] u, int start, int n) {
112 st.nextArrayOfInt(i, j, u, start, n);
113 for (int ii = start; ii < start + n; ii++)
114 u[ii] = j - i - u[ii];
115 }
116
117}
String toString()
Returns a string starting with "Antithetic of " and finishing with the result of the call to the toSt...
void resetStartSubstream()
Reinitializes the stream to the beginning of its current substream:
void nextArrayOfInt(int i, int j, int[] u, int start, int n)
Calls nextArrayOfInt (i, j, u, start, n) for the base stream, then replaces each u[i] by j - i - u[i]...
void resetStartStream()
Reinitializes the stream to its initial state : and are set to .
AntitheticStream(RandomStream stream)
Constructs a new antithetic stream, using the random numbers from the base stream stream.
int nextInt(int i, int j)
Returns j - i - s.nextInt(i, j) where s is the base stream.
void resetNextSubstream()
Reinitializes the stream to the beginning of its next substream:
double nextDouble()
Returns 1.0 - s.nextDouble() where s is the base stream.
void nextArrayOfDouble(double[] u, int start, int n)
Calls nextArrayOfDouble (u, start, n) for the base stream, then replaces each u[i] by 1....
This interface defines the basic structures to handle multiple streams of uniform (pseudo)random numb...