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

JSci.maths.statistics.ExponentialDistribution Maven / Gradle / Ivy

Go to download

JSci is a set of open source Java packages. The aim is to encapsulate scientific methods/principles in the most natural way possible. As such they should greatly aid the development of scientific based software. It offers: abstract math interfaces, linear algebra (support for various matrix and vector types), statistics (including probability distributions), wavelets, newtonian mechanics, chart/graph components (AWT and Swing), MathML DOM implementation, ... Note: some packages, like javax.comm, for the astro and instruments package aren't listed as dependencies (not available).

The newest version!
package JSci.maths.statistics;

/**
* The ExponentialDistribution class provides an object for encapsulating exponential distributions.
* @version 0.2
* @author Mark Hale
*/
public final class ExponentialDistribution extends ProbabilityDistribution {
        private double lambda;

        /**
        * Constructs the standard exponential distribution.
        */
        public ExponentialDistribution() {
                this(1.0);
        }
        /**
        * Constructs an exponential distribution.
        * @param decay the scale parameter.
        */
        public ExponentialDistribution(double decay) {
                if(decay<0.0)
                        throw new OutOfRangeException("The scale parameter should be positive.");
                lambda=decay;
        }
        /**
        * Constructs an exponential distribution from a data set.
        * @param array a sample.
        */
        public ExponentialDistribution(double array[]) {
                double sumX=array[0];
                for(int i=1;ie-lambdaX.
        * @return the probability that a stochastic variable x has the value X, i.e. P(x=X).
        */
        public double probability(double X) {
                checkRange(X,0.0,Double.MAX_VALUE);
                return lambda*Math.exp(-lambda*X);
        }
        /**
        * Cumulative exponential distribution function.
	* @return the probability that a stochastic variable x is less than or equal to X, i.e. P(x<=X).
        */
        public double cumulative(double X) {
                checkRange(X,0.0,Double.MAX_VALUE);
                return 1.0-Math.exp(-lambda*X);
        }
        /**
	* Inverse of the cumulative exponential distribution function.
        * @return the value X for which P(x<=X).
        */
        public double inverse(double probability) {
                checkRange(probability);
                return -Math.log(1.0-probability)/lambda;
        }
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy