Example usage for java.lang Double POSITIVE_INFINITY

List of usage examples for java.lang Double POSITIVE_INFINITY

Introduction

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

Prototype

double POSITIVE_INFINITY

To view the source code for java.lang Double POSITIVE_INFINITY.

Click Source Link

Document

A constant holding the positive infinity of type double .

Usage

From source file:net.sf.click.jquery.examples.util.JQInlineValidationHelper.java

public void renderValue(HtmlStringBuffer buffer, double min, double max) {
    if (min == Double.NEGATIVE_INFINITY && max == Double.POSITIVE_INFINITY) {
        return;//from   w  w  w.  j  av a2s. c  om
    }

    if (buffer.length() > 0) {
        buffer.append(",");
    } else {
        buffer.append("validate[");
    }
    if (min != Double.NEGATIVE_INFINITY) {
        buffer.append("minvalue[").append(min).append("]");
    }
    if (max != Double.POSITIVE_INFINITY) {
        buffer.append("maxvalue[").append(max).append("]");
    }
}

From source file:de.tudarmstadt.lt.lm.app.LineProbPerp.java

void processLine(String line, ModelPerplexity<String> perp, ModelPerplexity<String> perp_oov) {

    if (line.trim().isEmpty()) {
        println(getOutputLine(line, 0, 0, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY,
                Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY));
        return;//from w ww.  j a v  a 2 s .co m
    }

    List<String>[] ngrams;
    try {
        List<String> tokens = _lm_prvdr.tokenizeSentence(line);
        if (tokens == null || tokens.isEmpty()) {
            println(getOutputLine(line, 0, 0, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY,
                    Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY));
            return;
        }
        ngrams = _lm_prvdr.getNgramSequence(tokens);
        if (ngrams == null || ngrams.length == 0) {
            println(getOutputLine(line, 0, 0, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY,
                    Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY));
            return;
        }
    } catch (Exception e) {
        LOG.error("{}: Could not get ngrams from line '{}'.", _rmi_string, StringUtils.abbreviate(line, 100),
                e);
        return;
    }

    perp.reset();
    perp_oov.reset();
    for (List<String> ngram : ngrams) {
        if (ngram.isEmpty())
            continue;
        try {
            perp_oov.addLog10Prob(ngram);
            if (!_lm_prvdr.ngramEndsWithOOV(ngram))
                perp.addLog10Prob(ngram);

        } catch (Exception e) {
            LOG.error("{}: Could not add ngram '{}' to perplexity.", _rmi_string, ngram);
            continue;
        }
    }
    println(getOutputLine(line, perp_oov.getN(), perp_oov.getN() - perp.getN(), perp_oov.getLog10Probs(),
            perp_oov.get(), perp.getLog10Probs(), perp.get()));

}

From source file:com.opengamma.analytics.financial.interestrate.future.provider.BondFutureHullWhiteMethod.java

/**
 * Computes the future price from the curves used to price the underlying bonds and a Hull-White one factor model.
 * @param future The future security.//  w w w .j av a  2 s . c  o  m
 * @param data The curve and Hull-White parameters.
 * @param nbPoint The number of point in the numerical cross estimation.
 * @return The future price.
 */
public double price(final BondFuture future, final HullWhiteIssuerProviderInterface data, final int nbPoint) {
    ArgumentChecker.notNull(future, "Future");
    ArgumentChecker.notNull(data, "Hull-White data bundle");
    final Pair<String, Currency> issuerCcy = future.getDeliveryBasket()[0].getIssuerCcy();
    ArgumentChecker.isTrue(data.getHullWhiteIssuerCurrency().equals(issuerCcy),
            "Incompatible data and futures");
    final int nbBond = future.getDeliveryBasket().length;
    final String issuerName = future.getDeliveryBasket()[0].getIssuer();
    final HullWhiteOneFactorPiecewiseConstantParameters parameters = data.getHullWhiteParameters();
    final IssuerProviderInterface issuer = data.getIssuerProvider();
    final MulticurveProviderInterface multicurvesDecorated = new MulticurveProviderDiscountingDecoratedIssuer(
            issuer, future.getCurrency(), issuerName);
    final double expiry = future.getNoticeLastTime();
    final double delivery = future.getDeliveryLastTime();
    final double dfdelivery = data.getIssuerProvider().getDiscountFactor(issuerCcy, delivery);
    // Constructing non-homogeneous point series for the numerical estimations.
    final int nbPtWing = ((int) Math.floor(nbPoint / 20.)); // Number of point on each wing.
    final int nbPtCenter = nbPoint - 2 * nbPtWing;
    final double prob = 1.0 / (2.0 * nbPtCenter);
    final double xStart = NORMAL.getInverseCDF(prob);
    final double[] x = new double[nbPoint];
    for (int loopwing = 0; loopwing < nbPtWing; loopwing++) {
        x[loopwing] = xStart * (1.0 + (nbPtWing - loopwing) / 2.0);
        x[nbPoint - 1 - loopwing] = -xStart * (1.0 + (nbPtWing - loopwing) / 2.0);
    }
    for (int loopcent = 0; loopcent < nbPtCenter; loopcent++) {
        x[nbPtWing + loopcent] = xStart + loopcent * (-2.0 * xStart) / (nbPtCenter - 1);
    }
    // Figures for each bond
    final double[][] cfTime = new double[nbBond][];
    final double[][] df = new double[nbBond][];
    final double[][] alpha = new double[nbBond][];
    final double[][] beta = new double[nbBond][];
    final double[][] cfaAdjusted = new double[nbBond][];
    final double[] e = new double[nbBond];
    final double[][] pv = new double[nbPoint][nbBond];
    final AnnuityPaymentFixed[] cf = new AnnuityPaymentFixed[nbBond];
    for (int loopbnd = 0; loopbnd < nbBond; loopbnd++) {
        cf[loopbnd] = future.getDeliveryBasket()[loopbnd].accept(CFEC, multicurvesDecorated);
        final int nbCf = cf[loopbnd].getNumberOfPayments();
        cfTime[loopbnd] = new double[nbCf];
        df[loopbnd] = new double[nbCf];
        alpha[loopbnd] = new double[nbCf];
        beta[loopbnd] = new double[nbCf];
        cfaAdjusted[loopbnd] = new double[nbCf];
        for (int loopcf = 0; loopcf < nbCf; loopcf++) {
            cfTime[loopbnd][loopcf] = cf[loopbnd].getNthPayment(loopcf).getPaymentTime();
            df[loopbnd][loopcf] = issuer.getDiscountFactor(issuerCcy, cfTime[loopbnd][loopcf]);
            alpha[loopbnd][loopcf] = MODEL.alpha(parameters, 0.0, expiry, delivery, cfTime[loopbnd][loopcf]);
            beta[loopbnd][loopcf] = MODEL.futuresConvexityFactor(parameters, expiry, cfTime[loopbnd][loopcf],
                    delivery);
            cfaAdjusted[loopbnd][loopcf] = df[loopbnd][loopcf] / dfdelivery * beta[loopbnd][loopcf]
                    * cf[loopbnd].getNthPayment(loopcf).getAmount() / future.getConversionFactor()[loopbnd];
            for (int looppt = 0; looppt < nbPoint; looppt++) {
                pv[looppt][loopbnd] += cfaAdjusted[loopbnd][loopcf]
                        * Math.exp(-alpha[loopbnd][loopcf] * alpha[loopbnd][loopcf] / 2.0
                                - alpha[loopbnd][loopcf] * x[looppt]);
            }
        }
        e[loopbnd] = future.getDeliveryBasket()[loopbnd].getAccruedInterest()
                / future.getConversionFactor()[loopbnd];
        for (int looppt = 0; looppt < nbPoint; looppt++) {
            pv[looppt][loopbnd] -= e[loopbnd];
        }
    }
    // Minimum: create a list of index of the CTD in each interval and a first estimate of the crossing point (x[]).
    final double[] pvMin = new double[nbPoint];
    final int[] indMin = new int[nbPoint];
    for (int looppt = 0; looppt < nbPoint; looppt++) {
        pvMin[looppt] = Double.POSITIVE_INFINITY;
        for (int loopbnd = 0; loopbnd < nbBond; loopbnd++) {
            if (pv[looppt][loopbnd] < pvMin[looppt]) {
                pvMin[looppt] = pv[looppt][loopbnd];
                indMin[looppt] = loopbnd;
            }
        }
    }
    final ArrayList<Double> refx = new ArrayList<>();
    final ArrayList<Integer> ctd = new ArrayList<>();
    int lastInd = indMin[0];
    ctd.add(indMin[0]);
    for (int looppt = 1; looppt < nbPoint; looppt++) {
        if (indMin[looppt] != lastInd) {
            ctd.add(indMin[looppt]);
            lastInd = indMin[looppt];
            refx.add(x[looppt]);
        }
    }

    // Sum on each interval
    final int nbInt = ctd.size();
    final double[] kappa = new double[nbInt - 1];
    double price = 0.0;
    if (nbInt == 1) {
        for (int loopcf = 0; loopcf < cfaAdjusted[ctd.get(0)].length; loopcf++) {
            price += cfaAdjusted[ctd.get(0)][loopcf];
        }
        price -= e[ctd.get(0)];
    } else {
        // The intersections
        final BracketRoot bracketer = new BracketRoot();
        final double accuracy = 1.0E-8;
        final RidderSingleRootFinder rootFinder = new RidderSingleRootFinder(accuracy);
        for (int loopint = 1; loopint < nbInt; loopint++) {
            final BondDifference cross = new BondDifference(cfaAdjusted[ctd.get(loopint - 1)],
                    alpha[ctd.get(loopint - 1)], e[ctd.get(loopint - 1)], cfaAdjusted[ctd.get(loopint)],
                    alpha[ctd.get(loopint)], e[ctd.get(loopint)]);
            final double[] range = bracketer.getBracketedPoints(cross, refx.get(loopint - 1) - 0.01,
                    refx.get(loopint - 1) + 0.01);
            kappa[loopint - 1] = rootFinder.getRoot(cross, range[0], range[1]);
        }
        // From -infinity to first cross.
        for (int loopcf = 0; loopcf < cfaAdjusted[ctd.get(0)].length; loopcf++) {
            price += cfaAdjusted[ctd.get(0)][loopcf] * NORMAL.getCDF(kappa[0] + alpha[ctd.get(0)][loopcf]);
        }
        price -= e[ctd.get(0)] * NORMAL.getCDF(kappa[0]);
        // Between cross
        for (int loopint = 1; loopint < nbInt - 1; loopint++) {
            for (int loopcf = 0; loopcf < cfaAdjusted[ctd.get(loopint)].length; loopcf++) {
                price += cfaAdjusted[ctd.get(loopint)][loopcf]
                        * (NORMAL.getCDF(kappa[loopint] + alpha[ctd.get(loopint)][loopcf])
                                - NORMAL.getCDF(kappa[loopint - 1] + alpha[ctd.get(loopint)][loopcf]));
            }
            price -= e[ctd.get(loopint)] * (NORMAL.getCDF(kappa[loopint]) - NORMAL.getCDF(kappa[loopint - 1]));
        }
        // From last cross to +infinity
        for (int loopcf = 0; loopcf < cfaAdjusted[ctd.get(nbInt - 1)].length; loopcf++) {
            price += cfaAdjusted[ctd.get(nbInt - 1)][loopcf]
                    * (1.0 - NORMAL.getCDF(kappa[nbInt - 2] + alpha[ctd.get(nbInt - 1)][loopcf]));
        }
        price -= e[ctd.get(nbInt - 1)] * (1 - NORMAL.getCDF(kappa[nbInt - 2]));
    }

    return price;
}

From source file:ffx.xray.parsers.CIFFilter.java

/**
 * {@inheritDoc}/*w w w  .j  av  a  2 s  .  c om*/
 */
@Override
public double getResolution(File cifFile, Crystal crystal) {

    double resolution = Double.POSITIVE_INFINITY;

    try {
        BufferedReader br = new BufferedReader(new FileReader(cifFile));
        String string;
        int nCol = 0;
        boolean inHKL = false;
        while ((string = br.readLine()) != null) {
            String strArray[] = string.split("\\s+");
            if (strArray[0].startsWith("_refln.")) {
                inHKL = true;
                br.mark(0);
                String cifArray[] = strArray[0].split("\\.+");
                switch (Header.toHeader(cifArray[1])) {
                case index_h:
                    h = nCol;
                    break;
                case index_k:
                    k = nCol;
                    break;
                case index_l:
                    l = nCol;
                    break;
                }
                nCol++;
            } else if (inHKL) {
                if (h < 0 || k < 0 || l < 0) {
                    String message = " Fatal error in CIF file - no H K L indexes?\n";
                    logger.log(Level.SEVERE, message);
                    return -1.0;
                }
                break;
            }
        }

        // Go back to where the reflections start.
        br.reset();
        HKL hkl = new HKL();
        while ((string = br.readLine()) != null) {

            // Reached end, break.
            if (string.trim().startsWith("#END")) {
                break;
            } else if (string.trim().startsWith("data")) {
                break;
            } else if (string.trim().startsWith("#")) {
                continue;
            }

            // Some files split data on to multiple lines.
            String strArray[] = string.trim().split("\\s+");
            while (strArray.length < nCol) {
                string = string + " " + br.readLine();
                strArray = string.trim().split("\\s+");
            }

            int ih = Integer.parseInt(strArray[h]);
            int ik = Integer.parseInt(strArray[k]);
            int il = Integer.parseInt(strArray[l]);

            hkl.h(ih);
            hkl.k(ik);
            hkl.l(il);
            resolution = min(resolution, Crystal.res(crystal, hkl));
        }
    } catch (IOException e) {
        String message = " CIF IO Exception.";
        logger.log(Level.WARNING, message, e);
        return -1.0;
    }
    return resolution;
}

