JSci.maths.statistics.ProbabilityDistribution Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jsci Show documentation
Show all versions of jsci Show documentation
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 ProbabilityDistribution superclass provides an object for encapsulating probability distributions.
* @version 1.0
* @author Jaco van Kooten
*/
public abstract class ProbabilityDistribution extends Object {
/**
* Constructs a probability distribution.
*/
public ProbabilityDistribution() {}
/**
* Probability density function.
* @return the probability that a stochastic variable x has the value X, i.e. P(x=X).
*/
public abstract double probability(double X);
/**
* Cumulative distribution function.
* @return the probability that a stochastic variable x is less than or equal to X, i.e. P(x<=X).
*/
public abstract double cumulative(double X);
/**
* Inverse of the cumulative distribution function.
* @return the value X for which P(x<=X).
*/
public abstract double inverse(double probability);
/**
* Check if the range of the argument of the distribution method is between lo
and hi
.
* @exception OutOfRangeException If the argument is out of range.
*/
protected final void checkRange(double x, double lo, double hi) {
if(xhi)
throw new OutOfRangeException("The argument of the distribution method should be between "+lo+" and "+hi+".");
}
/**
* Check if the range of the argument of the distribution method is between 0.0 and 1.0.
* @exception OutOfRangeException If the argument is out of range.
*/
protected final void checkRange(double x) {
if(x<0.0 || x>1.0)
throw new OutOfRangeException("The argument of the distribution method should be between 0.0 and 1.0.");
}
private static final double FINDROOT_ACCURACY = 1.0e-15;
private static final int FINDROOT_MAX_ITERATIONS = 150;
/**
* This method approximates the value of X for which P(x<X)=prob.
* It applies a combination of a Newton-Raphson procedure and bisection method
* with the value guess as a starting point. Furthermore, to ensure convergency
* and stability, one should supply an inverval [xLo,xHi] in which the probalility
* distribution reaches the value prob. The method does no checking, it will produce
* bad results if wrong values for the parameters are supplied - use it with care.
*/
protected final double findRoot(double prob,double guess,double xLo,double xHi) {
double x=guess,xNew=guess;
double error,pdf,dx=1.0;
int i=0;
while(Math.abs(dx)>FINDROOT_ACCURACY && i++xHi || pdf==0.0) {
xNew=(xLo+xHi)/2.0;
dx=xNew-x;
}
x=xNew;
}
return x;
}
}