Changed deprecated MathRuntimeException in package stat.correlation

JIRA: MATH-459

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1239802 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Thomas Neidhart 2012-02-02 20:16:36 +00:00
parent 11f91fd0eb
commit c9369dc298
2 changed files with 20 additions and 24 deletions

View File

@ -16,10 +16,9 @@
*/
package org.apache.commons.math.stat.correlation;
import org.apache.commons.math.MathException;
import org.apache.commons.math.MathRuntimeException;
import org.apache.commons.math.distribution.TDistribution;
import org.apache.commons.math.exception.util.LocalizedFormats;
import org.apache.commons.math.exception.MathIllegalArgumentException;
import org.apache.commons.math.exception.NullArgumentException;
import org.apache.commons.math.exception.DimensionMismatchException;
import org.apache.commons.math.linear.RealMatrix;
@ -158,9 +157,10 @@ public class PearsonsCorrelation {
* <i>significance</i> of the corresponding correlation coefficients.</p>
*
* @return matrix of p-values
* @throws MathException if an error occurs estimating probabilities
* @throws org.apache.commons.math.exception.MaxCountExceededException
* if an error occurs estimating probabilities
*/
public RealMatrix getCorrelationPValues() throws MathException {
public RealMatrix getCorrelationPValues() {
TDistribution tDistribution = new TDistribution(nObs - 2);
int nVars = correlationMatrix.getColumnDimension();
double[][] out = new double[nVars][nVars];
@ -221,16 +221,16 @@ public class PearsonsCorrelation {
* @param xArray first data array
* @param yArray second data array
* @return Returns Pearson's correlation coefficient for the two arrays
* @throws IllegalArgumentException if the arrays lengths do not match or
* there is insufficient data
* @throws DimensionMismatchException if the arrays lengths do not match
* @throws MathIllegalArgumentException if there is insufficient data
*/
public double correlation(final double[] xArray, final double[] yArray) throws IllegalArgumentException {
public double correlation(final double[] xArray, final double[] yArray) {
SimpleRegression regression = new SimpleRegression();
if (xArray.length != yArray.length) {
throw new DimensionMismatchException(xArray.length, yArray.length);
} else if (xArray.length < 2) {
throw MathRuntimeException.createIllegalArgumentException(
LocalizedFormats.INSUFFICIENT_DIMENSION, xArray.length, 2);
throw new MathIllegalArgumentException(LocalizedFormats.INSUFFICIENT_DIMENSION,
xArray.length, 2);
} else {
for(int i=0; i<xArray.length; i++) {
regression.addData(xArray[i], yArray[i]);
@ -271,14 +271,14 @@ public class PearsonsCorrelation {
* two columns and two rows
*
* @param matrix matrix to check for sufficiency
* @throws MathIllegalArgumentException if there is insufficient data
*/
private void checkSufficientData(final RealMatrix matrix) {
int nRows = matrix.getRowDimension();
int nCols = matrix.getColumnDimension();
if (nRows < 2 || nCols < 2) {
throw MathRuntimeException.createIllegalArgumentException(
LocalizedFormats.INSUFFICIENT_ROWS_AND_COLUMNS,
nRows, nCols);
throw new MathIllegalArgumentException(LocalizedFormats.INSUFFICIENT_ROWS_AND_COLUMNS,
nRows, nCols);
}
}
}

View File

@ -17,7 +17,8 @@
package org.apache.commons.math.stat.correlation;
import org.apache.commons.math.MathRuntimeException;
import org.apache.commons.math.exception.DimensionMismatchException;
import org.apache.commons.math.exception.MathIllegalArgumentException;
import org.apache.commons.math.exception.util.LocalizedFormats;
import org.apache.commons.math.linear.BlockRealMatrix;
import org.apache.commons.math.linear.RealMatrix;
@ -135,23 +136,18 @@ public class SpearmansCorrelation {
/**
* Computes the Spearman's rank correlation coefficient between the two arrays.
*
* </p>Throws IllegalArgumentException if the arrays do not have the same length
* or their common length is less than 2</p>
*
* @param xArray first data array
* @param yArray second data array
* @return Returns Spearman's rank correlation coefficient for the two arrays
* @throws IllegalArgumentException if the arrays lengths do not match or
* there is insufficient data
* @throws DimensionMismatchException if the arrays lengths do not match
* @throws MathIllegalArgumentException if the array length is less than 2
*/
public double correlation(final double[] xArray, final double[] yArray)
throws IllegalArgumentException {
public double correlation(final double[] xArray, final double[] yArray) {
if (xArray.length != yArray.length) {
throw MathRuntimeException.createIllegalArgumentException(
LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE, xArray.length, yArray.length);
throw new DimensionMismatchException(xArray.length, yArray.length);
} else if (xArray.length < 2) {
throw MathRuntimeException.createIllegalArgumentException(
LocalizedFormats.INSUFFICIENT_DIMENSION, xArray.length, 2);
throw new MathIllegalArgumentException(LocalizedFormats.INSUFFICIENT_DIMENSION,
xArray.length, 2);
} else {
return new PearsonsCorrelation().correlation(rankingAlgorithm.rank(xArray),
rankingAlgorithm.rank(yArray));