All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.opengamma.strata.math.impl.cern.AbstractDistribution Maven / Gradle / Ivy

There is a newer version: 2.12.46
Show newest version
/*
 * Copyright (C) 2009 - present by OpenGamma Inc. and the OpenGamma group of companies
 *
 * Please see distribution for license.
 */
/*
 * This code is copied from the original library from the `cern.jet.random` package.
 * Changes:
 * - package name
 * - missing Javadoc param tags
 * - reformat
 * - use Java 8 function interfaces
 * - make package scoped
 */
/*
Copyright � 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 com.opengamma.strata.math.impl.cern;

import java.util.function.DoubleUnaryOperator;
import java.util.function.IntUnaryOperator;

//CSOFF: ALL
/**
 * 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 MersenneTwister} 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 {@code 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. *

* @author [email protected] * @version 1.0, 09/24/99 */ abstract class AbstractDistribution extends PersistentObject implements DoubleUnaryOperator, IntUnaryOperator { private static final long serialVersionUID = 1L; protected RandomEngine randomGenerator; /** * Makes this class non instantiable, but still let's others inherit from it. */ protected AbstractDistribution() { } /** Equivalent to nextDouble(). This has the effect that distributions can now be used as function objects, returning a random number upon function evaluation. */ @Override public double applyAsDouble(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. */ @Override public int applyAsInt(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. */ @Override public Object clone() { AbstractDistribution copy = (AbstractDistribution) super.clone(); if (this.randomGenerator != null) copy.randomGenerator = (RandomEngine) this.randomGenerator.clone(); return copy; } /** * Returns the used uniform random number generator; * @return result */ protected RandomEngine getRandomGenerator() { return randomGenerator; } /** * Constructs and returns a new uniform random number generation engine seeded with the current time. * Currently this is {@link MersenneTwister}. * @return result */ public static RandomEngine makeDefaultGenerator() { return RandomEngine.makeDefault(); } /** * Returns a random number from the distribution. * @return result */ public abstract double nextDouble(); /** * Returns a random number from the distribution; returns (int) Math.round(nextDouble()). * Override this method if necessary. * @return result */ public int nextInt() { return (int) Math.round(nextDouble()); } /** * Sets the uniform random generator internally used. * @param randomGenerator input */ protected void setRandomGenerator(RandomEngine randomGenerator) { this.randomGenerator = randomGenerator; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy