Top Description Fields Constructors Methods
org.apache.commons.math3.random

public Class ValueServer

extends Object
Class Inheritance
Imports
java.io.BufferedReader, .IOException, .InputStreamReader, java.net.MalformedURLException, .URL, org.apache.commons.math3.exception.MathIllegalArgumentException, .MathIllegalStateException, .NullArgumentException, .ZeroException, org.apache.commons.math3.exception.util.LocalizedFormats

Generates values for use in simulation applications.

How values are generated is determined by the mode property.

Supported mode values are:

Field Summary

Modifier and TypeField and Description
public static final int
CONSTANT_MODE

Always return mu

public static final int
DIGEST_MODE

Use empirical distribution.

private EmpiricalDistribution
empiricalDistribution

Empirical probability distribution for use with DIGEST_MODE.

public static final int
EXPONENTIAL_MODE

Exponential random deviates with mean = μ.

private BufferedReader
filePointer

File pointer for REPLAY_MODE.

public static final int
GAUSSIAN_MODE

Gaussian random deviates with mean = μ, std dev = σ.

private int
mode

mode determines how values are generated.

private double
mu

Mean for use with non-data-driven modes.

private final RandomDataGenerator
randomData

Deprecated as a consequence of RandomDataGenerator being deprecated.
RandomDataImpl to use for random data generation.
public static final int
REPLAY_MODE

Replay data from valuesFilePath.

private double
sigma

Standard deviation for use with GAUSSIAN_MODE.

public static final int
UNIFORM_MODE

Uniform random deviates with mean = μ.

private URL
valuesFileURL

URI to raw data values.

Constructor Summary

AccessConstructor and Description
public
ValueServer()

Creates new ValueServer

public
ValueServer(RandomDataImpl
the RandomDataImpl instance used to source random data
randomData
)

Construct a ValueServer instance using a RandomDataImpl as its source of random data.

public
ValueServer(RandomGenerator
source of random data
generator
)

Construct a ValueServer instance using a RandomGenerator as its source of random data.

Method Summary

Modifier and TypeMethod and Description
public void
closeReplayFile()

Closes valuesFileURL after use in REPLAY_MODE.

public void
computeDistribution()

Computes the empirical distribution using values from the file in valuesFileURL, using the default number of bins.

public void
computeDistribution(int
the number of bins used in computing the empirical distribution
binCount
)

Computes the empirical distribution using values from the file in valuesFileURL and binCount bins.

public void
fill(double[]
array to be filled
values
)

Fills the input array with values generated using getNext() repeatedly.

public double[]

Returns:

array of generated values
fill
(int
length of output array
length
)

Returns an array of length length with values generated using getNext() repeatedly.

public EmpiricalDistribution

Returns:

EmpircalDistribution built by computeDistribution()
getEmpiricalDistribution
()

Returns the EmpiricalDistribution used when operating in 0.

public int

Returns:

Value of property mode.
getMode
()

Returns the data generation mode.

public double

Returns:

Mean used in data generation.
getMu
()

Returns the mean used when operating in GAUSSIAN_MODE, EXPONENTIAL_MODE or UNIFORM_MODE.

public double

Returns:

generated value
getNext
()

Returns the next generated value, generated according to the mode value (see MODE constants).

private double

Returns:

next random value from the empirical distribution digest
getNextDigest
()

Gets a random value in DIGEST_MODE.

private double

Returns:

random exponential value
getNextExponential
()

Gets an exponentially distributed random value with mean = mu.

private double

Returns:

random Gaussian value
getNextGaussian
()

Gets a Gaussian distributed random value with mean = mu and standard deviation = sigma.

private double

Returns:

next value from the replay file
getNextReplay
()

Gets next sequential value from the valuesFileURL.

private double

Returns:

random uniform value
getNextUniform
()

Gets a uniformly distributed random value with mean = mu.

public double

Returns:

Standard deviation used when operating in GAUSSIAN_MODE.
getSigma
()

Returns the standard deviation used when operating in GAUSSIAN_MODE.

public URL

Returns:

Values file URL.
getValuesFileURL
()

Returns the URL for the file used to build the empirical distribution when using DIGEST_MODE.

public void
reSeed(long
Value with which to reseed the RandomDataImpl used to generate random data.
seed
)

Reseeds the random data generator.

public void
resetReplayFile()

Resets REPLAY_MODE file pointer to the beginning of the valuesFileURL.

public void
setMode(int
New value of the data generation mode.
mode
)

Sets the data generation mode.

public void
setMu(double
new Mean value.
mu
)

Sets the mean used in data generation.

