Example usage for java.lang Double compare

List of usage examples for java.lang Double compare

Introduction

In this page you can find the example usage for java.lang Double compare.

Prototype

public static int compare(double d1, double d2) 

Source Link

Document

Compares the two specified double values.

Usage

From source file:com.rapidminer.tools.Tools.java

/**
 * Returns <code>false</code> if either d1 or d2 is Double.NaN. Returns <code>true</code> if the
 * d1 is greater than d2 or both are equal.
 *///from  w w  w  . ja  v  a  2  s.c om
public static boolean isGreaterEqual(double d1, double d2) {
    if (Double.isNaN(d1) || Double.isNaN(d2)) {
        return false;
    }
    return Double.compare(d1, d2) > 0 || isEqual(d1, d2);
}

From source file:com.joptimizer.util.ColtUtils.java

/**
 * Return a new array with all the occurences of oldValue replaced by newValue.
 *///from   w  w w .  j av a 2 s.  c o m
public static final DoubleMatrix1D replaceValues(DoubleMatrix1D v, double oldValue, double newValue) {
    if (v == null) {
        return null;
    }
    DoubleFactory1D F1 = (v instanceof SparseDoubleMatrix1D) ? DoubleFactory1D.sparse : DoubleFactory1D.dense;
    DoubleMatrix1D ret = F1.make(v.size());
    for (int i = 0; i < v.size(); i++) {
        double vi = v.getQuick(i);
        if (Double.compare(oldValue, vi) != 0) {
            // no substitution
            ret.setQuick(i, vi);
        } else {
            ret.setQuick(i, newValue);
        }
    }
    return ret;
}

From source file:com.rapidminer.tools.Tools.java

/**
 * Returns <code>false</code> if either d1 or d2 is Double.NaN. Returns <code>true</code> if the
 * d1 is less than d2./*from   w  w  w  .  j  a  va 2 s .  c  o m*/
 */
public static boolean isLess(double d1, double d2) {
    if (Double.isNaN(d1) || Double.isNaN(d2)) {
        return false;
    }
    return Double.compare(d1, d2) < 0;
}

From source file:ml.shifu.shifu.core.binning.UpdateBinningInfoReducer.java

private double[] computeRateForMultiClassfication(long[] binCount) {
    double[] rate = new double[binCount.length];
    double sum = 0d;
    for (int i = 0; i < binCount.length; i++) {
        sum += binCount[i];/*  w w  w. j  ava  2s.com*/
    }
    for (int i = 0; i < binCount.length; i++) {
        if (Double.compare(sum, 0d) != 0) {
            rate[i] = binCount[i] * 1.0d / sum;
        }
    }
    return rate;
}

From source file:com.joptimizer.util.MPSParser.java

protected boolean isLbUnbounded(Double lb) {
    return Double.compare(unboundedLBValue, lb) == 0;
}

From source file:com.joptimizer.util.MPSParser.java

protected boolean isUbUnbounded(Double ub) {
    return Double.compare(unboundedUBValue, ub) == 0;
}

From source file:com.rapidminer.tools.Tools.java

/**
 * Returns <code>false</code> if either d1 or d2 is Double.NaN. Returns <code>true</code> if the
 * d1 is less than d2 or both are equal.
 *//*from  w  ww.  j a  v  a 2  s.co m*/
public static boolean isLessEqual(double d1, double d2) {
    if (Double.isNaN(d1) || Double.isNaN(d2)) {
        return false;
    }
    return Double.compare(d1, d2) < 0 || isEqual(d1, d2);
}

From source file:cz.cuni.mff.spl.evaluator.statistics.KolmogorovSmirnovTestFlag.java

private long integralKolmogorovSmirnovStatistic(double[] x, double[] y) {
    checkArray(x);// w  ww.  ja v a2 s.  c om
    checkArray(y);
    // Copy and sort the sample arrays
    final double[] sx = MathArrays.copyOf(x);
    final double[] sy = MathArrays.copyOf(y);
    Arrays.sort(sx);
    Arrays.sort(sy);
    final int n = sx.length;
    final int m = sy.length;

    int rankX = 0;
    int rankY = 0;
    long curD = 0l;

    // Find the max difference between cdf_x and cdf_y
    long supD = 0l;
    do {
        double z = Double.compare(sx[rankX], sy[rankY]) <= 0 ? sx[rankX] : sy[rankY];
        while (rankX < n && Double.compare(sx[rankX], z) == 0) {
            rankX += 1;
            curD += m;
        }
        while (rankY < m && Double.compare(sy[rankY], z) == 0) {
            rankY += 1;
            curD -= n;
        }
        if (curD > supD) {
            supD = curD;
        } else if (-curD > supD) {
            supD = -curD;
        }
    } while (rankX < n && rankY < m);
    return supD;
}

From source file:org.esa.nest.gpf.ASARCalibrator.java

