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:Main.java

/**
 * Finds the first occurrence of given value in <code>double</code>
 * array from specified given position.//from  w  ww  .  j a  v  a2  s.c o  m
 */
public static int indexOf(double[] array, double value, int startIndex) {
    for (int i = startIndex; i < array.length; i++) {
        if (Double.compare(array[i], value) == 0) {
            return i;
        }
    }
    return -1;
}

From source file:com.opengamma.analytics.financial.equity.option.EquityOptionDefinition.java

@Override
public boolean equals(final Object obj) {
    if (this == obj) {
        return true;
    }/*from w  ww .  j a v a 2s. c  o  m*/
    if (!(obj instanceof EquityOptionDefinition)) {
        return false;
    }
    final EquityOptionDefinition other = (EquityOptionDefinition) obj;
    if (Double.compare(_strike, other._strike) != 0) {
        return false;
    }
    if (_isCall != other._isCall) {
        return false;
    }
    if (_exerciseType != other._exerciseType) {
        return false;
    }
    if (_settlementType != other._settlementType) {
        return false;
    }
    if (Double.compare(_pointValue, other._pointValue) != 0) {
        return false;
    }
    if (!ObjectUtils.equals(_expiryDT, other._expiryDT)) {
        return false;
    }
    if (!ObjectUtils.equals(_currency, other._currency)) {
        return false;
    }
    if (!ObjectUtils.equals(_settlementDate, other._settlementDate)) {
        return false;
    }
    return true;
}

From source file:com.opengamma.analytics.financial.commodity.derivative.CommodityFuture.java

@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }//from w  ww .  jav a  2s  .c  o  m
    if (obj == null) {
        return false;
    }
    if (!(obj instanceof CommodityFuture)) {
        return false;
    }
    final CommodityFuture other = (CommodityFuture) obj;
    if (Double.doubleToLongBits(_expiry) != Double.doubleToLongBits(other._expiry)) {
        return false;
    }
    if (!ObjectUtils.equals(_underlying, other._underlying)) {
        return false;
    }
    if (!ObjectUtils.equals(_firstDeliveryDate, other._firstDeliveryDate)) {
        return false;
    }
    if (!ObjectUtils.equals(_lastDeliveryDate, other._lastDeliveryDate)) {
        return false;
    }
    if (!ObjectUtils.equals(_unitName, other._unitName)) {
        return false;
    }
    if (!ObjectUtils.equals(_settlementType, other._settlementType)) {
        return false;
    }
    if (!ObjectUtils.equals(_currency, other._currency)) {
        return false;
    }
    if (Double.compare(_amount, other._amount) != 0) {
        return false;
    }
    if (Double.compare(_settlement, other._settlement) != 0) {
        return false;
    }
    if (Double.compare(_referencePrice, other._referencePrice) != 0) {
        return false;
    }
    return true;
}

From source file:ml.shifu.shifu.core.dtrain.Weight.java

public double[] calculateWeights(double[] weights, double[] gradients, int iteration) {
    if (this.updateRule != null) {
        this.updateRule.update(gradients, weights, iteration, this.fixedWeights);
        return weights;
    } else {/*  www  .  j  av a2  s .  com*/
        for (int i = 0; i < gradients.length; i++) {
            switch (this.rl) {
            case NONE:
                weights[i] += updateWeight(i, weights, gradients);
                break;
            case L1:
                if (Double.compare(this.reg, 0d) == 0) {
                    weights[i] += updateWeight(i, weights, gradients);
                } else {
                    double shrinkValue = this.reg / getNumTrainSize();
                    double delta = updateWeight(i, weights, gradients);
                    weights[i] = Math.signum(delta) * Math.max(0.0, Math.abs(delta) - shrinkValue);
                }
                break;
            case L2:
            default:
                weights[i] += (updateWeight(i, weights, gradients) - this.reg * weights[i] / getNumTrainSize());
                break;
            }
        }
        return weights;
    }
}

From source file:be.ceau.chart.color.Color.java

/**
 * <p>//from w  w  w  .  j a va2s.com
 * Verify that argument is valid value for the alpha channel.
 * </p>
 * 
 * <p>
 * Any double between 0.0d and 1.0d (inclusive) is valid.
 * </p>
 * 
 * @param alpha
 * @return true if argument is valid alpha value
 */
public static boolean isAlphaWithinBounds(double alpha) {
    return Double.compare(0.0d, alpha) <= 0 && Double.compare(1.0d, alpha) >= 0;
}

From source file:org.diorite.commons.math.DioriteRandomUtils.java

public static double getRandomDouble(Random random, double min, double max) throws IllegalArgumentException {
    if (Double.compare(min, max) == 0) {
        return max;
    }/*from   w w  w .j  av  a2 s. c  o m*/
    Validate.isTrue(max > min, "Max can't be smaller than min!");
    return (random.nextDouble() * (max - min)) + min;
}

From source file:com.joptimizer.algebra.CholeskyFactorization.java

/**
 * //from   ww w  .j  av a2s . c  o m
 * @deprecated use the solve() methods instead
 */