From source file:gmc_hdfs.distribution.ParetoDistribution.java

/**
 * {@inheritDoc}//from   w w  w  .  j  a v a 2  s.  c  om
 * <p>
 * For scale {@code k} and shape {@code }, the variance is given by
 * <ul>
 * <li>{@code } if {@code 1 <  <= 2},</li>
 * <li>{@code k^2 *  / (( - 1)^2 * ( - 2))} otherwise.</li>
 * </ul>
 */
public double getNumericalVariance() {
    if (shape <= 2) {
        return Double.POSITIVE_INFINITY;
    }
    double s = shape - 1;
    return scale * scale * shape / (s * s) / (shape - 2);
}

From source file:com.rapidminer.gui.plotter.charts.BubbleChartPlotter.java

private void prepareNominalData() {
    DataTable dataTable = getDataTable();
    this.nominal = true;
    xyzDataSet = new DefaultXYZDataset();

    if (axis[X_AXIS] >= 0 && axis[Y_AXIS] >= 0 && axis[BUBBLE_SIZE_AXIS] >= 0) {

        this.bubbleSizeMin = Double.POSITIVE_INFINITY;
        this.bubbleSizeMax = Double.NEGATIVE_INFINITY;
        this.xAxisMin = Double.POSITIVE_INFINITY;
        this.xAxisMax = Double.NEGATIVE_INFINITY;
        this.yAxisMin = Double.POSITIVE_INFINITY;
        this.yAxisMax = Double.NEGATIVE_INFINITY;
        this.minColor = Double.POSITIVE_INFINITY;
        this.maxColor = Double.NEGATIVE_INFINITY;

        Map<String, List<double[]>> dataCollection = new LinkedHashMap<>();

        synchronized (dataTable) {
            Iterator<DataTableRow> i = dataTable.iterator();
            while (i.hasNext()) {
                DataTableRow row = i.next();

                double xValue = row.getValue(axis[X_AXIS]);
                double yValue = row.getValue(axis[Y_AXIS]);
                double bubbleSizeValue = row.getValue(axis[BUBBLE_SIZE_AXIS]);

                double colorValue = Double.NaN;
                if (colorColumn >= 0) {
                    colorValue = row.getValue(colorColumn);
                }//from w  ww  .j  av a2s.  c o  m

                if (!Double.isNaN(xValue) && !Double.isNaN(yValue) && !Double.isNaN(bubbleSizeValue)) {
                    addPoint(dataTable, dataCollection, xValue, yValue, bubbleSizeValue, colorValue);
                }
            }
        }

        Iterator<Map.Entry<String, List<double[]>>> i = dataCollection.entrySet().iterator();
        double scaleFactor = Math.min(this.xAxisMax - this.xAxisMin, this.yAxisMax - this.yAxisMin) / 4.0d;
        while (i.hasNext()) {
            Map.Entry<String, List<double[]>> entry = i.next();
            String seriesName = entry.getKey();
            List<double[]> dataList = entry.getValue();
            double[][] data = new double[3][dataList.size()];
            int listCounter = 0;
            Iterator<double[]> j = dataList.iterator();
            while (j.hasNext()) {
                double[] current = j.next();
                data[X_AXIS][listCounter] = current[X_AXIS];
                data[Y_AXIS][listCounter] = current[Y_AXIS];
                data[BUBBLE_SIZE_AXIS][listCounter] = ((current[BUBBLE_SIZE_AXIS] - bubbleSizeMin)
                        / (bubbleSizeMax - bubbleSizeMin) + 0.1) * scaleFactor;
                listCounter++;
            }
            xyzDataSet.addSeries(seriesName, data);
        }
    }
}

