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

JSci.maths.statistics.GeometricDistribution 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 GeometricDistribution class provides an object for encapsulating geometric distributions.
* @version 0.2
* @author Mark Hale
*/
public final class GeometricDistribution extends ProbabilityDistribution {
        private double success;
        private double failure;

        /**
        * Constructs a geometric distribution.
        * @param prob the probability of success.
        */
        public GeometricDistribution(double prob) {
                if(prob<0.0 || prob>1.0)
                        throw new OutOfRangeException("The probability should be between 0.0 and 1.0.");
                success=prob;
                failure=1.0-prob;
        }
        /**
        * Returns the success parameter.
        */
        public double getSuccessParameter() {
                return success;
        }
        /**
        * Returns the mean.
        */
        public double getMean() {
                return 1.0/success;
        }
        /**
        * Returns the variance.
        */
        public double getVariance() {
                return failure/(success*success);
        }
        /**
        * Probability density function of a geometric distribution.
        * P(X) = p (1-p)X-1.
        * @param X should be integer-valued.
        * @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 success*Math.pow(failure,X-1);
        }
        /**
        * Cumulative geometric distribution function.
        * @param X should be integer-valued.
	* @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.pow(failure,X);
        }
        /**
	* Inverse of the cumulative geometric distribution function.
        * @return the value X for which P(x<=X).
        */
        public double inverse(double probability) {
                checkRange(probability);
                return Math.log(1.0-probability)/Math.log(failure);
        }
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy