|
SSJ V. 2.6. |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object umontreal.iro.lecuyer.randvar.RandomVariateGen umontreal.iro.lecuyer.randvar.RandomVariateGenWithCache
public class RandomVariateGenWithCache
This class represents a random variate generator whose values
are cached for more efficiency when using
common random numbers. An object
from this class is constructed with a reference to a
RandomVariateGen
instance used to
get the random numbers. These numbers
are stored in an internal array to be retrieved later.
The dimension of the array increases as the values
are generated.
If the nextDouble
method is called after
the object is reset (by calling
setCachedValues
), it gives back the cached
values instead of computing new ones.
If the cache is exhausted before the generator is reset,
new values are computed and added to the cache.
Such caching allows for a better performance with common random numbers, when generating random variates is time-consuming. However, using such caching may lead to memory problems if a large quantity of random numbers are needed.
Constructor Summary | |
---|---|
RandomVariateGenWithCache(RandomVariateGen rvg)
Constructs a new cached random variate generator with internal generator rvg. |
|
RandomVariateGenWithCache(RandomVariateGen rvg,
int initialCapacity)
Constructs a new cached random variate generator with internal generator rvg. |
Method Summary | |
---|---|
void |
clearCache()
Clears the cached values for this cached generator. |
RandomVariateGen |
getCachedGen()
Returns a reference to the random variate generator whose values are cached. |
cern.colt.list.DoubleArrayList |
getCachedValues()
Returns an array list containing the values cached by this random variate generator. |
int |
getCacheIndex()
Return the index of the next cached value that will be returned by the generator. |
Distribution |
getDistribution()
Returns the Distribution used by this generator. |
int |
getNumCachedValues()
Returns the total number of values cached by this generator. |
RandomStream |
getStream()
Returns the RandomStream used by this generator. |
void |
initCache()
Resets this generator to recover values from the cache. |
boolean |
isCaching()
Determines if the random variate generator is caching values, default being true. |
void |
nextArrayOfDouble(double[] v,
int start,
int n)
Generates n random numbers from the continuous distribution contained in this object. |
double |
nextDouble()
Generates a random number from the continuous distribution contained in this object. |
void |
setCachedGen(RandomVariateGen rvg)
Sets the random variate generator whose values are cached to rvg. |
void |
setCachedValues(cern.colt.list.DoubleArrayList values)
Sets the array list containing the cached values to values. |
void |
setCacheIndex(int newIndex)
Sets the index, in the cache, of the next value returned by nextDouble . |
void |
setCaching(boolean caching)
Sets the caching indicator to caching. |
Methods inherited from class umontreal.iro.lecuyer.randvar.RandomVariateGen |
---|
setStream, toString |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public RandomVariateGenWithCache(RandomVariateGen rvg)
rvg
- the random variate generator whose values are cached.
NullPointerException
- if rvg is null.public RandomVariateGenWithCache(RandomVariateGen rvg, int initialCapacity)
rvg
- the random variate generator whose values are cached.initialCapacity
- the number of cached values.
NullPointerException
- if rvg is null.Method Detail |
---|
public boolean isCaching()
nextDouble
method simply calls the corresponding method on the internal
random variate generator, without storing the generated values.
public void setCaching(boolean caching)
clearCache
to clear the cached values.
caching
- the new value of the caching indicator.public RandomVariateGen getCachedGen()
public void setCachedGen(RandomVariateGen rvg)
clearCache
method is called.
rvg
- the new random variate generator whose values are cached.
NullPointerException
- if rvg is null.public void clearCache()
public void initCache()
nextDouble
will return the cached random
values until all the values are returned. When the array
of cached values is exhausted, the internal random variate
generator is used to generate new values which are added
to the internal array as well.
This method is equivalent to calling setCacheIndex
.
public int getNumCachedValues()
public int getCacheIndex()
getNumCachedValues
, and a subsequent call to
nextDouble
will generate a new variate rather than
reading a previous one from the cache.
If caching is disabled, this always returns 0.
public void setCacheIndex(int newIndex)
nextDouble
.
If newIndex is 0, this is equivalent to
calling initCache
.
If newIndex is getNumCachedValues
,
subsequent calls to nextDouble
will add
new values to the cache.
newIndex
- the new index.
IllegalArgumentException
- if newIndex
is negative or greater than or equal to the cache size.public cern.colt.list.DoubleArrayList getCachedValues()
public void setCachedValues(cern.colt.list.DoubleArrayList values)
values
- the array list of cached values.
NullPointerException
- if values is null.public double nextDouble()
RandomVariateGen
inverseF
method of the distribution object.
Alternative generating methods are provided in subclasses.
nextDouble
in class RandomVariateGen
public void nextArrayOfDouble(double[] v, int start, int n)
RandomVariateGen
nextDouble()
n
times, but one can override it in subclasses for better efficiency.
nextArrayOfDouble
in class RandomVariateGen
v
- array in which the variates will be storedstart
- starting index, in v, of the new variatesn
- number of variates to generatepublic RandomStream getStream()
RandomVariateGen
RandomStream
used by this generator.
getStream
in class RandomVariateGen
public Distribution getDistribution()
RandomVariateGen
Distribution
used by this generator.
getDistribution
in class RandomVariateGen
|
SSJ V. 2.6. |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |