You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by md...@apache.org on 2003/09/07 05:12:57 UTC
cvs commit: jakarta-commons-sandbox/math checkstyle.xml
mdiggory 2003/09/06 20:12:57
Modified: math/src/java/org/apache/commons/math/stat/univariate/moment
FourthMoment.java Kurtosis.java Variance.java
Skewness.java
math/src/java/org/apache/commons/math/util
ContractableDoubleArray.java
ExpandableDoubleArray.java FixedDoubleArray.java
ContinuedFraction.java
math/src/java/org/apache/commons/math/stat
BeanListUnivariateImpl.java ListUnivariateImpl.java
StatUtils.java StoreUnivariateImpl.java
math/src/java/org/apache/commons/math/analysis
RootFinding.java SplineInterpolator.java
UnivariateRealSolverUtil.java
UnivariateRealSolverFactory.java
math/src/test/org/apache/commons/math/analysis
InterpolatorTest.java
math/src/java/org/apache/commons/math/random
EmpiricalDistribution.java
EmpiricalDistributionImpl.java RandomDataImpl.java
math checkstyle.xml
Log:
PR: http://nagoya.apache.org/bugzilla/show_bug.cgi?id=22954
Submitted by: Brent Worden
Reviewed by: Mark Diggory
Revision Changes Path
1.8 +3 -6 jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/moment/FourthMoment.java
Index: FourthMoment.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/moment/FourthMoment.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- FourthMoment.java 9 Aug 2003 04:03:40 -0000 1.7
+++ FourthMoment.java 7 Sep 2003 03:12:56 -0000 1.8
@@ -91,11 +91,8 @@
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);
}
/**
1.8 +6 -10 jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/moment/Kurtosis.java
Index: Kurtosis.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/moment/Kurtosis.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- Kurtosis.java 9 Aug 2003 04:03:40 -0000 1.7
+++ Kurtosis.java 7 Sep 2003 03:12:56 -0000 1.8
@@ -119,13 +119,9 @@
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 @@
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
1.9 +3 -4 jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/moment/Variance.java
Index: Variance.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/moment/Variance.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- Variance.java 9 Aug 2003 04:03:40 -0000 1.8
+++ Variance.java 7 Sep 2003 03:12:56 -0000 1.9
@@ -177,9 +177,8 @@
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;
1.8 +5 -9 jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/moment/Skewness.java
Index: Skewness.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/moment/Skewness.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- Skewness.java 9 Aug 2003 04:03:40 -0000 1.7
+++ Skewness.java 7 Sep 2003 03:12:56 -0000 1.8
@@ -119,12 +119,8 @@
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 @@
}
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.
1.4 +12 -12 jakarta-commons-sandbox/math/src/java/org/apache/commons/math/util/ContractableDoubleArray.java
Index: ContractableDoubleArray.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/util/ContractableDoubleArray.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ContractableDoubleArray.java 9 Jul 2003 20:04:12 -0000 1.3
+++ ContractableDoubleArray.java 7 Sep 2003 03:12:56 -0000 1.4
@@ -292,27 +292,27 @@
if (contractionCritera < expansionFactor) {
String msg =
- "Contraction criteria can never be smaller than "
- + "the expansion factor. This would lead to a never "
- + "ending loop of expansion and contraction as a newly "
- + "expanded internal storage array would immediately "
- + "satisfy the criteria for contraction";
+ "Contraction criteria can never be smaller than " +
+ "the expansion factor. This would lead to a never " +
+ "ending loop of expansion and contraction as a newly " +
+ "expanded internal storage array would immediately " +
+ "satisfy the criteria for contraction";
throw new IllegalArgumentException(msg);
}
if (contractionCriteria <= 1.0) {
String msg =
- "The contraction criteria must be a number larger "
- + "than one. If the contractionCriteria is less than or "
- + "equal to one an endless loop of contraction and "
- + "expansion would ensue as an internalArray.length "
- + "== numElements would satisfy the contraction criteria";
+ "The contraction criteria must be a number larger " +
+ "than one. If the contractionCriteria is less than or " +
+ "equal to one an endless loop of contraction and " +
+ "expansion would ensue as an internalArray.length " +
+ "== numElements would satisfy the contraction criteria";
throw new IllegalArgumentException(msg);
}
if (expansionFactor < 1.0) {
String msg =
- "The expansion factor must be a number greater " + "than 1.0";
+ "The expansion factor must be a number greater than 1.0";
throw new IllegalArgumentException(msg);
}
}
1.5 +8 -11 jakarta-commons-sandbox/math/src/java/org/apache/commons/math/util/ExpandableDoubleArray.java
Index: ExpandableDoubleArray.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/util/ExpandableDoubleArray.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ExpandableDoubleArray.java 9 Jul 2003 20:04:12 -0000 1.4
+++ ExpandableDoubleArray.java 7 Sep 2003 03:12:56 -0000 1.5
@@ -199,9 +199,8 @@
this.initialCapacity = initialCapacity;
} else {
String msg =
- "The initial capacity supplied: "
- + initialCapacity
- + "must be a positive integer";
+ "The initial capacity supplied: " + initialCapacity +
+ "must be a positive integer";
throw new IllegalArgumentException(msg);
}
}
@@ -270,15 +269,14 @@
double value = Double.NaN;
if (index >= numElements) {
String msg =
- "The index specified: "
- + index
- + " is larger than the current number of elements";
+ "The index specified: " + index +
+ " is larger than the current number of elements";
throw new ArrayIndexOutOfBoundsException(msg);
} else if (index >= 0) {
value = internalArray[startIndex + index];
} else {
String msg =
- "Elements cannot be retrieved from a negative " + "array index";
+ "Elements cannot be retrieved from a negative array index";
throw new ArrayIndexOutOfBoundsException(msg);
}
return value;
@@ -403,9 +401,8 @@
public synchronized void discardFrontElements(int i) {
if (i > numElements) {
- String msg =
- "Cannot discard more elements than are"
- + "contained in this array.";
+ String msg = "Cannot discard more elements than are" +
+ "contained in this array.";
throw new IllegalArgumentException(msg);
} else if (i < 0) {
String msg = "Cannot discard a negative number of elements.";
1.6 +6 -6 jakarta-commons-sandbox/math/src/java/org/apache/commons/math/util/FixedDoubleArray.java
Index: FixedDoubleArray.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/util/FixedDoubleArray.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- FixedDoubleArray.java 9 Jul 2003 20:04:12 -0000 1.5
+++ FixedDoubleArray.java 7 Sep 2003 03:12:56 -0000 1.6
@@ -164,8 +164,8 @@
public double getElement(int index) {
if (index > (size - 1)) {
String msg =
- "Attempted to retrieve an element outside of "
- + "the element array";
+ "Attempted to retrieve an element outside of " +
+ "the element array";
throw new ArrayIndexOutOfBoundsException(msg);
} else {
// Return the element requested, if the index supplied
@@ -235,9 +235,9 @@
// is trying to add an element beyond the boundaries of the
// fixed array.
String msg =
- "Attempted to add a value to an array of fixed "
- + "size, please use addElementRolling "
- + "to avoid this exception";
+ "Attempted to add a value to an array of fixed " +
+ "size, please use addElementRolling " +
+ "to avoid this exception";
throw new ArrayIndexOutOfBoundsException(msg);
}
}
1.4 +4 -3 jakarta-commons-sandbox/math/src/java/org/apache/commons/math/util/ContinuedFraction.java
Index: ContinuedFraction.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/util/ContinuedFraction.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ContinuedFraction.java 9 Jul 2003 20:04:12 -0000 1.3
+++ ContinuedFraction.java 7 Sep 2003 03:12:56 -0000 1.4
@@ -189,8 +189,9 @@
f[1][1] = (a[1][0] * an[0][1]) + (a[1][1] * an[1][1]);
// determine if we're close enough
- if (Math.abs((f[0][0] * f[1][1]) - (f[1][0] * f[0][1]))
- < Math.abs(epsilon * f[1][0] * f[1][1])) {
+ if (Math.abs((f[0][0] * f[1][1]) - (f[1][0] * f[0][1])) <
+ Math.abs(epsilon * f[1][0] * f[1][1]))
+ {
ret = f[0][0] / f[1][0];
} else {
if (n >= maxIterations) {
1.5 +6 -6 jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/BeanListUnivariateImpl.java
Index: BeanListUnivariateImpl.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/BeanListUnivariateImpl.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- BeanListUnivariateImpl.java 9 Aug 2003 04:03:41 -0000 1.4
+++ BeanListUnivariateImpl.java 7 Sep 2003 03:12:56 -0000 1.5
@@ -113,11 +113,11 @@
*/
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);
}
1.5 +12 -7 jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/ListUnivariateImpl.java
Index: ListUnivariateImpl.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/ListUnivariateImpl.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ListUnivariateImpl.java 15 Jul 2003 03:45:10 -0000 1.4
+++ ListUnivariateImpl.java 7 Sep 2003 03:12:56 -0000 1.5
@@ -88,6 +88,7 @@
/**
* 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 @@
// 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 @@
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 @@
}
/**
- * @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;
1.16 +3 -3 jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/StatUtils.java
Index: StatUtils.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/StatUtils.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- StatUtils.java 9 Aug 2003 04:03:41 -0000 1.15
+++ StatUtils.java 7 Sep 2003 03:12:56 -0000 1.16
@@ -255,8 +255,8 @@
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;
}
1.6 +3 -3 jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/StoreUnivariateImpl.java
Index: StoreUnivariateImpl.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/StoreUnivariateImpl.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- StoreUnivariateImpl.java 15 Jul 2003 03:45:10 -0000 1.5
+++ StoreUnivariateImpl.java 7 Sep 2003 03:12:56 -0000 1.6
@@ -113,8 +113,8 @@
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 {
1.4 +1 -4 jakarta-commons-sandbox/math/src/java/org/apache/commons/math/analysis/RootFinding.java
Index: RootFinding.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/analysis/RootFinding.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- RootFinding.java 9 Jul 2003 20:02:43 -0000 1.3
+++ RootFinding.java 7 Sep 2003 03:12:56 -0000 1.4
@@ -61,9 +61,6 @@
* @version $Revision$ $Date$
*/
public class RootFinding {
- /** Maximum allowed numerical error. */
- private static final double EPSILON = 10e-9;
-
/**
* Default constructor. Prohibit construction.
*/
1.4 +2 -3 jakarta-commons-sandbox/math/src/java/org/apache/commons/math/analysis/SplineInterpolator.java
Index: SplineInterpolator.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/analysis/SplineInterpolator.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- SplineInterpolator.java 30 Jul 2003 21:58:10 -0000 1.3
+++ SplineInterpolator.java 7 Sep 2003 03:12:56 -0000 1.4
@@ -60,6 +60,7 @@
*
*/
public class SplineInterpolator implements UnivariateRealInterpolator {
+ /** the natural spline coefficients. */
private double[][] c = null;
/**
@@ -67,8 +68,6 @@
* @param xval the arguments for the interpolation points
* @param yval the values for the interpolation points
* @return a function which interpolates the data set
- * @throws MathException if arguments violate assumptions made by the
- * interpolationg algorithm
*/
public UnivariateRealFunction interpolate(double[] xval, double[] yval) {
if (xval.length != yval.length) {
1.2 +2 -2 jakarta-commons-sandbox/math/src/java/org/apache/commons/math/analysis/UnivariateRealSolverUtil.java
Index: UnivariateRealSolverUtil.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/analysis/UnivariateRealSolverUtil.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- UnivariateRealSolverUtil.java 30 Jul 2003 22:06:37 -0000 1.1
+++ UnivariateRealSolverUtil.java 7 Sep 2003 03:12:56 -0000 1.2
@@ -56,8 +56,8 @@
import org.apache.commons.math.MathException;
/**
+ * Utility routines for {@link UnivariateRealSolver} objects.
* @version $Revision$ $Date$
- * @todo add comment
*/
public class UnivariateRealSolverUtil {
/**
1.5 +2 -2 jakarta-commons-sandbox/math/src/java/org/apache/commons/math/analysis/UnivariateRealSolverFactory.java
Index: UnivariateRealSolverFactory.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/analysis/UnivariateRealSolverFactory.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- UnivariateRealSolverFactory.java 30 Jul 2003 21:58:10 -0000 1.4
+++ UnivariateRealSolverFactory.java 7 Sep 2003 03:12:56 -0000 1.5
@@ -71,8 +71,8 @@
}
/**
+ * Create a new factory.
* @return a new factory.
- * @todo add comment
* @todo for now, return the only concrete factory. Later, allow for a
* plugable implementation, possibly using SPI and commons-discovery.
*/
1.2 +2 -2 jakarta-commons-sandbox/math/src/test/org/apache/commons/math/analysis/InterpolatorTest.java
Index: InterpolatorTest.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/math/src/test/org/apache/commons/math/analysis/InterpolatorTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- InterpolatorTest.java 25 Jun 2003 01:28:59 -0000 1.1
+++ InterpolatorTest.java 7 Sep 2003 03:12:56 -0000 1.2
@@ -344,7 +344,7 @@
try {
double xval[] = { 0.0, 1.0 };
double yval[] = { 0.0, 1.0, 2.0 };
- UnivariateRealFunction f = i.interpolate(xval, yval);
+ i.interpolate(xval, yval);
fail("Failed to detect data set array with different sizes.");
} catch (IllegalArgumentException iae) {
}
@@ -352,7 +352,7 @@
try {
double xval[] = { 0.0, 1.0, 0.5 };
double yval[] = { 0.0, 1.0, 2.0 };
- UnivariateRealFunction f = i.interpolate(xval, yval);
+ i.interpolate(xval, yval);
fail("Failed to detect unsorted arguments.");
} catch (IllegalArgumentException iae) {
}
1.4 +4 -2 jakarta-commons-sandbox/math/src/java/org/apache/commons/math/random/EmpiricalDistribution.java
Index: EmpiricalDistribution.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/random/EmpiricalDistribution.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- EmpiricalDistribution.java 9 Jul 2003 20:02:59 -0000 1.3
+++ EmpiricalDistribution.java 7 Sep 2003 03:12:56 -0000 1.4
@@ -102,6 +102,7 @@
* Generates a random value from this distribution<p>
* <strong>Preconditions:</strong><ul>
* <li>the distribution must be loaded before invoking this method</li></ul>
+ * @return the random value.
* @throws IllegalStateException if the distribution has not been loaded
*/
double getNextValue() throws IllegalStateException;
@@ -111,9 +112,10 @@
* <p>Returns a Univariate describing this distribution</p>
* <strong>Preconditions:</strong><ul>
* <li>the distribution must be loaded before invoking this method</li></ul>
+ * @return the sample statistics
* @throws IllegalStateException if the distribution has not been loaded
*/
- Univariate getSampleStats();
+ Univariate getSampleStats() throws IllegalStateException;
/**
* Loads a saved distribution from a file.
1.4 +6 -2 jakarta-commons-sandbox/math/src/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java
Index: EmpiricalDistributionImpl.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- EmpiricalDistributionImpl.java 9 Jul 2003 20:02:59 -0000 1.3
+++ EmpiricalDistributionImpl.java 7 Sep 2003 03:12:56 -0000 1.4
@@ -217,7 +217,11 @@
loaded = true;
}
- /** Generates a random value from this distribution */
+ /**
+ * Generates a random value from this distribution
+ * @return the random value.
+ * @throws IllegalStateException if the distribution has not been loaded
+ */
public double getNextValue() throws IllegalStateException {
if (!loaded) {
1.3 +68 -11 jakarta-commons-sandbox/math/src/java/org/apache/commons/math/random/RandomDataImpl.java
Index: RandomDataImpl.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/random/RandomDataImpl.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- RandomDataImpl.java 7 Jul 2003 23:19:21 -0000 1.2
+++ RandomDataImpl.java 7 Sep 2003 03:12:56 -0000 1.3
@@ -127,6 +127,8 @@
* len/2+1 binary bytes are generated using the underlying Random</li>
* <li>
* Each binary byte is translated into 2 hex digits</li></ol>
+ * @param len the desired string length.
+ * @return the random string.
*/
public String nextHexString(int len) {
if (len <= 0) {
@@ -162,7 +164,14 @@
}
return outBuffer.toString().substring(0, len);
}
-
+
+ /**
+ * Generate a random int value uniformly distributed between
+ * <code>lower</code> and <code>upper</code>, 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 @@
return lower + (int) (rand.nextDouble() * (upper - lower + 1));
}
+ /**
+ * Generate a random long value uniformly distributed between
+ * <code>lower</code> and <code>upper</code>, 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 @@
* <p>
* 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 @@
return outBuffer.toString().substring(0, len);
}
+ /**
+ * Generate a random int value uniformly distributed between
+ * <code>lower</code> and <code>upper</code>, 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 @@
return lower + (int) (sec.nextDouble() * (upper - lower + 1));
}
+ /**
+ * Generate a random long value uniformly distributed between
+ * <code>lower</code> and <code>upper</code>, 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 @@
* described
* <a href ="http://dmawww.epfl.ch/benarous/Pmmi/interactive/rng7.htm">
* here</a>
- *
+ * @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 @@
}
}
+ /**
+ * Generate a random value from a Normal distribution. This algorithm
+ * generates random values for the general Normal distribution with the
+ * given mean, <code>mu</code> and the given standard deviation,
+ * <code>sigma</code>.
+ * @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 @@
* <strong>Algorithm Description</strong>: Uses the
* <a href="http://www.jesus.ox.ac.uk/~clifford/a5/chap1/node5.html">
* Inversion Method</a> 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 @@
* 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 @@
("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 @@
* Uses a 2-cycle permutation shuffle, as described
* <a href=http://www.maths.abdn.ac.uk/~igc/tch/mx4002/notes/node83.html>
* here</a>
- *
+ * @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 @@
* This technique is described, and proven to generate random samples,
* <a href="http://www.maths.abdn.ac.uk/~igc/tch/mx4002/notes/node83.html">
* here</a>
+ * @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();
1.2 +11 -3 jakarta-commons-sandbox/math/checkstyle.xml
Index: checkstyle.xml
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/math/checkstyle.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- checkstyle.xml 7 Jul 2003 13:57:13 -0000 1.1
+++ checkstyle.xml 7 Sep 2003 03:12:56 -0000 1.2
@@ -1,8 +1,6 @@
<?xml version="1.0"?>
-<!DOCTYPE module PUBLIC
- "-//Puppy Crawl//DTD Check Configuration 1.1//EN"
- "http://www.puppycrawl.com/dtds/configuration_1_1.dtd">
+<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.1//EN" "http://www.puppycrawl.com/dtds/configuration_1_1.dtd">
<!-- commons math customization of default Checkstyle behavior -->
<module name="Checker">
@@ -18,6 +16,16 @@
<module name="OperatorWrap">
<property name="option" value="eol"/>
</module>
+
+ <module name="JavadocType">
+ <property name="versionFormat" value="\$Revision.*\$ \$Date.*\$"/>
+ </module>
+
+ <module name="JavadocMethod">
+ <property name="allowUndeclaredRTE" value="true"/>
+ </module>
+
+ <module name="JavadocVariable"/>
</module>
</module>