completed internationalization of all error messages
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@773189 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f4dbd2ecf5
commit
2ba5fd1cbc
|
@ -91,6 +91,8 @@ public class MessagesResources_fr
|
||||||
// org.apache.commons.math.optimization.general.AbstractLeastSquaresOptimizer
|
// org.apache.commons.math.optimization.general.AbstractLeastSquaresOptimizer
|
||||||
// org.apache.commons.math.ode.ContinuousOutputModel
|
// org.apache.commons.math.ode.ContinuousOutputModel
|
||||||
// org.apache.commons.math.random.UncorrelatedRandomVectorGenerator
|
// org.apache.commons.math.random.UncorrelatedRandomVectorGenerator
|
||||||
|
// org.apache.commons.math.stat.regression.AbstractMultipleLinearRegression
|
||||||
|
// org.apache.commons.math.stat.inference.ChiSquareTestImpl
|
||||||
{ "dimension mismatch {0} != {1}",
|
{ "dimension mismatch {0} != {1}",
|
||||||
"dimensions incompatibles {0} != {1}" },
|
"dimensions incompatibles {0} != {1}" },
|
||||||
|
|
||||||
|
@ -333,6 +335,7 @@ public class MessagesResources_fr
|
||||||
"non sym\u00e9triques n''est pas encore disponible" },
|
"non sym\u00e9triques n''est pas encore disponible" },
|
||||||
|
|
||||||
// org.apache.commons.math.linear.decomposition.NonSquareMatrixException
|
// org.apache.commons.math.linear.decomposition.NonSquareMatrixException
|
||||||
|
// org.apache.commons.math.stat.regression.AbstractMultipleLinearRegression
|
||||||
{ "a {0}x{1} matrix was provided instead of a square matrix",
|
{ "a {0}x{1} matrix was provided instead of a square matrix",
|
||||||
"une matrice {0}x{1} a \u00e9t\u00e9 fournie \u00e0 la place d''une matrice carr\u00e9e" },
|
"une matrice {0}x{1} a \u00e9t\u00e9 fournie \u00e0 la place d''une matrice carr\u00e9e" },
|
||||||
|
|
||||||
|
@ -382,6 +385,10 @@ public class MessagesResources_fr
|
||||||
"une matrice doit comporter au moins une ligne" },
|
"une matrice doit comporter au moins une ligne" },
|
||||||
{ "matrix must have at least one column",
|
{ "matrix must have at least one column",
|
||||||
"une matrice doit comporter au moins une colonne" },
|
"une matrice doit comporter au moins une colonne" },
|
||||||
|
|
||||||
|
// org.apache.commons.math.linear.AbstractRealMatrix
|
||||||
|
// org.apache.commons.math.linear.AbstractFieldMatrix
|
||||||
|
// org.apache.commons.math.stat.inference.ChiSquareTestImpl
|
||||||
{ "some rows have length {0} while others have length {1}",
|
{ "some rows have length {0} while others have length {1}",
|
||||||
"certaines lignes ont une longueur de {0} alors que d''autres ont une longueur de {1}" },
|
"certaines lignes ont une longueur de {0} alors que d''autres ont une longueur de {1}" },
|
||||||
|
|
||||||
|
@ -635,9 +642,48 @@ public class MessagesResources_fr
|
||||||
"les statistiques bas\u00e9es sur des moments externes " +
|
"les statistiques bas\u00e9es sur des moments externes " +
|
||||||
"ne peuvent pas \u00eatre remises \u00e0 z\u00e9ro" },
|
"ne peuvent pas \u00eatre remises \u00e0 z\u00e9ro" },
|
||||||
|
|
||||||
|
// org.apache.commons.math.stat.inference.ChiSquareTestImpl
|
||||||
|
{ "expected array length = {0}, must be at least 2",
|
||||||
|
"le tableau des valeurs attendues a une longueur de {0}, elle devrait \u00eatre au moins de 2" },
|
||||||
|
{ "observed array length = {0}, must be at least 2",
|
||||||
|
"le tableau des valeurs observ\u00e9es a une longueur de {0}, elle devrait \u00eatre au moins de 2" },
|
||||||
|
{ "observed counts are all 0 in first observed array",
|
||||||
|
"aucune occurrence dans le premier tableau des observations" },
|
||||||
|
{ "observed counts are all 0 in second observed array",
|
||||||
|
"aucune occurrence dans le second tableau des observations" },
|
||||||
|
{ "observed counts are both zero for entry {0}",
|
||||||
|
"les occurrences observ\u00e9es sont toutes deux nulles pour l'entr\u00e9e {0}" },
|
||||||
|
{ "invalid row dimension: {0} (must be at least 2)",
|
||||||
|
"nombre de lignes invalide : {0} (doit \u00eatre au moins de 2)" },
|
||||||
|
{ "invalid column dimension: {0} (must be at least 2)",
|
||||||
|
"nombre de colonnes invalide : {0} (doit \u00eatre au moins de 2)" },
|
||||||
|
{ "element {0} is not positive: {1}",
|
||||||
|
"l''\u00e9l\u00e9ment {0} n''est pas positif : {1}" },
|
||||||
|
{ "element {0} is negative: {1}",
|
||||||
|
"l''\u00e9l\u00e9ment {0} est n\u00e9gatif : {1}" },
|
||||||
|
{ "element ({0}, {1}) is negative: {2}",
|
||||||
|
"l''\u00e9l\u00e9ment ({0}, {1}) est n\u00e9gatif : {2}" },
|
||||||
|
|
||||||
|
// org.apache.commons.math.stat.inference.OneWayAnovaImpl
|
||||||
|
{ "two or more categories required, got {0}",
|
||||||
|
"deux cat\u00e9gories ou plus sont n\u00e9cessaires, il y en a {0}" },
|
||||||
|
{ "two or more values required in each category, one has {0}",
|
||||||
|
"deux valeurs ou plus sont n\u00e9cessaires pour chaque cat\u00e9gorie, une cat\u00e9gorie en a {0}" },
|
||||||
|
|
||||||
|
// org.apache.commons.math.stat.inference.TTestImpl
|
||||||
|
{ "insufficient data for t statistic, needs at least 2, got {0}",
|
||||||
|
"deux valeurs ou plus sont n\u00e9cessaires pour la statistique t, il y en a {0}" },
|
||||||
|
|
||||||
|
// org.apache.commons.math.stat.inference.ChiSquareTestImpl
|
||||||
|
// org.apache.commons.math.stat.inference.TTestImpl
|
||||||
|
// org.apache.commons.math.stat.inference.OneWayAnovaImpl
|
||||||
// org.apache.commons.math.stat.Regression
|
// org.apache.commons.math.stat.Regression
|
||||||
{ "out of bounds significance level {0}, must be in (0, 1)",
|
{ "out of bounds significance level {0}, must be between {1} and {2}",
|
||||||
"niveau de signification {0} hors domaine, doit \u00eatre dans l''intervalle ]0, 1[" },
|
"niveau de signification {0} hors domaine, doit \u00eatre entre {1} et {2}" },
|
||||||
|
|
||||||
|
// org.apache.commons.math.stat.regression.OLSMultipleLinearRegression
|
||||||
|
{ "matrix is not upper-triangular, entry ({0}, {1}) = {2} is too large",
|
||||||
|
"matrice non triangulaire sup\u00e9rieure, l''\u00e9l\u00e9ment ({0}, {1}) = {2} est trop grand" },
|
||||||
|
|
||||||
// org.apache.commons.math.distribution.AbstractContinuousDistribution
|
// org.apache.commons.math.distribution.AbstractContinuousDistribution
|
||||||
// org.apache.commons.math.distribution.AbstractIntegerDistribution
|
// org.apache.commons.math.distribution.AbstractIntegerDistribution
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
package org.apache.commons.math.stat.inference;
|
package org.apache.commons.math.stat.inference;
|
||||||
|
|
||||||
import org.apache.commons.math.MathException;
|
import org.apache.commons.math.MathException;
|
||||||
|
import org.apache.commons.math.MathRuntimeException;
|
||||||
import org.apache.commons.math.distribution.ChiSquaredDistribution;
|
import org.apache.commons.math.distribution.ChiSquaredDistribution;
|
||||||
import org.apache.commons.math.distribution.ChiSquaredDistributionImpl;
|
import org.apache.commons.math.distribution.ChiSquaredDistributionImpl;
|
||||||
|
|
||||||
|
@ -62,14 +63,17 @@ public class ChiSquareTestImpl implements UnknownDistributionChiSquareTest {
|
||||||
*/
|
*/
|
||||||
public double chiSquare(double[] expected, long[] observed)
|
public double chiSquare(double[] expected, long[] observed)
|
||||||
throws IllegalArgumentException {
|
throws IllegalArgumentException {
|
||||||
if ((expected.length < 2) || (expected.length != observed.length)) {
|
if (expected.length < 2) {
|
||||||
throw new IllegalArgumentException(
|
throw MathRuntimeException.createIllegalArgumentException(
|
||||||
"observed, expected array lengths incorrect");
|
"expected array length = {0}, must be at least 2",
|
||||||
|
expected.length);
|
||||||
}
|
}
|
||||||
if (!isPositive(expected) || !isNonNegative(observed)) {
|
if (expected.length != observed.length) {
|
||||||
throw new IllegalArgumentException(
|
throw MathRuntimeException.createIllegalArgumentException(
|
||||||
"observed counts must be non-negative and expected counts must be postive");
|
"dimension mismatch {0} != {1}", expected.length, observed.length);
|
||||||
}
|
}
|
||||||
|
checkPositive(expected);
|
||||||
|
checkNonNegative(observed);
|
||||||
double sumExpected = 0d;
|
double sumExpected = 0d;
|
||||||
double sumObserved = 0d;
|
double sumObserved = 0d;
|
||||||
for (int i = 0; i < observed.length; i++) {
|
for (int i = 0; i < observed.length; i++) {
|
||||||
|
@ -132,8 +136,9 @@ public class ChiSquareTestImpl implements UnknownDistributionChiSquareTest {
|
||||||
public boolean chiSquareTest(double[] expected, long[] observed,
|
public boolean chiSquareTest(double[] expected, long[] observed,
|
||||||
double alpha) throws IllegalArgumentException, MathException {
|
double alpha) throws IllegalArgumentException, MathException {
|
||||||
if ((alpha <= 0) || (alpha > 0.5)) {
|
if ((alpha <= 0) || (alpha > 0.5)) {
|
||||||
throw new IllegalArgumentException(
|
throw MathRuntimeException.createIllegalArgumentException(
|
||||||
"bad significance level: " + alpha);
|
"out of bounds significance level {0}, must be between {1} and {2}",
|
||||||
|
alpha, 0, 0.5);
|
||||||
}
|
}
|
||||||
return (chiSquareTest(expected, observed) < alpha);
|
return (chiSquareTest(expected, observed) < alpha);
|
||||||
}
|
}
|
||||||
|
@ -199,7 +204,9 @@ public class ChiSquareTestImpl implements UnknownDistributionChiSquareTest {
|
||||||
public boolean chiSquareTest(long[][] counts, double alpha)
|
public boolean chiSquareTest(long[][] counts, double alpha)
|
||||||
throws IllegalArgumentException, MathException {
|
throws IllegalArgumentException, MathException {
|
||||||
if ((alpha <= 0) || (alpha > 0.5)) {
|
if ((alpha <= 0) || (alpha > 0.5)) {
|
||||||
throw new IllegalArgumentException("bad significance level: " + alpha);
|
throw MathRuntimeException.createIllegalArgumentException(
|
||||||
|
"out of bounds significance level {0}, must be between {1} and {2}",
|
||||||
|
alpha, 0.0, 0.5);
|
||||||
}
|
}
|
||||||
return (chiSquareTest(counts) < alpha);
|
return (chiSquareTest(counts) < alpha);
|
||||||
}
|
}
|
||||||
|
@ -215,15 +222,21 @@ public class ChiSquareTestImpl implements UnknownDistributionChiSquareTest {
|
||||||
throws IllegalArgumentException {
|
throws IllegalArgumentException {
|
||||||
|
|
||||||
// Make sure lengths are same
|
// Make sure lengths are same
|
||||||
if ((observed1.length < 2) || (observed1.length != observed2.length)) {
|
if (observed1.length < 2) {
|
||||||
throw new IllegalArgumentException(
|
throw MathRuntimeException.createIllegalArgumentException(
|
||||||
"oberved1, observed2 array lengths incorrect");
|
"observed array length = {0}, must be at least 2",
|
||||||
|
observed1.length);
|
||||||
}
|
}
|
||||||
|
if (observed1.length != observed2.length) {
|
||||||
|
throw MathRuntimeException.createIllegalArgumentException(
|
||||||
|
"dimension mismatch {0} != {1}",
|
||||||
|
observed1.length, observed2.length);
|
||||||
|
}
|
||||||
|
|
||||||
// Ensure non-negative counts
|
// Ensure non-negative counts
|
||||||
if (!isNonNegative(observed1) || !isNonNegative(observed2)) {
|
checkNonNegative(observed1);
|
||||||
throw new IllegalArgumentException(
|
checkNonNegative(observed2);
|
||||||
"observed counts must be non-negative");
|
|
||||||
}
|
|
||||||
// Compute and compare count sums
|
// Compute and compare count sums
|
||||||
long countSum1 = 0;
|
long countSum1 = 0;
|
||||||
long countSum2 = 0;
|
long countSum2 = 0;
|
||||||
|
@ -234,9 +247,13 @@ public class ChiSquareTestImpl implements UnknownDistributionChiSquareTest {
|
||||||
countSum2 += observed2[i];
|
countSum2 += observed2[i];
|
||||||
}
|
}
|
||||||
// Ensure neither sample is uniformly 0
|
// Ensure neither sample is uniformly 0
|
||||||
if (countSum1 * countSum2 == 0) {
|
if (countSum1 == 0) {
|
||||||
throw new IllegalArgumentException(
|
throw MathRuntimeException.createIllegalArgumentException(
|
||||||
"observed counts cannot all be 0");
|
"observed counts are all 0 in first observed array");
|
||||||
|
}
|
||||||
|
if (countSum2 == 0) {
|
||||||
|
throw MathRuntimeException.createIllegalArgumentException(
|
||||||
|
"observed counts are all 0 in second observed array");
|
||||||
}
|
}
|
||||||
// Compare and compute weight only if different
|
// Compare and compute weight only if different
|
||||||
unequalCounts = (countSum1 != countSum2);
|
unequalCounts = (countSum1 != countSum2);
|
||||||
|
@ -250,8 +267,8 @@ public class ChiSquareTestImpl implements UnknownDistributionChiSquareTest {
|
||||||
double obs2 = 0.0d;
|
double obs2 = 0.0d;
|
||||||
for (int i = 0; i < observed1.length; i++) {
|
for (int i = 0; i < observed1.length; i++) {
|
||||||
if (observed1[i] == 0 && observed2[i] == 0) {
|
if (observed1[i] == 0 && observed2[i] == 0) {
|
||||||
throw new IllegalArgumentException(
|
throw MathRuntimeException.createIllegalArgumentException(
|
||||||
"observed counts must not both be zero");
|
"observed counts are both zero for entry {0}", i);
|
||||||
} else {
|
} else {
|
||||||
obs1 = observed1[i];
|
obs1 = observed1[i];
|
||||||
obs2 = observed2[i];
|
obs2 = observed2[i];
|
||||||
|
@ -294,8 +311,9 @@ public class ChiSquareTestImpl implements UnknownDistributionChiSquareTest {
|
||||||
public boolean chiSquareTestDataSetsComparison(long[] observed1, long[] observed2,
|
public boolean chiSquareTestDataSetsComparison(long[] observed1, long[] observed2,
|
||||||
double alpha) throws IllegalArgumentException, MathException {
|
double alpha) throws IllegalArgumentException, MathException {
|
||||||
if ((alpha <= 0) || (alpha > 0.5)) {
|
if ((alpha <= 0) || (alpha > 0.5)) {
|
||||||
throw new IllegalArgumentException(
|
throw MathRuntimeException.createIllegalArgumentException(
|
||||||
"bad significance level: " + alpha);
|
"out of bounds significance level {0}, must be between {1} and {2}",
|
||||||
|
alpha, 0.0, 0.5);
|
||||||
}
|
}
|
||||||
return (chiSquareTestDataSetsComparison(observed1, observed2) < alpha);
|
return (chiSquareTestDataSetsComparison(observed1, observed2) < alpha);
|
||||||
}
|
}
|
||||||
|
@ -311,20 +329,19 @@ public class ChiSquareTestImpl implements UnknownDistributionChiSquareTest {
|
||||||
private void checkArray(long[][] in) throws IllegalArgumentException {
|
private void checkArray(long[][] in) throws IllegalArgumentException {
|
||||||
|
|
||||||
if (in.length < 2) {
|
if (in.length < 2) {
|
||||||
throw new IllegalArgumentException("Input table must have at least two rows");
|
throw MathRuntimeException.createIllegalArgumentException(
|
||||||
|
"invalid row dimension: {0} (must be at least 2)",
|
||||||
|
in.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in[0].length < 2) {
|
if (in[0].length < 2) {
|
||||||
throw new IllegalArgumentException("Input table must have at least two columns");
|
throw MathRuntimeException.createIllegalArgumentException(
|
||||||
|
"invalid column dimension: {0} (must be at least 2)",
|
||||||
|
in[0].length);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isRectangular(in)) {
|
checkRectangular(in);
|
||||||
throw new IllegalArgumentException("Input table must be rectangular");
|
checkNonNegative(in);
|
||||||
}
|
|
||||||
|
|
||||||
if (!isNonNegative(in)) {
|
|
||||||
throw new IllegalArgumentException("All entries in input 2-way table must be non-negative");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -338,66 +355,64 @@ public class ChiSquareTestImpl implements UnknownDistributionChiSquareTest {
|
||||||
* @throws NullPointerException if input array is null
|
* @throws NullPointerException if input array is null
|
||||||
* @throws ArrayIndexOutOfBoundsException if input array is empty
|
* @throws ArrayIndexOutOfBoundsException if input array is empty
|
||||||
*/
|
*/
|
||||||
private boolean isRectangular(long[][] in) {
|
private void checkRectangular(long[][] in) {
|
||||||
for (int i = 1; i < in.length; i++) {
|
for (int i = 1; i < in.length; i++) {
|
||||||
if (in[i].length != in[0].length) {
|
if (in[i].length != in[0].length) {
|
||||||
return false;
|
throw MathRuntimeException.createIllegalArgumentException(
|
||||||
|
"some rows have length {0} while others have length {1}",
|
||||||
|
in[i].length, in[0].length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true iff all entries of the input array are > 0.
|
* Check all entries of the input array are > 0.
|
||||||
* Returns true if the array is non-null, but empty
|
|
||||||
*
|
*
|
||||||
* @param in array to be tested
|
* @param in array to be tested
|
||||||
* @return true if all entries of the array are positive
|
* @exception IllegalArgumentException if one entry is not positive
|
||||||
* @throws NullPointerException if input array is null
|
|
||||||
*/
|
*/
|
||||||
private boolean isPositive(double[] in) {
|
private void checkPositive(double[] in) throws IllegalArgumentException {
|
||||||
for (int i = 0; i < in.length; i ++) {
|
for (int i = 0; i < in.length; i++) {
|
||||||
if (in[i] <= 0) {
|
if (in[i] <= 0) {
|
||||||
return false;
|
throw MathRuntimeException.createIllegalArgumentException(
|
||||||
|
"element {0} is not positive: {1}",
|
||||||
|
i, in[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true iff all entries of the input array are >= 0.
|
* Check all entries of the input array are >= 0.
|
||||||
* Returns true if the array is non-null, but empty
|
|
||||||
*
|
*
|
||||||
* @param in array to be tested
|
* @param in array to be tested
|
||||||
* @return true if all entries of the array are non-negative
|
* @exception IllegalArgumentException if one entry is negative
|
||||||
* @throws NullPointerException if input array is null
|
|
||||||
*/
|
*/
|
||||||
private boolean isNonNegative(long[] in) {
|
private void checkNonNegative(long[] in) throws IllegalArgumentException {
|
||||||
for (int i = 0; i < in.length; i ++) {
|
for (int i = 0; i < in.length; i++) {
|
||||||
if (in[i] < 0) {
|
if (in[i] < 0) {
|
||||||
return false;
|
throw MathRuntimeException.createIllegalArgumentException(
|
||||||
|
"element {0} is negative: {1}",
|
||||||
|
i, in[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true iff all entries of (all subarrays of) the input array are >= 0.
|
* Check all entries of the input array are >= 0.
|
||||||
* Returns true if the array is non-null, but empty
|
|
||||||
*
|
*
|
||||||
* @param in array to be tested
|
* @param in array to be tested
|
||||||
* @return true if all entries of the array are non-negative
|
* @exception IllegalArgumentException if one entry is negative
|
||||||
* @throws NullPointerException if input array is null
|
|
||||||
*/
|
*/
|
||||||
private boolean isNonNegative(long[][] in) {
|
private void checkNonNegative(long[][] in) throws IllegalArgumentException {
|
||||||
for (int i = 0; i < in.length; i ++) {
|
for (int i = 0; i < in.length; i ++) {
|
||||||
for (int j = 0; j < in[i].length; j++) {
|
for (int j = 0; j < in[i].length; j++) {
|
||||||
if (in[i][j] < 0) {
|
if (in[i][j] < 0) {
|
||||||
return false;
|
throw MathRuntimeException.createIllegalArgumentException(
|
||||||
|
"element ({0}, {1}) is negative: {2}",
|
||||||
|
i, j, in[i][j]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -19,6 +19,7 @@ package org.apache.commons.math.stat.inference;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
import org.apache.commons.math.MathException;
|
import org.apache.commons.math.MathException;
|
||||||
|
import org.apache.commons.math.MathRuntimeException;
|
||||||
import org.apache.commons.math.distribution.FDistribution;
|
import org.apache.commons.math.distribution.FDistribution;
|
||||||
import org.apache.commons.math.distribution.FDistributionImpl;
|
import org.apache.commons.math.distribution.FDistributionImpl;
|
||||||
import org.apache.commons.math.stat.descriptive.summary.Sum;
|
import org.apache.commons.math.stat.descriptive.summary.Sum;
|
||||||
|
@ -100,7 +101,9 @@ public class OneWayAnovaImpl implements OneWayAnova {
|
||||||
public boolean anovaTest(Collection<double[]> categoryData, double alpha)
|
public boolean anovaTest(Collection<double[]> categoryData, double alpha)
|
||||||
throws IllegalArgumentException, MathException {
|
throws IllegalArgumentException, MathException {
|
||||||
if ((alpha <= 0) || (alpha > 0.5)) {
|
if ((alpha <= 0) || (alpha > 0.5)) {
|
||||||
throw new IllegalArgumentException("bad significance level: " + alpha);
|
throw MathRuntimeException.createIllegalArgumentException(
|
||||||
|
"out of bounds significance level {0}, must be between {1} and {2}",
|
||||||
|
alpha, 0, 0.5);
|
||||||
}
|
}
|
||||||
return (anovaPValue(categoryData) < alpha);
|
return (anovaPValue(categoryData) < alpha);
|
||||||
}
|
}
|
||||||
|
@ -121,15 +124,17 @@ public class OneWayAnovaImpl implements OneWayAnova {
|
||||||
|
|
||||||
// check if we have enough categories
|
// check if we have enough categories
|
||||||
if (categoryData.size() < 2) {
|
if (categoryData.size() < 2) {
|
||||||
throw new IllegalArgumentException(
|
throw MathRuntimeException.createIllegalArgumentException(
|
||||||
"ANOVA: two or more categories required");
|
"two or more categories required, got {0}",
|
||||||
|
categoryData.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if each category has enough data and all is double[]
|
// check if each category has enough data and all is double[]
|
||||||
for (double[] array : categoryData) {
|
for (double[] array : categoryData) {
|
||||||
if (array.length <= 1) {
|
if (array.length <= 1) {
|
||||||
throw new IllegalArgumentException(
|
throw MathRuntimeException.createIllegalArgumentException(
|
||||||
"ANOVA: one element of categoryData has fewer than 2 values.");
|
"two or more values required in each category, one has {0}",
|
||||||
|
array.length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
package org.apache.commons.math.stat.inference;
|
package org.apache.commons.math.stat.inference;
|
||||||
|
|
||||||
import org.apache.commons.math.MathException;
|
import org.apache.commons.math.MathException;
|
||||||
|
import org.apache.commons.math.MathRuntimeException;
|
||||||
import org.apache.commons.math.distribution.TDistribution;
|
import org.apache.commons.math.distribution.TDistribution;
|
||||||
import org.apache.commons.math.distribution.TDistributionImpl;
|
import org.apache.commons.math.distribution.TDistributionImpl;
|
||||||
import org.apache.commons.math.stat.StatUtils;
|
import org.apache.commons.math.stat.StatUtils;
|
||||||
|
@ -75,10 +76,8 @@ public class TTestImpl implements TTest {
|
||||||
*/
|
*/
|
||||||
public double pairedT(double[] sample1, double[] sample2)
|
public double pairedT(double[] sample1, double[] sample2)
|
||||||
throws IllegalArgumentException, MathException {
|
throws IllegalArgumentException, MathException {
|
||||||
if ((sample1 == null) || (sample2 == null ||
|
checkSampleData(sample1);
|
||||||
Math.min(sample1.length, sample2.length) < 2)) {
|
checkSampleData(sample2);
|
||||||
throw new IllegalArgumentException("insufficient data for t statistic");
|
|
||||||
}
|
|
||||||
double meanDifference = StatUtils.meanDifference(sample1, sample2);
|
double meanDifference = StatUtils.meanDifference(sample1, sample2);
|
||||||
return t(meanDifference, 0,
|
return t(meanDifference, 0,
|
||||||
StatUtils.varianceDifference(sample1, sample2, meanDifference),
|
StatUtils.varianceDifference(sample1, sample2, meanDifference),
|
||||||
|
@ -160,9 +159,7 @@ public class TTestImpl implements TTest {
|
||||||
*/
|
*/
|
||||||
public boolean pairedTTest(double[] sample1, double[] sample2, double alpha)
|
public boolean pairedTTest(double[] sample1, double[] sample2, double alpha)
|
||||||
throws IllegalArgumentException, MathException {
|
throws IllegalArgumentException, MathException {
|
||||||
if ((alpha <= 0) || (alpha > 0.5)) {
|
checkSignificanceLevel(alpha);
|
||||||
throw new IllegalArgumentException("bad significance level: " + alpha);
|
|
||||||
}
|
|
||||||
return (pairedTTest(sample1, sample2) < alpha);
|
return (pairedTTest(sample1, sample2) < alpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,9 +180,7 @@ public class TTestImpl implements TTest {
|
||||||
*/
|
*/
|
||||||
public double t(double mu, double[] observed)
|
public double t(double mu, double[] observed)
|
||||||
throws IllegalArgumentException {
|
throws IllegalArgumentException {
|
||||||
if ((observed == null) || (observed.length < 2)) {
|
checkSampleData(observed);
|
||||||
throw new IllegalArgumentException("insufficient data for t statistic");
|
|
||||||
}
|
|
||||||
return t(StatUtils.mean(observed), mu, StatUtils.variance(observed),
|
return t(StatUtils.mean(observed), mu, StatUtils.variance(observed),
|
||||||
observed.length);
|
observed.length);
|
||||||
}
|
}
|
||||||
|
@ -208,9 +203,7 @@ public class TTestImpl implements TTest {
|
||||||
*/
|
*/
|
||||||
public double t(double mu, StatisticalSummary sampleStats)
|
public double t(double mu, StatisticalSummary sampleStats)
|
||||||
throws IllegalArgumentException {
|
throws IllegalArgumentException {
|
||||||
if ((sampleStats == null) || (sampleStats.getN() < 2)) {
|
checkSampleData(sampleStats);
|
||||||
throw new IllegalArgumentException("insufficient data for t statistic");
|
|
||||||
}
|
|
||||||
return t(sampleStats.getMean(), mu, sampleStats.getVariance(),
|
return t(sampleStats.getMean(), mu, sampleStats.getVariance(),
|
||||||
sampleStats.getN());
|
sampleStats.getN());
|
||||||
}
|
}
|
||||||
|
@ -250,10 +243,8 @@ public class TTestImpl implements TTest {
|
||||||
*/
|
*/
|
||||||
public double homoscedasticT(double[] sample1, double[] sample2)
|
public double homoscedasticT(double[] sample1, double[] sample2)
|
||||||
throws IllegalArgumentException {
|
throws IllegalArgumentException {
|
||||||
if ((sample1 == null) || (sample2 == null ||
|
checkSampleData(sample1);
|
||||||
Math.min(sample1.length, sample2.length) < 2)) {
|
checkSampleData(sample2);
|
||||||
throw new IllegalArgumentException("insufficient data for t statistic");
|
|
||||||
}
|
|
||||||
return homoscedasticT(StatUtils.mean(sample1), StatUtils.mean(sample2),
|
return homoscedasticT(StatUtils.mean(sample1), StatUtils.mean(sample2),
|
||||||
StatUtils.variance(sample1), StatUtils.variance(sample2),
|
StatUtils.variance(sample1), StatUtils.variance(sample2),
|
||||||
sample1.length, sample2.length);
|
sample1.length, sample2.length);
|
||||||
|
@ -289,10 +280,8 @@ public class TTestImpl implements TTest {
|
||||||
*/
|
*/
|
||||||
public double t(double[] sample1, double[] sample2)
|
public double t(double[] sample1, double[] sample2)
|
||||||
throws IllegalArgumentException {
|
throws IllegalArgumentException {
|
||||||
if ((sample1 == null) || (sample2 == null ||
|
checkSampleData(sample1);
|
||||||
Math.min(sample1.length, sample2.length) < 2)) {
|
checkSampleData(sample2);
|
||||||
throw new IllegalArgumentException("insufficient data for t statistic");
|
|
||||||
}
|
|
||||||
return t(StatUtils.mean(sample1), StatUtils.mean(sample2),
|
return t(StatUtils.mean(sample1), StatUtils.mean(sample2),
|
||||||
StatUtils.variance(sample1), StatUtils.variance(sample2),
|
StatUtils.variance(sample1), StatUtils.variance(sample2),
|
||||||
sample1.length, sample2.length);
|
sample1.length, sample2.length);
|
||||||
|
@ -330,13 +319,10 @@ public class TTestImpl implements TTest {
|
||||||
* @throws IllegalArgumentException if the precondition is not met
|
* @throws IllegalArgumentException if the precondition is not met
|
||||||
*/
|
*/
|
||||||
public double t(StatisticalSummary sampleStats1,
|
public double t(StatisticalSummary sampleStats1,
|
||||||
StatisticalSummary sampleStats2)
|
StatisticalSummary sampleStats2)
|
||||||
throws IllegalArgumentException {
|
throws IllegalArgumentException {
|
||||||
if ((sampleStats1 == null) ||
|
checkSampleData(sampleStats1);
|
||||||
(sampleStats2 == null ||
|
checkSampleData(sampleStats2);
|
||||||
Math.min(sampleStats1.getN(), sampleStats2.getN()) < 2)) {
|
|
||||||
throw new IllegalArgumentException("insufficient data for t statistic");
|
|
||||||
}
|
|
||||||
return t(sampleStats1.getMean(), sampleStats2.getMean(),
|
return t(sampleStats1.getMean(), sampleStats2.getMean(),
|
||||||
sampleStats1.getVariance(), sampleStats2.getVariance(),
|
sampleStats1.getVariance(), sampleStats2.getVariance(),
|
||||||
sampleStats1.getN(), sampleStats2.getN());
|
sampleStats1.getN(), sampleStats2.getN());
|
||||||
|
@ -380,11 +366,8 @@ public class TTestImpl implements TTest {
|
||||||
public double homoscedasticT(StatisticalSummary sampleStats1,
|
public double homoscedasticT(StatisticalSummary sampleStats1,
|
||||||
StatisticalSummary sampleStats2)
|
StatisticalSummary sampleStats2)
|
||||||
throws IllegalArgumentException {
|
throws IllegalArgumentException {
|
||||||
if ((sampleStats1 == null) ||
|
checkSampleData(sampleStats1);
|
||||||
(sampleStats2 == null ||
|
checkSampleData(sampleStats2);
|
||||||
Math.min(sampleStats1.getN(), sampleStats2.getN()) < 2)) {
|
|
||||||
throw new IllegalArgumentException("insufficient data for t statistic");
|
|
||||||
}
|
|
||||||
return homoscedasticT(sampleStats1.getMean(), sampleStats2.getMean(),
|
return homoscedasticT(sampleStats1.getMean(), sampleStats2.getMean(),
|
||||||
sampleStats1.getVariance(), sampleStats2.getVariance(),
|
sampleStats1.getVariance(), sampleStats2.getVariance(),
|
||||||
sampleStats1.getN(), sampleStats2.getN());
|
sampleStats1.getN(), sampleStats2.getN());
|
||||||
|
@ -418,9 +401,7 @@ public class TTestImpl implements TTest {
|
||||||
*/
|
*/
|
||||||
public double tTest(double mu, double[] sample)
|
public double tTest(double mu, double[] sample)
|
||||||
throws IllegalArgumentException, MathException {
|
throws IllegalArgumentException, MathException {
|
||||||
if ((sample == null) || (sample.length < 2)) {
|
checkSampleData(sample);
|
||||||
throw new IllegalArgumentException("insufficient data for t statistic");
|
|
||||||
}
|
|
||||||
return tTest( StatUtils.mean(sample), mu, StatUtils.variance(sample),
|
return tTest( StatUtils.mean(sample), mu, StatUtils.variance(sample),
|
||||||
sample.length);
|
sample.length);
|
||||||
}
|
}
|
||||||
|
@ -462,9 +443,7 @@ public class TTestImpl implements TTest {
|
||||||
*/
|
*/
|
||||||
public boolean tTest(double mu, double[] sample, double alpha)
|
public boolean tTest(double mu, double[] sample, double alpha)
|
||||||
throws IllegalArgumentException, MathException {
|
throws IllegalArgumentException, MathException {
|
||||||
if ((alpha <= 0) || (alpha > 0.5)) {
|
checkSignificanceLevel(alpha);
|
||||||
throw new IllegalArgumentException("bad significance level: " + alpha);
|
|
||||||
}
|
|
||||||
return (tTest(mu, sample) < alpha);
|
return (tTest(mu, sample) < alpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -498,9 +477,7 @@ public class TTestImpl implements TTest {
|
||||||
*/
|
*/
|
||||||
public double tTest(double mu, StatisticalSummary sampleStats)
|
public double tTest(double mu, StatisticalSummary sampleStats)
|
||||||
throws IllegalArgumentException, MathException {
|
throws IllegalArgumentException, MathException {
|
||||||
if ((sampleStats == null) || (sampleStats.getN() < 2)) {
|
checkSampleData(sampleStats);
|
||||||
throw new IllegalArgumentException("insufficient data for t statistic");
|
|
||||||
}
|
|
||||||
return tTest(sampleStats.getMean(), mu, sampleStats.getVariance(),
|
return tTest(sampleStats.getMean(), mu, sampleStats.getVariance(),
|
||||||
sampleStats.getN());
|
sampleStats.getN());
|
||||||
}
|
}
|
||||||
|
@ -544,9 +521,7 @@ public class TTestImpl implements TTest {
|
||||||
public boolean tTest( double mu, StatisticalSummary sampleStats,
|
public boolean tTest( double mu, StatisticalSummary sampleStats,
|
||||||
double alpha)
|
double alpha)
|
||||||
throws IllegalArgumentException, MathException {
|
throws IllegalArgumentException, MathException {
|
||||||
if ((alpha <= 0) || (alpha > 0.5)) {
|
checkSignificanceLevel(alpha);
|
||||||
throw new IllegalArgumentException("bad significance level: " + alpha);
|
|
||||||
}
|
|
||||||
return (tTest(mu, sampleStats) < alpha);
|
return (tTest(mu, sampleStats) < alpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -588,10 +563,8 @@ public class TTestImpl implements TTest {
|
||||||
*/
|
*/
|
||||||
public double tTest(double[] sample1, double[] sample2)
|
public double tTest(double[] sample1, double[] sample2)
|
||||||
throws IllegalArgumentException, MathException {
|
throws IllegalArgumentException, MathException {
|
||||||
if ((sample1 == null) || (sample2 == null ||
|
checkSampleData(sample1);
|
||||||
Math.min(sample1.length, sample2.length) < 2)) {
|
checkSampleData(sample2);
|
||||||
throw new IllegalArgumentException("insufficient data");
|
|
||||||
}
|
|
||||||
return tTest(StatUtils.mean(sample1), StatUtils.mean(sample2),
|
return tTest(StatUtils.mean(sample1), StatUtils.mean(sample2),
|
||||||
StatUtils.variance(sample1), StatUtils.variance(sample2),
|
StatUtils.variance(sample1), StatUtils.variance(sample2),
|
||||||
sample1.length, sample2.length);
|
sample1.length, sample2.length);
|
||||||
|
@ -632,10 +605,8 @@ public class TTestImpl implements TTest {
|
||||||
*/
|
*/
|
||||||
public double homoscedasticTTest(double[] sample1, double[] sample2)
|
public double homoscedasticTTest(double[] sample1, double[] sample2)
|
||||||
throws IllegalArgumentException, MathException {
|
throws IllegalArgumentException, MathException {
|
||||||
if ((sample1 == null) || (sample2 == null ||
|
checkSampleData(sample1);
|
||||||
Math.min(sample1.length, sample2.length) < 2)) {
|
checkSampleData(sample2);
|
||||||
throw new IllegalArgumentException("insufficient data");
|
|
||||||
}
|
|
||||||
return homoscedasticTTest(StatUtils.mean(sample1),
|
return homoscedasticTTest(StatUtils.mean(sample1),
|
||||||
StatUtils.mean(sample2), StatUtils.variance(sample1),
|
StatUtils.mean(sample2), StatUtils.variance(sample1),
|
||||||
StatUtils.variance(sample2), sample1.length,
|
StatUtils.variance(sample2), sample1.length,
|
||||||
|
@ -697,9 +668,7 @@ public class TTestImpl implements TTest {
|
||||||
public boolean tTest(double[] sample1, double[] sample2,
|
public boolean tTest(double[] sample1, double[] sample2,
|
||||||
double alpha)
|
double alpha)
|
||||||
throws IllegalArgumentException, MathException {
|
throws IllegalArgumentException, MathException {
|
||||||
if ((alpha <= 0) || (alpha > 0.5)) {
|
checkSignificanceLevel(alpha);
|
||||||
throw new IllegalArgumentException("bad significance level: " + alpha);
|
|
||||||
}
|
|
||||||
return (tTest(sample1, sample2) < alpha);
|
return (tTest(sample1, sample2) < alpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -757,9 +726,7 @@ public class TTestImpl implements TTest {
|
||||||
public boolean homoscedasticTTest(double[] sample1, double[] sample2,
|
public boolean homoscedasticTTest(double[] sample1, double[] sample2,
|
||||||
double alpha)
|
double alpha)
|
||||||
throws IllegalArgumentException, MathException {
|
throws IllegalArgumentException, MathException {
|
||||||
if ((alpha <= 0) || (alpha > 0.5)) {
|
checkSignificanceLevel(alpha);
|
||||||
throw new IllegalArgumentException("bad significance level: " + alpha);
|
|
||||||
}
|
|
||||||
return (homoscedasticTTest(sample1, sample2) < alpha);
|
return (homoscedasticTTest(sample1, sample2) < alpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -799,10 +766,8 @@ public class TTestImpl implements TTest {
|
||||||
*/
|
*/
|
||||||
public double tTest(StatisticalSummary sampleStats1, StatisticalSummary sampleStats2)
|
public double tTest(StatisticalSummary sampleStats1, StatisticalSummary sampleStats2)
|
||||||
throws IllegalArgumentException, MathException {
|
throws IllegalArgumentException, MathException {
|
||||||
if ((sampleStats1 == null) || (sampleStats2 == null ||
|
checkSampleData(sampleStats1);
|
||||||
Math.min(sampleStats1.getN(), sampleStats2.getN()) < 2)) {
|
checkSampleData(sampleStats2);
|
||||||
throw new IllegalArgumentException("insufficient data for t statistic");
|
|
||||||
}
|
|
||||||
return tTest(sampleStats1.getMean(), sampleStats2.getMean(), sampleStats1.getVariance(),
|
return tTest(sampleStats1.getMean(), sampleStats2.getMean(), sampleStats1.getVariance(),
|
||||||
sampleStats2.getVariance(), sampleStats1.getN(),
|
sampleStats2.getVariance(), sampleStats1.getN(),
|
||||||
sampleStats2.getN());
|
sampleStats2.getN());
|
||||||
|
@ -842,12 +807,10 @@ public class TTestImpl implements TTest {
|
||||||
* @throws MathException if an error occurs computing the p-value
|
* @throws MathException if an error occurs computing the p-value
|
||||||
*/
|
*/
|
||||||
public double homoscedasticTTest(StatisticalSummary sampleStats1,
|
public double homoscedasticTTest(StatisticalSummary sampleStats1,
|
||||||
StatisticalSummary sampleStats2)
|
StatisticalSummary sampleStats2)
|
||||||
throws IllegalArgumentException, MathException {
|
throws IllegalArgumentException, MathException {
|
||||||
if ((sampleStats1 == null) || (sampleStats2 == null ||
|
checkSampleData(sampleStats1);
|
||||||
Math.min(sampleStats1.getN(), sampleStats2.getN()) < 2)) {
|
checkSampleData(sampleStats2);
|
||||||
throw new IllegalArgumentException("insufficient data for t statistic");
|
|
||||||
}
|
|
||||||
return homoscedasticTTest(sampleStats1.getMean(),
|
return homoscedasticTTest(sampleStats1.getMean(),
|
||||||
sampleStats2.getMean(), sampleStats1.getVariance(),
|
sampleStats2.getMean(), sampleStats1.getVariance(),
|
||||||
sampleStats2.getVariance(), sampleStats1.getN(),
|
sampleStats2.getVariance(), sampleStats1.getN(),
|
||||||
|
@ -910,9 +873,7 @@ public class TTestImpl implements TTest {
|
||||||
public boolean tTest(StatisticalSummary sampleStats1,
|
public boolean tTest(StatisticalSummary sampleStats1,
|
||||||
StatisticalSummary sampleStats2, double alpha)
|
StatisticalSummary sampleStats2, double alpha)
|
||||||
throws IllegalArgumentException, MathException {
|
throws IllegalArgumentException, MathException {
|
||||||
if ((alpha <= 0) || (alpha > 0.5)) {
|
checkSignificanceLevel(alpha);
|
||||||
throw new IllegalArgumentException("bad significance level: " + alpha);
|
|
||||||
}
|
|
||||||
return (tTest(sampleStats1, sampleStats2) < alpha);
|
return (tTest(sampleStats1, sampleStats2) < alpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1056,4 +1017,44 @@ public class TTestImpl implements TTest {
|
||||||
public void setDistribution(TDistribution value) {
|
public void setDistribution(TDistribution value) {
|
||||||
distribution = value;
|
distribution = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Check significance level.
|
||||||
|
* @param alpha significance level
|
||||||
|
* @exception IllegalArgumentException if significance level is out of bounds
|
||||||
|
*/
|
||||||
|
private void checkSignificanceLevel(final double alpha)
|
||||||
|
throws IllegalArgumentException {
|
||||||
|
if ((alpha <= 0) || (alpha > 0.5)) {
|
||||||
|
throw MathRuntimeException.createIllegalArgumentException(
|
||||||
|
"out of bounds significance level {0}, must be between {1} and {2}",
|
||||||
|
alpha, 0.0, 0.5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Check sample data.
|
||||||
|
* @param data sample data
|
||||||
|
* @exception IllegalArgumentException if there is not enough sample data
|
||||||
|
*/
|
||||||
|
private void checkSampleData(final double[] data)
|
||||||
|
throws IllegalArgumentException {
|
||||||
|
if ((data == null) || (data.length < 2)) {
|
||||||
|
throw MathRuntimeException.createIllegalArgumentException(
|
||||||
|
"insufficient data for t statistic, needs at least 2, got {0}",
|
||||||
|
(data == null) ? 0 : data.length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Check sample data.
|
||||||
|
* @param stat statistical summary
|
||||||
|
* @exception IllegalArgumentException if there is not enough sample data
|
||||||
|
*/
|
||||||
|
private void checkSampleData(final StatisticalSummary stat)
|
||||||
|
throws IllegalArgumentException {
|
||||||
|
if ((stat == null) || (stat.getN() < 2)) {
|
||||||
|
throw MathRuntimeException.createIllegalArgumentException(
|
||||||
|
"insufficient data for t statistic, needs at least 2, got {0}",
|
||||||
|
(stat == null) ? 0 : stat.getN());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.commons.math.stat.regression;
|
package org.apache.commons.math.stat.regression;
|
||||||
|
|
||||||
|
import org.apache.commons.math.MathRuntimeException;
|
||||||
import org.apache.commons.math.linear.RealMatrix;
|
import org.apache.commons.math.linear.RealMatrix;
|
||||||
import org.apache.commons.math.linear.RealMatrixImpl;
|
import org.apache.commons.math.linear.RealMatrixImpl;
|
||||||
import org.apache.commons.math.linear.RealVector;
|
import org.apache.commons.math.linear.RealVector;
|
||||||
|
@ -85,15 +86,11 @@ public abstract class AbstractMultipleLinearRegression implements
|
||||||
* compatible for the regression
|
* compatible for the regression
|
||||||
*/
|
*/
|
||||||
protected void validateSampleData(double[][] x, double[] y) {
|
protected void validateSampleData(double[][] x, double[] y) {
|
||||||
if (x == null) {
|
if ((x == null) || (y == null) || (x.length != y.length)) {
|
||||||
throw new IllegalArgumentException("The regressors matrix x cannot be null.");
|
throw MathRuntimeException.createIllegalArgumentException(
|
||||||
}
|
"dimension mismatch {0} != {1}",
|
||||||
if (y == null) {
|
(x == null) ? 0 : x.length,
|
||||||
throw new IllegalArgumentException("The regressand vector y cannot be null.");
|
(y == null) ? 0 : y.length);
|
||||||
}
|
|
||||||
if (x.length != y.length) {
|
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"The regressors matrix x columns must have the same length of the regressand vector y");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,15 +103,14 @@ public abstract class AbstractMultipleLinearRegression implements
|
||||||
* matrix are not compatible for the regression
|
* matrix are not compatible for the regression
|
||||||
*/
|
*/
|
||||||
protected void validateCovarianceData(double[][] x, double[][] covariance) {
|
protected void validateCovarianceData(double[][] x, double[][] covariance) {
|
||||||
if (covariance == null) {
|
|
||||||
throw new IllegalArgumentException("Covariance matrix cannot be null.");
|
|
||||||
}
|
|
||||||
if (x.length != covariance.length) {
|
if (x.length != covariance.length) {
|
||||||
throw new IllegalArgumentException(
|
throw MathRuntimeException.createIllegalArgumentException(
|
||||||
"The regressors matrix x columns must have the same length of the covariance matrix columns");
|
"dimension mismatch {0} != {1}", x.length, covariance.length);
|
||||||
}
|
}
|
||||||
if (covariance.length > 0 && covariance.length != covariance[0].length) {
|
if (covariance.length > 0 && covariance.length != covariance[0].length) {
|
||||||
throw new IllegalArgumentException("The covariance matrix must be square");
|
throw MathRuntimeException.createIllegalArgumentException(
|
||||||
|
"a {0}x{1} matrix was provided instead of a square matrix",
|
||||||
|
covariance.length, covariance[0].length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.commons.math.stat.regression;
|
package org.apache.commons.math.stat.regression;
|
||||||
|
|
||||||
|
import org.apache.commons.math.MathRuntimeException;
|
||||||
import org.apache.commons.math.linear.RealMatrix;
|
import org.apache.commons.math.linear.RealMatrix;
|
||||||
import org.apache.commons.math.linear.RealMatrixImpl;
|
import org.apache.commons.math.linear.RealMatrixImpl;
|
||||||
import org.apache.commons.math.linear.RealVector;
|
import org.apache.commons.math.linear.RealVector;
|
||||||
|
@ -199,10 +200,7 @@ public class OLSMultipleLinearRegression extends AbstractMultipleLinearRegressio
|
||||||
*/
|
*/
|
||||||
private static RealVector solveUpperTriangular(RealMatrix coefficients,
|
private static RealVector solveUpperTriangular(RealMatrix coefficients,
|
||||||
RealVector constants) {
|
RealVector constants) {
|
||||||
if (!isUpperTriangular(coefficients, 1E-12)) {
|
checkUpperTriangular(coefficients, 1E-12);
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"Coefficients is not upper-triangular");
|
|
||||||
}
|
|
||||||
int length = coefficients.getColumnDimension();
|
int length = coefficients.getColumnDimension();
|
||||||
double x[] = new double[length];
|
double x[] = new double[length];
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
|
@ -217,7 +215,7 @@ public class OLSMultipleLinearRegression extends AbstractMultipleLinearRegressio
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Returns true iff m is an upper-triangular matrix.</p>
|
* <p>Check if a matrix is upper-triangular.</p>
|
||||||
*
|
*
|
||||||
* <p>Makes sure all below-diagonal elements are within epsilon of 0.</p>
|
* <p>Makes sure all below-diagonal elements are within epsilon of 0.</p>
|
||||||
*
|
*
|
||||||
|
@ -225,20 +223,20 @@ public class OLSMultipleLinearRegression extends AbstractMultipleLinearRegressio
|
||||||
* @param epsilon maximum allowable absolute value for elements below
|
* @param epsilon maximum allowable absolute value for elements below
|
||||||
* the main diagonal
|
* the main diagonal
|
||||||
*
|
*
|
||||||
* @return true if m is upper-triangular; false otherwise
|
* @throws IllegalArgumentException if m is not upper-triangular
|
||||||
* @throws NullPointerException if m is null
|
|
||||||
*/
|
*/
|
||||||
private static boolean isUpperTriangular(RealMatrix m, double epsilon) {
|
private static void checkUpperTriangular(RealMatrix m, double epsilon) {
|
||||||
int nCols = m.getColumnDimension();
|
int nCols = m.getColumnDimension();
|
||||||
int nRows = m.getRowDimension();
|
int nRows = m.getRowDimension();
|
||||||
for (int r = 0; r < nRows; r++) {
|
for (int r = 0; r < nRows; r++) {
|
||||||
int bound = Math.min(r, nCols);
|
int bound = Math.min(r, nCols);
|
||||||
for (int c = 0; c < bound; c++) {
|
for (int c = 0; c < bound; c++) {
|
||||||
if (Math.abs(m.getEntry(r, c)) > epsilon) {
|
if (Math.abs(m.getEntry(r, c)) > epsilon) {
|
||||||
return false;
|
throw MathRuntimeException.createIllegalArgumentException(
|
||||||
|
"matrix is not upper-triangular, entry ({0}, {1}) = {2} is too large",
|
||||||
|
r, c, m.getEntry(r, c));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -548,8 +548,8 @@ public class SimpleRegression implements Serializable {
|
||||||
throws MathException {
|
throws MathException {
|
||||||
if (alpha >= 1 || alpha <= 0) {
|
if (alpha >= 1 || alpha <= 0) {
|
||||||
throw MathRuntimeException.createIllegalArgumentException(
|
throw MathRuntimeException.createIllegalArgumentException(
|
||||||
"out of bounds significance level {0}, must be in (0, 1)",
|
"out of bounds significance level {0}, must be between {1} and {2}",
|
||||||
alpha);
|
alpha, 0.0, 1.0);
|
||||||
}
|
}
|
||||||
return getSlopeStdErr() *
|
return getSlopeStdErr() *
|
||||||
distribution.inverseCumulativeProbability(1d - alpha / 2d);
|
distribution.inverseCumulativeProbability(1d - alpha / 2d);
|
||||||
|
|
|
@ -39,6 +39,9 @@ The <action> type attribute can be add,update,fix,remove.
|
||||||
</properties>
|
</properties>
|
||||||
<body>
|
<body>
|
||||||
<release version="2.0" date="TBD" description="TBD">
|
<release version="2.0" date="TBD" description="TBD">
|
||||||
|
<action dev="luc" type="update" >
|
||||||
|
Completed internationalization of all error messages
|
||||||
|
</action>
|
||||||
<action dev="luc" type="add" issue="MATH-266" due-to="Benjamin McCann">
|
<action dev="luc" type="add" issue="MATH-266" due-to="Benjamin McCann">
|
||||||
Added a clustering package with an implementation of the k-means++ algorithm
|
Added a clustering package with an implementation of the k-means++ algorithm
|
||||||
</action>
|
</action>
|
||||||
|
|
Loading…
Reference in New Issue