本文整理汇总了Java中org.apache.commons.math3.util.Precision类的典型用法代码示例。如果您正苦于以下问题:Java Precision类的具体用法?Java Precision怎么用?Java Precision使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Precision类属于org.apache.commons.math3.util包,在下文中一共展示了Precision类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: Arc
import org.apache.commons.math3.util.Precision; //导入依赖的package包/类
/** Simple constructor.
* <p>
* If either {@code lower} is equals to {@code upper} or
* the interval exceeds \( 2 \pi \), the arc is considered
* to be the full circle and its initial defining boundaries
* will be forgotten. {@code lower} is not allowed to be
* greater than {@code upper} (an exception is thrown in this case).
* {@code lower} will be canonicalized between 0 and \( 2 \pi \), and
* upper shifted accordingly, so the {@link #getInf()} and {@link #getSup()}
* may not return the value used at instance construction.
* </p>
* @param lower lower angular bound of the arc
* @param upper upper angular bound of the arc
* @param tolerance tolerance below which angles are considered identical
* @exception NumberIsTooLargeException if lower is greater than upper
*/
public Arc(final double lower, final double upper, final double tolerance)
throws NumberIsTooLargeException {
this.tolerance = tolerance;
if (Precision.equals(lower, upper, 0) || (upper - lower) >= MathUtils.TWO_PI) {
// the arc must cover the whole circle
this.lower = 0;
this.upper = MathUtils.TWO_PI;
this.middle = FastMath.PI;
} else if (lower <= upper) {
this.lower = MathUtils.normalizeAngle(lower, FastMath.PI);
this.upper = this.lower + (upper - lower);
this.middle = 0.5 * (this.lower + this.upper);
} else {
throw new NumberIsTooLargeException(LocalizedFormats.ENDPOINTS_NOT_AN_INTERVAL,
lower, upper, true);
}
}
示例2: computeGeometricalProperties
import org.apache.commons.math3.util.Precision; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
protected void computeGeometricalProperties() {
if (getTree(false).getCut() == null) {
setBarycenter(S1Point.NaN);
setSize(((Boolean) getTree(false).getAttribute()) ? MathUtils.TWO_PI : 0);
} else {
double size = 0.0;
double sum = 0.0;
for (final double[] a : this) {
final double length = a[1] - a[0];
size += length;
sum += length * (a[0] + a[1]);
}
setSize(size);
if (Precision.equals(size, MathUtils.TWO_PI, 0)) {
setBarycenter(S1Point.NaN);
} else if (size >= Precision.SAFE_MIN) {
setBarycenter(new S1Point(sum / (2 * size)));
} else {
final LimitAngle limit = (LimitAngle) getTree(false).getCut().getHyperplane();
setBarycenter(limit.getLocation());
}
}
}
示例3: computeGeometricalProperties
import org.apache.commons.math3.util.Precision; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
protected void computeGeometricalProperties() {
if (getTree(false).getCut() == null) {
setBarycenter((Point<Euclidean1D>) Vector1D.NaN);
setSize(((Boolean) getTree(false).getAttribute()) ? Double.POSITIVE_INFINITY : 0);
} else {
double size = 0.0;
double sum = 0.0;
for (final Interval interval : asList()) {
size += interval.getSize();
sum += interval.getSize() * interval.getBarycenter();
}
setSize(size);
if (Double.isInfinite(size)) {
setBarycenter((Point<Euclidean1D>) Vector1D.NaN);
} else if (size >= Precision.SAFE_MIN) {
setBarycenter((Point<Euclidean1D>) new Vector1D(sum / size));
} else {
setBarycenter((Point<Euclidean1D>) ((OrientedPoint) getTree(false).getCut().getHyperplane()).getLocation());
}
}
}
示例4: distance
import org.apache.commons.math3.util.Precision; //导入依赖的package包/类
/** Compute the shortest distance between the instance and another line.
* @param line line to check against the instance
* @return shortest distance between the instance and the line
*/
public double distance(final Line line) {
final Vector3D normal = Vector3D.crossProduct(direction, line.direction);
final double n = normal.getNorm();
if (n < Precision.SAFE_MIN) {
// lines are parallel
return distance(line.zero);
}
// signed separation of the two parallel planes that contains the lines
final double offset = line.zero.subtract(zero).dotProduct(normal) / n;
return FastMath.abs(offset);
}
示例5: closestPoint
import org.apache.commons.math3.util.Precision; //导入依赖的package包/类
/** Compute the point of the instance closest to another line.
* @param line line to check against the instance
* @return point of the instance closest to another line
*/
public Vector3D closestPoint(final Line line) {
final double cos = direction.dotProduct(line.direction);
final double n = 1 - cos * cos;
if (n < Precision.EPSILON) {
// the lines are parallel
return zero;
}
final Vector3D delta0 = line.zero.subtract(zero);
final double a = delta0.dotProduct(direction);
final double b = delta0.dotProduct(line.direction);
return new Vector3D(1, zero, (a - b * cos) / n, direction);
}
示例6: equals
import org.apache.commons.math3.util.Precision; //导入依赖的package包/类
/**
* Returns true iff <code>object</code> is a
* <code>StatisticalSummaryValues</code> instance and all statistics have
* the same values as this.
*
* @param object the object to test equality against.
* @return true if object equals this
*/
@Override
public boolean equals(Object object) {
if (object == this ) {
return true;
}
if (object instanceof StatisticalSummaryValues == false) {
return false;
}
StatisticalSummaryValues stat = (StatisticalSummaryValues) object;
return Precision.equalsIncludingNaN(stat.getMax(), getMax()) &&
Precision.equalsIncludingNaN(stat.getMean(), getMean()) &&
Precision.equalsIncludingNaN(stat.getMin(), getMin()) &&
Precision.equalsIncludingNaN(stat.getN(), getN()) &&
Precision.equalsIncludingNaN(stat.getSum(), getSum()) &&
Precision.equalsIncludingNaN(stat.getVariance(), getVariance());
}
示例7: equals
import org.apache.commons.math3.util.Precision; //导入依赖的package包/类
/**
* Returns true iff <code>object</code> is a
* <code>SummaryStatistics</code> instance and all statistics have the
* same values as this.
* @param object the object to test equality against.
* @return true if object equals this
*/
@Override
public boolean equals(Object object) {
if (object == this) {
return true;
}
if (object instanceof SummaryStatistics == false) {
return false;
}
SummaryStatistics stat = (SummaryStatistics)object;
return Precision.equalsIncludingNaN(stat.getGeometricMean(), getGeometricMean()) &&
Precision.equalsIncludingNaN(stat.getMax(), getMax()) &&
Precision.equalsIncludingNaN(stat.getMean(), getMean()) &&
Precision.equalsIncludingNaN(stat.getMin(), getMin()) &&
Precision.equalsIncludingNaN(stat.getN(), getN()) &&
Precision.equalsIncludingNaN(stat.getSum(), getSum()) &&
Precision.equalsIncludingNaN(stat.getSumsq(), getSumsq()) &&
Precision.equalsIncludingNaN(stat.getVariance(), getVariance());
}
示例8: equals
import org.apache.commons.math3.util.Precision; //导入依赖的package包/类
/**
* Returns true iff <code>object</code> is a <code>MultivariateSummaryStatistics</code>
* instance and all statistics have the same values as this.
* @param object the object to test equality against.
* @return true if object equals this
*/
@Override
public boolean equals(Object object) {
if (object == this ) {
return true;
}
if (object instanceof MultivariateSummaryStatistics == false) {
return false;
}
MultivariateSummaryStatistics stat = (MultivariateSummaryStatistics) object;
return MathArrays.equalsIncludingNaN(stat.getGeometricMean(), getGeometricMean()) &&
MathArrays.equalsIncludingNaN(stat.getMax(), getMax()) &&
MathArrays.equalsIncludingNaN(stat.getMean(), getMean()) &&
MathArrays.equalsIncludingNaN(stat.getMin(), getMin()) &&
Precision.equalsIncludingNaN(stat.getN(), getN()) &&
MathArrays.equalsIncludingNaN(stat.getSum(), getSum()) &&
MathArrays.equalsIncludingNaN(stat.getSumSq(), getSumSq()) &&
MathArrays.equalsIncludingNaN(stat.getSumLog(), getSumLog()) &&
stat.getCovariance().equals( getCovariance());
}
示例9: solvePhase1
import org.apache.commons.math3.util.Precision; //导入依赖的package包/类
/**
* Solves Phase 1 of the Simplex method.
* @param tableau simple tableau for the problem
* @throws MaxCountExceededException if the maximal iteration count has been exceeded
* @throws UnboundedSolutionException if the model is found not to have a bounded solution
* @throws NoFeasibleSolutionException if there is no feasible solution
*/
protected void solvePhase1(final SimplexTableau tableau)
throws MaxCountExceededException, UnboundedSolutionException, NoFeasibleSolutionException {
// make sure we're in Phase 1
if (tableau.getNumArtificialVariables() == 0) {
return;
}
while (!tableau.isOptimal()) {
doIteration(tableau);
}
// if W is not zero then we have no feasible solution
if (!Precision.equals(tableau.getEntry(0, tableau.getRhsOffset()), 0d, epsilon)) {
throw new NoFeasibleSolutionException();
}
}
示例10: SmoothingPolynomialBicubicSplineInterpolator
import org.apache.commons.math3.util.Precision; //导入依赖的package包/类
/**
* @param xDegree Degree of the polynomial fitting functions along the
* x-dimension.
* @param yDegree Degree of the polynomial fitting functions along the
* y-dimension.
* @exception NotPositiveException if degrees are not positive
*/
public SmoothingPolynomialBicubicSplineInterpolator(int xDegree, int yDegree)
throws NotPositiveException {
if (xDegree < 0) {
throw new NotPositiveException(xDegree);
}
if (yDegree < 0) {
throw new NotPositiveException(yDegree);
}
this.xDegree = xDegree;
this.yDegree = yDegree;
final double safeFactor = 1e2;
final SimpleVectorValueChecker checker
= new SimpleVectorValueChecker(safeFactor * Precision.EPSILON,
safeFactor * Precision.SAFE_MIN);
xFitter = new PolynomialFitter(new GaussNewtonOptimizer(false, checker));
yFitter = new PolynomialFitter(new GaussNewtonOptimizer(false, checker));
}
示例11: solvePhase1
import org.apache.commons.math3.util.Precision; //导入依赖的package包/类
/**
* Solves Phase 1 of the Simplex method.
*
* @param tableau Simple tableau for the problem.
* @throws TooManyIterationsException if the allowed number of iterations has been exhausted.
* @throws UnboundedSolutionException if the model is found not to have a bounded solution.
* @throws NoFeasibleSolutionException if there is no feasible solution?
*/
protected void solvePhase1(final SimplexTableau tableau)
throws TooManyIterationsException,
UnboundedSolutionException,
NoFeasibleSolutionException {
// make sure we're in Phase 1
if (tableau.getNumArtificialVariables() == 0) {
return;
}
while (!tableau.isOptimal()) {
doIteration(tableau);
}
// if W is not zero then we have no feasible solution
if (!Precision.equals(tableau.getEntry(0, tableau.getRhsOffset()), 0d, epsilon)) {
throw new NoFeasibleSolutionException();
}
}
示例12: getD
import org.apache.commons.math3.util.Precision; //导入依赖的package包/类
/**
* Gets the block diagonal matrix D of the decomposition.
* D is a block diagonal matrix.
* Real eigenvalues are on the diagonal while complex values are on
* 2x2 blocks { {real +imaginary}, {-imaginary, real} }.
*
* @return the D matrix.
*
* @see #getRealEigenvalues()
* @see #getImagEigenvalues()
*/
public RealMatrix getD() {
if (cachedD == null) {
// cache the matrix for subsequent calls
cachedD = MatrixUtils.createRealDiagonalMatrix(realEigenvalues);
for (int i = 0; i < imagEigenvalues.length; i++) {
if (Precision.compareTo(imagEigenvalues[i], 0.0, EPSILON) > 0) {
cachedD.setEntry(i, i+1, imagEigenvalues[i]);
} else if (Precision.compareTo(imagEigenvalues[i], 0.0, EPSILON) < 0) {
cachedD.setEntry(i, i-1, imagEigenvalues[i]);
}
}
}
return cachedD;
}
示例13: isNonSingular
import org.apache.commons.math3.util.Precision; //导入依赖的package包/类
/**
* Checks whether the decomposed matrix is non-singular.
*
* @return true if the decomposed matrix is non-singular.
*/
public boolean isNonSingular() {
double largestEigenvalueNorm = 0.0;
// Looping over all values (in case they are not sorted in decreasing
// order of their norm).
for (int i = 0; i < realEigenvalues.length; ++i) {
largestEigenvalueNorm = FastMath.max(largestEigenvalueNorm, eigenvalueNorm(i));
}
// Corner case: zero matrix, all exactly 0 eigenvalues
if (largestEigenvalueNorm == 0.0) {
return false;
}
for (int i = 0; i < realEigenvalues.length; ++i) {
// Looking for eigenvalues that are 0, where we consider anything much much smaller
// than the largest eigenvalue to be effectively 0.
if (Precision.equals(eigenvalueNorm(i) / largestEigenvalueNorm, 0, EPSILON)) {
return false;
}
}
return true;
}
示例14: transformToSchur
import org.apache.commons.math3.util.Precision; //导入依赖的package包/类
/**
* Transforms the matrix to Schur form and calculates the eigenvalues.
*
* @param matrix Matrix to transform.
* @return the {@link SchurTransformer Shur transform} for this matrix
*/
private SchurTransformer transformToSchur(final RealMatrix matrix) {
final SchurTransformer schurTransform = new SchurTransformer(matrix);
final double[][] matT = schurTransform.getT().getData();
realEigenvalues = new double[matT.length];
imagEigenvalues = new double[matT.length];
for (int i = 0; i < realEigenvalues.length; i++) {
if (i == (realEigenvalues.length - 1) ||
Precision.equals(matT[i + 1][i], 0.0, EPSILON)) {
realEigenvalues[i] = matT[i][i];
} else {
final double x = matT[i + 1][i + 1];
final double p = 0.5 * (matT[i][i] - x);
final double z = FastMath.sqrt(FastMath.abs(p * p + matT[i + 1][i] * matT[i][i + 1]));
realEigenvalues[i] = x + p;
imagEigenvalues[i] = z;
realEigenvalues[i + 1] = x + p;
imagEigenvalues[i + 1] = -z;
i++;
}
}
return schurTransform;
}
示例15: solveLowerTriangularSystem
import org.apache.commons.math3.util.Precision; //导入依赖的package包/类
/**Solve a system of composed of a Lower Triangular Matrix
* {@link RealMatrix}.
* <p>
* This method is called to solve systems of equations which are
* of the lower triangular form. The matrix {@link RealMatrix}
* is assumed, though not checked, to be in lower triangular form.
* The vector {@link RealVector} is overwritten with the solution.
* The matrix is checked that it is square and its dimensions match
* the length of the vector.
* </p>
* @param rm RealMatrix which is lower triangular
* @param b RealVector this is overwritten
* @throws DimensionMismatchException if the matrix and vector are not
* conformable
* @throws NonSquareMatrixException if the matrix {@code rm} is not square
* @throws MathArithmeticException if the absolute value of one of the diagonal
* coefficient of {@code rm} is lower than {@link Precision#SAFE_MIN}
*/
public static void solveLowerTriangularSystem(RealMatrix rm, RealVector b)
throws DimensionMismatchException, MathArithmeticException,
NonSquareMatrixException {
if ((rm == null) || (b == null) || ( rm.getRowDimension() != b.getDimension())) {
throw new DimensionMismatchException(
(rm == null) ? 0 : rm.getRowDimension(),
(b == null) ? 0 : b.getDimension());
}
if( rm.getColumnDimension() != rm.getRowDimension() ){
throw new NonSquareMatrixException(rm.getRowDimension(),
rm.getColumnDimension());
}
int rows = rm.getRowDimension();
for( int i = 0 ; i < rows ; i++ ){
double diag = rm.getEntry(i, i);
if( FastMath.abs(diag) < Precision.SAFE_MIN ){
throw new MathArithmeticException(LocalizedFormats.ZERO_DENOMINATOR);
}
double bi = b.getEntry(i)/diag;
b.setEntry(i, bi );
for( int j = i+1; j< rows; j++ ){
b.setEntry(j, b.getEntry(j)-bi*rm.getEntry(j,i) );
}
}
}