本文整理汇总了Java中org.apache.commons.math.MathRuntimeException.createIllegalArgumentException方法的典型用法代码示例。如果您正苦于以下问题:Java MathRuntimeException.createIllegalArgumentException方法的具体用法?Java MathRuntimeException.createIllegalArgumentException怎么用?Java MathRuntimeException.createIllegalArgumentException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.math.MathRuntimeException
的用法示例。
在下文中一共展示了MathRuntimeException.createIllegalArgumentException方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: covariance
import org.apache.commons.math.MathRuntimeException; //导入方法依赖的package包/类
/**
* Computes the covariance between the two arrays.
*
* <p>Array lengths must match and the common length must be at least 2.</p>
*
* @param xArray first data array
* @param yArray second data array
* @param biasCorrected if true, returned value will be bias-corrected
* @return returns the covariance for the two arrays
* @throws IllegalArgumentException if the arrays lengths do not match or
* there is insufficient data
*/
public double covariance(final double[] xArray, final double[] yArray, boolean biasCorrected)
throws IllegalArgumentException {
Mean mean = new Mean();
double result = 0d;
int length = xArray.length;
if(length == yArray.length && length > 1) {
double xMean = mean.evaluate(xArray);
double yMean = mean.evaluate(yArray);
for (int i = 0; i < length; i++) {
double xDev = xArray[i] - xMean;
double yDev = yArray[i] - yMean;
result += (xDev * yDev - result) / (i + 1);
}
}
else {
throw MathRuntimeException.createIllegalArgumentException(
"arrays must have the same length and both must have at " +
"least two elements. xArray has size {0}, yArray has {1} elements",
length, yArray.length);
}
return biasCorrected ? result * ((double) length / (double)(length - 1)) : result;
}
示例2: checkContractExpand
import org.apache.commons.math.MathRuntimeException; //导入方法依赖的package包/类
/**
* Checks the expansion factor and the contraction criteria and throws an
* IllegalArgumentException if the contractionCriteria is less than the
* expansionCriteria
*
* @param expansion factor to be checked
* @param contraction criteria to be checked
* @throws IllegalArgumentException if the contractionCriteria is less than
* the expansionCriteria.
*/
protected void checkContractExpand(float contraction, float expansion) {
if (contraction < expansion) {
throw MathRuntimeException.createIllegalArgumentException(
"contraction criteria ({0}) smaller than the expansion factor ({1}). This would " +
"lead to a never ending loop of expansion and contraction as a newly expanded " +
"internal storage array would immediately satisfy the criteria for contraction",
contraction, expansion);
}
if (contraction <= 1.0) {
throw MathRuntimeException.createIllegalArgumentException(
"contraction criteria smaller than one ({0}). This would lead to a never ending " +
"loop of expansion and contraction as an internal storage array length equal " +
"to the number of elements would satisfy the contraction criteria.",
contraction);
}
if (expansion <= 1.0) {
throw MathRuntimeException.createIllegalArgumentException(
"expansion factor smaller than one ({0})",
expansion);
}
}
示例3: BigMatrixImpl
import org.apache.commons.math.MathRuntimeException; //导入方法依赖的package包/类
/**
* Create a new BigMatrix using <code>d</code> as the underlying
* data array.
* <p>Since the underlying array will hold <code>BigDecimal</code>
* instances, it will be created.</p>
*
* @param d data for new matrix
* @throws IllegalArgumentException if <code>d</code> is not rectangular
* (not all rows have the same length) or empty
* @throws NullPointerException if <code>d</code> is null
*/
public BigMatrixImpl(double[][] d) {
final int nRows = d.length;
if (nRows == 0) {
throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one row");
}
final int nCols = d[0].length;
if (nCols == 0) {
throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one column");
}
for (int row = 1; row < nRows; row++) {
if (d[row].length != nCols) {
throw MathRuntimeException.createIllegalArgumentException(
"some rows have length {0} while others have length {1}",
nCols, d[row].length);
}
}
this.copyIn(d);
lu = null;
}
示例4: divide
import org.apache.commons.math.MathRuntimeException; //导入方法依赖的package包/类
/**
* <p>Divide the value of this fraction by another.</p>
*
* @param fraction the fraction to divide by, must not be <code>null</code>
* @return a <code>Fraction</code> instance with the resulting values
* @throws IllegalArgumentException if the fraction is <code>null</code>
* @throws ArithmeticException if the fraction to divide by is zero
* @throws ArithmeticException if the resulting numerator or denominator exceeds
* <code>Integer.MAX_VALUE</code>
*/
public Fraction divide(Fraction fraction) {
if (fraction == null) {
throw MathRuntimeException.createIllegalArgumentException(NULL_FRACTION);
}
if (fraction.numerator == 0) {
throw MathRuntimeException.createArithmeticException(
"the fraction to divide by must not be zero: {0}/{1}",
fraction.numerator, fraction.denominator);
}
return multiply(fraction.reciprocal());
}
示例5: verifyIterationCount
import org.apache.commons.math.MathRuntimeException; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
protected void verifyIterationCount() throws IllegalArgumentException {
super.verifyIterationCount();
// at most 64 bisection refinements
if (maximalIterationCount > 64) {
throw MathRuntimeException.createIllegalArgumentException(
"invalid iteration limits: min={0}, max={1}",
0, 64);
}
}
示例6: RecursiveLayoutRealMatrix
import org.apache.commons.math.MathRuntimeException; //导入方法依赖的package包/类
/**
* Create a new dense matrix copying entries from recursive layout data.
* <p>The input array <em>must</em> already be in recursive layout.</p>
* @param rows the number of rows in the new matrix
* @param columns the number of columns in the new matrix
* @param data data for new matrix, in recursive layout
* @param copyArray if true, the input array will be copied, otherwise
* it will be referenced
*
* @exception IllegalArgumentException if <code>data</code> size is
* inconsistent with matrix size
* @see #toRecursiveLayout(double[][])
* @see #RecursiveLayoutRealMatrix(double[][])
*/
public RecursiveLayoutRealMatrix(final int rows, final int columns,
final double[] data, final boolean copyArray)
throws IllegalArgumentException {
super(rows, columns);
this.rows = rows;
this.columns = columns;
// compute optimal layout
tileNumber = tilesNumber(rows, columns);
tileSizeRows = tileSize(rows, tileNumber);
tileSizeColumns = tileSize(columns, tileNumber);
// create storage array
final int expectedLength = tileNumber * tileNumber * tileSizeRows * tileSizeColumns;
if (data.length != expectedLength) {
throw MathRuntimeException.createIllegalArgumentException(
"wrong array size (got {0}, expected {1})",
data.length, expectedLength);
}
if (copyArray) {
// allocate storage array
this.data = data.clone();
} else {
// reference existing array
this.data = data;
}
}
示例7: setDenominatorDegreesOfFreedom
import org.apache.commons.math.MathRuntimeException; //导入方法依赖的package包/类
/**
* Modify the denominator degrees of freedom.
* @param degreesOfFreedom the new denominator degrees of freedom.
* @throws IllegalArgumentException if <code>degreesOfFreedom</code> is not
* positive.
*/
public void setDenominatorDegreesOfFreedom(double degreesOfFreedom) {
if (degreesOfFreedom <= 0.0) {
throw MathRuntimeException.createIllegalArgumentException(
"degrees of freedom must be positive ({0})",
degreesOfFreedom);
}
this.denominatorDegreesOfFreedom = degreesOfFreedom;
}
示例8: PearsonsCorrelation
import org.apache.commons.math.MathRuntimeException; //导入方法依赖的package包/类
/**
* Create a PearsonsCorrelation from a {@link Covariance}. The correlation
* matrix is computed by scaling the Covariance's covariance matrix.
* The Covariance instance must have been created from a data matrix with
* columns representing variable values.
*
* @param covariance Covariance instance
*/
public PearsonsCorrelation(Covariance covariance) {
RealMatrix covarianceMatrix = covariance.getCovarianceMatrix();
if (covarianceMatrix == null) {
throw MathRuntimeException.createIllegalArgumentException("covariance matrix is null");
}
nObs = covariance.getN();
correlationMatrix = covarianceToCorrelation(covarianceMatrix);
}
示例9: createRowFieldMatrix
import org.apache.commons.math.MathRuntimeException; //导入方法依赖的package包/类
/**
* Creates a row {@link FieldMatrix} using the data from the input
* array.
*
* @param <T> the type of the field elements
* @param rowData the input row data
* @return a 1 x rowData.length FieldMatrix
* @throws IllegalArgumentException if <code>rowData</code> is empty
* @throws NullPointerException if <code>rowData</code>is null
*/
public static <T extends FieldElement<T>> FieldMatrix<T>
createRowFieldMatrix(final T[] rowData) {
final int nCols = rowData.length;
if (nCols == 0) {
throw MathRuntimeException.createIllegalArgumentException("matrix must have at least one column");
}
final FieldMatrix<T> m = createFieldMatrix(rowData[0].getField(), 1, nCols);
for (int i = 0; i < nCols; ++i) {
m.setEntry(0, i, rowData[i]);
}
return m;
}
示例10: checkSufficientData
import org.apache.commons.math.MathRuntimeException; //导入方法依赖的package包/类
/**
* Throws IllegalArgumentException of the matrix does not have at least
* two columns and two rows
*
* @param matrix matrix to check for sufficiency
*/
private void checkSufficientData(final RealMatrix matrix) {
int nRows = matrix.getRowDimension();
int nCols = matrix.getColumnDimension();
if (nRows < 2 || nCols < 2) {
throw MathRuntimeException.createIllegalArgumentException(
"insufficient data: only {0} rows and {1} columns.",
nRows, nCols);
}
}
示例11: setProbabilityOfSuccess
import org.apache.commons.math.MathRuntimeException; //导入方法依赖的package包/类
/**
* Change the probability of success for this distribution.
* @param p the new probability of success
* @throws IllegalArgumentException if <code>p</code> is not a valid
* probability.
*/
public void setProbabilityOfSuccess(double p) {
if (p < 0.0 || p > 1.0) {
throw MathRuntimeException.createIllegalArgumentException(
"{0} out of [{1}, {2}] range", p, 0.0, 1.0);
}
probabilityOfSuccess = p;
}
示例12: pow
import org.apache.commons.math.MathRuntimeException; //导入方法依赖的package包/类
/**
* Raise a BigInteger to an int power.
* @param k number to raise
* @param e exponent (must be positive or null)
* @return k<sup>e</sup>
* @exception IllegalArgumentException if e is negative
*/
public static BigInteger pow(final BigInteger k, int e)
throws IllegalArgumentException {
if (e < 0) {
throw MathRuntimeException.createIllegalArgumentException(
"cannot raise an integral value to a negative power ({0}^{1})",
k, e);
}
return k.pow(e);
}
示例13: checkSubtractionCompatible
import org.apache.commons.math.MathRuntimeException; //导入方法依赖的package包/类
/**
* Check if matrices are subtraction compatible
* @param left left hand side matrix
* @param right right hand side matrix
* @exception IllegalArgumentException if matrices are not subtraction compatible
*/
public static void checkSubtractionCompatible(final AnyMatrix left, final AnyMatrix right)
throws IllegalArgumentException {
if ((left.getRowDimension() != right.getRowDimension()) ||
(left.getColumnDimension() != right.getColumnDimension())) {
throw MathRuntimeException.createIllegalArgumentException(
"{0}x{1} and {2}x{3} matrices are not subtraction compatible",
left.getRowDimension(), left.getColumnDimension(),
right.getRowDimension(), right.getColumnDimension());
}
}
示例14: setAlpha
import org.apache.commons.math.MathRuntimeException; //导入方法依赖的package包/类
/**
* Modify the shape parameter, alpha.
* @param alpha the new shape parameter.
* @throws IllegalArgumentException if <code>alpha</code> is not positive.
*/
public void setAlpha(double alpha) {
if (alpha <= 0.0) {
throw MathRuntimeException.createIllegalArgumentException(
"alpha must be positive ({0})",
alpha);
}
this.alpha = alpha;
}
示例15: fct
import org.apache.commons.math.MathRuntimeException; //导入方法依赖的package包/类
/**
* Perform the FCT algorithm (including inverse).
*
* @param f the real data array to be transformed
* @return the real transformed array
* @throws IllegalArgumentException if any parameters are invalid
*/
protected double[] fct(double f[])
throws IllegalArgumentException {
double A, B, C, F1, x[], F[] = new double[f.length];
int N = f.length - 1;
if (!FastFourierTransformer.isPowerOf2(N)) {
throw MathRuntimeException.createIllegalArgumentException(
"{0} is not a power of 2 plus one",
f.length);
}
if (N == 1) { // trivial case
F[0] = 0.5 * (f[0] + f[1]);
F[1] = 0.5 * (f[0] - f[1]);
return F;
}
// construct a new array and perform FFT on it
x = new double[N];
x[0] = 0.5 * (f[0] + f[N]);
x[N >> 1] = f[N >> 1];
F1 = 0.5 * (f[0] - f[N]); // temporary variable for F[1]
for (int i = 1; i < (N >> 1); i++) {
A = 0.5 * (f[i] + f[N-i]);
B = Math.sin(i * Math.PI / N) * (f[i] - f[N-i]);
C = Math.cos(i * Math.PI / N) * (f[i] - f[N-i]);
x[i] = A - B;
x[N-i] = A + B;
F1 += C;
}
FastFourierTransformer transformer = new FastFourierTransformer();
Complex y[] = transformer.transform(x);
// reconstruct the FCT result for the original array
F[0] = y[0].getReal();
F[1] = F1;
for (int i = 1; i < (N >> 1); i++) {
F[2*i] = y[i].getReal();
F[2*i+1] = F[2*i-1] - y[i].getImaginary();
}
F[N] = y[N >> 1].getReal();
return F;
}