当前位置: 首页>>代码示例>>Java>>正文


Java Precision.compareTo方法代码示例

本文整理汇总了Java中org.apache.commons.math3.util.Precision.compareTo方法的典型用法代码示例。如果您正苦于以下问题:Java Precision.compareTo方法的具体用法?Java Precision.compareTo怎么用?Java Precision.compareTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.math3.util.Precision的用法示例。


在下文中一共展示了Precision.compareTo方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:28,代码来源:EigenDecomposition.java

示例2: getBPS

import org.apache.commons.math3.util.Precision; //导入方法依赖的package包/类
private double[] getBPS(double[] lr) {
    double[] lrSorted = new double[lr.length];
    System.arraycopy(lr, 0, lrSorted, 0, lr.length);
    Arrays.sort(lrSorted);

    double[][] dis = new double[lrSorted.length-1][3];
    for (int i = 1; i < lrSorted.length; i++) {
        dis[i-1][0] = lrSorted[i] - lrSorted[i-1];
        dis[i-1][1] = lrSorted[i];
        dis[i-1][2] = lrSorted[i-1];
    }

    java.util.Arrays.sort(dis, DIS_COMPARATOR);
    ArrayList<Double> bpsArr = new ArrayList<>(dis.length);
    for (double[] bp : dis) {
        if (Precision.compareTo(bp[0], 0.1, EPSILON) < 0)
            break;
        bpsArr.add((bp[1] + bp[2]) / 2);

    }
    return convertDoubles(bpsArr);
}
 
开发者ID:AstraZeneca-NGS,项目名称:Seq2CJava,代码行数:23,代码来源:Lr2gene.java

示例3: createSegmentsSet

import org.apache.commons.math3.util.Precision; //导入方法依赖的package包/类
private TreeSet<Segment> createSegmentsSet(double[] values, Segment first) {
    TreeSet<Segment> map = new TreeSet<>(new Comparator<Segment>() {
        @Override
        public int compare(Segment s1, Segment s2) {
            return Precision.compareTo(s1.errorWithNext, s2.errorWithNext, TimeSeriesPrecision.EPSILON);
        }
    });

    Segment current = first;
    while (current.next != null) {
        double mean = getUnifiedMean(current, current.next);
        current.errorWithNext = getUnifiedError(current, current.next, values, mean);
        map.add(current);
        current = current.next;
    }
    return map;
}
 
开发者ID:octavian-h,项目名称:time-series-math,代码行数:18,代码来源:AdaptivePiecewiseConstantApproximation.java

示例4: isConvex

import org.apache.commons.math3.util.Precision; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:33,代码来源:ConvexHull2D.java

示例5: isOptimal

import org.apache.commons.math3.util.Precision; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:14,代码来源:SimplexTableau.java

示例6: isOptimal

import org.apache.commons.math3.util.Precision; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:16,代码来源:SimplexTableau.java

示例7: isConvex

import org.apache.commons.math3.util.Precision; //导入方法依赖的package包/类
protected final boolean isConvex(final ConvexHull2D hull, final boolean includesCollinearPoints,
                                 final double tolerance) {

    final Vector2D[] points = hull.getVertices();
    int sign = 0;

    for (int i = 0; i < points.length; i++) {
        Vector2D p1 = points[i == 0 ? points.length - 1 : i - 1];
        Vector2D p2 = points[i];
        Vector2D p3 = points[i == points.length - 1 ? 0 : i + 1];

        Vector2D d1 = p2.subtract(p1);
        Vector2D d2 = p3.subtract(p2);

        Assert.assertTrue(d1.getNorm() > 1e-10);
        Assert.assertTrue(d2.getNorm() > 1e-10);

        final double cross = MathArrays.linearCombination(d1.getX(), d2.getY(), -d1.getY(), d2.getX());
        final int cmp = Precision.compareTo(cross, 0.0, tolerance);

        if (sign != 0 && cmp != sign) {
            if (includesCollinearPoints && cmp == 0) {
                // in case of collinear points the cross product will be zero
            } else {
                return false;
            }
        }
        
        sign = cmp;
    }
    
    return true;
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:34,代码来源:ConvexHullGenerator2DAbstractTest.java

示例8: validSolution

import org.apache.commons.math3.util.Precision; //导入方法依赖的package包/类
private static boolean validSolution(PointValuePair solution, List<LinearConstraint> constraints, double epsilon) {
    double[] vals = solution.getPoint();
    for (LinearConstraint c : constraints) {
        double[] coeffs = c.getCoefficients().toArray();
        double result = 0.0d;
        for (int i = 0; i < vals.length; i++) {
            result += vals[i] * coeffs[i];
        }
        
        switch (c.getRelationship()) {
        case EQ:
            if (!Precision.equals(result, c.getValue(), epsilon)) {
                return false;
            }
            break;
            
        case GEQ:
            if (Precision.compareTo(result, c.getValue(), epsilon) < 0) {
                return false;
            }
            break;
            
        case LEQ:
            if (Precision.compareTo(result, c.getValue(), epsilon) > 0) {
                return false;
            }
            break;
        }
    }
    
    return true;
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:33,代码来源:SimplexSolverTest.java

示例9: doOptimize

import org.apache.commons.math3.util.Precision; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
public PointValuePair doOptimize()
    throws TooManyIterationsException,
           UnboundedSolutionException,
           NoFeasibleSolutionException {

    // reset the tableau to indicate a non-feasible solution in case
    // we do not pass phase 1 successfully
    if (solutionCallback != null) {
        solutionCallback.setTableau(null);
    }

    final SimplexTableau tableau =
        new SimplexTableau(getFunction(),
                           getConstraints(),
                           getGoalType(),
                           isRestrictedToNonNegative(),
                           epsilon,
                           maxUlps);

    solvePhase1(tableau);
    tableau.dropPhase1Objective();

    // after phase 1, we are sure to have a feasible solution
    if (solutionCallback != null) {
        solutionCallback.setTableau(tableau);
    }

    while (!tableau.isOptimal()) {
        doIteration(tableau);
    }

    // check that the solution respects the nonNegative restriction in case
    // the epsilon/cutOff values are too large for the actual linear problem
    // (e.g. with very small constraint coefficients), the solver might actually
    // find a non-valid solution (with negative coefficients).
    final PointValuePair solution = tableau.getSolution();
    if (isRestrictedToNonNegative()) {
        final double[] coeff = solution.getPoint();
        for (int i = 0; i < coeff.length; i++) {
            if (Precision.compareTo(coeff[i], 0, epsilon) < 0) {
                throw new NoFeasibleSolutionException();
            }
        }
    }
    return solution;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:49,代码来源:SimplexSolver.java

示例10: isValidPivotColumn

import org.apache.commons.math3.util.Precision; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:24,代码来源:SimplexSolver.java


注:本文中的org.apache.commons.math3.util.Precision.compareTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。