SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
StratifiedUnitCubeAnti.java
1/*
2 * Class: StratifiedUnitCubeAnti
3 * Description:
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 * SSJ is free software: you can redistribute it and/or modify it under
12 * the terms of the GNU General Public License (GPL) as published by the
13 * Free Software Foundation, either version 3 of the License, or
14 * any later version.
15
16 * SSJ is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20
21 * A copy of the GNU General Public License is available at
22 <a href="http://www.gnu.org/licenses">GPL licence site</a>.
23 */
24package umontreal.ssj.hups;
25
26import umontreal.ssj.rng.RandomStream;
27
39public class StratifiedUnitCubeAnti extends CachedPointSet {
40
44 protected int[] numDiv; // Number of divisions in each dimension, k_j
45
49 protected double[] delta;
50
58 public StratifiedUnitCubeAnti(int[] k, int dim) {
59 this.dim = dim;
60 delta = new double[dim];
61 numDiv = new int[dim];
62 numPoints = 2;
63 for (int j = 0; j < dim; j++) {
64 numDiv[j] = k[j];
65 numPoints *= k[j];
66 delta[j] = 1.0 / (double) numDiv[j];
67 }
68 x = new double[numPoints][dim];
69 }
70
77 public StratifiedUnitCubeAnti(int k, int dim) {
78 this.dim = dim;
79 delta = new double[dim];
80 numDiv = new int[dim];
81 numPoints = 2;
82 for (int j = 0; j < dim; j++) {
83 numDiv[j] = k;
84 numPoints *= k;
85 delta[j] = 1.0 / (double) k;
86 }
87 x = new double[numPoints][dim];
88 }
89
99 public void randomize(RandomStream stream) {
100 int i;
101 double u;
102 int[] current = new int[dim]; // current[j] = current division for
103 // dim j when we enumerate the points
104 for (int j = 0; j < dim; j++)
105 current[j] = 0;
106 int numBoxes = numPoints / 2;
107 for (int b = 0; b < numBoxes; b++) {
108 // Generate random point i=2b in box b, and compute locally antithetic point
109 // i+1.
110 i = 2 * b;
111 for (int j = 0; j < dim; j++) {
112 u = stream.nextDouble();
113 x[i][j] = (current[j] + u) * delta[j];
114 x[i + 1][j] = (current[j] + 1.0 - u) * delta[j];
115 }
116 // Find the next box.
117 for (int l = 0; l < dim; l++) {
118 current[l]++;
119 if (current[l] >= numDiv[l])
120 current[l] = 0; // next, we will add the carry to current[l+1].
121 else
122 l = dim; // Exit loop.
123 }
124 }
125 }
126
132 public void addRandomShift(int fromDim, int toDim, RandomStream stream) {
133 randomize(stream);
134 }
135
141 randomize(rand.getStream());
142 }
143
144 public String toString() {
145 return "StratifiedUnitCubeAnti: locally antithetic stratified point set over the unit cube in " + dim
146 + "dimensions.";
147 }
148}
int numPoints
Number of points.
int dim
Dimension of the points.
void randomize(RandomStream stream)
This randomization generates one point randomly in its corresponding box, and the compute a locally a...
void addRandomShift(int fromDim, int toDim, RandomStream stream)
Random shifts and partial randomizations are irrelevant here, so this method is redefined to be equiv...
StratifiedUnitCubeAnti(int[] k, int dim)
Builds a stratified points set in dim dimensions, with k[j] intervals in dimension j.
double[] delta
Size of divisions in each dimension, delta[j] = 1/numDiv[j].
StratifiedUnitCubeAnti(int k, int dim)
Same as StratifiedUnitCube (int[] k, int dim) with all coordinates of the vector k equal to the integ...
void randomize(PointSetRandomization rand)
Randomizes the points using the locally antithetic stratification, regardless of what rand is.
String toString()
Formats a string that contains information about the point set.
int[] numDiv
Number of divisions in each dimension, numDiv[j] for coordinate j.
This interface is for a randomization that can be used to randomize a umontreal.ssj....
RandomStream getStream()
Returns the internal umontreal.ssj.rng.RandomStream.
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,...