You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mahout.apache.org by td...@apache.org on 2010/08/15 09:02:46 UTC
svn commit: r985619 -
/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/stat/Probability.java
Author: tdunning
Date: Sun Aug 15 07:02:46 2010
New Revision: 985619
URL: http://svn.apache.org/viewvc?rev=985619&view=rev
Log:
Style fixes
Modified:
mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/stat/Probability.java
Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/stat/Probability.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/stat/Probability.java?rev=985619&r1=985618&r2=985619&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/stat/Probability.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/jet/stat/Probability.java Sun Aug 15 07:02:46 2010
@@ -31,7 +31,7 @@ import org.apache.mahout.math.jet.random
/** Partially deprecated until unit tests are in place. Until this time, this class/interface is unsupported. */
public class Probability extends Constants {
- private static final Normal unitNormal = new Normal(0, 1, null);
+ private static final Normal UNIT_NORMAL = new Normal(0, 1, null);
/**
* ********************************************** COEFFICIENTS FOR METHOD normalInverse() *
@@ -39,22 +39,22 @@ public class Probability extends Constan
*/
/* approximation for 0 <= |y - 0.5| <= 3/8 */
private static final double[] P0 = {
- -5.99633501014107895267E1,
- 9.80010754185999661536E1,
- -5.66762857469070293439E1,
- 1.39312609387279679503E1,
- -1.23916583867381258016E0,
+ -5.99633501014107895267E1,
+ 9.80010754185999661536E1,
+ -5.66762857469070293439E1,
+ 1.39312609387279679503E1,
+ -1.23916583867381258016E0,
};
private static final double[] Q0 = {
- /* 1.00000000000000000000E0,*/
- 1.95448858338141759834E0,
- 4.67627912898881538453E0,
- 8.63602421390890590575E1,
- -2.25462687854119370527E2,
- 2.00260212380060660359E2,
- -8.20372256168333339912E1,
- 1.59056225126211695515E1,
- -1.18331621121330003142E0,
+ /* 1.00000000000000000000E0,*/
+ 1.95448858338141759834E0,
+ 4.67627912898881538453E0,
+ 8.63602421390890590575E1,
+ -2.25462687854119370527E2,
+ 2.00260212380060660359E2,
+ -8.20372256168333339912E1,
+ 1.59056225126211695515E1,
+ -1.18331621121330003142E0,
};
@@ -62,52 +62,53 @@ public class Probability extends Constan
* i.e., y between exp(-2) = .135 and exp(-32) = 1.27e-14.
*/
private static final double[] P1 = {
- 4.05544892305962419923E0,
- 3.15251094599893866154E1,
- 5.71628192246421288162E1,
- 4.40805073893200834700E1,
- 1.46849561928858024014E1,
- 2.18663306850790267539E0,
- -1.40256079171354495875E-1,
- -3.50424626827848203418E-2,
- -8.57456785154685413611E-4,
+ 4.05544892305962419923E0,
+ 3.15251094599893866154E1,
+ 5.71628192246421288162E1,
+ 4.40805073893200834700E1,
+ 1.46849561928858024014E1,
+ 2.18663306850790267539E0,
+ -1.40256079171354495875E-1,
+ -3.50424626827848203418E-2,
+ -8.57456785154685413611E-4,
};
+
private static final double[] Q1 = {
- /* 1.00000000000000000000E0,*/
- 1.57799883256466749731E1,
- 4.53907635128879210584E1,
- 4.13172038254672030440E1,
- 1.50425385692907503408E1,
- 2.50464946208309415979E0,
- -1.42182922854787788574E-1,
- -3.80806407691578277194E-2,
- -9.33259480895457427372E-4,
+ /* 1.00000000000000000000E0,*/
+ 1.57799883256466749731E1,
+ 4.53907635128879210584E1,
+ 4.13172038254672030440E1,
+ 1.50425385692907503408E1,
+ 2.50464946208309415979E0,
+ -1.42182922854787788574E-1,
+ -3.80806407691578277194E-2,
+ -9.33259480895457427372E-4,
};
/* Approximation for interval z = sqrt(-2 log y ) between 8 and 64
* i.e., y between exp(-32) = 1.27e-14 and exp(-2048) = 3.67e-890.
*/
private static final double[] P2 = {
- 3.23774891776946035970E0,
- 6.91522889068984211695E0,
- 3.93881025292474443415E0,
- 1.33303460815807542389E0,
- 2.01485389549179081538E-1,
- 1.23716634817820021358E-2,
- 3.01581553508235416007E-4,
- 2.65806974686737550832E-6,
- 6.23974539184983293730E-9,
+ 3.23774891776946035970E0,
+ 6.91522889068984211695E0,
+ 3.93881025292474443415E0,
+ 1.33303460815807542389E0,
+ 2.01485389549179081538E-1,
+ 1.23716634817820021358E-2,
+ 3.01581553508235416007E-4,
+ 2.65806974686737550832E-6,
+ 6.23974539184983293730E-9,
};
private static final double[] Q2 = {
- /* 1.00000000000000000000E0,*/
- 6.02427039364742014255E0,
- 3.67983563856160859403E0,
- 1.37702099489081330271E0,
- 2.16236993594496635890E-1,
- 1.34204006088543189037E-2,
- 3.28014464682127739104E-4,
- 2.89247864745380683936E-6,
- 6.79019408009981274425E-9,
+ /* 1.00000000000000000000E0,*/
+ 6.02427039364742014255E0,
+ 3.67983563856160859403E0,
+ 1.37702099489081330271E0,
+ 2.16236993594496635890E-1,
+ 1.34204006088543189037E-2,
+ 3.28014464682127739104E-4,
+ 2.89247864745380683936E-6,
+ 6.79019408009981274425E-9,
};
/** Makes this class non instantiable, but still let's others inherit from it. */
@@ -171,7 +172,7 @@ public class Probability extends Constan
}
if (k == n) {
- return (1.0);
+ return 1.0;
}
if (k == 0) {
return Math.pow(1.0 - p, n);
@@ -207,7 +208,7 @@ public class Probability extends Constan
}
if (k == n) {
- return (0.0);
+ return 0.0;
}
if (k == 0) {
return 1.0 - Math.pow(1.0 - p, n);
@@ -235,7 +236,7 @@ public class Probability extends Constan
* @param x integration end point.
*/
@Deprecated
- public static double chiSquare(double v, double x) throws ArithmeticException {
+ public static double chiSquare(double v, double x) {
if (x < 0.0 || v < 1.0) {
return 0.0;
}
@@ -266,7 +267,7 @@ public class Probability extends Constan
* @param v degrees of freedom.
*/
@Deprecated
- public static double chiSquareComplemented(double v, double x) throws ArithmeticException {
+ public static double chiSquareComplemented(double v, double x) {
if (x < 0.0 || v < 1.0) {
return 0.0;
}
@@ -284,36 +285,38 @@ public class Probability extends Constan
* -
* 0
* </pre>
- * <b>Implementation:</b> For <tt>0 <= |x| < 1, erf(x) = x * P4(x**2)/Q5(x**2)</tt>; otherwise <tt>erf(x) = 1 -
- * erfc(x)</tt>. <p> Code adapted from the <A HREF="http://www.sci.usq.edu.au/staff/leighb/graph/Top.html">Java 2D
- * Graph Package 2.4</A>, which in turn is a port from the <A HREF="http://people.ne.mediaone.net/moshier/index.html#Cephes">Cephes
+ * <b>Implementation:</b> For <tt>0 <= |x| < 1, erf(x) = x * P4(x**2)/Q5(x**2)</tt>; otherwise
+ * <tt>erf(x) = 1 - erfc(x)</tt>. <p> Code adapted from the
+ * <A HREF="http://www.sci.usq.edu.au/staff/leighb/graph/Top.html">Java 2D
+ * Graph Package 2.4</A>, which in turn is a port from the
+ * <A HREF="http://people.ne.mediaone.net/moshier/index.html#Cephes">Cephes
* 2.2</A> Math Library (C).
*
* @param x the argument to the function.
*/
@Deprecated
- public static double errorFunction(double x) throws ArithmeticException {
- double[] T = {
- 9.60497373987051638749E0,
- 9.00260197203842689217E1,
- 2.23200534594684319226E3,
- 7.00332514112805075473E3,
- 5.55923013010394962768E4
+ public static double errorFunction(double x) {
+ double[] t = {
+ 9.60497373987051638749E0,
+ 9.00260197203842689217E1,
+ 2.23200534594684319226E3,
+ 7.00332514112805075473E3,
+ 5.55923013010394962768E4
};
- double[] U = {
- //1.00000000000000000000E0,
- 3.35617141647503099647E1,
- 5.21357949780152679795E2,
- 4.59432382970980127987E3,
- 2.26290000613890934246E4,
- 4.92673942608635921086E4
+ double[] u = {
+ //1.00000000000000000000E0,
+ 3.35617141647503099647E1,
+ 5.21357949780152679795E2,
+ 4.59432382970980127987E3,
+ 2.26290000613890934246E4,
+ 4.92673942608635921086E4
};
if (Math.abs(x) > 1.0) {
- return (1.0 - errorFunctionComplemented(x));
+ return 1.0 - errorFunctionComplemented(x);
}
double z = x * x;
- return x * Polynomial.polevl(z, T, 4) / Polynomial.p1evl(z, U, 5);
+ return x * Polynomial.polevl(z, t, 4) / Polynomial.p1evl(z, u, 5);
}
/**
@@ -337,48 +340,48 @@ public class Probability extends Constan
* @param a the argument to the function.
*/
@Deprecated
- public static double errorFunctionComplemented(double a) throws ArithmeticException {
+ public static double errorFunctionComplemented(double a) {
double x;
- double[] P = {
- 2.46196981473530512524E-10,
- 5.64189564831068821977E-1,
- 7.46321056442269912687E0,
- 4.86371970985681366614E1,
- 1.96520832956077098242E2,
- 5.26445194995477358631E2,
- 9.34528527171957607540E2,
- 1.02755188689515710272E3,
- 5.57535335369399327526E2
+ double[] p = {
+ 2.46196981473530512524E-10,
+ 5.64189564831068821977E-1,
+ 7.46321056442269912687E0,
+ 4.86371970985681366614E1,
+ 1.96520832956077098242E2,
+ 5.26445194995477358631E2,
+ 9.34528527171957607540E2,
+ 1.02755188689515710272E3,
+ 5.57535335369399327526E2
};
- double[] Q = {
- //1.0
- 1.32281951154744992508E1,
- 8.67072140885989742329E1,
- 3.54937778887819891062E2,
- 9.75708501743205489753E2,
- 1.82390916687909736289E3,
- 2.24633760818710981792E3,
- 1.65666309194161350182E3,
- 5.57535340817727675546E2
+ double[] q = {
+ //1.0
+ 1.32281951154744992508E1,
+ 8.67072140885989742329E1,
+ 3.54937778887819891062E2,
+ 9.75708501743205489753E2,
+ 1.82390916687909736289E3,
+ 2.24633760818710981792E3,
+ 1.65666309194161350182E3,
+ 5.57535340817727675546E2
};
- double[] R = {
- 5.64189583547755073984E-1,
- 1.27536670759978104416E0,
- 5.01905042251180477414E0,
- 6.16021097993053585195E0,
- 7.40974269950448939160E0,
- 2.97886665372100240670E0
+ double[] r = {
+ 5.64189583547755073984E-1,
+ 1.27536670759978104416E0,
+ 5.01905042251180477414E0,
+ 6.16021097993053585195E0,
+ 7.40974269950448939160E0,
+ 2.97886665372100240670E0
};
- double[] S = {
- //1.00000000000000000000E0,
- 2.26052863220117276590E0,
- 9.39603524938001434673E0,
- 1.20489539808096656605E1,
- 1.70814450747565897222E1,
- 9.60896809063285878198E0,
- 3.36907645100081516050E0
+ double[] s = {
+ //1.00000000000000000000E0,
+ 2.26052863220117276590E0,
+ 9.39603524938001434673E0,
+ 1.20489539808096656605E1,
+ 1.70814450747565897222E1,
+ 9.60896809063285878198E0,
+ 3.36907645100081516050E0
};
x = a < 0.0 ? -a : a;
@@ -395,17 +398,17 @@ public class Probability extends Constan
z = Math.exp(z);
- double q;
- double p;
+ double qval;
+ double pval;
if (x < 8.0) {
- p = Polynomial.polevl(x, P, 8);
- q = Polynomial.p1evl(x, Q, 8);
+ pval = Polynomial.polevl(x, p, 8);
+ qval = Polynomial.p1evl(x, q, 8);
} else {
- p = Polynomial.polevl(x, R, 5);
- q = Polynomial.p1evl(x, S, 6);
+ pval = Polynomial.polevl(x, r, 5);
+ qval = Polynomial.p1evl(x, s, 6);
}
- double y = (z * p) / q;
+ double y = (z * pval) / qval;
if (a < 0) {
y = 2.0 - y;
@@ -553,7 +556,7 @@ public class Probability extends Constan
* and http://en.wikipedia.org/wiki/Normal_distribution#Numerical_approximations_of_the_normal_cdf
*/
- public static double normal(double a) throws ArithmeticException {
+ public static double normal(double a) {
if (a < 0) {
return 1 - normal(-a);
}
@@ -564,7 +567,7 @@ public class Probability extends Constan
double b4 = -1.821255978;
double b5 = 1.330274429;
double t = 1 / (1 + b0 * a);
- return 1 - unitNormal.pdf(a) * t * (b1 + t * (b2 + t * (b3 + t * (b4 + t * b5))));
+ return 1 - UNIT_NORMAL.pdf(a) * t * (b1 + t * (b2 + t * (b3 + t * (b4 + t * b5))));
}
/**
@@ -586,7 +589,7 @@ public class Probability extends Constan
* @param variance the variance of the normal distribution.
* @param x the integration limit.
*/
- public static double normal(double mean, double variance, double x) throws ArithmeticException {
+ public static double normal(double mean, double variance, double x) {
return normal((x - mean) / Math.sqrt(variance));
}
@@ -600,7 +603,7 @@ public class Probability extends Constan
* R(w**2)/S(w**2))</tt>.
*/
@Deprecated
- public static double normalInverse(double y0) throws ArithmeticException {
+ public static double normalInverse(double y0) {
double s2pi = Math.sqrt(2.0 * Math.PI);
@@ -623,7 +626,7 @@ public class Probability extends Constan
double y2 = y * y;
x = y + y * (y2 * Polynomial.polevl(y2, P0, 4) / Polynomial.p1evl(y2, Q0, 8));
x *= s2pi;
- return (x);
+ return x;
}
x = Math.sqrt(-2.0 * Math.log(y));
@@ -640,7 +643,7 @@ public class Probability extends Constan
if (code != 0) {
x = -x;
}
- return (x);
+ return x;
}
/**
@@ -660,7 +663,7 @@ public class Probability extends Constan
* @param k number of terms.
* @param mean the mean of the poisson distribution.
*/
- public static double poisson(int k, double mean) throws ArithmeticException {
+ public static double poisson(int k, double mean) {
if (mean < 0) {
throw new IllegalArgumentException();
}
@@ -688,7 +691,7 @@ public class Probability extends Constan
* @param mean the mean of the poisson distribution.
*/
@Deprecated
- public static double poissonComplemented(int k, double mean) throws ArithmeticException {
+ public static double poissonComplemented(int k, double mean) {
if (mean < 0) {
throw new IllegalArgumentException();
}
@@ -722,12 +725,12 @@ public class Probability extends Constan
* @param t integration end point.
*/
@Deprecated
- public static double studentT(double k, double t) throws ArithmeticException {
+ public static double studentT(double k, double t) {
if (k <= 0) {
throw new IllegalArgumentException();
}
if (t == 0) {
- return (0.5);
+ return 0.5;
}
double cdf = 0.5 * Gamma.incompleteBeta(0.5 * k, 0.5, k / (k + t * t));