/*************************************************************************** * Copyright (C) 1995, 1996, Jun Sun, jsun@junsun.net. * * * *************************************************************************** */ /* implementation of exponential distribution */ /* only random generator are implemented currently */ #include #include #include "random_variates.h" Exponential::Exponential(double beta) { _beta = beta; } Exponential::~Exponential(){} double Exponential::sample() { return -_beta * log(randp->sample()); } double Exponential::distribution(double x) { if (x<0.0) return 0.0; else return 1.0 - exp(-x/_beta); } double Exponential::density(double x) { if (x<0.0) return 0.0; else return exp(-x/_beta)/_beta; } double Exponential::probability(double x1, double x2) { assert(x2>=x1); return distribution(x2) - distribution(x1); } double Exponential::inverse_distribution(double p) { return -_beta * log(1-p); }