本文整理汇总了Java中org.apache.commons.math3.util.MathUtils.checkNotNull方法的典型用法代码示例。如果您正苦于以下问题:Java MathUtils.checkNotNull方法的具体用法?Java MathUtils.checkNotNull怎么用?Java MathUtils.checkNotNull使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.math3.util.MathUtils
的用法示例。
在下文中一共展示了MathUtils.checkNotNull方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generate
import org.apache.commons.math3.util.MathUtils; //导入方法依赖的package包/类
/** {@inheritDoc} */
public ConvexHull2D generate(final Collection<Vector2D> points)
throws NullArgumentException, ConvergenceException {
// check for null points
MathUtils.checkNotNull(points);
Collection<Vector2D> hullVertices = null;
if (points.size() < 2) {
hullVertices = points;
} else {
hullVertices = findHullVertices(points);
}
try {
return new ConvexHull2D(hullVertices.toArray(new Vector2D[hullVertices.size()]),
tolerance);
} catch (MathIllegalArgumentException e) {
// the hull vertices may not form a convex hull if the tolerance value is to large
throw new ConvergenceException();
}
}
示例2: setup
import org.apache.commons.math3.util.MathUtils; //导入方法依赖的package包/类
/**
* Prepare for computation.
* Subclasses must call this method if they override any of the
* {@code solve} methods.
*
* @param maxEval Maximum number of evaluations.
* @param f the integrand function
* @param lower the min bound for the interval
* @param upper the upper bound for the interval
* @throws NullArgumentException if {@code f} is {@code null}.
* @throws MathIllegalArgumentException if {@code min >= max}.
*/
protected void setup(final int maxEval,
final UnivariateFunction f,
final double lower, final double upper)
throws NullArgumentException, MathIllegalArgumentException {
// Checks.
MathUtils.checkNotNull(f);
UnivariateSolverUtils.verifyInterval(lower, upper);
// Reset.
min = lower;
max = upper;
function = f;
evaluations = evaluations.withMaximalCount(maxEval).withStart(0);
count = count.withStart(0);
}
示例3: inverse
import org.apache.commons.math3.util.MathUtils; //导入方法依赖的package包/类
/**
* Computes the inverse of the given matrix.
* <p>
* By default, the inverse of the matrix is computed using the QR-decomposition,
* unless a more efficient method can be determined for the input matrix.
*
* @param matrix Matrix whose inverse shall be computed
* @param threshold Singularity threshold
* @return the inverse of {@code m}
* @throws NullArgumentException if {@code matrix} is {@code null}
* @throws SingularMatrixException if matrix is singular
* @throws NonSquareMatrixException if matrix is not square
* @since 3.3
*/
public static RealMatrix inverse(RealMatrix matrix, double threshold)
throws NullArgumentException, SingularMatrixException, NonSquareMatrixException {
MathUtils.checkNotNull(matrix);
if (!matrix.isSquare()) {
throw new NonSquareMatrixException(matrix.getRowDimension(),
matrix.getColumnDimension());
}
if (matrix instanceof DiagonalMatrix) {
return ((DiagonalMatrix) matrix).inverse(threshold);
} else {
QRDecomposition decomposition = new QRDecomposition(matrix, threshold);
return decomposition.getSolver().getInverse();
}
}
示例4: load
import org.apache.commons.math3.util.MathUtils; //导入方法依赖的package包/类
/**
* Computes the empirical distribution using data read from a URL.
*
* <p>The input file <i>must</i> be an ASCII text file containing one
* valid numeric entry per line.</p>
*
* @param url url of the input file
*
* @throws IOException if an IO error occurs
* @throws NullArgumentException if url is null
* @throws ZeroException if URL contains no data
*/
public void load(URL url) throws IOException, NullArgumentException, ZeroException {
MathUtils.checkNotNull(url);
Charset charset = Charset.forName(FILE_CHARSET);
BufferedReader in =
new BufferedReader(new InputStreamReader(url.openStream(), charset));
try {
DataAdapter da = new StreamDataAdapter(in);
da.computeStats();
if (sampleStats.getN() == 0) {
throw new ZeroException(LocalizedFormats.URL_CONTAINS_NO_DATA, url);
}
// new adapter for the second pass
in = new BufferedReader(new InputStreamReader(url.openStream(), charset));
fillBinStats(new StreamDataAdapter(in));
loaded = true;
} finally {
try {
in.close();
} catch (IOException ex) { //NOPMD
// ignore
}
}
}
示例5: setSubMatrix
import org.apache.commons.math3.util.MathUtils; //导入方法依赖的package包/类
/** {@inheritDoc} */
public void setSubMatrix(final double[][] subMatrix, final int row, final int column)
throws NoDataException, DimensionMismatchException, NullArgumentException {
MathUtils.checkNotNull(subMatrix);
final int nRows = subMatrix.length;
if (nRows == 0) {
throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_ROW);
}
final int nCols = subMatrix[0].length;
if (nCols == 0) {
throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_COLUMN);
}
for (int r = 1; r < nRows; ++r) {
if (subMatrix[r].length != nCols) {
throw new DimensionMismatchException(nCols, subMatrix[r].length);
}
}
MatrixUtils.checkRowIndex(this, row);
MatrixUtils.checkColumnIndex(this, column);
MatrixUtils.checkRowIndex(this, nRows + row - 1);
MatrixUtils.checkColumnIndex(this, nCols + column - 1);
for (int i = 0; i < nRows; ++i) {
for (int j = 0; j < nCols; ++j) {
setEntry(row + i, column + j, subMatrix[i][j]);
}
}
}
示例6: setSubMatrix
import org.apache.commons.math3.util.MathUtils; //导入方法依赖的package包/类
/** {@inheritDoc} */
public void setSubMatrix(final double[][] subMatrix, final int row, final int column)
throws NoDataException, OutOfRangeException,
DimensionMismatchException, NullArgumentException {
MathUtils.checkNotNull(subMatrix);
final int nRows = subMatrix.length;
if (nRows == 0) {
throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_ROW);
}
final int nCols = subMatrix[0].length;
if (nCols == 0) {
throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_COLUMN);
}
for (int r = 1; r < nRows; ++r) {
if (subMatrix[r].length != nCols) {
throw new DimensionMismatchException(nCols, subMatrix[r].length);
}
}
MatrixUtils.checkRowIndex(this, row);
MatrixUtils.checkColumnIndex(this, column);
MatrixUtils.checkRowIndex(this, nRows + row - 1);
MatrixUtils.checkColumnIndex(this, nCols + column - 1);
for (int i = 0; i < nRows; ++i) {
for (int j = 0; j < nCols; ++j) {
setEntry(row + i, column + j, subMatrix[i][j]);
}
}
}
示例7: ArrayFieldVector
import org.apache.commons.math3.util.MathUtils; //导入方法依赖的package包/类
/**
* Construct a vector from another vector, using a deep copy.
*
* @param v Vector to copy.
* @throws NullArgumentException if {@code v} is {@code null}.
*/
public ArrayFieldVector(ArrayFieldVector<T> v)
throws NullArgumentException {
MathUtils.checkNotNull(v);
field = v.getField();
data = v.data.clone();
}
示例8: solve
import org.apache.commons.math3.util.MathUtils; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*
* @throws NonSelfAdjointOperatorException if {@link #getCheck()} is
* {@code true}, and {@code a} is not self-adjoint
* @throws IllConditionedOperatorException if {@code a} is ill-conditioned
*/
@Override
public RealVector solve(final RealLinearOperator a, final RealVector b)
throws NullArgumentException, NonSquareOperatorException,
DimensionMismatchException, NonSelfAdjointOperatorException,
IllConditionedOperatorException, MaxCountExceededException {
MathUtils.checkNotNull(a);
final RealVector x = new ArrayRealVector(a.getColumnDimension());
x.set(0.);
return solveInPlace(a, null, b, x, false, 0.);
}
示例9: Percentile
import org.apache.commons.math3.util.MathUtils; //导入方法依赖的package包/类
/**
* Constructs a Percentile with the specific quantile value,
* {@link EstimationType}, {@link NaNStrategy} and {@link KthSelector}.
*
* @param quantile the quantile to be computed
* @param estimationType one of the percentile {@link EstimationType estimation types}
* @param nanStrategy one of {@link NaNStrategy} to handle with NaNs
* @param kthSelector a {@link KthSelector} to use for pivoting during search
* @throws MathIllegalArgumentException if p is not within (0,100]
* @throws NullArgumentException if type or NaNStrategy passed is null
*/
protected Percentile(final double quantile,
final EstimationType estimationType,
final NaNStrategy nanStrategy,
final KthSelector kthSelector)
throws MathIllegalArgumentException {
setQuantile(quantile);
cachedPivots = null;
MathUtils.checkNotNull(estimationType);
MathUtils.checkNotNull(nanStrategy);
MathUtils.checkNotNull(kthSelector);
this.estimationType = estimationType;
this.nanStrategy = nanStrategy;
this.kthSelector = kthSelector;
}
示例10: copy
import org.apache.commons.math3.util.MathUtils; //导入方法依赖的package包/类
/**
* Copies source to dest.
* <p>Neither source nor dest can be null.</p>
*
* @param source FirstMoment to copy
* @param dest FirstMoment to copy to
* @throws NullArgumentException if either source or dest is null
*/
public static void copy(FirstMoment source, FirstMoment dest)
throws NullArgumentException {
MathUtils.checkNotNull(source);
MathUtils.checkNotNull(dest);
dest.setData(source.getDataRef());
dest.n = source.n;
dest.m1 = source.m1;
dest.dev = source.dev;
dest.nDev = source.nDev;
}
示例11: add
import org.apache.commons.math3.util.MathUtils; //导入方法依赖的package包/类
/**
* <p>
* Adds the value of this fraction to the passed {@link BigInteger},
* returning the result in reduced form.
* </p>
*
* @param bg
* the {@link BigInteger} to add, must'nt be <code>null</code>.
* @return a <code>BigFraction</code> instance with the resulting values.
* @throws NullArgumentException
* if the {@link BigInteger} is <code>null</code>.
*/
public BigFraction add(final BigInteger bg) throws NullArgumentException {
MathUtils.checkNotNull(bg);
if (numerator.signum() == 0) {
return new BigFraction(bg);
}
if (bg.signum() == 0) {
return this;
}
return new BigFraction(numerator.add(denominator.multiply(bg)), denominator);
}
示例12: copy
import org.apache.commons.math3.util.MathUtils; //导入方法依赖的package包/类
/**
* Copies source to dest.
* <p>Neither source nor dest can be null.</p>
* <p>Acquires synchronization lock on source, then dest before copying.</p>
*
* @param source SynchronizedSummaryStatistics to copy
* @param dest SynchronizedSummaryStatistics to copy to
* @throws NullArgumentException if either source or dest is null
*/
public static void copy(SynchronizedSummaryStatistics source,
SynchronizedSummaryStatistics dest)
throws NullArgumentException {
MathUtils.checkNotNull(source);
MathUtils.checkNotNull(dest);
synchronized (source) {
synchronized (dest) {
SummaryStatistics.copy(source, dest);
}
}
}
示例13: copy
import org.apache.commons.math3.util.MathUtils; //导入方法依赖的package包/类
/**
* Copies source to dest.
* <p>Neither source nor dest can be null.</p>
* <p>Acquires synchronization lock on source, then dest before copying.</p>
*
* @param source SynchronizedDescriptiveStatistics to copy
* @param dest SynchronizedDescriptiveStatistics to copy to
* @throws NullArgumentException if either source or dest is null
*/
public static void copy(SynchronizedDescriptiveStatistics source,
SynchronizedDescriptiveStatistics dest)
throws NullArgumentException {
MathUtils.checkNotNull(source);
MathUtils.checkNotNull(dest);
synchronized (source) {
synchronized (dest) {
DescriptiveStatistics.copy(source, dest);
}
}
}
示例14: correct
import org.apache.commons.math3.util.MathUtils; //导入方法依赖的package包/类
/**
* Correct the current state estimate with an actual measurement.
*
* @param z
* the measurement vector
* @throws NullArgumentException
* if the measurement vector is {@code null}
* @throws DimensionMismatchException
* if the dimension of the measurement vector does not fit
* @throws SingularMatrixException
* if the covariance matrix could not be inverted
*/
public void correct(final RealVector z) throws NullArgumentException,
DimensionMismatchException, SingularMatrixException
{
// sanity checks
MathUtils.checkNotNull(z);
if (z.getDimension() != measurementMatrix.getRowDimension())
{
throw new DimensionMismatchException(z.getDimension(),
measurementMatrix.getRowDimension());
}
// S = H * P(k) * H' + R
RealMatrix s = measurementMatrix.multiply(errorCovariance)
.multiply(measurementMatrixT)
.add(measurementModel.getMeasurementNoise());
// Inn = z(k) - H * xHat(k)-
RealVector innovation = z.subtract(measurementMatrix
.operate(stateEstimation));
// calculate gain matrix
// K(k) = P(k)- * H' * (H * P(k)- * H' + R)^-1
// K(k) = P(k)- * H' * S^-1
// instead of calculating the inverse of S we can rearrange the formula,
// and then solve the linear equation A x X = B with A = S', X = K' and
// B = (H * P)'
// K(k) * S = P(k)- * H'
// S' * K(k)' = H * P(k)-'
RealMatrix kalmanGain = new CholeskyDecomposition(s).getSolver()
.solve(measurementMatrix.multiply(errorCovariance.transpose()))
.transpose();
// update estimate with measurement z(k)
// xHat(k) = xHat(k)- + K * Inn
stateEstimation = stateEstimation.add(kalmanGain.operate(innovation));
// update covariance of prediction error
// P(k) = (I - K * H) * P(k)-
RealMatrix identity = MatrixUtils.createRealIdentityMatrix(kalmanGain
.getRowDimension());
errorCovariance = identity.subtract(
kalmanGain.multiply(measurementMatrix)).multiply(
errorCovariance);
}
示例15: setSubMatrix
import org.apache.commons.math3.util.MathUtils; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
public void setSubMatrix(final double[][] subMatrix, final int row,
final int column)
throws OutOfRangeException, NoDataException, NullArgumentException,
DimensionMismatchException {
// safety checks
MathUtils.checkNotNull(subMatrix);
final int refLength = subMatrix[0].length;
if (refLength == 0) {
throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_COLUMN);
}
final int endRow = row + subMatrix.length - 1;
final int endColumn = column + refLength - 1;
MatrixUtils.checkSubMatrixIndex(this, row, endRow, column, endColumn);
for (final double[] subRow : subMatrix) {
if (subRow.length != refLength) {
throw new DimensionMismatchException(refLength, subRow.length);
}
}
// compute blocks bounds
final int blockStartRow = row / BLOCK_SIZE;
final int blockEndRow = (endRow + BLOCK_SIZE) / BLOCK_SIZE;
final int blockStartColumn = column / BLOCK_SIZE;
final int blockEndColumn = (endColumn + BLOCK_SIZE) / BLOCK_SIZE;
// perform copy block-wise, to ensure good cache behavior
for (int iBlock = blockStartRow; iBlock < blockEndRow; ++iBlock) {
final int iHeight = blockHeight(iBlock);
final int firstRow = iBlock * BLOCK_SIZE;
final int iStart = FastMath.max(row, firstRow);
final int iEnd = FastMath.min(endRow + 1, firstRow + iHeight);
for (int jBlock = blockStartColumn; jBlock < blockEndColumn; ++jBlock) {
final int jWidth = blockWidth(jBlock);
final int firstColumn = jBlock * BLOCK_SIZE;
final int jStart = FastMath.max(column, firstColumn);
final int jEnd = FastMath.min(endColumn + 1, firstColumn + jWidth);
final int jLength = jEnd - jStart;
// handle one block, row by row
final double[] block = blocks[iBlock * blockColumns + jBlock];
for (int i = iStart; i < iEnd; ++i) {
System.arraycopy(subMatrix[i - row], jStart - column,
block, (i - firstRow) * jWidth + (jStart - firstColumn),
jLength);
}
}
}
}