本文整理汇总了Java中org.apache.commons.math3.exception.util.LocalizedFormats.INSUFFICIENT_DIMENSION属性的典型用法代码示例。如果您正苦于以下问题:Java LocalizedFormats.INSUFFICIENT_DIMENSION属性的具体用法?Java LocalizedFormats.INSUFFICIENT_DIMENSION怎么用?Java LocalizedFormats.INSUFFICIENT_DIMENSION使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.apache.commons.math3.exception.util.LocalizedFormats
的用法示例。
在下文中一共展示了LocalizedFormats.INSUFFICIENT_DIMENSION属性的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: correlation
/**
* Computes the Spearman's rank correlation coefficient between the two arrays.
*
* @param xArray first data array
* @param yArray second data array
* @return Returns Spearman's rank correlation coefficient for the two arrays
* @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) {
if (xArray.length != yArray.length) {
throw new DimensionMismatchException(xArray.length, yArray.length);
} else if (xArray.length < 2) {
throw new MathIllegalArgumentException(LocalizedFormats.INSUFFICIENT_DIMENSION,
xArray.length, 2);
} else {
double[] x = xArray;
double[] y = yArray;
if (rankingAlgorithm instanceof NaturalRanking &&
NaNStrategy.REMOVED == ((NaturalRanking) rankingAlgorithm).getNanStrategy()) {
final Set<Integer> nanPositions = new HashSet<Integer>();
nanPositions.addAll(getNaNPositions(xArray));
nanPositions.addAll(getNaNPositions(yArray));
x = removeValues(xArray, nanPositions);
y = removeValues(yArray, nanPositions);
}
return new PearsonsCorrelation().correlation(rankingAlgorithm.rank(x), rankingAlgorithm.rank(y));
}
}
示例2: sumDifference
/**
* Returns the sum of the (signed) differences between corresponding elements of the
* input arrays -- i.e., sum(sample1[i] - sample2[i]).
*
* @param sample1 the first array
* @param sample2 the second array
* @return sum of paired differences
* @throws DimensionMismatchException if the arrays do not have the same
* (positive) length.
* @throws NoDataException if the sample arrays are empty.
*/
public static double sumDifference(final double[] sample1, final double[] sample2)
throws DimensionMismatchException, NoDataException {
int n = sample1.length;
if (n != sample2.length) {
throw new DimensionMismatchException(n, sample2.length);
}
if (n <= 0) {
throw new NoDataException(LocalizedFormats.INSUFFICIENT_DIMENSION);
}
double result = 0;
for (int i = 0; i < n; i++) {
result += sample1[i] - sample2[i];
}
return result;
}
示例3: getResult
/**
* Return the current covariance estimate.
*
* @return the current covariance
* @throws NumberIsTooSmallException if the number of observations
* is < 2
*/
public double getResult() throws NumberIsTooSmallException {
if (n < 2) {
throw new NumberIsTooSmallException(LocalizedFormats.INSUFFICIENT_DIMENSION,
n, 2, true);
}
if (biasCorrected) {
return covarianceNumerator / (n - 1d);
} else {
return covarianceNumerator / n;
}
}
示例4: correlation
/**
* Computes the Pearson's product-moment correlation coefficient between two arrays.
*
* <p>Throws MathIllegalArgumentException if the arrays do not have the same length
* or their common length is less than 2. Returns {@code NaN} if either of the arrays
* has zero variance (i.e., if one of the arrays does not contain at least two distinct
* values).</p>
*
* @param xArray first data array
* @param yArray second data array
* @return Returns Pearson's correlation coefficient for the two arrays
* @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) {
SimpleRegression regression = new SimpleRegression();
if (xArray.length != yArray.length) {
throw new DimensionMismatchException(xArray.length, yArray.length);
} else if (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]);
}
return regression.getR();
}
}