cern.jet.random.tdouble.AbstractDoubleDistribution Maven / Gradle / Ivy
Show all versions of parallelcolt Show documentation
/*
Copyright (C) 1999 CERN - European Organization for Nuclear Research.
Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose
is hereby granted without fee, provided that the above copyright notice appear in all copies and
that both that copyright notice and this permission notice appear in supporting documentation.
CERN makes no representations about the suitability of this software for any purpose.
It is provided "as is" without expressed or implied warranty.
*/
package cern.jet.random.tdouble;
import cern.jet.random.tdouble.engine.DoubleRandomEngine;
/**
* Abstract base class for all random distributions.
*
* A subclass of this class need to override method nextDouble() and,
* in rare cases, also nextInt().
*
* Currently all subclasses use a uniform pseudo-random number generation engine
* and transform its results to the target distribution. Thus, they expect such
* a uniform engine upon instance construction.
*
* {@link cern.jet.random.tdouble.engine.DoubleMersenneTwister} is recommended
* as uniform pseudo-random number generation engine, since it is very strong
* and at the same time quick. {@link #makeDefaultGenerator()} will conveniently
* construct and return such a magic thing. You can also, for example, use
* {@link cern.jet.random.tdouble.engine.DRand}, a quicker (but much weaker)
* uniform random number generation engine. Of course, you can also use other
* strong uniform random number generation engines.
*
*
* Ressources on the Web:
*
Check the Web version of the CERN Data Analysis
* Briefbook . This will clarify the definitions of most distributions.
* Also consult the StatSoft Electronic
* Textbook - the definite web book.
*
* Other useful ressources:
*
* Another site and yet another site
* describing the definitions of several distributions.
* You may want to check out a
* Glossary of Statistical Terms.
* The GNU Scientific Library contains an extensive (but hardly readable) list of
* definition of distributions.
* Use this Web interface to plot all sort of
* distributions.
* Even more ressources: Internet
* glossary of Statistical Terms, a text book,
*
* another text book.
* Finally, a good link list Statistics on the
* Web.
*
*
* @see cern.jet.random.tdouble.engine
* @author [email protected]
* @version 1.0, 09/24/99
*/
public abstract class AbstractDoubleDistribution extends cern.colt.PersistentObject implements
cern.colt.function.tdouble.DoubleFunction, cern.colt.function.tint.IntFunction {
/**
*
*/
private static final long serialVersionUID = 1L;
protected DoubleRandomEngine randomGenerator;
/**
* Makes this class non instantiable, but still let's others inherit from
* it.
*/
protected AbstractDoubleDistribution() {
}
/**
* Equivalent to nextDouble(). This has the effect that
* distributions can now be used as function objects, returning a random
* number upon function evaluation.
*/
public double apply(double dummy) {
return nextDouble();
}
/**
* Equivalent to nextInt(). This has the effect that distributions
* can now be used as function objects, returning a random number upon
* function evaluation.
*/
public int apply(int dummy) {
return nextInt();
}
/**
* Returns a deep copy of the receiver; the copy will produce identical
* sequences. After this call has returned, the copy and the receiver have
* equal but separate state.
*
* @return a copy of the receiver.
*/
public Object clone() {
AbstractDoubleDistribution copy = (AbstractDoubleDistribution) super.clone();
if (this.randomGenerator != null)
copy.randomGenerator = (DoubleRandomEngine) this.randomGenerator.clone();
return copy;
}
/**
* Returns the used uniform random number generator;
*/
protected DoubleRandomEngine getRandomGenerator() {
return randomGenerator;
}
/**
* Constructs and returns a new uniform random number generation engine
* seeded with the current time. Currently this is
* {@link cern.jet.random.tdouble.engine.DoubleMersenneTwister}.
*/
public static DoubleRandomEngine makeDefaultGenerator() {
return cern.jet.random.tdouble.engine.DoubleRandomEngine.makeDefault();
}
/**
* Returns a random number from the distribution.
*/
public abstract double nextDouble();
/**
* Returns a random number from the distribution; returns
* (int) Math.round(nextDouble()). Override this method if
* necessary.
*/
public int nextInt() {
return (int) Math.round(nextDouble());
}
/**
* Sets the uniform random generator internally used.
*/
protected void setRandomGenerator(DoubleRandomEngine randomGenerator) {
this.randomGenerator = randomGenerator;
}
}