Java API By Example, From Geeks To Geeks.

# Java > Open Source Codes > JSci > maths > statistics > ProbabilityDistribution

 `1 package JSci.maths.statistics;2 3 /**4 * The ProbabilityDistribution superclass provides an object for encapsulating probability distributions.5 * @version 1.06 * @author Jaco van Kooten7 */8 public abstract class ProbabilityDistribution extends Object {9         /**10         * Constructs a probability distribution.11         */12         public ProbabilityDistribution() {}13         /**14         * Probability density function.15         * @return the probability that a stochastic variable x has the value X, i.e. P(x=X).16         */17         public abstract double probability(double X);18         /**19         * Cumulative distribution function.20     * @return the probability that a stochastic variable x is less then X, i.e. P(x<X).21         */22         public abstract double cumulative(double X);23         /**24     * Inverse of the cumulative distribution function.25         * @return the value X for which P(x<X).26         */27         public abstract double inverse(double probability);28         /**29     * Check if the range of the argument of the distribution method is between lo and hi.30         * @exception OutOfRangeException If the argument is out of range.31         */32         protected final void checkRange(double x, double lo, double hi) {33                 if(xhi)34                         throw new OutOfRangeException("The argument of the distribution method should be between "+lo+" and "+hi+".");35         }36         /**37     * Check if the range of the argument of the distribution method is between 0.0 and 1.0.38         * @exception OutOfRangeException If the argument is out of range.39         */40         protected final void checkRange(double x) {41             if(x<0.0 || x>1.0)42                 throw new OutOfRangeException("The argument of the distribution method should be between 0.0 and 1.0.");43         }44 45         private static final double FINDROOT_ACCURACY = 1.0e-15;46         private static final int FINDROOT_MAX_ITERATIONS = 150;47         /**48         * This method approximates the value of X for which P(x<X)=prob.49         * It applies a combination of a Newton-Raphson procedure and bisection method50         * with the value guess as a starting point. Furthermore, to ensure convergency51         * and stability, one should supply an inverval [xLo,xHi] in which the probalility52         * distribution reaches the value prob. The method does no checking, it will produce53         * bad results if wrong values for the parameters are supplied - use it with care.54         */55         protected final double findRoot(double prob,double guess,double xLo,double xHi) {56                 double x=guess,xNew=guess;57                 double error,pdf,dx=1.0;58                 int i=0;59                 while(Math.abs(dx)>FINDROOT_ACCURACY && i++xHi || pdf==0.0) {75                                 xNew=(xLo+xHi)/2.0;76                                 dx=xNew-x;77                         }78                         x=xNew;79                 }80                 return x;81         }82 }83 84 ` Popular Tags