public void
setSigma(double
New standard deviation.
sigma
)

Sets the standard deviation used in GAUSSIAN_MODE.

public void
setValuesFileURL(String
String representation for new valuesFileURL.
url
)

Sets the values file URL using a string URL representation.

public void
setValuesFileURL(URL
URL of the values file.
url
)

Sets the the values file URL.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CONSTANT_MODEback to summary
public static final int CONSTANT_MODE

Always return mu

DIGEST_MODEback to summary
public static final int DIGEST_MODE

Use empirical distribution.

empiricalDistributionback to summary
private EmpiricalDistribution empiricalDistribution

Empirical probability distribution for use with DIGEST_MODE.

EXPONENTIAL_MODEback to summary
public static final int EXPONENTIAL_MODE

Exponential random deviates with mean = μ.

filePointerback to summary
private BufferedReader filePointer

File pointer for REPLAY_MODE.

GAUSSIAN_MODEback to summary
public static final int GAUSSIAN_MODE

Gaussian random deviates with mean = μ, std dev = σ.

modeback to summary
private int mode

mode determines how values are generated.

muback to summary
private double mu

Mean for use with non-data-driven modes.

randomDataback to summary
private final RandomDataGenerator randomData

Deprecated

as a consequence of RandomDataGenerator being deprecated. See corresponding docs for further information.

RandomDataImpl to use for random data generation.

REPLAY_MODEback to summary
public static final int REPLAY_MODE

Replay data from valuesFilePath.

sigmaback to summary
private double sigma

Standard deviation for use with GAUSSIAN_MODE.

UNIFORM_MODEback to summary
public static final int UNIFORM_MODE

Uniform random deviates with mean = μ.

valuesFileURLback to summary
private URL valuesFileURL

URI to raw data values.

Constructor Detail

ValueServerback to summary
public ValueServer()

Creates new ValueServer

ValueServerback to summary
public ValueServer(RandomDataImpl randomData)

Construct a ValueServer instance using a RandomDataImpl as its source of random data.

Parameters
randomData:RandomDataImpl

the RandomDataImpl instance used to source random data

Annotations
@Deprecated
Since
3.0
ValueServerback to summary
public ValueServer(RandomGenerator generator)

Construct a ValueServer instance using a RandomGenerator as its source of random data.

Parameters
generator:RandomGenerator

source of random data

Since
3.1

Method Detail

closeReplayFileback to summary
public void closeReplayFile() throws IOException

Closes valuesFileURL after use in REPLAY_MODE.

Exceptions
IOException:
if an error occurs closing the file
computeDistributionback to summary
public void computeDistribution() throws IOException, ZeroException, NullArgumentException

Computes the empirical distribution using values from the file in valuesFileURL, using the default number of bins.

valuesFileURL must exist and be readable by *this at runtime.

This method must be called before using getNext() with mode = DIGEST_MODE

Exceptions
IOException:
if an I/O error occurs reading the input file
ZeroException:
if URL contains no data
NullArgumentException:
if the valuesFileURL has not been set
computeDistributionback to summary
public void computeDistribution(int binCount) throws NullArgumentException, IOException, ZeroException

Computes the empirical distribution using values from the file in valuesFileURL and binCount bins.

valuesFileURL must exist and be readable by this process at runtime.

This method must be called before using getNext() with mode = DIGEST_MODE

Parameters
binCount:int

the number of bins used in computing the empirical distribution

Exceptions
NullArgumentException:
if the valuesFileURL has not been set
IOException:
if an error occurs reading the input file
ZeroException:
if URL contains no data
fillback to summary
public void fill(double[] values) throws IOException, MathIllegalStateException, MathIllegalArgumentException

Fills the input array with values generated using getNext() repeatedly.

Parameters
values:double[]

array to be filled

Exceptions
IOException:
in REPLAY_MODE if a file I/O error occurs
MathIllegalStateException:
if mode is not recognized
MathIllegalArgumentException:
if the underlying random generator thwrows one
fillback to summary
public double[] fill(int length) throws IOException, MathIllegalStateException, MathIllegalArgumentException

Returns an array of length length with values generated using getNext() repeatedly.

Parameters
length:int

length of output array

Returns:double[]

array of generated values

Exceptions
IOException:
in REPLAY_MODE if a file I/O error occurs
MathIllegalStateException:
if mode is not recognized
MathIllegalArgumentException:
if the underlying random generator thwrows one
getEmpiricalDistributionback to summary
public EmpiricalDistribution getEmpiricalDistribution()

Returns the EmpiricalDistribution used when operating in 0.

Returns:EmpiricalDistribution

EmpircalDistribution built by computeDistribution()