From source file:net.sourceforge.jasa.report.HistoricalDataReport.java

public double getLowestAcceptedBidPrice() {
    Iterator<Order> i = bids.iterator();
    double lowestAcceptedBidPrice = Double.POSITIVE_INFINITY;
    while (i.hasNext()) {
        Order s = i.next();/*from w w w. ja v a2s.  c  om*/
        if (accepted(s)) {
            if (s.getPriceAsDouble() < lowestAcceptedBidPrice) {
                lowestAcceptedBidPrice = s.getPriceAsDouble();
            }
        }
    }
    return lowestAcceptedBidPrice;

}

From source file:edu.cuny.cat.stat.HistoricalReport.java

private void initializePriceRanges() {
    highestBidPrice = Double.NEGATIVE_INFINITY;
    lowestAskPrice = Double.POSITIVE_INFINITY;

    highestUnmatchedBid = null;
    lowestUnmatchedAsk = null;
}

From source file:it.uniroma2.sag.kelp.learningalgorithm.classification.dcd.DCDLearningAlgorithm.java

private double getU(Example e) {
    if (dcdLoss == DCDLoss.L1) {
        if (e.isExampleOf(label))
            return cp;
        else//  w w  w  . java2s. co m
            return cn;
    } else
        return Double.POSITIVE_INFINITY;
}

From source file:guineu.modules.filter.Alignment.SerumHuNormalization.SerumHuNormalizationTask.java

