Package org.apache.commons.math.random
Class ValueServer
java.lang.Object
org.apache.commons.math.random.ValueServer
Generates values for use in simulation applications.
How values are generated is determined by the mode
property.
Supported mode values are:
- DIGEST_MODE -- uses an empirical distribution
- REPLAY_MODE -- replays data from
valuesFileURL - UNIFORM_MODE -- generates uniformly distributed random values with
mean =
mu - EXPONENTIAL_MODE -- generates exponentially distributed random values
with mean =
mu - GAUSSIAN_MODE -- generates Gaussian distributed random values with
mean =
muand standard deviation =sigma - CONSTANT_MODE -- returns
muevery time.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intAlways return mustatic final intUse empirical distribution.static final intExponential random deviates with mean = μ.static final intGaussian random deviates with mean = μ, std dev = σ.static final intReplay data from valuesFilePath.static final intUniform random deviates with mean = μ. -
Constructor Summary
ConstructorsConstructorDescriptionCreates new ValueServerValueServer(RandomData randomData) Construct a ValueServer instance using a RandomData as its source of random data. -
Method Summary
Modifier and TypeMethodDescriptionvoidClosesvaluesFileURLafter use in REPLAY_MODE.voidComputes the empirical distribution using values from the file invaluesFileURL, using the default number of bins.voidcomputeDistribution(int binCount) Computes the empirical distribution using values from the file invaluesFileURLandbinCountbins.voidfill(double[] values) Fills the input array with values generated using getNext() repeatedly.double[]fill(int length) Returns an array of lengthlengthwith values generated using getNext() repeatedly.Getter for property empiricalDistribution.intgetMode()Getter for property mode.doublegetMu()Getter for property mu.doublegetNext()Returns the next generated value, generated according to the mode value (see MODE constants).doublegetSigma()Getter for property sigma.Getter forvaluesFileURLvoidResets REPLAY_MODE file pointer to the beginning of thevaluesFileURL.voidsetMode(int mode) Setter for property mode.voidsetMu(double mu) Setter for property mu.voidsetSigma(double sigma) Setter for property sigma.voidsetValuesFileURL(String url) Sets thevaluesFileURLusing a string URL representationvoidsetValuesFileURL(URL url) Sets thevaluesFileURL
-
Field Details
-
DIGEST_MODE
public static final int DIGEST_MODEUse empirical distribution.- See Also:
-
REPLAY_MODE
public static final int REPLAY_MODEReplay data from valuesFilePath.- See Also:
-
UNIFORM_MODE
public static final int UNIFORM_MODEUniform random deviates with mean = μ.- See Also:
-
EXPONENTIAL_MODE
public static final int EXPONENTIAL_MODEExponential random deviates with mean = μ.- See Also:
-
GAUSSIAN_MODE
public static final int GAUSSIAN_MODEGaussian random deviates with mean = μ, std dev = σ.- See Also:
-
CONSTANT_MODE
public static final int CONSTANT_MODEAlways return mu- See Also:
-
-
Constructor Details
-
ValueServer
public ValueServer()Creates new ValueServer -
ValueServer
Construct a ValueServer instance using a RandomData as its source of random data.- Parameters:
randomData- the RandomData instance used to source random data- Since:
- 1.1
-
-
Method Details
-
getNext
Returns the next generated value, generated according to the mode value (see MODE constants).- Returns:
- generated value
- Throws:
IOException- in REPLAY_MODE if a file I/O error occurs
-
fill
Fills the input array with values generated using getNext() repeatedly.- Parameters:
values- array to be filled- Throws:
IOException- in REPLAY_MODE if a file I/O error occurs
-
fill
Returns an array of lengthlengthwith values generated using getNext() repeatedly.- Parameters:
length- length of output array- Returns:
- array of generated values
- Throws:
IOException- in REPLAY_MODE if a file I/O error occurs
-
computeDistribution
Computes the empirical distribution using values from the file invaluesFileURL, using the default number of bins.valuesFileURLmust exist and be readable by *this at runtime.This method must be called before using
getNext()withmode = DIGEST_MODE- Throws:
IOException- if an I/O error occurs reading the input file
-
computeDistribution
Computes the empirical distribution using values from the file invaluesFileURLandbinCountbins.valuesFileURLmust exist and be readable by this process at runtime.This method must be called before using
getNext()withmode = DIGEST_MODE- Parameters:
binCount- the number of bins used in computing the empirical distribution- Throws:
IOException- if an error occurs reading the input file
-
getMode
public int getMode()Getter for property mode.- Returns:
- Value of property mode.
-
setMode
public void setMode(int mode) Setter for property mode.- Parameters:
mode- New value of property mode.
-
getValuesFileURL
Getter forvaluesFileURL- Returns:
- Value of property valuesFileURL.
-
setValuesFileURL
Sets thevaluesFileURLusing a string URL representation- Parameters:
url- String representation for new valuesFileURL.- Throws:
MalformedURLException- if url is not well formed
-
setValuesFileURL
Sets thevaluesFileURL- Parameters:
url- New value of property valuesFileURL.
-
getEmpiricalDistribution
Getter for property empiricalDistribution.- Returns:
- Value of property empiricalDistribution.
-
resetReplayFile
Resets REPLAY_MODE file pointer to the beginning of thevaluesFileURL.- Throws:
IOException- if an error occurs opening the file
-
closeReplayFile
ClosesvaluesFileURLafter use in REPLAY_MODE.- Throws:
IOException- if an error occurs closing the file
-
getMu
public double getMu()Getter for property mu.- Returns:
- Value of property mu.
-
setMu
public void setMu(double mu) Setter for property mu.- Parameters:
mu- New value of property mu.
-
getSigma
public double getSigma()Getter for property sigma.- Returns:
- Value of property sigma.
-
setSigma
public void setSigma(double sigma) Setter for property sigma.- Parameters:
sigma- New value of property sigma.
-