Package jsl.utilities.random.robj
Class DPopulation
- java.lang.Object
-
- jsl.utilities.random.robj.DPopulation
-
- All Implemented Interfaces:
ControllableIfc
,GetNameIfc
,GetValueIfc
,IdentityIfc
,NewInstanceIfc<DPopulation>
,ParametersIfc
,RandomIfc
,GetRandomNumberStreamIfc
,RNStreamControlIfc
,SetRandomNumberStreamIfc
,SampleIfc
public class DPopulation extends java.lang.Object implements RandomIfc, SampleIfc, ControllableIfc, ParametersIfc, NewInstanceIfc<DPopulation>
A DPopulation is a population of doubles that can be sampled from and permuted.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
DPopulation.DPopControls
-
Constructor Summary
Constructors Constructor Description DPopulation(double[] elements)
DPopulation(double[] elements, RNStreamIfc stream)
DPopulation(double[] elements, RNStreamIfc stream, java.lang.String name)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
advanceToNextSubstream()
Positions the RNG at the beginning of its next substreamdouble
get(int index)
Returns the value at the supplied indexboolean
getAntitheticOption()
Controls
getControls()
Returns a valid instance of Controls that can be used with this ControllableIfc or nullint
getId()
java.lang.String
getName()
Gets the name.double[]
getParameters()
Gets the parametersdouble[]
getPermutation()
Creates a new array that contains a random permutation of the populationprotected int
getRandomIndex()
Returns a random index into the population (assuming elements numbered starting at zero)RNStreamIfc
getRandomNumberStream()
double[]
getSampleWithoutReplacement(int sampleSize)
Creates a new array that contains a randomly sampled values without replacement from the existing population.double
getValue()
Returns a randomly selected element from the population.DPopulation
newInstance()
Returns a new instance of the random source with the same parameters but an independent generatorDPopulation
newInstance(RNStreamIfc stream)
Returns a new instance of the random source with the same parameters but an independent generatorvoid
permute()
Causes the population to form a new permutation, The ordering of the elements in the population will be changed.void
resetStartStream()
The resetStartStream method will position the RNG at the beginning of its stream.void
resetStartSubstream()
Resets the position of the RNG at the start of the current substreamdouble
sample()
void
set(int index, double value)
Sets the element at the supplied index to the supplied valuevoid
setAntitheticOption(boolean flag)
Tells the stream to start producing antithetic variatesvoid
setControls(Controls controls)
Takes in a valid instance of Controls for this class If controls is null or if it was not created by this class this method should throw an IllegalArgumentExceptionprotected void
setId()
void
setName(java.lang.String str)
Sets the namevoid
setParameters(double[] elements)
Sets the parametersvoid
setRandomNumberStream(RNStreamIfc stream)
Sets the underlying random number streamint
size()
Returns the number of elements in the populationjava.lang.String
toString()
static java.lang.String
toString(double[] x)
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface jsl.utilities.random.rng.GetRandomNumberStreamIfc
getStreamNumber
-
Methods inherited from interface jsl.utilities.random.rng.SetRandomNumberStreamIfc
setRandomNumberStream
-
-
-
-
Constructor Detail
-
DPopulation
public DPopulation(double[] elements)
- Parameters:
elements
- the elements to sample from
-
DPopulation
public DPopulation(double[] elements, RNStreamIfc stream)
- Parameters:
elements
- the elements to sample fromstream
- the stream to use for sampling
-
DPopulation
public DPopulation(double[] elements, RNStreamIfc stream, java.lang.String name)
- Parameters:
elements
- the elements to sample fromstream
- the stream to use for samplingname
- the name of the population, optional
-
-
Method Detail
-
getName
public final java.lang.String getName()
Gets the name.- Specified by:
getName
in interfaceGetNameIfc
- Returns:
- The name of object.
-
setName
public final void setName(java.lang.String str)
Sets the name- Parameters:
str
- The name as a string.
-
getId
public final int getId()
- Specified by:
getId
in interfaceIdentityIfc
- Returns:
- Returns the id
-
newInstance
public final DPopulation newInstance()
Returns a new instance of the random source with the same parameters but an independent generator- Specified by:
newInstance
in interfaceNewInstanceIfc<DPopulation>
- Returns:
- Returns a new instance of the population with the same parameters but a different random stream
-
newInstance
public final DPopulation newInstance(RNStreamIfc stream)
Returns a new instance of the random source with the same parameters but an independent generator- Parameters:
stream
- a random number stream, must not null.- Returns:
- Returns a new instance of the population with the same parameters but a different random stream
-
getSampleWithoutReplacement
public final double[] getSampleWithoutReplacement(int sampleSize)
Creates a new array that contains a randomly sampled values without replacement from the existing population.- Parameters:
sampleSize
- the number to sample- Returns:
- the sampled array
-
getPermutation
public final double[] getPermutation()
Creates a new array that contains a random permutation of the population- Returns:
- a new array that contains a random permutation of the population
-
permute
public final void permute()
Causes the population to form a new permutation, The ordering of the elements in the population will be changed.
-
get
public final double get(int index)
Returns the value at the supplied index- Parameters:
index
- must be > 0 and less than size() - 1- Returns:
- the value at the supplied index
-
set
public final void set(int index, double value)
Sets the element at the supplied index to the supplied value- Parameters:
index
- an index into the arrayvalue
- the value to set
-
size
public final int size()
Returns the number of elements in the population- Returns:
- the size of the population
-
getParameters
public double[] getParameters()
Description copied from interface:ParametersIfc
Gets the parameters- Specified by:
getParameters
in interfaceParametersIfc
- Returns:
- Gets a copy of the population array, in its current state
-
setParameters
public final void setParameters(double[] elements)
Description copied from interface:ParametersIfc
Sets the parameters- Specified by:
setParameters
in interfaceParametersIfc
- Parameters:
elements
- Copies the values from the supplied array to the population array
-
getControls
public Controls getControls()
Description copied from interface:ControllableIfc
Returns a valid instance of Controls that can be used with this ControllableIfc or null- Specified by:
getControls
in interfaceControllableIfc
- Returns:
-
setControls
public void setControls(Controls controls)
Description copied from interface:ControllableIfc
Takes in a valid instance of Controls for this class If controls is null or if it was not created by this class this method should throw an IllegalArgumentException- Specified by:
setControls
in interfaceControllableIfc
-
getValue
public final double getValue()
Returns a randomly selected element from the population. All elements are equally likely.- Specified by:
getValue
in interfaceGetValueIfc
- Returns:
- the randomly selected element
-
sample
public final double sample()
-
getRandomIndex
protected final int getRandomIndex()
Returns a random index into the population (assuming elements numbered starting at zero)- Returns:
- a random index
-
advanceToNextSubstream
public final void advanceToNextSubstream()
Description copied from interface:RNStreamControlIfc
Positions the RNG at the beginning of its next substream- Specified by:
advanceToNextSubstream
in interfaceRNStreamControlIfc
-
resetStartStream
public final void resetStartStream()
Description copied from interface:RNStreamControlIfc
The resetStartStream method will position the RNG at the beginning of its stream. This is the same location in the stream as assigned when the RNG was created and initialized.- Specified by:
resetStartStream
in interfaceRNStreamControlIfc
-
resetStartSubstream
public final void resetStartSubstream()
Description copied from interface:RNStreamControlIfc
Resets the position of the RNG at the start of the current substream- Specified by:
resetStartSubstream
in interfaceRNStreamControlIfc
-
getAntitheticOption
public final boolean getAntitheticOption()
- Specified by:
getAntitheticOption
in interfaceRNStreamControlIfc
- Returns:
- true means on
-
setAntitheticOption
public final void setAntitheticOption(boolean flag)
Description copied from interface:RNStreamControlIfc
Tells the stream to start producing antithetic variates- Specified by:
setAntitheticOption
in interfaceRNStreamControlIfc
- Parameters:
flag
- true means that it produces antithetic variates.
-
getRandomNumberStream
public final RNStreamIfc getRandomNumberStream()
- Specified by:
getRandomNumberStream
in interfaceGetRandomNumberStreamIfc
- Returns:
- the random number stream reference
-
setRandomNumberStream
public final void setRandomNumberStream(RNStreamIfc stream)
Description copied from interface:SetRandomNumberStreamIfc
Sets the underlying random number stream- Specified by:
setRandomNumberStream
in interfaceSetRandomNumberStreamIfc
- Parameters:
stream
- the reference to the random number stream, must not be null
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
toString
public static java.lang.String toString(double[] x)
-
setId
protected final void setId()
-
-