org.apache.commons.math.random
public class ValueServer extends Object
How values are generated is determined by the mode
property.
Supported mode
values are:
valuesFileURL
mu
mu
mu
and
standard deviation = sigma
mu
every time.Modifier and Type | Field and Description |
---|---|
static int |
CONSTANT_MODE
Always return mu
|
static int |
DIGEST_MODE
Use empirical distribution.
|
private EmpiricalDistribution |
empiricalDistribution
Empirical probability distribution for use with DIGEST_MODE.
|
static int |
EXPONENTIAL_MODE
Exponential random deviates with mean = μ.
|
private BufferedReader |
filePointer
File pointer for REPLAY_MODE.
|
static 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 RandomData |
randomData
RandomDataImpl to use for random data generation.
|
static int |
REPLAY_MODE
Replay data from valuesFilePath.
|
private double |
sigma
Standard deviation for use with GAUSSIAN_MODE.
|
static int |
UNIFORM_MODE
Uniform random deviates with mean = μ.
|
private URL |
valuesFileURL
URI to raw data values.
|
Constructor and Description |
---|
ValueServer()
Creates new ValueServer
|
ValueServer(RandomData randomData)
Construct a ValueServer instance using a RandomData as its source
of random data.
|
Modifier and Type | Method and Description |
---|---|
void |
closeReplayFile()
Closes
valuesFileURL after use in REPLAY_MODE. |
void |
computeDistribution()
Computes the empirical distribution using values from the file
in
valuesFileURL , using the default number of bins. |
void |
computeDistribution(int binCount)
Computes the empirical distribution using values from the file
in
valuesFileURL and binCount bins. |
void |
fill(double[] values)
Fills the input array with values generated using getNext() repeatedly.
|
double[] |
fill(int length)
Returns an array of length
length with values generated
using getNext() repeatedly. |
EmpiricalDistribution |
getEmpiricalDistribution()
Getter for property empiricalDistribution.
|
int |
getMode()
Getter for property mode.
|
double |
getMu()
Getter for property mu.
|
double |
getNext()
Returns the next generated value, generated according
to the mode value (see MODE constants).
|
private double |
getNextDigest()
Gets a random value in DIGEST_MODE.
|
private double |
getNextExponential()
Gets an exponentially distributed random value with mean = mu.
|
private double |
getNextGaussian()
Gets a Gaussian distributed random value with mean = mu
and standard deviation = sigma.
|
private double |
getNextReplay()
Gets next sequential value from the
valuesFileURL . |
private double |
getNextUniform()
Gets a uniformly distributed random value with mean = mu.
|
double |
getSigma()
Getter for property sigma.
|
URL |
getValuesFileURL()
Getter for
valuesFileURL |
void |
resetReplayFile()
Resets REPLAY_MODE file pointer to the beginning of the
valuesFileURL . |
void |
setMode(int mode)
Setter for property mode.
|
void |
setMu(double mu)
Setter for property mu.
|
void |
setSigma(double sigma)
Setter for property sigma.
|
void |
setValuesFileURL(String url)
Sets the
valuesFileURL using a string URL representation |
void |
setValuesFileURL(URL url)
Sets the
valuesFileURL |
public static final int DIGEST_MODE
public static final int REPLAY_MODE
public static final int UNIFORM_MODE
public static final int EXPONENTIAL_MODE
public static final int GAUSSIAN_MODE
public static final int CONSTANT_MODE
private int mode
private URL valuesFileURL
private double mu
private double sigma
private EmpiricalDistribution empiricalDistribution
private BufferedReader filePointer
private final RandomData randomData
public ValueServer()
public ValueServer(RandomData randomData)
randomData
- the RandomData instance used to source random datapublic double getNext() throws IOException
IOException
- in REPLAY_MODE if a file I/O error occurspublic void fill(double[] values) throws IOException
values
- array to be filledIOException
- in REPLAY_MODE if a file I/O error occurspublic double[] fill(int length) throws IOException
length
with values generated
using getNext() repeatedly.length
- length of output arrayIOException
- in REPLAY_MODE if a file I/O error occurspublic void computeDistribution() throws IOException
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
IOException
- if an I/O error occurs reading the input filepublic void computeDistribution(int binCount) throws IOException
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
binCount
- the number of bins used in computing the empirical
distributionIOException
- if an error occurs reading the input filepublic int getMode()
public void setMode(int mode)
mode
- New value of property mode.public URL getValuesFileURL()
valuesFileURL
public void setValuesFileURL(String url) throws MalformedURLException
valuesFileURL
using a string URL representationurl
- String representation for new valuesFileURL.MalformedURLException
- if url is not well formedpublic void setValuesFileURL(URL url)
valuesFileURL
url
- New value of property valuesFileURL.public EmpiricalDistribution getEmpiricalDistribution()
public void resetReplayFile() throws IOException
valuesFileURL
.IOException
- if an error occurs opening the filepublic void closeReplayFile() throws IOException
valuesFileURL
after use in REPLAY_MODE.IOException
- if an error occurs closing the filepublic double getMu()
public void setMu(double mu)
mu
- New value of property mu.public double getSigma()
public void setSigma(double sigma)
sigma
- New value of property sigma.private double getNextDigest()
Preconditions:
computeDistribution()
must have completed successfully; otherwise an
IllegalStateException
will be thrownprivate double getNextReplay() throws IOException
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.
IOException
- if there is a problem reading from the fileNumberFormatException
- if an invalid numeric string is
encountered in the fileprivate double getNextUniform()
private double getNextExponential()
private double getNextGaussian()
Copyright (c) 2003-2013 Apache Software Foundation