diff --git a/checkstyle.xml b/checkstyle.xml
index 31ad5789e..718e105ec 100644
--- a/checkstyle.xml
+++ b/checkstyle.xml
@@ -1,8 +1,6 @@
-
+
* Preconditions:
Returns a Univariate describing this distribution
* Preconditions:lower
and upper
, inclusive.
+ * @param lower the lower bound.
+ * @param upper the upper bound.
+ * @return the random integer.
+ */
public int nextInt(int lower, int upper) {
if (lower >= upper) {
throw new IllegalArgumentException
@@ -172,6 +181,13 @@ public class RandomDataImpl implements RandomData {
return lower + (int) (rand.nextDouble() * (upper - lower + 1));
}
+ /**
+ * Generate a random long value uniformly distributed between
+ * lower
and upper
, inclusive.
+ * @param lower the lower bound.
+ * @param upper the upper bound.
+ * @return the random integer.
+ */
public long nextLong(long lower, long upper) {
if (lower >= upper) {
throw new IllegalArgumentException
@@ -194,6 +210,8 @@ public class RandomDataImpl implements RandomData {
*
* TODO: find external reference or provide justification for the claim
* that this yields a cryptographically secure sequence of hex strings.
+ * @param len the desired string length.
+ * @return the random string.
*/
public String nextSecureHexString(int len) {
if (len <= 0) {
@@ -243,6 +261,14 @@ public class RandomDataImpl implements RandomData {
return outBuffer.toString().substring(0, len);
}
+ /**
+ * Generate a random int value uniformly distributed between
+ * lower
and upper
, inclusive. This algorithm
+ * using a secure random number generator for its engine.
+ * @param lower the lower bound.
+ * @param upper the upper bound.
+ * @return the random integer.
+ */
public int nextSecureInt(int lower, int upper) {
if (lower >= upper) {
throw new IllegalArgumentException
@@ -252,6 +278,14 @@ public class RandomDataImpl implements RandomData {
return lower + (int) (sec.nextDouble() * (upper - lower + 1));
}
+ /**
+ * Generate a random long value uniformly distributed between
+ * lower
and upper
, inclusive. This algorithm
+ * using a secure random number generator for its engine.
+ * @param lower the lower bound.
+ * @param upper the upper bound.
+ * @return the random integer.
+ */
public long nextSecureLong(long lower, long upper) {
if (lower >= upper) {
throw new IllegalArgumentException
@@ -267,16 +301,17 @@ public class RandomDataImpl implements RandomData {
* described
*
* here
- *
+ * @param mean mean of the Poisson distribution.
+ * @return the random Poisson value.
*/
public long nextPoisson(double mean) {
+ if (mean <= 0) {
+ throw new IllegalArgumentException("Poisson mean must be > 0");
+ }
double p = Math.exp(-mean);
long n = 0;
double r = 1.0d;
Random rand = getRan();
- if (mean <= 0) {
- throw new IllegalArgumentException("Poisson mean must be > 0");
- }
while (true) {
double rnd = rand.nextDouble();
r = r * rnd;
@@ -288,6 +323,15 @@ public class RandomDataImpl implements RandomData {
}
}
+ /**
+ * Generate a random value from a Normal distribution. This algorithm
+ * generates random values for the general Normal distribution with the
+ * given mean, mu
and the given standard deviation,
+ * sigma
.
+ * @param mu the mean of the distribution.
+ * @param sigma the standard deviation of the distribution.
+ * @return the random Normal value.
+ */
public double nextGaussian(double mu, double sigma) {
if (sigma <= 0) {
throw new IllegalArgumentException("Gaussian std dev must be > 0");
@@ -300,6 +344,8 @@ public class RandomDataImpl implements RandomData {
* Algorithm Description: Uses the
*
* Inversion Method to generate exponential from uniform deviates.
+ * @param mean the mean of the distribution.
+ * @return the random Exponential value.
*/
public double nextExponential(double mean) {
if (mean < 0.0) {
@@ -320,6 +366,9 @@ public class RandomDataImpl implements RandomData {
* random double if Random.nextDouble() returns 0).
* This is necessary to provide a symmetric output interval
* (both endpoints excluded).
+ * @param lower the lower bound.
+ * @param upper the upper bound.
+ * @return the random value.
*/
public double nextUniform(double lower, double upper) {
if (lower >= upper) {
@@ -327,11 +376,14 @@ public class RandomDataImpl implements RandomData {
("lower bound must be <= upper bound");
}
Random rand = getRan();
- double result = lower + rand.nextDouble() * (upper - lower);
- while (result == lower) {
- result = lower + rand.nextDouble() * (upper - lower);
+
+ // insure nextDouble() isn't 0.0
+ double u = rand.nextDouble();
+ while(u <= 0.0){
+ u = rand.nextDouble();
}
- return result;
+
+ return lower + u * (upper - lower);
}
/**
@@ -442,7 +494,9 @@ public class RandomDataImpl implements RandomData {
* Uses a 2-cycle permutation shuffle, as described
*
* here
- *
+ * @param n the population size.
+ * @param k the number to choose.
+ * @return the random permutation.
*/
public int[] nextPermutation(int n, int k) {
if (k > n) {
@@ -472,6 +526,9 @@ public class RandomDataImpl implements RandomData {
* This technique is described, and proven to generate random samples,
*
* here
+ * @param c Collection to sample from.
+ * @param k sample size.
+ * @return the random sample.
*/
public Object[] nextSample(Collection c, int k) {
int len = c.size();
diff --git a/src/java/org/apache/commons/math/stat/BeanListUnivariateImpl.java b/src/java/org/apache/commons/math/stat/BeanListUnivariateImpl.java
index 12dc50fea..916258638 100644
--- a/src/java/org/apache/commons/math/stat/BeanListUnivariateImpl.java
+++ b/src/java/org/apache/commons/math/stat/BeanListUnivariateImpl.java
@@ -62,7 +62,7 @@ import org.apache.commons.math.util.BeanTransformer;
* univariate statistics for a List of Java Beans by property. This
* implementation uses beanutils' PropertyUtils to get a simple, nested,
* indexed, mapped, or combined property from an element of a List.
- * @version $Revision: 1.4 $ $Date: 2003/08/09 04:03:41 $
+ * @version $Revision: 1.5 $ $Date: 2003/09/07 03:12:56 $
*/
public class BeanListUnivariateImpl extends ListUnivariateImpl {
@@ -113,11 +113,11 @@ public class BeanListUnivariateImpl extends ListUnivariateImpl {
*/
public void addValue(double v) {
String msg =
- "The BeanListUnivariateImpl does not accept values "
- + "through the addValue method. Because elements of this list "
- + "are JavaBeans, one must be sure to set the 'propertyName' "
- + "property and add new Beans to the underlying list via the "
- + "addBean(Object bean) method";
+ "The BeanListUnivariateImpl does not accept values " +
+ "through the addValue method. Because elements of this list " +
+ "are JavaBeans, one must be sure to set the 'propertyName' " +
+ "property and add new Beans to the underlying list via the " +
+ "addBean(Object bean) method";
throw new UnsupportedOperationException(msg);
}
diff --git a/src/java/org/apache/commons/math/stat/ListUnivariateImpl.java b/src/java/org/apache/commons/math/stat/ListUnivariateImpl.java
index 631c30f74..4870f258f 100644
--- a/src/java/org/apache/commons/math/stat/ListUnivariateImpl.java
+++ b/src/java/org/apache/commons/math/stat/ListUnivariateImpl.java
@@ -60,7 +60,7 @@ import org.apache.commons.math.util.DefaultTransformer;
import org.apache.commons.math.util.NumberTransformer;
/**
- * @version $Revision: 1.4 $ $Date: 2003/07/15 03:45:10 $
+ * @version $Revision: 1.5 $ $Date: 2003/09/07 03:12:56 $
*/
public class ListUnivariateImpl
extends AbstractStoreUnivariate
@@ -88,6 +88,7 @@ public class ListUnivariateImpl
/**
* Construct a ListUnivariate with a specific List.
* @param list The list that will back this Univariate
+ * @param transformer the number transformer used to convert the list items.
*/
public ListUnivariateImpl(List list, NumberTransformer transformer) {
super();
@@ -107,8 +108,9 @@ public class ListUnivariateImpl
// take into account only the last n elements of the list
// as definied by windowSize
- if (windowSize != Univariate.INFINITE_WINDOW
- && windowSize < list.size()) {
+ if (windowSize != Univariate.INFINITE_WINDOW &&
+ windowSize < list.size())
+ {
length = list.size() - Math.max(0, list.size() - windowSize);
}
@@ -130,8 +132,9 @@ public class ListUnivariateImpl
int calcIndex = index;
- if (windowSize != Univariate.INFINITE_WINDOW
- && windowSize < list.size()) {
+ if (windowSize != Univariate.INFINITE_WINDOW &&
+ windowSize < list.size())
+ {
calcIndex = (list.size() - windowSize) + index;
}
@@ -198,14 +201,16 @@ public class ListUnivariateImpl
}
/**
- * @return
+ * Access the number transformer.
+ * @return the number transformer.
*/
public NumberTransformer getTransformer() {
return transformer;
}
/**
- * @param transformer
+ * Modify the number transformer.
+ * @param transformer the new number transformer.
*/
public void setTransformer(NumberTransformer transformer) {
this.transformer = transformer;
diff --git a/src/java/org/apache/commons/math/stat/StatUtils.java b/src/java/org/apache/commons/math/stat/StatUtils.java
index 2f322740a..80bfce45d 100644
--- a/src/java/org/apache/commons/math/stat/StatUtils.java
+++ b/src/java/org/apache/commons/math/stat/StatUtils.java
@@ -57,7 +57,7 @@ package org.apache.commons.math.stat;
* StatUtils provides easy static implementations of common double[] based
* statistical methods. These return a single result value or in some cases, as
* identified in the javadoc for each method, Double.NaN.
- * @version $Revision: 1.15 $ $Date: 2003/08/09 04:03:41 $
+ * @version $Revision: 1.16 $ $Date: 2003/09/07 03:12:56 $
*/
public final class StatUtils {
@@ -255,8 +255,8 @@ public final class StatUtils {
accum2 += (values[i] - mean);
}
variance =
- (accum - (Math.pow(accum2, 2) / ((double) length)))
- / (double) (length - 1);
+ (accum - (Math.pow(accum2, 2) / ((double) length))) /
+ (double) (length - 1);
}
return variance;
}
diff --git a/src/java/org/apache/commons/math/stat/StoreUnivariateImpl.java b/src/java/org/apache/commons/math/stat/StoreUnivariateImpl.java
index 173a0c6b2..8c0439371 100644
--- a/src/java/org/apache/commons/math/stat/StoreUnivariateImpl.java
+++ b/src/java/org/apache/commons/math/stat/StoreUnivariateImpl.java
@@ -57,7 +57,7 @@ import org.apache.commons.math.stat.univariate.UnivariateStatistic;
import org.apache.commons.math.util.ContractableDoubleArray;
/**
- * @version $Revision: 1.5 $ $Date: 2003/07/15 03:45:10 $
+ * @version $Revision: 1.6 $ $Date: 2003/09/07 03:12:56 $
*/
public class StoreUnivariateImpl extends AbstractStoreUnivariate {
@@ -113,8 +113,8 @@ public class StoreUnivariateImpl extends AbstractStoreUnivariate {
eDA.addElement(v);
} else {
String msg =
- "A window Univariate had more element than "
- + "the windowSize. This is an inconsistent state.";
+ "A window Univariate had more element than " +
+ "the windowSize. This is an inconsistent state.";
throw new RuntimeException(msg);
}
} else {
diff --git a/src/java/org/apache/commons/math/stat/univariate/moment/FourthMoment.java b/src/java/org/apache/commons/math/stat/univariate/moment/FourthMoment.java
index 3536d3cc4..687301352 100644
--- a/src/java/org/apache/commons/math/stat/univariate/moment/FourthMoment.java
+++ b/src/java/org/apache/commons/math/stat/univariate/moment/FourthMoment.java
@@ -58,7 +58,7 @@ package org.apache.commons.math.stat.univariate.moment;
*
* recursive strategy
* . Both incremental and evaluation strategies currently use this approach.
- * @version $Revision: 1.7 $ $Date: 2003/08/09 04:03:40 $
+ * @version $Revision: 1.8 $ $Date: 2003/09/07 03:12:56 $
*/
public class FourthMoment extends ThirdMoment {
@@ -91,11 +91,8 @@ public class FourthMoment extends ThirdMoment {
n3 = (double) (n - 3);
- m4 =
- m4
- - (4.0 * v * prevM3)
- + (6.0 * v2 * prevM2)
- + ((n0 * n0) - 3 * n1) * (v2 * v2 * n1 * n0);
+ m4 = m4 - (4.0 * v * prevM3) + (6.0 * v2 * prevM2) +
+ ((n0 * n0) - 3 * n1) * (v2 * v2 * n1 * n0);
}
/**
diff --git a/src/java/org/apache/commons/math/stat/univariate/moment/Kurtosis.java b/src/java/org/apache/commons/math/stat/univariate/moment/Kurtosis.java
index afc5469b3..7bacd72ea 100644
--- a/src/java/org/apache/commons/math/stat/univariate/moment/Kurtosis.java
+++ b/src/java/org/apache/commons/math/stat/univariate/moment/Kurtosis.java
@@ -62,7 +62,7 @@ import org
.AbstractStorelessUnivariateStatistic;
/**
- * @version $Revision: 1.7 $ $Date: 2003/08/09 04:03:40 $
+ * @version $Revision: 1.8 $ $Date: 2003/09/07 03:12:56 $
*/
public class Kurtosis extends AbstractStorelessUnivariateStatistic {
@@ -119,13 +119,9 @@ public class Kurtosis extends AbstractStorelessUnivariateStatistic {
kurtosis = 0.0;
} else {
kurtosis =
- (moment.n0 * (moment.n0 + 1) * moment.m4
- - 3 * moment.m2 * moment.m2 * moment.n1)
- / (moment.n1
- * moment.n2
- * moment.n3
- * variance
- * variance);
+ (moment.n0 * (moment.n0 + 1) * moment.m4 -
+ 3 * moment.m2 * moment.m2 * moment.n1) /
+ (moment.n1 * moment.n2 * moment.n3 * variance * variance);
}
n = moment.n;
}
@@ -193,8 +189,8 @@ public class Kurtosis extends AbstractStorelessUnivariateStatistic {
double stdDev =
Math.sqrt(
- (accum - (Math.pow(accum2, 2) / ((double) length)))
- / (double) (length - 1));
+ (accum - (Math.pow(accum2, 2) / ((double) length))) /
+ (double) (length - 1));
// Sum the ^4 of the distance from the mean divided by the
// standard deviation
diff --git a/src/java/org/apache/commons/math/stat/univariate/moment/Skewness.java b/src/java/org/apache/commons/math/stat/univariate/moment/Skewness.java
index 1e9a9e903..6db815d8f 100644
--- a/src/java/org/apache/commons/math/stat/univariate/moment/Skewness.java
+++ b/src/java/org/apache/commons/math/stat/univariate/moment/Skewness.java
@@ -63,7 +63,7 @@ import org
/**
*
- * @version $Revision: 1.7 $ $Date: 2003/08/09 04:03:40 $
+ * @version $Revision: 1.8 $ $Date: 2003/09/07 03:12:56 $
*/
public class Skewness extends AbstractStorelessUnivariateStatistic {
@@ -119,12 +119,8 @@ public class Skewness extends AbstractStorelessUnivariateStatistic {
if (moment.n <= 2 || variance < 10E-20) {
skewness = 0.0;
} else {
- skewness =
- (moment.n0 * moment.m3)
- / (moment.n1
- * moment.n2
- * Math.sqrt(variance)
- * variance);
+ skewness = (moment.n0 * moment.m3) /
+ (moment.n1 * moment.n2 * Math.sqrt(variance) * variance);
}
n = moment.n;
}
@@ -191,8 +187,8 @@ public class Skewness extends AbstractStorelessUnivariateStatistic {
}
double stdDev =
Math.sqrt(
- (accum - (Math.pow(accum2, 2) / ((double) length)))
- / (double) (length - 1));
+ (accum - (Math.pow(accum2, 2) / ((double) length))) /
+ (double) (length - 1));
// Calculate the skew as the sum the cubes of the distance
// from the mean divided by the standard deviation.
diff --git a/src/java/org/apache/commons/math/stat/univariate/moment/Variance.java b/src/java/org/apache/commons/math/stat/univariate/moment/Variance.java
index d661eecaf..50bd88654 100644
--- a/src/java/org/apache/commons/math/stat/univariate/moment/Variance.java
+++ b/src/java/org/apache/commons/math/stat/univariate/moment/Variance.java
@@ -57,7 +57,7 @@ import org.apache.commons.math.stat.univariate.AbstractStorelessUnivariateStatis
/**
*
- * @version $Revision: 1.8 $ $Date: 2003/08/09 04:03:40 $
+ * @version $Revision: 1.9 $ $Date: 2003/09/07 03:12:56 $
*/
public class Variance extends AbstractStorelessUnivariateStatistic {
@@ -177,9 +177,8 @@ public class Variance extends AbstractStorelessUnivariateStatistic {
accum += Math.pow((values[i] - m), 2.0);
accum2 += (values[i] - m);
}
- var =
- (accum - (Math.pow(accum2, 2) / ((double) length)))
- / (double) (length - 1);
+ var = (accum - (Math.pow(accum2, 2) / ((double) length))) /
+ (double) (length - 1);
}
}
return var;
diff --git a/src/java/org/apache/commons/math/util/ContinuedFraction.java b/src/java/org/apache/commons/math/util/ContinuedFraction.java
index e1a2d69a6..bb8201c88 100644
--- a/src/java/org/apache/commons/math/util/ContinuedFraction.java
+++ b/src/java/org/apache/commons/math/util/ContinuedFraction.java
@@ -64,7 +64,7 @@ import org.apache.commons.math.analysis.ConvergenceException;
*