JSci.maths.statistics.CauchyDistribution 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 CauchyDistribution class provides an object for encapsulating Cauchy distributions.
* @version 0.2
* @author Mark Hale
*/
public final class CauchyDistribution extends ProbabilityDistribution {
private double alpha;
private double gamma;
/**
* Constructs the standard Cauchy distribution.
*/
public CauchyDistribution() {
this(0.0,1.0);
}
/**
* Constructs a Cauchy distribution.
* @param location the location parameter.
* @param scale the scale parameter.
*/
public CauchyDistribution(double location,double scale) {
if(scale<0.0)
throw new OutOfRangeException("The scale parameter should be positive.");
alpha=location;
gamma=scale;
}
/**
* Returns the location parameter.
*/
public double getLocationParameter() {
return alpha;
}
/**
* Returns the scale parameter.
*/
public double getScaleParameter() {
return gamma;
}
/**
* Probability density function of a Cauchy distribution.
* P(X) = /((2+(X-)2)).
* @return the probability that a stochastic variable x has the value X, i.e. P(x=X).
*/
public double probability(double X) {
final double y=X-alpha;
return gamma/(Math.PI*(gamma*gamma+y*y));
}
/**
* Cumulative Cauchy 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) {
return 0.5+Math.atan((X-alpha)/gamma)/Math.PI;
}
/**
* Inverse of the cumulative Cauchy distribution function.
* @return the value X for which P(x<=X).
*/
public double inverse(double probability) {
checkRange(probability);
return alpha-gamma/Math.tan(Math.PI*probability);
}
}