getModeback to summary
public int getMode()

Returns the data generation mode. See the class javadoc for description of the valid values of this property.

Returns:int

Value of property mode.

getMuback to summary
public double getMu()

Returns the mean used when operating in GAUSSIAN_MODE, EXPONENTIAL_MODE or UNIFORM_MODE. When operating in CONSTANT_MODE, this is the constant value always returned. Calling computeDistribution() sets this value to the overall mean of the values in the values file.

Returns:double

Mean used in data generation.

getNextback to summary
public double getNext() throws IOException, MathIllegalStateException, MathIllegalArgumentException

Returns the next generated value, generated according to the mode value (see MODE constants).

Returns:double

generated value

Exceptions
IOException:
in REPLAY_MODE if a file I/O error occurs
MathIllegalStateException:
if mode is not recognized
MathIllegalArgumentException:
if the underlying random generator thwrows one
getNextDigestback to summary
private double getNextDigest() throws MathIllegalStateException

Gets a random value in DIGEST_MODE.

Preconditions:

  • Before this method is called, computeDistribution() must have completed successfully; otherwise an IllegalStateException will be thrown

Returns:double

next random value from the empirical distribution digest

Exceptions
MathIllegalStateException:
if digest has not been initialized
getNextExponentialback to summary
private double getNextExponential() throws MathIllegalArgumentException

Gets an exponentially distributed random value with mean = mu.

Returns:double

random exponential value

Exceptions
MathIllegalArgumentException:
if the underlying random generator thwrows one
getNextGaussianback to summary
private double getNextGaussian() throws MathIllegalArgumentException

Gets a Gaussian distributed random value with mean = mu and standard deviation = sigma.

Returns:double

random Gaussian value

Exceptions
MathIllegalArgumentException:
if the underlying random generator thwrows one
getNextReplayback to summary
private double getNextReplay() throws IOException, MathIllegalStateException

Gets next sequential value from the valuesFileURL.

Throws an IOException if the read fails.

This method will open the valuesFileURL if there is no replay file open.

The valuesFileURL will be closed and reopened to wrap around from EOF to BOF if EOF is encountered. EOFException (which is a kind of IOException) may still be thrown if the valuesFileURL is empty.

Returns:double

next value from the replay file

Exceptions
IOException:
if there is a problem reading from the file
MathIllegalStateException:
if URL contains no data
NumberFormatException:
if an invalid numeric string is encountered in the file
getNextUniformback to summary
private double getNextUniform() throws MathIllegalArgumentException

Gets a uniformly distributed random value with mean = mu.

Returns:double

random uniform value

Exceptions
MathIllegalArgumentException:
if the underlying random generator thwrows one
getSigmaback to summary
public double getSigma()

Returns the standard deviation used when operating in GAUSSIAN_MODE. Calling computeDistribution() sets this value to the overall standard deviation of the values in the values file. This property has no effect when the data generation mode is not GAUSSIAN_MODE.

Returns:double

Standard deviation used when operating in GAUSSIAN_MODE.

getValuesFileURLback to summary
public URL getValuesFileURL()

Returns the URL for the file used to build the empirical distribution when using DIGEST_MODE.

Returns:URL

Values file URL.

reSeedback to summary
public void reSeed(long seed)

Reseeds the random data generator.

Parameters
seed:long

Value with which to reseed the RandomDataImpl used to generate random data.

resetReplayFileback to summary
public void resetReplayFile() throws IOException

Resets REPLAY_MODE file pointer to the beginning of the valuesFileURL.

Exceptions
IOException:
if an error occurs opening the file
NullPointerException:
if the valuesFileURL has not been set.
setModeback to summary
public void setMode(int mode)

Sets the data generation mode.

Parameters
mode:int

New value of the data generation mode.

setMuback to summary
public void setMu(double mu)

Sets the mean used in data generation. Note that calling this method after computeDistribution() has been called will have no effect on data generated in DIGEST_MODE.

Parameters
mu:double

new Mean value.

setSigmaback to summary
public void setSigma(double sigma)

Sets the standard deviation used in GAUSSIAN_MODE.

Parameters
sigma:double

New standard deviation.

setValuesFileURLback to summary
public void setValuesFileURL(String url) throws MalformedURLException

Sets the values file URL using a string URL representation.

Parameters
url:String

String representation for new valuesFileURL.

Exceptions
MalformedURLException:
if url is not well formed
setValuesFileURLback to summary
public void setValuesFileURL(URL url)

Sets the the values file URL.

The values file must be an ASCII text file containing one valid numeric entry per line.

Parameters
url:URL

URL of the values file.