/**
 * Get calibration factor from user specified auxiliary data.
 *
 * @param auxFilePath       The absolute path to the aux file.
 * @param swath             The product swath.
 * @param mdsPolar          The product polarizations.
 * @param productType       The product type.
 * @param calibrationFactor The calibration factors.
 *//*  w ww .ja  v  a2s  .co m*/
public static void getCalibrationFactorFromExternalAuxFile(String auxFilePath, String swath, String[] mdsPolar,
        String productType, double[] calibrationFactor) {

    final EnvisatAuxReader reader = new EnvisatAuxReader();

    try {

        reader.readProduct(auxFilePath);

        final int numOfSwaths = 7;
        String calibrationFactorName;
        for (int i = 0; i < 2 && mdsPolar[i] != null && mdsPolar[i].length() != 0; i++) {

            calibrationFactor[i] = 0;

            if (productType.contains("ASA_IMP_1")) {
                calibrationFactorName = "ext_cal_im_pri_" + mdsPolar[i];
            } else if (productType.contains("ASA_IMM_1")) {
                calibrationFactorName = "ext_cal_im_med_" + mdsPolar[i];
            } else if (productType.contains("ASA_APP_1")) {
                calibrationFactorName = "ext_cal_ap_pri_" + mdsPolar[i];
            } else if (productType.contains("ASA_APM_1")) {
                calibrationFactorName = "ext_cal_ap_med_" + mdsPolar[i];
            } else if (productType.contains("ASA_WS")) {
                calibrationFactorName = "ext_cal_ws_" + mdsPolar[i];
            } else if (productType.contains("ASA_GM1_1")) {
                calibrationFactorName = "ext_cal_gm_" + mdsPolar[i];
            } else if (productType.contains("ASA_IMG_1")) {
                calibrationFactorName = "ext_cal_im_geo_" + mdsPolar[i];
            } else if (productType.contains("ASA_APG_1")) {
                calibrationFactorName = "ext_cal_ap_geo_" + mdsPolar[i];
            } else if (productType.contains("ASA_IMS_1")) {
                calibrationFactorName = "ext_cal_im_" + mdsPolar[i];
            } else if (productType.contains("ASA_APS_1")) {
                calibrationFactorName = "ext_cal_ap_" + mdsPolar[i];
            } else {
                throw new OperatorException("Invalid ASAR product type.");
            }

            final ProductData factorData = reader.getAuxData(calibrationFactorName);
            final float[] factors = (float[]) factorData.getElems();

            if (productType.contains("ASA_WS") || productType.contains("ASA_GM1")) {
                calibrationFactor[i] = factors[0];
            } else {
                if (factors.length != numOfSwaths) {
                    throw new OperatorException("Incorrect array length for " + calibrationFactorName);
                }
                if (swath.contains("S1")) {
                    calibrationFactor[i] = factors[0];
                } else if (swath.contains("S2")) {
                    calibrationFactor[i] = factors[1];
                } else if (swath.contains("S3")) {
                    calibrationFactor[i] = factors[2];
                } else if (swath.contains("S4")) {
                    calibrationFactor[i] = factors[3];
                } else if (swath.contains("S5")) {
                    calibrationFactor[i] = factors[4];
                } else if (swath.contains("S6")) {
                    calibrationFactor[i] = factors[5];
                } else if (swath.contains("S7")) {
                    calibrationFactor[i] = factors[6];
                } else {
                    throw new OperatorException("Invalid swath");
                }
            }
        }

    } catch (IOException e) {
        throw new OperatorException(e);
    }

    if (Double.compare(calibrationFactor[0], 0.0) == 0 && Double.compare(calibrationFactor[1], 0.0) == 0) {
        throw new OperatorException("Calibration factors in user provided auxiliary file are zero");
    }
}

From source file:ml.shifu.shifu.core.dtrain.dt.DTMaster.java

/**
 * Split node into left and right for leaf-wised tree growth, doneNode should be populated by
 * {@link #populateGainInfoToNode(int, Node, GainInfo)}.
 *//*from  www.  ja v a 2 s  . c  o  m*/
private void splitNodeForLeafWisedTree(int treeId, Node doneNode) {
    boolean isOverMaxLeaves = this.trees.get(treeId).getNodeNum() + 1 > this.maxLeaves;
    boolean canSplit = !isOverMaxLeaves && Double.compare(doneNode.getLeftImpurity(), 0d) != 0;
    // if can split left, at the same time create left and right node
    if (canSplit) {
        int leftIndex = Node.leftIndex(doneNode.getId());
        Node left = new Node(leftIndex, doneNode.getLeftPredict(), doneNode.getLeftImpurity(), true);

        doneNode.setLeft(left);
        this.trees.get(treeId).incrNodeNum();
        this.toDoQueue.offer(new TreeNode(treeId, left));

        int rightIndex = Node.rightIndex(doneNode.getId());
        Node right = new Node(rightIndex, doneNode.getRightPredict(), doneNode.getRightImpurity(), true);

        doneNode.setRight(right);
        this.trees.get(treeId).incrNodeNum();
        this.toDoQueue.offer(new TreeNode(treeId, right));
    }
}