@Deprecated
public DoubleMatrix2D getInverse() {

    //QInv = LTInv * LInv, but for symmetry (QInv=QInvT)
    //QInv = LInvT * LTInvT = LInvT * LInv, so
    //LInvT = LTInv, and we calculate
    //QInv = LInvT * LInv

    double[][] lTData = getLT().toArray();
    int dim = lTData.length;

    // LTInv calculation (it will be x)
    // NB: LInv is lower-triangular
    double[][] x = new double[dim][dim];
    for (int j = 0; j < dim; j++) {
        final double[] xJ = x[j];
        xJ[j] = 1.;
        final double[] lTJ = lTData[j];
        final double lTJJ = lTJ[j];
        for (int k = 0; k < j + 1; ++k) {
            xJ[k] /= lTJJ;
        }
        for (int i = j + 1; i < dim; i++) {
            final double[] xI = x[i];
            final double lTJI = lTJ[i];
            if (Double.compare(lTJI, 0.) != 0) {
                for (int k = 0; k < j + 1; ++k) {
                    xI[k] -= xJ[k] * lTJI;
                }
            }
        }
    }

    // transposition (L is upper-triangular)
    double[][] LInvTData = new double[dim][dim];
    for (int i = 0; i < dim; i++) {
        double[] LInvTDatai = LInvTData[i];
        for (int j = i; j < dim; j++) {
            LInvTDatai[j] = x[j][i];
        }
    }

    // QInv
    // NB: LInvT is upper-triangular, so LInvT[i][j]=0 if i>j
    final DoubleMatrix2D QInvData = F2.make(dim, dim);
    for (int row = 0; row < dim; row++) {
        final double[] LInvTDataRow = LInvTData[row];
        final DoubleMatrix1D QInvDataRow = QInvData.viewRow(row);
        for (int col = row; col < dim; col++) {// symmetry of QInv
            final double[] LInvTDataCol = LInvTData[col];
            double sum = 0;
            for (int i = col; i < dim; i++) {// upper triangular
                sum += LInvTDataRow[i] * LInvTDataCol[i];
            }
            QInvDataRow.setQuick(col, sum);
            QInvData.setQuick(col, row, sum);// symmetry of QInv
        }
    }

    return QInvData;
}

From source file:Business.InvertedIndex.java

public List searchForWholePhrase(List<DocInfo> docList, String[] queryTerms) {

    HashMap<DocInfo, Integer> documentPhraseScore = new HashMap<>();

    for (DocInfo doc : docList) {
        documentPhraseScore.put(doc, 0);
        int count = 0;
        for (String word1 : queryTerms) {
            String word2 = word1.replaceAll("[^\\w]", "");
            es.setCurrent(word2);/*from w ww  . j av a2 s.co  m*/
            es.stem();
            String queryTerm = es.getCurrent();
            HashSet<Integer> positions = new HashSet<>();

            if (doc.getTermsInADocument().containsKey(queryTerm)) {
                if (positions.isEmpty()) {
                    positions.addAll(doc.getTermsInADocument().get(queryTerm).getPositions());
                } else {
                    ArrayList<Integer> newPositions = doc.getTermsInADocument().get(queryTerm).getPositions();
                    ArrayList<Integer> tempList = new ArrayList<>();
                    boolean b = false;
                    for (int po : newPositions) {

                        if (positions.contains(po - 1)) {
                            tempList.add(po);
                            int currentScore = documentPhraseScore.get(doc);
                            int newScore = currentScore + count;
                            documentPhraseScore.put(doc, newScore);
                            b = true;
                        }
                    }
                    if (b) {
                        positions.clear();
                        positions.addAll(tempList);
                    }
                }
            }
            if (count == 0) {
                count++;
            } else {
                count = count * 10;
            }
        }

    }

    Set<DocInfo> set = documentPhraseScore.keySet();
    List<DocInfo> sortedDocs = new ArrayList<>(set);

    Collections.sort(sortedDocs, (DocInfo s1, DocInfo s2) -> Double.compare(documentPhraseScore.get(s2),
            documentPhraseScore.get(s1)));
    return sortedDocs;
}

From source file:edu.tum.cs.vis.model.util.HandleComparator.java

@Override
public int compare(HandleAnnotation o1, HandleAnnotation o2) {
    double w1 = getHandleWeight(o1, model, minRadius, maxRadius, minLength, maxLength);
    double w2 = getHandleWeight(o2, model, minRadius, maxRadius, minLength, maxLength);
    return Double.compare(w1, w2) * (-1);
}

From source file:smodelkit.util.Helper.java

/**
 * Returns an array of indexes into the given array, where the indexes are ordered such that
 * they sort their targets from greatest to least.
 * @param array//from   w w w . j a  va2 s  . c  o  m
 * @return
 */
public static Integer[] sortIndexesDescending(final double[] in) {
    Integer[] result = new Integer[in.length];

    for (int i = 0; i < result.length; i++)
        result[i] = i;

    Comparator<Integer> comparator = new Comparator<Integer>() {
        @Override
        public int compare(Integer i1, Integer i2) {
            return Double.compare(in[i1], in[i2]) * -1;
        }

    };
    Arrays.sort(result, comparator);
    return result;
}