Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
 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 org.apache.mahout.math.jet.random;
public class Exponential extends AbstractContinousDistribution {
  // rate parameter for the distribution.  Mean is 1/lambda.
  private double lambda;

  
Provides a negative exponential distribution given a rate parameter lambda and an underlying random number generator. The mean of this distribution will be equal to 1/lambda.

Parameters:
lambda The rate parameter of the distribution.
randomGenerator The PRNG that is used to generate values.
  public Exponential(double lambdaRandom randomGenerator) {
    setRandomGenerator(randomGenerator);
    this. = lambda;
  }

  
Returns the cumulative distribution function.

Parameters:
x The point at which the cumulative distribution function is to be evaluated.
Returns:
Returns the integral from -infinity to x of the PDF, also known as the cumulative distribution function.
  public double cdf(double x) {
    if (x <= 0.0) {
      return 0.0;
    }
    return 1.0 - Math.exp(-x * );
  }

  
Returns a random number from the distribution.
  public double nextDouble() {
    return -Math.log1p(-randomDouble()) / ;
  }

  
Returns the value of the probability density function at a particular point.

Parameters:
x The point at which the probability density function is to be evaluated.
Returns:
The value of the probability density function at the specified point.
  public double pdf(double x) {
    if (x < 0.0) {
      return 0.0;
    }
    return  * Math.exp(-x * );
  }

  
Sets the rate parameter.

Parameters:
lambda The new value of the rate parameter.
  public void setState(double lambda) {
    this. = lambda;
  }

  
Returns a String representation of the receiver.
  public String toString() {
    return String.format(."%s(%.4f)"this.getClass().getName(), );
  }
New to GrepCode? Check out our FAQ X