SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
StratifiedUnitCube.java
1/*
2 * Class: StratifiedUnitCube
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
51public class StratifiedUnitCube extends CachedPointSet {
52
56 protected int[] numDiv; // Number of divisions in each dimension, k_j
57
61 protected double[] delta;
62
70 public StratifiedUnitCube(int[] k, int dim) {
71 this.dim = dim;
72 delta = new double[dim];
73 numDiv = new int[dim];
74 numPoints = 1;
75 for (int j = 0; j < dim; j++) {
76 numDiv[j] = k[j];
77 numPoints *= k[j];
78 delta[j] = 1.0 / (double) numDiv[j];
79 }
80 x = new double[numPoints][dim];
81 }
82
90 public StratifiedUnitCube(int k, int dim) {
91 this.dim = dim;
92 delta = new double[dim];
93 numDiv = new int[dim];
94 numPoints = 1;
95 for (int j = 0; j < dim; j++) {
96 numDiv[j] = k;
97 numPoints *= k;
98 delta[j] = 1.0 / (double) k;
99 }
100 x = new double[numPoints][dim];
101 }
102
111 public void randomize(RandomStream stream) {
112 int[] current = new int[dim]; // current[j] = current division for
113 // dim j when we enumerate the points
114 for (int j = 0; j < dim; j++)
115 current[j] = 0;
116 for (int i = 0; i < numPoints; i++) {
117 // Generate random point in current box; this is point i.
118 for (int j = 0; j < dim; j++)
119 x[i][j] = (current[j] + stream.nextDouble()) * delta[j];
120 // Find the next box.
121 for (int l = 0; l < dim; l++) {
122 current[l]++;
123 if (current[l] >= numDiv[l])
124 current[l] = 0; // next, we will add the carry to current[l+1].
125 else
126 l = dim; // Exit loop.
127 }
128 }
129 }
130
136 public void addRandomShift(int fromDim, int toDim, RandomStream stream) {
137 randomize(stream);
138 }
139
145 randomize(rand.getStream());
146 }
147
148 public String toString() {
149 return "StratifiedUnitCube: stratified point set over the unit cube in " + dim + "dimensions.";
150 }
151}
int numPoints
Number of points.
int dim
Dimension of the points.
double[] delta
Size of divisions in each dimension, delta[j] = 1/numDiv[j].
void randomize(RandomStream stream)
This randomization generates one point randomly in its corresponding box, for each of the boxes.
int[] numDiv
Number of divisions in each dimension, numDiv[j] for coordinate j.
StratifiedUnitCube(int k, int dim)
Same as StratifiedUnitCube (int[] k, int dim) with all coordinates of the vector k equal to the integ...
void addRandomShift(int fromDim, int toDim, RandomStream stream)
Random shifts and partial randomizations are irrelevant here, so this method is redefined to be equiv...
void randomize(PointSetRandomization rand)
Randomizes the points using stratification, regardless of what rand is.
StratifiedUnitCube(int[] k, int dim)
Builds a stratified points set in dim dimensions, with k[j] intervals in dimension j.
String toString()
Formats a string that contains information about the point set.
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,...