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

sim.util.distribution.Exponential Maven / Gradle / Ivy

Go to download

MASON is a fast discrete-event multiagent simulation library core in Java, designed to be the foundation for large custom-purpose Java simulations, and also to provide more than enough functionality for many lightweight simulation needs. MASON contains both a model library and an optional suite of visualization tools in 2D and 3D.

The newest version!
/*
  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 sim.util.distribution;
import ec.util.MersenneTwisterFast;

/**
 * Exponential Distribution (aka Negative Exponential Distribution); See the  math definition
 *  animated definition.
 * 

* p(x) = lambda*exp(-x*lambda) for x >= 0, lambda > 0. *

* 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. *

* * @author [email protected] * @version 1.0, 09/24/99 */ public class Exponential extends AbstractContinousDistribution { private static final long serialVersionUID = 1; protected double lambda; /** * Constructs a Negative Exponential distribution. */ public Exponential(double lambda, MersenneTwisterFast randomGenerator) { setRandomGenerator(randomGenerator); setState(lambda); } /** * Returns the cumulative distribution function. */ public double cdf(double x) { if (x <= 0.0) return 0.0; return 1.0 - Math.exp(-x * lambda); } /** * Returns a random number from the distribution. */ public double nextDouble() { return nextDouble(lambda); } /** * Returns a random number from the distribution; bypasses the internal state. */ public double nextDouble(double lambda) { return - Math.log(randomGenerator.nextDouble()) / lambda; } /** * Returns the probability distribution function. */ public double pdf(double x) { if (x < 0.0) return 0.0; return lambda*Math.exp(-x*lambda); } /** * Sets the mean. */ public void setState(double lambda) { this.lambda = lambda; } /** * Returns a String representation of the receiver. */ public String toString() { return this.getClass().getName()+"("+lambda+")"; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy