net.sourceforge.cilib.math.random
Class RandomNumber

java.lang.Object
  extended by net.sourceforge.cilib.math.random.RandomNumber
All Implemented Interfaces:
Serializable, Cloneable

public class RandomNumber
extends Object
implements Cloneable

This class provides the needed functionality to sample random numbers from different continuous valued distributions.

These distributions include:

Author:
Gary Pampara
See Also:
Serialized Form

Constructor Summary
RandomNumber()
          Create a RandomNumber instance.
RandomNumber(RandomNumber copy)
           
 
Method Summary
 double getCauchy()
          Convenience method to obtain a Cauchy number.
 double getCauchy(double location, double scale)
          Return a random number sampled from the Cauchy distribution.
 RandomNumber getClone()
          Create a cloned copy of the current object and return it.
 double getGaussian()
          Return a random number from the Guassian distribution with a mean of 0.0 and a deviation of 1.0.
 double getGaussian(double location, double scale)
          Return a random number with the mean of mean and a deviation of deviation.
 double getNormal()
           
 double getNormal(double location, double scale)
          Convenience method for getGaussian().
 Random getRandomGenerator()
          Return the random number generator being used.
 double getUniform()
          Get a uniform random number located within 0 <= x < 1.
 double getUniform(double lower, double upper)
          Get the uniform random number.
 void setRandomGenerator(Random random)
          Set the random number generator to be used.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RandomNumber

public RandomNumber()
Create a RandomNumber instance. The internal random number generator is defined to be the MersenneTwister by default with a mean of 0.0 and a deviation of 1.0.


RandomNumber

public RandomNumber(RandomNumber copy)
Method Detail

getClone

public RandomNumber getClone()
Description copied from interface: Cloneable
Create a cloned copy of the current object and return it. In general the created copy will be a deep copy of the provided instance. As a result this operation an be quite expensive if used incorrectly.

Specified by:
getClone in interface Cloneable
Returns:
An exact clone of the current object instance.
See Also:
Object.clone()

getRandomGenerator

public Random getRandomGenerator()
Return the random number generator being used.

Returns:
The random number generator.

setRandomGenerator

public void setRandomGenerator(Random random)
Set the random number generator to be used.

Parameters:
random - The random number generator to be used.

getGaussian

public double getGaussian()
Return a random number from the Guassian distribution with a mean of 0.0 and a deviation of 1.0.

Returns:
Random number ~ N(0,1).

getGaussian

public double getGaussian(double location,
                          double scale)
Return a random number with the mean of mean and a deviation of deviation. Based on the formula:
s*U(0, 1) + m == U(m, s)

ALGORITHM 712, COLLECTED ALGORITHMS FROM ACM.
THIS WORK PUBLISHED IN TRANSACTIONS ON MATHEMATICAL SOFTWARE,
VOL. 18, NO. 4, DECEMBER, 1992, PP. 434-435.
The function returns a normally distributed pseudo-random number
with a given mean and standard deviation. Calls are made to a
function subprogram which must return independent random
numbers uniform in the interval (0,1).

The algorithm uses the ratio of uniforms method of A.J. Kinderman and J.F. Monahan augmented with quadratic bounding curves.

Returns:
A Gaussian number with mean mean and deviation deviation

getNormal

public double getNormal()
Returns:

getNormal

public double getNormal(double location,
                        double scale)
Convenience method for getGaussian().

Parameters:
location - The location of the mean of the distribution.
scale - The allowed variation that can be observed.
Returns:
A Guassian number with mean location and deviation scale.

getCauchy

public double getCauchy()
Convenience method to obtain a Cauchy number. The distribution has a mean of 0.0 and a deviation of 1.0.

Returns:
A cauchy number in the given distribution.

getCauchy

public double getCauchy(double location,
                        double scale)
Return a random number sampled from the Cauchy distribution.

Parameters:
location - The location of the mean of the distribution.
scale - The allowed variation that can be observed.
Returns:
A Cauchy random number with location location and scale parameter scale

getUniform

public double getUniform()
Get a uniform random number located within 0 <= x < 1.

Returns:
Uniform random number (0 <= x < 1).

getUniform

public double getUniform(double lower,
                         double upper)
Get the uniform random number. The number is located within A <= x < B where A == mean and B == deviation.

Parameters:
lower - The lower bound for the number generation.
upper - The upper bound for the number generation.
Returns:
Uniform random number (lower <= x < upper).


Copyright © 2009 CIRG. All Rights Reserved.