SSJ  3.3.1
Stochastic Simulation in Java
Classes | Public Member Functions | Protected Member Functions | Protected Attributes | Package Functions | Package Attributes | List of all members
CachedPointSet Class Reference

This container class caches a point set by precomputing and storing its points locally in an array. More...

Inheritance diagram for CachedPointSet:
[legend]
Collaboration diagram for CachedPointSet:
[legend]

Classes

class  CachedPointSetIterator
 This class implements a CachedPointSet iterator which takes the value directly in the array x in which the points are cached, rather than calling getCoordinate inherited from CachedPointSet. More...
 

Public Member Functions

 CachedPointSet (PointSet p, int fromPoint, int toPoint, int fromDim, int toDim)
 Creates a new PointSet object that contains an array storing the coordinates fromDim (inclusive) to toDim (exclusive) of the points numbered fromPoint (inclusive) to toPoint (exclusive) of p. More...
 
 CachedPointSet (PointSet p, int n, int dim)
 Same as CachedPointSet(p, 0, n, 0, dim).
 
 CachedPointSet (PointSet p)
 Creates a new PointSet object that contains an array storing the points of p. More...
 
PointSetIterator iterator ()
 Constructs and returns a point set iterator which gets the values directly from the array.
 
void setRandomizeParent (boolean randomizeParent)
 If randomizeParent is true, calls to randomize() will be defered to the parent point set (this is the default); otherwise, the randomize method of the PointSetRandomization instance is invoked with this CachedPointSet instance as its argument.
 
void addRandomShift (int d1, int d2, RandomStream stream)
 Generates a random shift, adds it to the contained point set, and re-caches the points. More...
 
void randomize (PointSetRandomization rand)
 Randomizes the underlying point set using rand and re-caches the points. More...
 
void sortByCoordinate (int j)
 Sorts the cached points by increasing order of coordinate j. More...
 
void stripCoordinates (int d)
 Removes the first d coordinates of each cached point. More...
 
String toString ()
 
double getCoordinate (int i, int j)
 
double [][] getArray ()
 
PointSet getParentPointSet ()
 Returns the reference point set that was passed to the constructor.
 
- Public Member Functions inherited from PointSet
int getDimension ()
 Returns the dimension (number of available coordinates) of the points. More...
 
int getNumPoints ()
 Returns the number of points. More...
 
abstract double getCoordinate (int i, int j)
 Returns \(u_{i,j}\), the coordinate \(j\) of the point \(i\). More...
 
PointSetIterator iterator ()
 Constructs and returns a point set iterator. More...
 
void randomize (PointSetRandomization rand)
 Randomizes this point set using the given rand. More...
 
void addRandomShift (int d1, int d2, RandomStream stream)
 By default, this method generates a random shift in the protected double[] array shift, to be used eventually for a random shift modulo 1. More...
 
void addRandomShift (RandomStream stream)
 Same as addRandomShift(0, dim, stream), where dim is the dimension of the point set. More...
 
void addRandomShift (int d1, int d2)
 Refreshes the random shift (generates new uniform values for the random shift coordinates) for coordinates d1 to d2-1, using the saved shiftStream.
 
void addRandomShift ()
 Same as addRandomShift(0, dim), where dim is the dimension of the point set.
 
void clearRandomShift ()
 Erases the current random shift, if any.
 
String toString ()
 Formats a string that contains information about the point set. More...
 
String formatPoints ()
 Same as invoking formatPoints(n, d) with \(n\) and \(d\) equal to the number of points and the dimension of this object, respectively. More...
 
String formatPoints (int n, int d)
 Formats a string that displays the same information as returned by toString, together with the first \(d\) coordinates of the first \(n\) points. More...
 
String formatPoints (PointSetIterator iter)
 Same as invoking formatPoints(iter, n, d) with \(n\) and \(d\) equal to the number of points and the dimension, respectively. More...
 
String formatPoints (PointSetIterator iter, int n, int d)
 Same as invoking formatPoints(n, d), but prints the points by calling iter repeatedly. More...
 
String formatPointsBase (int b)
 Similar to formatPoints(), but the points coordinates are printed in base \(b\). More...
 
String formatPointsBase (int n, int d, int b)
 Similar to formatPoints(n, d), but the points coordinates are printed in base \(b\). More...
 
String formatPointsBase (PointSetIterator iter, int b)
 Similar to formatPoints(iter), but the points coordinates are printed in base \(b\). More...
 
String formatPointsBase (PointSetIterator iter, int n, int d, int b)
 Similar to formatPoints(iter, n, d), but the points coordinates are printed in base \(b\). More...
 
String formatPointsNumbered ()
 Same as invoking formatPointsNumbered(n, d) with \(n\) and \(d\) equal to the number of points and the dimension, respectively. More...
 
