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

cern.jet.random.tdouble.ExponentialPower Maven / Gradle / Ivy

Go to download

Parallel Colt is a multithreaded version of Colt - a library for high performance scientific computing in Java. It contains efficient algorithms for data analysis, linear algebra, multi-dimensional arrays, Fourier transforms, statistics and histogramming.

The newest version!
/*
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;

/**
 * Exponential Power distribution.
 * 

* Valid parameter ranges: tau >= 1. *

* Instance methods operate on a user supplied uniform random number generator; * they are unsynchronized. *

Static methods operate on a default uniform random number generator; they * are synchronized. *

* Implementation: *

Method: Non-universal rejection method for logconcave densities. *
This is a port of epd.c from the C-RAND / * WIN-RAND library. C-RAND's implementation, in turn, is based upon *

* L. Devroye (1986): Non-Uniform Random Variate Generation , Springer Verlag, * New York. *

* * @author [email protected] * @version 1.0, 09/24/99 */ public class ExponentialPower extends AbstractContinousDoubleDistribution { /** * */ private static final long serialVersionUID = 1L; protected double tau; // cached vars for method nextDouble(tau) (for performance only) private double s, sm1, tau_set = -1.0; // The uniform random number generated shared by all static methods. protected static ExponentialPower shared = new ExponentialPower(1.0, makeDefaultGenerator()); /** * Constructs an Exponential Power distribution. Example: tau=1.0. * * @throws IllegalArgumentException * if tau < 1.0. */ public ExponentialPower(double tau, DoubleRandomEngine randomGenerator) { setRandomGenerator(randomGenerator); setState(tau); } /** * Returns a random number from the distribution. */ public double nextDouble() { return nextDouble(this.tau); } /** * Returns a random number from the distribution; bypasses the internal * state. * * @throws IllegalArgumentException * if tau < 1.0. */ public double nextDouble(double tau) { double u, u1, v, x, y; if (tau != tau_set) { // SET-UP s = 1.0 / tau; sm1 = 1.0 - s; tau_set = tau; } // GENERATOR do { u = randomGenerator.raw(); // U(0/1) u = (2.0 * u) - 1.0; // U(-1.0/1.0) u1 = Math.abs(u); // u1=|u| v = randomGenerator.raw(); // U(0/1) if (u1 <= sm1) { // Uniform hat-function for x <= (1-1/tau) x = u1; } else { // Exponential hat-function for x > (1-1/tau) y = tau * (1.0 - u1); // U(0/1) x = sm1 - s * Math.log(y); v = v * y; } } // Acceptance/Rejection while (Math.log(v) > -Math.exp(Math.log(x) * tau)); // Random sign if (u < 0.0) return x; else return -x; } /** * Sets the distribution parameter. * * @throws IllegalArgumentException * if tau < 1.0. */ public void setState(double tau) { if (tau < 1.0) throw new IllegalArgumentException(); this.tau = tau; } /** * Returns a random number from the distribution. * * @throws IllegalArgumentException * if tau < 1.0. */ public static double staticNextDouble(double tau) { synchronized (shared) { return shared.nextDouble(tau); } } /** * Returns a String representation of the receiver. */ public String toString() { return this.getClass().getName() + "(" + tau + ")"; } /** * Sets the uniform random number generated shared by all static * methods. * * @param randomGenerator * the new uniform random number generator to be shared. */ private static void xstaticSetRandomGenerator(DoubleRandomEngine randomGenerator) { synchronized (shared) { shared.setRandomGenerator(randomGenerator); } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy