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 classDPopulation.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 voidadvanceToNextSubstream()Positions the RNG at the beginning of its next substreamdoubleget(int index)Returns the value at the supplied indexbooleangetAntitheticOption()ControlsgetControls()Returns a valid instance of Controls that can be used with this ControllableIfc or nullintgetId()java.lang.StringgetName()Gets the name.double[]getParameters()Gets the parametersdouble[]getPermutation()Creates a new array that contains a random permutation of the populationprotected intgetRandomIndex()Returns a random index into the population (assuming elements numbered starting at zero)RNStreamIfcgetRandomNumberStream()double[]getSampleWithoutReplacement(int sampleSize)Creates a new array that contains a randomly sampled values without replacement from the existing population.doublegetValue()Returns a randomly selected element from the population.DPopulationnewInstance()Returns a new instance of the random source with the same parameters but an independent generatorDPopulationnewInstance(RNStreamIfc stream)Returns a new instance of the random source with the same parameters but an independent generatorvoidpermute()Causes the population to form a new permutation, The ordering of the elements in the population will be changed.voidresetStartStream()The resetStartStream method will position the RNG at the beginning of its stream.voidresetStartSubstream()Resets the position of the RNG at the start of the current substreamdoublesample()voidset(int index, double value)Sets the element at the supplied index to the supplied valuevoidsetAntitheticOption(boolean flag)Tells the stream to start producing antithetic variatesvoidsetControls(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 voidsetId()voidsetName(java.lang.String str)Sets the namevoidsetParameters(double[] elements)Sets the parametersvoidsetRandomNumberStream(RNStreamIfc stream)Sets the underlying random number streamintsize()Returns the number of elements in the populationjava.lang.StringtoString()static java.lang.StringtoString(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:
getNamein 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:
getIdin 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:
newInstancein 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:ParametersIfcGets the parameters- Specified by:
getParametersin interfaceParametersIfc- Returns:
- Gets a copy of the population array, in its current state
-
setParameters
public final void setParameters(double[] elements)
Description copied from interface:ParametersIfcSets the parameters- Specified by:
setParametersin interfaceParametersIfc- Parameters:
elements- Copies the values from the supplied array to the population array
-
getControls
public Controls getControls()
Description copied from interface:ControllableIfcReturns a valid instance of Controls that can be used with this ControllableIfc or null- Specified by:
getControlsin interfaceControllableIfc- Returns:
-
setControls
public void setControls(Controls controls)
Description copied from interface:ControllableIfcTakes 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:
setControlsin interfaceControllableIfc
-
getValue
public final double getValue()
Returns a randomly selected element from the population. All elements are equally likely.- Specified by:
getValuein 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:RNStreamControlIfcPositions the RNG at the beginning of its next substream- Specified by:
advanceToNextSubstreamin interfaceRNStreamControlIfc
-
resetStartStream
public final void resetStartStream()
Description copied from interface:RNStreamControlIfcThe 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:
resetStartStreamin interfaceRNStreamControlIfc
-
resetStartSubstream
public final void resetStartSubstream()
Description copied from interface:RNStreamControlIfcResets the position of the RNG at the start of the current substream- Specified by:
resetStartSubstreamin interfaceRNStreamControlIfc
-
getAntitheticOption
public final boolean getAntitheticOption()
- Specified by:
getAntitheticOptionin interfaceRNStreamControlIfc- Returns:
- true means on
-
setAntitheticOption
public final void setAntitheticOption(boolean flag)
Description copied from interface:RNStreamControlIfcTells the stream to start producing antithetic variates- Specified by:
setAntitheticOptionin interfaceRNStreamControlIfc- Parameters:
flag- true means that it produces antithetic variates.
-
getRandomNumberStream
public final RNStreamIfc getRandomNumberStream()
- Specified by:
getRandomNumberStreamin interfaceGetRandomNumberStreamIfc- Returns:
- the random number stream reference
-
setRandomNumberStream
public final void setRandomNumberStream(RNStreamIfc stream)
Description copied from interface:SetRandomNumberStreamIfcSets the underlying random number stream- Specified by:
setRandomNumberStreamin interfaceSetRandomNumberStreamIfc- Parameters:
stream- the reference to the random number stream, must not be null
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
toString
public static java.lang.String toString(double[] x)
-
setId
protected final void setId()
-
-