SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
RandShiftedMod1PointSet.java
1/*
2 * Class: RandShiftedPointSet
3 * Description: Point set to which a random shift modulo 1 is applied
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.hups;
26
27import umontreal.ssj.util.PrintfFormat;
28import umontreal.ssj.rng.*;
29
47
48 protected double[] shift; // The random shift.
49 // protected int dimShift = 0; // Current dimension of the shift.
50 // protected int capacityShift = 0; // Number of array elements for the shift;
51 // always >= dimShift.
52 // protected RandomStream shiftStream; // Used to generate random shifts.
53 // Already in PointSet
54
65 init(p);
66 if (dimShift <= 0) {
67 throw new IllegalArgumentException("Cannot construct RandShiftedPointSet with dimShift <= 0");
68 }
69 shiftStream = stream;
70 shift = new double[dimShift];
71 capacityShift = this.dimShift = dimShift;
72 }
73
77 public int getShiftDimension() {
78 return dimShift;
79 }
80
88 public void addRandomShift(int d1, int d2, RandomStream stream) {
89 if (null == stream)
90 throw new IllegalArgumentException(PrintfFormat.NEWLINE + " Calling addRandomShift with null stream");
91 // if (stream != shiftStream)
92 shiftStream = stream;
93 addRandomShift(d1, d2);
94 }
95
100 public void addRandomShift(RandomStream stream) {
101 // if (stream != shiftStream)
102 shiftStream = stream;
104 }
105
110 public void addRandomShift(int d1, int d2) {
111 if (d1 < 0 || d1 > d2)
112 throw new IllegalArgumentException("illegal parameter d1 or d2");
113 if (d2 > capacityShift) {
114 int d3 = Math.max(4, capacityShift);
115 while (d2 > d3)
116 d3 *= 2;
117 double[] temp = new double[d3];
118 capacityShift = d3;
119 for (int i = 0; i < d1; i++)
120 temp[i] = shift[i];
121 shift = temp;
122 }
123 dimShift = d2;
124 for (int i = d1; i < d2; i++)
125 shift[i] = shiftStream.nextDouble();
126
127 // Just for testing, to see the single uniform random point
128 // for(int k = 0; k < d2; k++)
129 // System.out.println ("shift " + k + " = " + shift[k]);
130 // System.out.println();
131 }
132
136 public void addRandomShift() {
138 }
139
143 public double getCoordinate(int i, int j) {
144 if (dimShift <= j)
145 // Must extend randomization.
146 addRandomShift(dimShift, 1 + j);
147 double u = P.getCoordinate(i, j) + shift[j];
148 if (u >= 1.0)
149 u -= 1.0;
150 if (u > 0.0)
151 return u;
152 return EpsilonHalf; // avoid u = 0
153 }
154
155 public String toString() {
156 return "RandShiftedPointSet of: {" + PrintfFormat.NEWLINE + P.toString() + PrintfFormat.NEWLINE + "}";
157 }
158
163 return new RandShiftedMod1PointSetIterator();
164 }
165
166 // ***************************************************************
167
172 private class RandShiftedMod1PointSetIterator extends ContainerPointSetIterator {
173
174 public double nextCoordinate() {
175 int d1 = innerIterator.getCurCoordIndex();
176 if (dimShift <= d1)
177 addRandomShift(dimShift, 1 + d1);
178 double u = shift[d1] + innerIterator.nextCoordinate();
179 if (u >= 1.0)
180 u -= 1.0;
181 if (u > 0.0)
182 return u;
183 return EpsilonHalf; // avoid u = 0
184 }
185
186 }
187}
This acts as a generic base class for all container classes that contain a point set and apply a spec...
void init(PointSet p0)
Initializes this container point set so that it will contain the point set p0.
double EpsilonHalf
Default constant epsilon/2 added to the points after a random shift.
This abstract class represents a general point set.
Definition PointSet.java:99
int dimShift
Current dimension of the shift.
double EpsilonHalf
To avoid 0 for nextCoordinate when random shifting, we add this to each coordinate.
double[] shift
This is the shift vector as a double[] array, which contains the current random shift in case we appl...
int capacityShift
Number of array elements in the shift vector, always >= dimShift.
RandomStream shiftStream
Stream used to generate the random shifts.
void addRandomShift(int d1, int d2, RandomStream stream)
Changes the stream used for the random shifts to stream, then refreshes the shift for coordinates d1 ...
double getCoordinate(int i, int j)
Returns the shifted coordinate .
RandShiftedMod1PointSet(PointSet p, int dimShift, RandomStream stream)
Constructs a structure to contain a randomly shifted version of p.
String toString()
Formats a string that contains information about the point set.
PointSetIterator iterator()
Returns a RandShiftedMod1PointSetIterator for this point set.
void addRandomShift(int d1, int d2)
Refreshes the random shift (generates new uniform values for the random shift coordinates) for coordi...
void addRandomShift(RandomStream stream)
Changes the stream used for the random shifts to stream, then refreshes all coordinates of the random...
int getShiftDimension()
Returns the number of dimensions of the current random shift.
void addRandomShift()
Refreshes all coordinates of the random shift, up to its current dimension.
This class acts like a StringBuffer which defines new types of append methods.
static final String NEWLINE
End-of-line symbol or line separator.
This is the interface for iterators that permit one to go through the points of a PointSet and the su...
int getCurCoordIndex()
Returns the index of the current coordinate.
double nextCoordinate()
Returns the current coordinate and advances to the next one.
This interface defines the basic structures to handle multiple streams of uniform (pseudo)random numb...