You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by br...@apache.org on 2004/04/27 18:42:35 UTC
cvs commit: jakarta-commons/math/src/java/org/apache/commons/math/stat/multivariate BivariateRegression.java
brentworden 2004/04/27 09:42:35
Modified: math/src/java/org/apache/commons/math/stat/univariate/moment
GeometricMean.java FirstMoment.java
SecondMoment.java Skewness.java ThirdMoment.java
Kurtosis.java StandardDeviation.java
FourthMoment.java Mean.java Variance.java
math/src/test/org/apache/commons/math/stat
StatUtilsTest.java
math/src/java/org/apache/commons/math/stat/univariate/summary
SumOfSquares.java Sum.java SumOfLogs.java
Product.java
math/src/test/org/apache/commons/math/stat/univariate
StorelessUnivariateStatisticAbstractTest.java
DescriptiveStatisticsTest.java
math/src/java/org/apache/commons/math/analysis
BisectionSolver.java UnivariateRealSolverImpl.java
math/src/java/org/apache/commons/math/stat/univariate/rank
Min.java Median.java Max.java Percentile.java
math/src/java/org/apache/commons/math/stat/univariate
AbstractUnivariateStatistic.java
math/src/java/org/apache/commons/math/util
ContractableDoubleArray.java FixedDoubleArray.java
ExpandableDoubleArray.java
math/src/java/org/apache/commons/math/stat/inference
TestStatisticImpl.java
math/src/java/org/apache/commons/math/distribution
NormalDistributionImpl.java
math/src/java/org/apache/commons/math/stat/multivariate
BivariateRegression.java
Added: math/src/test/org/apache/commons/math/analysis
UnivariateRealSolverFactoryImplTest.java
math/src/test/org/apache/commons/math/stat/univariate/moment
FirstMomentTest.java
Log:
Fixed some checkstyle warnings. Added some unit tests.
Revision Changes Path
1.18 +2 -1 jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/moment/GeometricMean.java
Index: GeometricMean.java
===================================================================
RCS file: /home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/moment/GeometricMean.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- GeometricMean.java 4 Mar 2004 04:25:09 -0000 1.17
+++ GeometricMean.java 27 Apr 2004 16:42:30 -0000 1.18
@@ -26,6 +26,7 @@
*/
public class GeometricMean extends SumOfLogs implements Serializable{
+ /** Serializable version identifier */
static final long serialVersionUID = -8178734905303459453L;
/** */
1.14 +2 -1 jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/moment/FirstMoment.java
Index: FirstMoment.java
===================================================================
RCS file: /home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/moment/FirstMoment.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- FirstMoment.java 21 Feb 2004 21:35:15 -0000 1.13
+++ FirstMoment.java 27 Apr 2004 16:42:30 -0000 1.14
@@ -30,6 +30,7 @@
*/
public class FirstMoment extends AbstractStorelessUnivariateStatistic implements Serializable{
+ /** Serializable version identifier */
static final long serialVersionUID = -803343206421984070L;
/** count of values that have been added */
1.15 +2 -1 jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/moment/SecondMoment.java
Index: SecondMoment.java
===================================================================
RCS file: /home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/moment/SecondMoment.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- SecondMoment.java 21 Feb 2004 21:35:15 -0000 1.14
+++ SecondMoment.java 27 Apr 2004 16:42:30 -0000 1.15
@@ -26,6 +26,7 @@
*/
public class SecondMoment extends FirstMoment implements Serializable {
+ /** Serializable version identifier */
static final long serialVersionUID = 3942403127395076445L;
/** second moment of values that have been added */
1.20 +4 -1 jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/moment/Skewness.java
Index: Skewness.java
===================================================================
RCS file: /home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/moment/Skewness.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- Skewness.java 21 Mar 2004 00:23:29 -0000 1.19
+++ Skewness.java 27 Apr 2004 16:42:30 -0000 1.20
@@ -32,6 +32,7 @@
*/
public class Skewness extends AbstractStorelessUnivariateStatistic implements Serializable {
+ /** Serializable version identifier */
static final long serialVersionUID = 7101857578996691352L;
/** */
@@ -75,6 +76,8 @@
* Returns the value of the statistic based on the values that have been added.
* <p>
* See {@link Skewness} for the definition used in the computation.
+ *
+ * @return the skewness of the available values.
*/
public double getResult() {
if (n < moment.n) {
1.15 +2 -1 jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/moment/ThirdMoment.java
Index: ThirdMoment.java
===================================================================
RCS file: /home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/moment/ThirdMoment.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- ThirdMoment.java 21 Feb 2004 21:35:15 -0000 1.14
+++ ThirdMoment.java 27 Apr 2004 16:42:30 -0000 1.15
@@ -26,6 +26,7 @@
*/
public class ThirdMoment extends SecondMoment implements Serializable {
+ /** Serializable version identifier */
static final long serialVersionUID = -7818711964045118679L;
/** third moment of values that have been added */
1.19 +2 -1 jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/moment/Kurtosis.java
Index: Kurtosis.java
===================================================================
RCS file: /home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/moment/Kurtosis.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- Kurtosis.java 21 Mar 2004 00:22:26 -0000 1.18
+++ Kurtosis.java 27 Apr 2004 16:42:30 -0000 1.19
@@ -32,6 +32,7 @@
*/
public class Kurtosis extends AbstractStorelessUnivariateStatistic implements Serializable {
+ /** Serializable version identifier */
static final long serialVersionUID = 2784465764798260919L;
/** */
1.16 +2 -1 jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/moment/StandardDeviation.java
Index: StandardDeviation.java
===================================================================
RCS file: /home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/moment/StandardDeviation.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- StandardDeviation.java 4 Mar 2004 04:25:09 -0000 1.15
+++ StandardDeviation.java 27 Apr 2004 16:42:30 -0000 1.16
@@ -23,6 +23,7 @@
*/
public class StandardDeviation extends Variance implements Serializable {
+ /** Serializable version identifier */
static final long serialVersionUID = 5728716329662425188L;
/** */
1.16 +2 -1 jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/moment/FourthMoment.java
Index: FourthMoment.java
===================================================================
RCS file: /home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/moment/FourthMoment.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- FourthMoment.java 21 Feb 2004 21:35:15 -0000 1.15
+++ FourthMoment.java 27 Apr 2004 16:42:30 -0000 1.16
@@ -26,6 +26,7 @@
*/
public class FourthMoment extends ThirdMoment implements Serializable{
+ /** Serializable version identifier */
static final long serialVersionUID = 4763990447117157611L;
/** fourth moment of values that have been added */
1.17 +3 -2 jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/moment/Mean.java
Index: Mean.java
===================================================================
RCS file: /home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/moment/Mean.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- Mean.java 4 Mar 2004 04:25:09 -0000 1.16
+++ Mean.java 27 Apr 2004 16:42:30 -0000 1.17
@@ -33,6 +33,7 @@
*/
public class Mean extends AbstractStorelessUnivariateStatistic implements Serializable{
+ /** Serializable version identifier */
static final long serialVersionUID = -1296043746617791564L;
/** first moment of values that have been added */
@@ -106,7 +107,7 @@
final int begin,
final int length) {
if (test(values, begin, length)) {
- return sum.evaluate(values) / ((double) length);
+ return sum.evaluate(values, begin, length) / ((double) length);
}
return Double.NaN;
}
1.19 +2 -1 jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/moment/Variance.java
Index: Variance.java
===================================================================
RCS file: /home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/moment/Variance.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- Variance.java 4 Mar 2004 04:25:09 -0000 1.18
+++ Variance.java 27 Apr 2004 16:42:30 -0000 1.19
@@ -29,6 +29,7 @@
*/
public class Variance extends AbstractStorelessUnivariateStatistic implements Serializable {
+ /** Serializable version identifier */
static final long serialVersionUID = -9111962718267217978L;
/** SecondMoment is used in incremental calculation of Variance*/
1.15 +230 -1 jakarta-commons/math/src/test/org/apache/commons/math/stat/StatUtilsTest.java
Index: StatUtilsTest.java
===================================================================
RCS file: /home/cvs/jakarta-commons/math/src/test/org/apache/commons/math/stat/StatUtilsTest.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- StatUtilsTest.java 12 Apr 2004 02:27:49 -0000 1.14
+++ StatUtilsTest.java 27 Apr 2004 16:42:31 -0000 1.15
@@ -19,6 +19,7 @@
import junit.framework.TestCase;
import junit.framework.TestSuite;
+import org.apache.commons.math.TestUtils;
import org.apache.commons.math.stat.univariate.DescriptiveStatistics;
/**
@@ -162,5 +163,233 @@
assertTrue(true);
}
+ }
+
+ public void testSumSq() {
+ double[] x = null;
+
+ // test null
+ try {
+ StatUtils.sumSq(x);
+ fail("null is not a valid data array.");
+ } catch (IllegalArgumentException ex) {
+ // success
+ }
+
+ try {
+ StatUtils.sumSq(x, 0, 4);
+ fail("null is not a valid data array.");
+ } catch (IllegalArgumentException ex) {
+ // success
+ }
+
+ // test empty
+ x = new double[] {};
+ TestUtils.assertEquals(Double.NaN, StatUtils.sumSq(x), tolerance);
+ TestUtils.assertEquals(Double.NaN, StatUtils.sumSq(x, 0, 0), tolerance);
+
+ // test one
+ x = new double[] {two};
+ TestUtils.assertEquals(4, StatUtils.sumSq(x), tolerance);
+ TestUtils.assertEquals(4, StatUtils.sumSq(x, 0, 1), tolerance);
+
+ // test many
+ x = new double[] {one, two, two, three};
+ TestUtils.assertEquals(18, StatUtils.sumSq(x), tolerance);
+ TestUtils.assertEquals(8, StatUtils.sumSq(x, 1, 2), tolerance);
+ }
+
+ public void testProduct() {
+ double[] x = null;
+
+ // test null
+ try {
+ StatUtils.product(x);
+ fail("null is not a valid data array.");
+ } catch (IllegalArgumentException ex) {
+ // success
+ }
+
+ try {
+ StatUtils.product(x, 0, 4);
+ fail("null is not a valid data array.");
+ } catch (IllegalArgumentException ex) {
+ // success
+ }
+
+ // test empty
+ x = new double[] {};
+ TestUtils.assertEquals(Double.NaN, StatUtils.product(x), tolerance);
+ TestUtils.assertEquals(Double.NaN, StatUtils.product(x, 0, 0), tolerance);
+
+ // test one
+ x = new double[] {two};
+ TestUtils.assertEquals(two, StatUtils.product(x), tolerance);
+ TestUtils.assertEquals(two, StatUtils.product(x, 0, 1), tolerance);
+
+ // test many
+ x = new double[] {one, two, two, three};
+ TestUtils.assertEquals(12, StatUtils.product(x), tolerance);
+ TestUtils.assertEquals(4, StatUtils.product(x, 1, 2), tolerance);
+ }
+
+ public void testSumLog() {
+ double[] x = null;
+
+ // test null
+ try {
+ StatUtils.sumLog(x);
+ fail("null is not a valid data array.");
+ } catch (IllegalArgumentException ex) {
+ // success
+ }
+
+ try {
+ StatUtils.sumLog(x, 0, 4);
+ fail("null is not a valid data array.");
+ } catch (IllegalArgumentException ex) {
+ // success
+ }
+
+ // test empty
+ x = new double[] {};
+ TestUtils.assertEquals(Double.NaN, StatUtils.sumLog(x), tolerance);
+ TestUtils.assertEquals(Double.NaN, StatUtils.sumLog(x, 0, 0), tolerance);
+
+ // test one
+ x = new double[] {two};
+ TestUtils.assertEquals(Math.log(two), StatUtils.sumLog(x), tolerance);
+ TestUtils.assertEquals(Math.log(two), StatUtils.sumLog(x, 0, 1), tolerance);
+
+ // test many
+ x = new double[] {one, two, two, three};
+ TestUtils.assertEquals(Math.log(one) + 2.0 * Math.log(two) + Math.log(three), StatUtils.sumLog(x), tolerance);
+ TestUtils.assertEquals(2.0 * Math.log(two), StatUtils.sumLog(x, 1, 2), tolerance);
+ }
+
+ public void testMean() {
+ double[] x = null;
+
+ try {
+ StatUtils.mean(x, 0, 4);
+ fail("null is not a valid data array.");
+ } catch (IllegalArgumentException ex) {
+ // success
+ }
+
+ // test empty
+ x = new double[] {};
+ TestUtils.assertEquals(Double.NaN, StatUtils.mean(x, 0, 0), tolerance);
+
+ // test one
+ x = new double[] {two};
+ TestUtils.assertEquals(two, StatUtils.mean(x, 0, 1), tolerance);
+
+ // test many
+ x = new double[] {one, two, two, three};
+ TestUtils.assertEquals(2.5, StatUtils.mean(x, 2, 2), tolerance);
+ }
+
+ public void testVariance() {
+ double[] x = null;
+
+ try {
+ StatUtils.variance(x, 0, 4);
+ fail("null is not a valid data array.");
+ } catch (IllegalArgumentException ex) {
+ // success
+ }
+
+ // test empty
+ x = new double[] {};
+ TestUtils.assertEquals(Double.NaN, StatUtils.variance(x, 0, 0), tolerance);
+
+ // test one
+ x = new double[] {two};
+ TestUtils.assertEquals(0.0, StatUtils.variance(x, 0, 1), tolerance);
+
+ // test many
+ x = new double[] {one, two, two, three};
+ TestUtils.assertEquals(0.5, StatUtils.variance(x, 2, 2), tolerance);
+ }
+
+ public void testMax() {
+ double[] x = null;
+
+ try {
+ StatUtils.max(x, 0, 4);
+ fail("null is not a valid data array.");
+ } catch (IllegalArgumentException ex) {
+ // success
+ }
+
+ // test empty
+ x = new double[] {};
+ TestUtils.assertEquals(Double.NaN, StatUtils.max(x, 0, 0), tolerance);
+
+ // test one
+ x = new double[] {two};
+ TestUtils.assertEquals(two, StatUtils.max(x, 0, 1), tolerance);
+
+ // test many
+ x = new double[] {one, two, two, three};
+ TestUtils.assertEquals(three, StatUtils.max(x, 1, 3), tolerance);
+ }
+
+ public void testMin() {
+ double[] x = null;
+
+ try {
+ StatUtils.min(x, 0, 4);
+ fail("null is not a valid data array.");
+ } catch (IllegalArgumentException ex) {
+ // success
+ }
+
+ // test empty
+ x = new double[] {};
+ TestUtils.assertEquals(Double.NaN, StatUtils.min(x, 0, 0), tolerance);
+
+ // test one
+ x = new double[] {two};
+ TestUtils.assertEquals(two, StatUtils.min(x, 0, 1), tolerance);
+
+ // test many
+ x = new double[] {one, two, two, three};
+ TestUtils.assertEquals(two, StatUtils.min(x, 1, 3), tolerance);
+ }
+
+ public void testPercentile() {
+ double[] x = null;
+
+ // test null
+ try {
+ StatUtils.percentile(x, .25);
+ fail("null is not a valid data array.");
+ } catch (IllegalArgumentException ex) {
+ // success
+ }
+
+ try {
+ StatUtils.percentile(x, 0, 4, 0.25);
+ fail("null is not a valid data array.");
+ } catch (IllegalArgumentException ex) {
+ // success
+ }
+
+ // test empty
+ x = new double[] {};
+ TestUtils.assertEquals(Double.NaN, StatUtils.percentile(x, 25), tolerance);
+ TestUtils.assertEquals(Double.NaN, StatUtils.percentile(x, 0, 0, 25), tolerance);
+
+ // test one
+ x = new double[] {two};
+ TestUtils.assertEquals(two, StatUtils.percentile(x, 25), tolerance);
+ TestUtils.assertEquals(two, StatUtils.percentile(x, 0, 1, 25), tolerance);
+
+ // test many
+ x = new double[] {one, two, two, three};
+ TestUtils.assertEquals(2.5, StatUtils.percentile(x, 70), tolerance);
+ TestUtils.assertEquals(2.5, StatUtils.percentile(x, 1, 3, 62.5), tolerance);
}
}
1.17 +2 -1 jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/summary/SumOfSquares.java
Index: SumOfSquares.java
===================================================================
RCS file: /home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/summary/SumOfSquares.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- SumOfSquares.java 26 Apr 2004 19:15:48 -0000 1.16
+++ SumOfSquares.java 27 Apr 2004 16:42:32 -0000 1.17
@@ -32,6 +32,7 @@
*/
public class SumOfSquares extends AbstractStorelessUnivariateStatistic implements Serializable {
+ /** Serializable version identifier */
static final long serialVersionUID = 1460986908574398008L;
/** */
1.19 +2 -1 jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/summary/Sum.java
Index: Sum.java
===================================================================
RCS file: /home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/summary/Sum.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- Sum.java 26 Apr 2004 19:15:48 -0000 1.18
+++ Sum.java 27 Apr 2004 16:42:32 -0000 1.19
@@ -26,6 +26,7 @@
*/
public class Sum extends AbstractStorelessUnivariateStatistic implements Serializable {
+ /** Serializable version identifier */
static final long serialVersionUID = -8231831954703408316L;
/** */
1.17 +2 -1 jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/summary/SumOfLogs.java
Index: SumOfLogs.java
===================================================================
RCS file: /home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/summary/SumOfLogs.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- SumOfLogs.java 26 Apr 2004 19:15:48 -0000 1.16
+++ SumOfLogs.java 27 Apr 2004 16:42:32 -0000 1.17
@@ -32,6 +32,7 @@
*/
public class SumOfLogs extends AbstractStorelessUnivariateStatistic implements Serializable {
+ /** Serializable version identifier */
static final long serialVersionUID = -370076995648386763L;
/** */
1.17 +2 -1 jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/summary/Product.java
Index: Product.java
===================================================================
RCS file: /home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/summary/Product.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- Product.java 26 Apr 2004 19:15:48 -0000 1.16
+++ Product.java 27 Apr 2004 16:42:32 -0000 1.17
@@ -32,6 +32,7 @@
*/
public class Product extends AbstractStorelessUnivariateStatistic implements Serializable {
+ /** Serializable version identifier */
static final long serialVersionUID = 2824226005990582538L;
/** */
1.1 jakarta-commons/math/src/test/org/apache/commons/math/analysis/UnivariateRealSolverFactoryImplTest.java
Index: UnivariateRealSolverFactoryImplTest.java
===================================================================
/*
*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.math.analysis;
import junit.framework.TestCase;
/**
* @version $Revision: 1.1 $ $Date: 2004/04/27 16:42:32 $
*/
public class UnivariateRealSolverFactoryImplTest extends TestCase {
/** solver factory */
private UnivariateRealSolverFactory factory;
/** function */
private DifferentiableUnivariateRealFunction function;
/**
* @throws java.lang.Exception
* @see junit.framework.TestCase#tearDown()
*/
protected void setUp() throws Exception {
super.setUp();
factory = new UnivariateRealSolverFactoryImpl();
function = new SinFunction();
}
/**
* @throws java.lang.Exception
* @see junit.framework.TestCase#tearDown()
*/
protected void tearDown() throws Exception {
factory = null;
function = null;
super.tearDown();
}
public void testNewBisectionSolverNull() {
try {
UnivariateRealSolver solver = factory.newBisectionSolver(null);
fail();
} catch(IllegalArgumentException ex) {
// success
}
}
public void testNewBisectionSolverValid() {
UnivariateRealSolver solver = factory.newBisectionSolver(function);
assertNotNull(solver);
assertTrue(solver instanceof BisectionSolver);
}
public void testNewNewtonSolverNull() {
try {
UnivariateRealSolver solver = factory.newNewtonSolver(null);
fail();
} catch(IllegalArgumentException ex) {
// success
}
}
public void testNewNewtonSolverValid() {
UnivariateRealSolver solver = factory.newNewtonSolver(function);
assertNotNull(solver);
assertTrue(solver instanceof NewtonSolver);
}
public void testNewBrentSolverNull() {
try {
UnivariateRealSolver solver = factory.newBrentSolver(null);
fail();
} catch(IllegalArgumentException ex) {
// success
}
}
public void testNewBrentSolverValid() {
UnivariateRealSolver solver = factory.newBrentSolver(function);
assertNotNull(solver);
assertTrue(solver instanceof BrentSolver);
}
public void testNewSecantSolverNull() {
try {
UnivariateRealSolver solver = factory.newSecantSolver(null);
fail();
} catch(IllegalArgumentException ex) {
// success
}
}
public void testNewSecantSolverValid() {
UnivariateRealSolver solver = factory.newSecantSolver(function);
assertNotNull(solver);
assertTrue(solver instanceof SecantSolver);
}
}
1.12 +2 -2 jakarta-commons/math/src/test/org/apache/commons/math/stat/univariate/StorelessUnivariateStatisticAbstractTest.java
Index: StorelessUnivariateStatisticAbstractTest.java
===================================================================
RCS file: /home/cvs/jakarta-commons/math/src/test/org/apache/commons/math/stat/univariate/StorelessUnivariateStatisticAbstractTest.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- StorelessUnivariateStatisticAbstractTest.java 21 Feb 2004 21:35:17 -0000 1.11
+++ StorelessUnivariateStatisticAbstractTest.java 27 Apr 2004 16:42:32 -0000 1.12
@@ -31,7 +31,7 @@
public abstract UnivariateStatistic getUnivariateStatistic();
public abstract double expectedValue();
-
+
public void testIncrementation() throws Exception {
StorelessUnivariateStatistic statistic =
1.2 +45 -2 jakarta-commons/math/src/test/org/apache/commons/math/stat/univariate/DescriptiveStatisticsTest.java
Index: DescriptiveStatisticsTest.java
===================================================================
RCS file: /home/cvs/jakarta-commons/math/src/test/org/apache/commons/math/stat/univariate/DescriptiveStatisticsTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DescriptiveStatisticsTest.java 12 Apr 2004 02:27:50 -0000 1.1
+++ DescriptiveStatisticsTest.java 27 Apr 2004 16:42:32 -0000 1.2
@@ -328,6 +328,49 @@
u2.clear();
assertEquals("total count",0,u2.getN(),tolerance);
}
-
+
+ public void testNewInstanceStringNull() {
+ try {
+ DescriptiveStatistics u = DescriptiveStatistics.newInstance((String)null);
+ fail("null is not a valid descriptive statistics class name");
+ } catch (NullPointerException ex) {
+ // success
+ } catch (Exception ex) {
+ fail();
+ }
+
+ }
+ public void testNewInstanceStringValid() {
+ try {
+ DescriptiveStatistics u = DescriptiveStatistics.newInstance(
+ "org.apache.commons.math.stat.univariate.DescriptiveStatisticsImpl");
+ assertNotNull(u);
+ assertTrue(u instanceof DescriptiveStatisticsImpl);
+ } catch (Exception ex) {
+ fail();
+ }
+ }
+
+ public void testNewInstanceClassNull() {
+ try {
+ DescriptiveStatistics u = DescriptiveStatistics.newInstance((Class)null);
+ fail("null is not a valid descriptive statistics class");
+ } catch (NullPointerException ex) {
+ // success
+ } catch (Exception ex) {
+ fail();
+ }
+
+ }
+ public void testNewInstanceClassValid() {
+ try {
+ DescriptiveStatistics u = DescriptiveStatistics.newInstance(
+ DescriptiveStatisticsImpl.class);
+ assertNotNull(u);
+ assertTrue(u instanceof DescriptiveStatisticsImpl);
+ } catch (Exception ex) {
+ fail();
+ }
+ }
}
1.15 +2 -1 jakarta-commons/math/src/java/org/apache/commons/math/analysis/BisectionSolver.java
Index: BisectionSolver.java
===================================================================
RCS file: /home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/analysis/BisectionSolver.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- BisectionSolver.java 27 Apr 2004 04:37:58 -0000 1.14
+++ BisectionSolver.java 27 Apr 2004 16:42:33 -0000 1.15
@@ -26,6 +26,7 @@
* @version $Revision$ $Date$
*/
public class BisectionSolver extends UnivariateRealSolverImpl implements Serializable {
+
/**
* Construct a solver for the given function.
* @param f function to solve.
1.12 +6 -1 jakarta-commons/math/src/java/org/apache/commons/math/analysis/UnivariateRealSolverImpl.java
Index: UnivariateRealSolverImpl.java
===================================================================
RCS file: /home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/analysis/UnivariateRealSolverImpl.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- UnivariateRealSolverImpl.java 23 Apr 2004 18:20:12 -0000 1.11
+++ UnivariateRealSolverImpl.java 27 Apr 2004 16:42:33 -0000 1.12
@@ -71,6 +71,7 @@
* @param f the function to solve.
* @param defaultAbsoluteAccuracy maximum absolue error.
* @param defaultMaximalIterationCount maximum number of iterations.
+ * @throws IllegalArgumentException if function is null.
*/
protected UnivariateRealSolverImpl(
UnivariateRealFunction f,
@@ -78,6 +79,10 @@
double defaultAbsoluteAccuracy) {
super();
+
+ if (f == null) {
+ throw new IllegalArgumentException("function can not be null.");
+ }
this.f = f;
this.defaultAbsoluteAccuracy = defaultAbsoluteAccuracy;
1.1 jakarta-commons/math/src/test/org/apache/commons/math/stat/univariate/moment/FirstMomentTest.java
Index: FirstMomentTest.java
===================================================================
/*
* Copyright 2003-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.math.stat.univariate.moment;
import org.apache.commons.math.stat.univariate.StorelessUnivariateStatisticAbstractTest;
import org.apache.commons.math.stat.univariate.UnivariateStatistic;
/**
* Test cases for the {@link UnivariateStatistic} class.
* @version $Revision: 1.1 $ $Date: 2004/04/27 16:42:33 $
*/
public class FirstMomentTest extends StorelessUnivariateStatisticAbstractTest{
/** descriptive statistic. */
protected FirstMoment stat;
/**
* @param name
*/
public FirstMomentTest(String name) {
super(name);
}
/**
* @see org.apache.commons.math.stat.univariate.UnivariateStatisticAbstractTest#getUnivariateStatistic()
*/
public UnivariateStatistic getUnivariateStatistic() {
if(stat == null)
stat = new FirstMoment();
return stat;
}
/**
* @see org.apache.commons.math.stat.univariate.UnivariateStatisticAbstractTest#expectedValue()
*/
public double expectedValue() {
return this.mean;
}
}
1.16 +2 -1 jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/rank/Min.java
Index: Min.java
===================================================================
RCS file: /home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/rank/Min.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- Min.java 26 Apr 2004 19:15:48 -0000 1.15
+++ Min.java 27 Apr 2004 16:42:33 -0000 1.16
@@ -32,6 +32,7 @@
*/
public class Min extends AbstractStorelessUnivariateStatistic implements Serializable {
+ /** Serializable version identifier */
static final long serialVersionUID = -2941995784909003131L;
/** */
1.13 +2 -1 jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/rank/Median.java
Index: Median.java
===================================================================
RCS file: /home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/rank/Median.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- Median.java 26 Apr 2004 19:15:48 -0000 1.12
+++ Median.java 27 Apr 2004 16:42:33 -0000 1.13
@@ -26,6 +26,7 @@
*/
public class Median extends Percentile implements Serializable {
+ /** Serializable version identifier */
static final long serialVersionUID = -3961477041290915687L;
/**
1.16 +2 -1 jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/rank/Max.java
Index: Max.java
===================================================================
RCS file: /home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/rank/Max.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- Max.java 26 Apr 2004 19:15:48 -0000 1.15
+++ Max.java 27 Apr 2004 16:42:33 -0000 1.16
@@ -32,6 +32,7 @@
*/
public class Max extends AbstractStorelessUnivariateStatistic implements Serializable {
+ /** Serializable version identifier */
static final long serialVersionUID = -5593383832225844641L;
/** */
1.18 +3 -1 jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/rank/Percentile.java
Index: Percentile.java
===================================================================
RCS file: /home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/rank/Percentile.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- Percentile.java 26 Apr 2004 19:15:48 -0000 1.17
+++ Percentile.java 27 Apr 2004 16:42:33 -0000 1.18
@@ -32,6 +32,7 @@
*/
public class Percentile extends AbstractUnivariateStatistic implements Serializable {
+ /** Serializable version identifier */
static final long serialVersionUID = -8091216485095130416L;
/** Determines what percentile is computed when evaluate() is activated with no quantile argument */
@@ -68,6 +69,7 @@
* if the array is empty
*/
public double evaluate(final double[] values, final double p) {
+ test(values, 0, 0);
return evaluate(values, 0, values.length, p);
}
1.16 +6 -5 jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/AbstractUnivariateStatistic.java
Index: AbstractUnivariateStatistic.java
===================================================================
RCS file: /home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/stat/univariate/AbstractUnivariateStatistic.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- AbstractUnivariateStatistic.java 12 Apr 2004 05:22:11 -0000 1.15
+++ AbstractUnivariateStatistic.java 27 Apr 2004 16:42:34 -0000 1.16
@@ -28,6 +28,7 @@
* @see org.apache.commons.math.stat.univariate.UnivariateStatistic#evaluate(double[])
*/
public double evaluate(final double[] values) {
+ test(values, 0, 0);
return evaluate(values, 0, values.length);
}
@@ -56,6 +57,10 @@
final int begin,
final int length) {
+ if (values == null) {
+ throw new IllegalArgumentException("input value array is null");
+ }
+
if (begin < 0) {
throw new IllegalArgumentException("start position cannot be negative");
}
@@ -64,10 +69,6 @@
throw new IllegalArgumentException("length cannot be negative");
}
- if (values == null) {
- throw new IllegalArgumentException("input value array is null");
- }
-
if (begin + length > values.length) {
throw new IllegalArgumentException(
"begin + length > values.length");
1.13 +2 -1 jakarta-commons/math/src/java/org/apache/commons/math/util/ContractableDoubleArray.java
Index: ContractableDoubleArray.java
===================================================================
RCS file: /home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/util/ContractableDoubleArray.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- ContractableDoubleArray.java 21 Feb 2004 21:35:16 -0000 1.12
+++ ContractableDoubleArray.java 27 Apr 2004 16:42:34 -0000 1.13
@@ -54,6 +54,7 @@
*/
public class ContractableDoubleArray extends ExpandableDoubleArray implements Serializable {
+ /** Serializable version identifier */
static final long serialVersionUID = -3485529955529426875L;
/** The contraction criteria defines the conditions under which this
1.15 +2 -1 jakarta-commons/math/src/java/org/apache/commons/math/util/FixedDoubleArray.java
Index: FixedDoubleArray.java
===================================================================
RCS file: /home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/util/FixedDoubleArray.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- FixedDoubleArray.java 21 Feb 2004 21:35:16 -0000 1.14
+++ FixedDoubleArray.java 27 Apr 2004 16:42:34 -0000 1.15
@@ -50,6 +50,7 @@
*/
public class FixedDoubleArray implements DoubleArray, Serializable {
+ /** Serializable version identifier */
static final long serialVersionUID = 1247853239629842963L;
/**
1.14 +2 -1 jakarta-commons/math/src/java/org/apache/commons/math/util/ExpandableDoubleArray.java
Index: ExpandableDoubleArray.java
===================================================================
RCS file: /home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/util/ExpandableDoubleArray.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- ExpandableDoubleArray.java 21 Feb 2004 21:35:16 -0000 1.13
+++ ExpandableDoubleArray.java 27 Apr 2004 16:42:34 -0000 1.14
@@ -54,6 +54,7 @@
*/
public class ExpandableDoubleArray implements Serializable, DoubleArray {
+ /** Serializable version identifier */
static final long serialVersionUID = -5697417774251632284L;
// TODO: expansionFactor is valuable, by if I only need storage
1.5 +16 -21 jakarta-commons/math/src/java/org/apache/commons/math/stat/inference/TestStatisticImpl.java
Index: TestStatisticImpl.java
===================================================================
RCS file: /home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/stat/inference/TestStatisticImpl.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- TestStatisticImpl.java 12 Apr 2004 02:27:49 -0000 1.4
+++ TestStatisticImpl.java 27 Apr 2004 16:42:34 -0000 1.5
@@ -32,15 +32,10 @@
*/
public class TestStatisticImpl implements TestStatistic, Serializable {
+ /** Serializable version identifier */
static final long serialVersionUID = 3357444126133491679L;
/**
- * Default constructor
- */
- public TestStatisticImpl() {
- }
-
- /**
* @param observed array of observed frequency counts
* @param expected array of expected frequency counts
* @return chi-square test statistic
@@ -55,8 +50,8 @@
throw new IllegalArgumentException("observed, expected array lengths incorrect");
}
if ((StatUtils.min(expected) <= 0) || (StatUtils.min(observed) < 0)) {
- throw new IllegalArgumentException( "observed counts must be non-negative,"
- + " expected counts must be postive");
+ throw new IllegalArgumentException(
+ "observed counts must be non-negative expected counts must be postive");
}
for (int i = 0; i < observed.length; i++) {
dev = (observed[i] - expected[i]);
@@ -134,8 +129,8 @@
*/
public double t(double[] sample1, double[] sample2)
throws IllegalArgumentException {
- if ((sample1 == null) || (sample2 == null
- || Math.min(sample1.length, sample2.length) < 5)) {
+ if ((sample1 == null) || (sample2 == null ||
+ Math.min(sample1.length, sample2.length) < 5)) {
throw new IllegalArgumentException("insufficient data for t statistic");
}
return t(StatUtils.mean(sample1), StatUtils.mean(sample2), StatUtils.variance(sample1),
@@ -152,8 +147,8 @@
*/
public double tTest(double[] sample1, double[] sample2)
throws IllegalArgumentException, MathException {
- if ((sample1 == null) || (sample2 == null
- || Math.min(sample1.length, sample2.length) < 5)) {
+ if ((sample1 == null) || (sample2 == null ||
+ Math.min(sample1.length, sample2.length) < 5)) {
throw new IllegalArgumentException("insufficient data");
}
return tTest(StatUtils.mean(sample1), StatUtils.mean(sample2), StatUtils.variance(sample1),
@@ -214,9 +209,9 @@
*/
public double t(StatisticalSummary sampleStats1, StatisticalSummary sampleStats2)
throws IllegalArgumentException {
- if ((sampleStats1 == null)
- || (sampleStats2 == null
- || Math.min(sampleStats1.getN(), sampleStats2.getN()) < 5)) {
+ if ((sampleStats1 == null) ||
+ (sampleStats2 == null ||
+ Math.min(sampleStats1.getN(), sampleStats2.getN()) < 5)) {
throw new IllegalArgumentException("insufficient data for t statistic");
}
return t(sampleStats1.getMean(), sampleStats2.getMean(), sampleStats1.getVariance(),
@@ -232,8 +227,8 @@
*/
public double tTest(StatisticalSummary sampleStats1, StatisticalSummary sampleStats2)
throws IllegalArgumentException, MathException {
- if ((sampleStats1 == null) || (sampleStats2 == null
- || Math.min(sampleStats1.getN(), sampleStats2.getN()) < 5)) {
+ if ((sampleStats1 == null) || (sampleStats2 == null ||
+ Math.min(sampleStats1.getN(), sampleStats2.getN()) < 5)) {
throw new IllegalArgumentException("insufficient data for t statistic");
}
return tTest(sampleStats1.getMean(), sampleStats2.getMean(), sampleStats1.getVariance(),
@@ -301,9 +296,9 @@
* @return approximate degrees of freedom
*/
private double df(double v1, double v2, double n1, double n2) {
- return (((v1 / n1) + (v2 / n2)) * ((v1 / n1) + (v2 / n2)))
- / ((v1 * v1) / (n1 * n1 * (n1 - 1d))
- + (v2 * v2) / (n2 * n2 * (n2 - 1d)));
+ return (((v1 / n1) + (v2 / n2)) * ((v1 / n1) + (v2 / n2))) /
+ ((v1 * v1) / (n1 * n1 * (n1 - 1d)) + (v2 * v2) /
+ (n2 * n2 * (n2 - 1d)));
}
/**
1.6 +46 -54 jakarta-commons/math/src/java/org/apache/commons/math/distribution/NormalDistributionImpl.java
Index: NormalDistributionImpl.java
===================================================================
RCS file: /home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/distribution/NormalDistributionImpl.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- NormalDistributionImpl.java 27 Apr 2004 04:37:58 -0000 1.5
+++ NormalDistributionImpl.java 27 Apr 2004 16:42:34 -0000 1.6
@@ -84,8 +84,9 @@
* @param sd standard deviation for this distribution
*/
public void setStandardDeviation(double sd) {
- if (sd < 0.0) {
- throw new IllegalArgumentException("Standard deviation must be" +
"positive or zero.");
+ if (sd <= 0.0) {
+ throw new IllegalArgumentException(
+ "Standard deviation must be positive.");
}
standardDeviation = sd;
}
@@ -96,12 +97,7 @@
* @return CDF evaluted at <code>x</code>.
*/
public double cumulativeProbability(double x) {
- double z = x;
- if(standardDeviation > 0){
- z = (x - mean) / standardDeviation;
- }else{
- return 0.0;
- }
+ double z = (x - mean) / standardDeviation;
return cdfAlgorithm.cdf(z);
}
@@ -137,11 +133,6 @@
"p must be between 0.0 and 1.0, inclusive.");
}
- //TODO is this ok?
- if(standardDeviation == 0){
- return mean;
- }
-
double r, val;
double q = p - 0.5;
@@ -152,49 +143,50 @@
33430.575583588128105) * r + 67265.770927008700853) * r +
45921.953931549871457) * r + 13731.693765509461125) * r +
1971.5909503065514427) * r + 133.14166789178437745) * r +
- 3.387132872796366608)
- / (((((((r * 5226.495278852854561 +
+ 3.387132872796366608) /
+ (((((((r * 5226.495278852854561 +
28729.085735721942674) * r + 39307.89580009271061) * r +
21213.794301586595867) * r + 5394.1960214247511077) * r +
687.1870074920579083) * r + 42.313330701600911252) * r + 1.);
- }else { //closer than 0.075 from {0,1} boundary
- if (q > 0) {
- r = 1 - p;
- } else {
- r = p;
- }
- r = Math.sqrt(- Math.log(r));
- if (r <= 5.0) {
- r += -1.6;
- val = (((((((r * 7.7454501427834140764e-4 +
- 0.0227238449892691845833) * r + 0.24178072517745061177) *
- r + 1.27045825245236838258) * r +
- 3.64784832476320460504) * r + 5.7694972214606914055) *
- r + 4.6303378461565452959) * r +
- 1.42343711074968357734)
- / (((((((r *
- 1.05075007164441684324e-9 + 5.475938084995344946e-4) *
- r + 0.0151986665636164571966) * r +
- 0.14810397642748007459) * r + 0.68976733498510000455) *
- r + 1.6763848301838038494) * r +
- 2.05319162663775882187) * r + 1.0);
- }else { //very close to 0 or 1
- r += -5.;
- val = (((((((r * 2.01033439929228813265e-7 +
- 2.71155556874348757815e-5) * r +
- 0.0012426609473880784386) * r + 0.026532189526576123093) *
- r + 0.29656057182850489123) * r +
- 1.7848265399172913358) * r + 5.4637849111641143699) *
- r + 6.6579046435011037772) /
- (((((((r *
- 2.04426310338993978564e-15 + 1.4215117583164458887e-7)*
- r + 1.8463183175100546818e-5) * r +
- 7.868691311456132591e-4) * r + 0.0148753612908506148525) *
- r + 0.13692988092273580531) * r +
- 0.59983220655588793769) * r + 1.0);
- }
- if(q < 0.0)
- val = -val;
+ } else { //closer than 0.075 from {0,1} boundary
+ if (q > 0) {
+ r = 1 - p;
+ } else {
+ r = p;
+ }
+ r = Math.sqrt(- Math.log(r));
+ if (r <= 5.0) {
+ r += -1.6;
+ val = (((((((r * 7.7454501427834140764e-4 +
+ 0.0227238449892691845833) * r + 0.24178072517745061177) *
+ r + 1.27045825245236838258) * r +
+ 3.64784832476320460504) * r + 5.7694972214606914055) *
+ r + 4.6303378461565452959) * r +
+ 1.42343711074968357734) /
+ (((((((r *
+ 1.05075007164441684324e-9 + 5.475938084995344946e-4) *
+ r + 0.0151986665636164571966) * r +
+ 0.14810397642748007459) * r + 0.68976733498510000455) *
+ r + 1.6763848301838038494) * r +
+ 2.05319162663775882187) * r + 1.0);
+ } else { //very close to 0 or 1
+ r += -5.;
+ val = (((((((r * 2.01033439929228813265e-7 +
+ 2.71155556874348757815e-5) * r +
+ 0.0012426609473880784386) * r + 0.026532189526576123093) *
+ r + 0.29656057182850489123) * r +
+ 1.7848265399172913358) * r + 5.4637849111641143699) *
+ r + 6.6579046435011037772) /
+ (((((((r *
+ 2.04426310338993978564e-15 + 1.4215117583164458887e-7)*
+ r + 1.8463183175100546818e-5) * r +
+ 7.868691311456132591e-4) * r + 0.0148753612908506148525) *
+ r + 0.13692988092273580531) * r +
+ 0.59983220655588793769) * r + 1.0);
+ }
+ if(q < 0.0) {
+ val = -val;
+ }
}
return mean + standardDeviation * val;
}
1.2 +9 -5 jakarta-commons/math/src/java/org/apache/commons/math/stat/multivariate/BivariateRegression.java
Index: BivariateRegression.java
===================================================================
RCS file: /home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/stat/multivariate/BivariateRegression.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- BivariateRegression.java 11 Apr 2004 21:52:28 -0000 1.1
+++ BivariateRegression.java 27 Apr 2004 16:42:34 -0000 1.2
@@ -53,6 +53,7 @@
*/
public class BivariateRegression implements Serializable {
+ /** Serializable version identifier */
static final long serialVersionUID = -3004689053607543335L;
/** sum of x values */
@@ -386,6 +387,8 @@
* Bivariate Normal Distribution</a>.
*
* @return half-width of 95% confidence interval for the slope estimate
+ *
+ * @exception MathException if the confidence interval can not be computed.
*/
public double getSlopeConfidenceInterval() throws MathException {
return getSlopeConfidenceInterval(0.05d);
@@ -420,14 +423,15 @@
*
* @param alpha the desired significance level
* @return half-width of 95% confidence interval for the slope estimate
+ * @exception MathException if the confidence interval can not be computed.
*/
public double getSlopeConfidenceInterval(double alpha)
throws MathException {
if (alpha >= 1 || alpha <= 0) {
throw new IllegalArgumentException();
}
- return getSlopeStdErr()
- * getTDistribution().inverseCumulativeProbability(1d - alpha / 2d);
+ return getSlopeStdErr() *
+ getTDistribution().inverseCumulativeProbability(1d - alpha / 2d);
}
/**
@@ -449,11 +453,11 @@
* <code>Double.NaN</code>.
*
* @return significance level for slope/correlation
+ * @exception MathException if the significance level can not be computed.
*/
public double getSignificance() throws MathException {
return (
- 1d
- - getTDistribution().cumulativeProbability(
+ 1.0 - getTDistribution().cumulativeProbability(
Math.abs(getSlope()) / getSlopeStdErr()));
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org