private void normalize(Dataset data, Dataset newData) {
    // First row => ids of the samples ( 0 == standard serum, 1 == normal sample)
    this.ids = data.getRow(0).clone();

    // Second row => run order
    this.runOrder = data.getRow(0).clone();

    // Third row => different data sets
    this.batches = data.getRow(0).clone();

    for (String name : data.getAllColumnNames()) {
        ids.setPeak(name, data.getParametersValue(name, this.id));
        runOrder.setPeak(name, data.getParametersValue(name, this.order));
        batches.setPeak(name, data.getParametersValue(name, this.batchesName));
    }/*from   w w w .  j  a  v a 2 s.co  m*/

    int numBatches = 1;
    double n = (Double) batches.getPeak(data.getAllColumnNames().get(0));

    for (String name : data.getAllColumnNames()) {
        if ((Double) batches.getPeak(name) > n) {
            numBatches++;
            n = (Double) batches.getPeak(name);
        }
    }

    this.createCurves(data, numBatches);
    for (int batch = 0; batch < numBatches; batch++) {
        message = "Normalizing";
        this.totalRows = data.getNumberRows();
        this.processedRows = 0;
        List<String> names = data.getAllColumnNames();
        for (int i = 0; i < data.getNumberRows(); i++) {
            this.processedRows++;
            PeakListRow row = data.getRow(i);
            PeakListRow newrow = newData.getRow(i);
            try {
                // Get the interpolation of all the human serum points using Loess 
                PolynomialSplineFunction function = functions.get(row.getID()).get(batch);

                if (function != null) {
                    // Prepare the points for the extrapolation
                    PolynomialFunction extrapolationFunction = null;
                    if (this.extrapolation) {
                        List<Double> points = new ArrayList<Double>();
                        for (int e = 0; e < row.getNumberPeaks(); e++) {
                            if ((Double) batches.getPeak(names.get(e)) == batch) {
                                try {
                                    points.add(function.value((Double) runOrder.getPeak(names.get(e))));
                                } catch (ArgumentOutsideDomainException ex) {
                                    Logger.getLogger(SerumHuNormalizationTask.class.getName()).log(Level.SEVERE,
                                            null, ex);
                                }
                            }
                        }

                        // Extrapolation function
                        extrapolationFunction = this.fittPolinomialFunction(batches, runOrder, names, batch,
                                points);
                    }
                    double lastPoint = 0;
                    for (int e = 0; e < row.getNumberPeaks(); e++) {
                        String sampleName = names.get(e);
                        if ((Double) ids.getPeak(sampleName) > 0.0) {
                            if ((Double) batches.getPeak(sampleName) == batch) {
                                try {

                                    if ((Double) ids.getPeak(sampleName) == 0) {
                                        lastPoint = function.value((Double) runOrder.getPeak(sampleName));
                                    }
                                    double value = 0;
                                    try {
                                        Double controlMol = function
                                                .value((Double) runOrder.getPeak(names.get(e)));
                                        if (controlMol < 0.0 || controlMol == Double.NaN
                                                || controlMol == Double.POSITIVE_INFINITY
                                                || controlMol == Double.NEGATIVE_INFINITY) {
                                            controlMol = getAverage(ids, row, e, names);
                                        }

                                        value = (Double) row.getPeak(sampleName) / controlMol;

                                        if (value < 0.0 || value == Double.NaN
                                                || value == Double.POSITIVE_INFINITY
                                                || value == Double.NEGATIVE_INFINITY) {
                                            controlMol = getAverage(ids, row, e, names);
                                        }

                                        value = (Double) row.getPeak(sampleName) / controlMol;
                                    } catch (ClassCastException exception) {
                                        value = -100;
                                    }
                                    newrow.setPeak(sampleName, value);
                                } catch (ArgumentOutsideDomainException ex) {
                                    // ex.printStackTrace();
                                    //if the value has to be extrapolated
                                    if (extrapolation && extrapolationFunction != null) {
                                        double value = 0;
                                        try {

                                            Double controlMol = extrapolationFunction
                                                    .value((Double) runOrder.getPeak(names.get(e)));
                                            if (controlMol < 0.0 || controlMol == Double.NaN
                                                    || controlMol == Double.POSITIVE_INFINITY
                                                    || controlMol == Double.NEGATIVE_INFINITY) {
                                                controlMol = getAverage(ids, row, e, names);
                                            }
                                            value = (Double) row.getPeak(sampleName) / controlMol;

                                            if (value < 0.0 || value == Double.NaN
                                                    || value == Double.POSITIVE_INFINITY
                                                    || value == Double.NEGATIVE_INFINITY) {
                                                controlMol = getAverage(ids, row, e, names);
                                            }

                                            value = (Double) row.getPeak(sampleName) / controlMol;
                                        } catch (ClassCastException exception) {
                                            value = -100;
                                        }
                                        newrow.setPeak(sampleName, value);
                                    } else {
                                        double value = 0;
                                        try {
                                            value = (Double) row.getPeak(sampleName) / lastPoint;//extrapolationFunction.value((Double) runOrder.getPeak(names.elementAt(e)));
                                        } catch (ClassCastException exception) {
                                            value = -100;
                                        }
                                        newrow.setPeak(sampleName, value);
                                    }

                                }
                            }
                        }
                    }
                } else {
                    System.out.println("Function is null" + row.getID());
                }
            } catch (Exception exception) {
                exception.printStackTrace();
                System.out.println(row.getID());

            }
        }
    }

}