String formatPointsNumbered (int n, int d)
 Same as invoking formatPoints(n,d), except that the points are numbered. More...
 

Protected Member Functions

void fillCache (int fromDim, int dim)
 Caches the points, skipping fromDim coordinates and taking the next dim ones.
 

Protected Attributes

PointSet P
 
double x [][]
 
- Protected Attributes inherited from PointSet
double EpsilonHalf = 1.0 / Num.TWOEXP[55]
 To avoid 0 for nextCoordinate when random shifting, we add this to each coordinate.
 
int dim = 0
 Dimension of the points.
 
int numPoints = 0
 Number of points.
 
int dimShift = 0
 Current dimension of the shift. More...
 
int capacityShift = 0
 Number of array elements in the shift vector, always >= dimShift.
 
double [] shift
 This is the shift vector as a double[] array, which contains the current random shift in case we apply a random shift modulo 1. More...
 
RandomStream shiftStream
 Stream used to generate the random shifts. More...
 

Package Functions

public< T > void sort (MultiDimSort< T > sort)
 Sorts the cached points (only) with the given umontreal.ssj.util.MultiDimSort sorting algorithm sort. More...
 

Package Attributes

int fromPoint = 0
 
int fromDim = 0
 
boolean randomizeParent = true
 

Additional Inherited Members

- Static Protected Attributes inherited from PointSet
static final int MAXBITS = 31
 Since Java has no unsigned type, the 32nd bit cannot be used efficiently, so we have only 31 bits. More...
 

Detailed Description

This container class caches a point set by precomputing and storing its points locally in an array.

This can be used to speed up computations when using a small low-dimensional point set more than once. Some types of point sets are also implemented directly as subclasses of this one, without having a contained point set p. Examples include LatinHypercube and StratifiedUnitCube.

After the points are stored in the array, this class uses the default methods and the default iterator type provided by the base class PointSet. This iterator relies exclusively on the #getCoordinate method. This is one (simple) special case where direct use of #getCoordinate is efficient. Pierre: We could also implement an iterator that directly returns x[i][j] instead of calling getCoordinate, for slightly better efficiency. On the other hand, even better efficiency can be achieved by getting an entire point at a time in an array.

There is a sort method available to sort the cached points via a umontreal.ssj.util.MultiDimSort, and a stripCoordinates method that remove some coordinates of the cached points. Those methods affect only the array where the points are cached; they have no impact on the (underlying) original point set. The randomize method, on the other hand, randomizes the underlying point set p and re-caches them.

Constructor & Destructor Documentation

◆ CachedPointSet() [1/2]

CachedPointSet ( PointSet  p,
int  fromPoint,
int  toPoint,
int  fromDim,
int  toDim 
)

Creates a new PointSet object that contains an array storing the coordinates fromDim (inclusive) to toDim (exclusive) of the points numbered fromPoint (inclusive) to toPoint (exclusive) of p.

Thus, the cached points have dim = fromDim - toDim coordinates and there are \(n = \mathtt{toPoint}-\mathtt{fromPoint}\) of them. The original point set p itself is not modified.

Parameters
ppoint set to be cached
fromPointnumber of skipped points (usually 0)
toPoint1 + number of the last point selected from p
fromDimnumber of skipped coordinates (often 0)
toDim1 + index of last coordinate in the original points

◆ CachedPointSet() [2/2]

Creates a new PointSet object that contains an array storing the points of p.

The number of points and their dimension are the same as in the original point set. Both must be finite.

Parameters
ppoint set to be cached

Member Function Documentation

◆ addRandomShift()

void addRandomShift ( int  d1,
int  d2,
RandomStream  stream 
)

Generates a random shift, adds it to the contained point set, and re-caches the points.

See the doc of the overridden method addRandomShift(d1, d2, stream) in PointSet. In case there is no underlying point set, this method should be redefined to randomize the cached points.

◆ randomize()

void randomize ( PointSetRandomization  rand)

Randomizes the underlying point set using rand and re-caches the points.

In case there is no underlying point set, this method must be redefined to randomize the cached points in the appropriate way. If setRandomizeParent(false) was called, this method invokes rand.randomize(this) instead of on the parent point set.

◆ sort()

public<T> void sort ( MultiDimSort< T >  sort)
package

Sorts the cached points (only) with the given umontreal.ssj.util.MultiDimSort sorting algorithm sort.

This does not affect the underlying point set p.

◆ sortByCoordinate()

void sortByCoordinate ( int  j)

Sorts the cached points by increasing order of coordinate j.

This is useful in the ArrayRQMC simulation method, for example. Note that the sort applies only to the cached points, and not to the original contained point set p.

◆ stripCoordinates()

void stripCoordinates ( int  d)

Removes the first d coordinates of each cached point.

This does not affect the underlying point set p. This could be useful in particular for the ArrayRQMC simulation method.


The documentation for this class was generated from the following file: