本文整理了Java中org.apache.commons.math3.util.Precision.compareTo()
方法的一些代码示例,展示了Precision.compareTo()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Precision.compareTo()
方法的具体详情如下:
包路径:org.apache.commons.math3.util.Precision
类名称:Precision
方法名:compareTo
[英]Compares two numbers given some amount of allowed error.
[中]在允许的误差范围内比较两个数字。
代码示例来源:origin: org.apache.commons/commons-math3
/**
* 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;
}
代码示例来源:origin: org.apache.commons/commons-math3
/** {@inheritDoc} */
public int compare(final Vector2D o1, final Vector2D o2) {
final double tolerance = getTolerance();
// need to take the tolerance value into account, otherwise collinear points
// will not be handled correctly when building the upper/lower hull
final int diff = Precision.compareTo(o1.getX(), o2.getX(), tolerance);
if (diff == 0) {
return Precision.compareTo(o1.getY(), o2.getY(), tolerance);
} else {
return diff;
}
}
});
代码示例来源:origin: org.apache.commons/commons-math3
/**
* Returns whether the problem is at an optimal state.
* @return whether the model has been solved
*/
boolean isOptimal() {
for (int i = getNumObjectiveFunctions(); i < getWidth() - 1; i++) {
final double entry = tableau.getEntry(0, i);
if (Precision.compareTo(entry, 0d, epsilon) < 0) {
return false;
}
}
return true;
}
代码示例来源:origin: org.apache.commons/commons-math3
/**
* Returns whether the problem is at an optimal state.
* @return whether the model has been solved
*/
boolean isOptimal() {
final double[] objectiveFunctionRow = getRow(0);
final int end = getRhsOffset();
for (int i = getNumObjectiveFunctions(); i < end; i++) {
final double entry = objectiveFunctionRow[i];
if (Precision.compareTo(entry, 0d, epsilon) < 0) {
return false;
}
}
return true;
}
代码示例来源:origin: org.apache.commons/commons-math3
/**
* Checks whether the given column is valid pivot column, i.e. will result
* in a valid pivot row.
* <p>
* When applying Bland's rule to select the pivot column, it may happen that
* there is no corresponding pivot row. This method will check if the selected
* pivot column will return a valid pivot row.
*
* @param tableau simplex tableau for the problem
* @param col the column to test
* @return {@code true} if the pivot column is valid, {@code false} otherwise
*/
private boolean isValidPivotColumn(SimplexTableau tableau, int col) {
for (int i = tableau.getNumObjectiveFunctions(); i < tableau.getHeight(); i++) {
final double entry = tableau.getEntry(i, col);
// do the same check as in getPivotRow
if (Precision.compareTo(entry, 0d, cutOff) > 0) {
return true;
}
}
return false;
}
代码示例来源:origin: org.apache.commons/commons-math3
if (Precision.compareTo(entry, 0d, epsilon) > 0) {
columnsToDrop.add(i);
代码示例来源:origin: org.apache.commons/commons-math3
if (Precision.compareTo(entry, 0d, epsilon) > 0) {
columnsToDrop.add(i);
代码示例来源:origin: org.apache.commons/commons-math3
if (Precision.compareTo(entry, 0d, cutOff) > 0) {
final double ratio = FastMath.abs(rhs / entry);
代码示例来源:origin: org.apache.commons/commons-math3
final double entry = tableau.getEntry(i, col);
if (Precision.compareTo(entry, 0d, maxUlps) > 0) {
final double ratio = rhs / entry;
代码示例来源:origin: org.apache.commons/commons-math3
/**
* Checks whether the given hull vertices form a convex hull.
* @param hullVertices the hull vertices
* @return {@code true} if the vertices form a convex hull, {@code false} otherwise
*/
private boolean isConvex(final Vector2D[] hullVertices) {
if (hullVertices.length < 3) {
return true;
}
int sign = 0;
for (int i = 0; i < hullVertices.length; i++) {
final Vector2D p1 = hullVertices[i == 0 ? hullVertices.length - 1 : i - 1];
final Vector2D p2 = hullVertices[i];
final Vector2D p3 = hullVertices[i == hullVertices.length - 1 ? 0 : i + 1];
final Vector2D d1 = p2.subtract(p1);
final Vector2D d2 = p3.subtract(p2);
final double crossProduct = MathArrays.linearCombination(d1.getX(), d2.getY(), -d1.getY(), d2.getX());
final int cmp = Precision.compareTo(crossProduct, 0.0, tolerance);
// in case of collinear points the cross product will be zero
if (cmp != 0.0) {
if (sign != 0.0 && cmp != sign) {
return false;
}
sign = cmp;
}
}
return true;
}
代码示例来源:origin: org.apache.commons/commons-math3
final double[] coeff = solution.getPoint();
for (int i = 0; i < coeff.length; i++) {
if (Precision.compareTo(coeff[i], 0, epsilon) < 0) {
throw new NoFeasibleSolutionException();
代码示例来源:origin: org.apache.commons/commons-math3
r += matrixT[i][j] * matrixT[j][idx];
if (Precision.compareTo(imagEigenvalues[i], 0.0, EPSILON) < 0) {
z = w;
s = r;
if (Precision.compareTo(imagEigenvalues[i], 0.0, EPSILON) < 0) {
z = w;
r = ra;
代码示例来源:origin: io.virtdata/virtdata-lib-realer
/** {@inheritDoc} */
public int compare(final Vector2D o1, final Vector2D o2) {
final double tolerance = getTolerance();
// need to take the tolerance value into account, otherwise collinear points
// will not be handled correctly when building the upper/lower hull
final int diff = Precision.compareTo(o1.getX(), o2.getX(), tolerance);
if (diff == 0) {
return Precision.compareTo(o1.getY(), o2.getY(), tolerance);
} else {
return diff;
}
}
});
代码示例来源:origin: io.virtdata/virtdata-lib-realer
/**
* Returns whether the problem is at an optimal state.
* @return whether the model has been solved
*/
boolean isOptimal() {
for (int i = getNumObjectiveFunctions(); i < getWidth() - 1; i++) {
final double entry = tableau.getEntry(0, i);
if (Precision.compareTo(entry, 0d, epsilon) < 0) {
return false;
}
}
return true;
}
代码示例来源:origin: geogebra/geogebra
/**
* Returns whether the problem is at an optimal state.
* @return whether the model has been solved
*/
boolean isOptimal() {
final double[] objectiveFunctionRow = getRow(0);
final int end = getRhsOffset();
for (int i = getNumObjectiveFunctions(); i < end; i++) {
final double entry = objectiveFunctionRow[i];
if (Precision.compareTo(entry, 0d, epsilon) < 0) {
return false;
}
}
return true;
}
代码示例来源:origin: io.virtdata/virtdata-lib-realer
/**
* Returns whether the problem is at an optimal state.
* @return whether the model has been solved
*/
boolean isOptimal() {
final double[] objectiveFunctionRow = getRow(0);
final int end = getRhsOffset();
for (int i = getNumObjectiveFunctions(); i < end; i++) {
final double entry = objectiveFunctionRow[i];
if (Precision.compareTo(entry, 0d, epsilon) < 0) {
return false;
}
}
return true;
}
代码示例来源:origin: geogebra/geogebra
/**
* Checks whether the given column is valid pivot column, i.e. will result
* in a valid pivot row.
* <p>
* When applying Bland's rule to select the pivot column, it may happen that
* there is no corresponding pivot row. This method will check if the selected
* pivot column will return a valid pivot row.
*
* @param tableau simplex tableau for the problem
* @param col the column to test
* @return {@code true} if the pivot column is valid, {@code false} otherwise
*/
private boolean isValidPivotColumn(SimplexTableau tableau, int col) {
for (int i = tableau.getNumObjectiveFunctions(); i < tableau.getHeight(); i++) {
final double entry = tableau.getEntry(i, col);
// do the same check as in getPivotRow
if (Precision.compareTo(entry, 0d, cutOff) > 0) {
return true;
}
}
return false;
}
代码示例来源:origin: io.virtdata/virtdata-lib-realer
/**
* Checks whether the given column is valid pivot column, i.e. will result
* in a valid pivot row.
* <p>
* When applying Bland's rule to select the pivot column, it may happen that
* there is no corresponding pivot row. This method will check if the selected
* pivot column will return a valid pivot row.
*
* @param tableau simplex tableau for the problem
* @param col the column to test
* @return {@code true} if the pivot column is valid, {@code false} otherwise
*/
private boolean isValidPivotColumn(SimplexTableau tableau, int col) {
for (int i = tableau.getNumObjectiveFunctions(); i < tableau.getHeight(); i++) {
final double entry = tableau.getEntry(i, col);
// do the same check as in getPivotRow
if (Precision.compareTo(entry, 0d, cutOff) > 0) {
return true;
}
}
return false;
}
代码示例来源:origin: googlegenomics/dataflow-java
@Test
public void testGridSearch() {
Interval interval = Solver.gridSearch(new Parabola(0.25), 0.0, 1.0, 0.1);
assertEquals(Precision.compareTo(interval.getInf(), 0.1, 1), 0);
assertEquals(Precision.compareTo(interval.getSup(), 0.3, 1), 0);
interval = Solver.gridSearch(new Parabola(1.2), 0.0, 1.0, 0.1);
assertEquals(Precision.compareTo(interval.getInf(), 0.9, 1), 0);
assertEquals(Precision.compareTo(interval.getSup(), 1.0, 1), 0);
interval = Solver.gridSearch(new Parabola(1.2), 0.0, 1.0, 0.3);
assertEquals(Precision.compareTo(interval.getInf(), 0.9, 1), 0);
assertEquals(Precision.compareTo(interval.getSup(), 1.0, 1), 0);
}
代码示例来源:origin: googlegenomics/dataflow-java
@Test
public void testMaximize() {
assertEquals(Precision.compareTo(Solver.maximize(new Parabola(0.47), 0.0, 1.0,
0.1, 0.00001, 0.00001, 100, 100), 0.47, 0.00001), 0);
}
内容来源于网络,如有侵权,请联系作者删除!