Example usage for java.lang Double isFinite

List of usage examples for java.lang Double isFinite

Introduction

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

Prototype

public static boolean isFinite(double d) 

Source Link

Document

Returns true if the argument is a finite floating-point value; returns false otherwise (for NaN and infinity arguments).

Usage

From source file:edu.umd.umiacs.clip.tools.math.Formatter.java

public static double format(double d) {
    return Double.isFinite(d) ? round(d * 100) / 100d : d;
}

From source file:org.cirdles.ludwig.squid25.Utilities.java

/**
 * Performs excel-style rounding of double to a given number of significant
 * figures./*w ww  .  j a va 2 s .  c o  m*/
 *
 * @param value double to round
 * @param sigFigs count of significant digits for rounding
 * @return double rounded to sigFigs significant digits
 */
public static double roundedToSize(double value, int sigFigs) {
    BigDecimal valueBDtoSize = BigDecimal.ZERO;
    if (Double.isFinite(value)) {
        BigDecimal valueBD = new BigDecimal(value);
        int newScale = sigFigs - (valueBD.precision() - valueBD.scale());
        valueBDtoSize = valueBD.setScale(newScale, RoundingMode.HALF_UP);
    }
    return valueBDtoSize.doubleValue();
}

From source file:org.rhwlab.BHC.GammaRatio.java

public double getRatio(int n) {

    Double ret = ratios.get(n);/*from ww w  .jav a2  s  .co  m*/
    if (ret != null) {
        return ret;
    }

    double logr = 0.0;
    double r;
    if (n % 2 == 0) {

        for (int j = 1; j <= n / 2; ++j) {
            for (int i = 1; i <= d; ++i) {
                logr = logr + Math.log(((nu - 1.0 - i) / 2.0) + j);
            }
        }
        r = Math.exp(logr);
        ratios.put(n, r);
    } else {
        for (int j = 1; j <= (n - 1) / 2; ++j) {
            for (int i = 1; i <= d; ++i) {
                logr = logr + Math.log(((nu - i) / 2.0) + j);
            }
        }
        for (int i = 1; i <= d; ++i) {
            logr = logr + Gamma.logGamma((nu + 2.0 - i) / 2.0) - Gamma.logGamma((nu + 1.0 - i) / 2.0);
        }
        r = Math.exp(logr);
    }

    if (!Double.isFinite(r)) {
        System.out.println("Gamma ratio error");
        System.exit(n);
    }
    return r;
}

From source file:nars.util.meter.func.BasicStatistics.java

@Override
public Double getValue(Object key, int index) {

    if (index == 0) {
        double nextValue = newestValue().doubleValue();
        if (Double.isFinite(nextValue)) {
            if (stat instanceof SummaryStatistics)
                ((SummaryStatistics) stat).addValue(nextValue);
            else if (stat instanceof DescriptiveStatistics)
                ((DescriptiveStatistics) stat).addValue(nextValue);
        }//from   w w  w.j ava 2  s. c  om
    }

    switch (index) {
    case 0:
        return stat.getMean();
    case 1:
        return stat.getStandardDeviation();
    }

    return null;
}

From source file:ptrman.meter.func.BasicStatistics.java

@Override
protected Double getValue(Object key, int index) {

    if (index == 0) {
        double nextValue = newestValue().doubleValue();
        if (Double.isFinite(nextValue)) {
            if (stat instanceof SummaryStatistics)
                ((SummaryStatistics) stat).addValue(nextValue);
            else if (stat instanceof DescriptiveStatistics)
                ((DescriptiveStatistics) stat).addValue(nextValue);
        }//from   w  w  w . jav  a  2s.  c  om
    }

    switch (index) {
    case 0:
        return stat.getMean();
    case 1:
        return stat.getStandardDeviation();
    }

    return null;
}

From source file:org.apache.edgent.analytics.math3.stat.JsonStorelessStatistic.java

@Override
public void result(JsonElement partition, JsonObject result) {
    double rv = statImpl.getResult();

    if (Double.isFinite(rv))
        result.addProperty(stat.name(), rv);
}

From source file:nars.util.meter.event.PeriodMeter.java

public DescriptiveStatistics hit() {
    double now;//from ww  w . j av a 2 s . c om
    now = sinceStart() > window ? reset() : now(nanoSeconds);
    if (Double.isFinite(prev)) {
        double dt = now - prev;
        stat.addValue(dt);
    }
    prev = now;
    return stat;
}

From source file:ptrman.meter.event.PeriodMeter.java

public DescriptiveStatistics hit() {
    double now;//from   www . j  av a 2 s . c om
    if (sinceStart() > window) {
        now = reset();
    } else {
        now = now(nanoSeconds);
    }
    if (Double.isFinite(this.prev)) {
        double dt = now - this.prev;
        stat.addValue(dt);
    }
    this.prev = now;
    return stat;
}

From source file:ijfx.ui.utils.ChartUpdater.java

public void updateChart() {

    final double min; // minimum value
    final double max; // maximum value
    double range; // max - min
    final double binSize;
    // int maximumBinNumber = 30;
    int finalBinNumber;

    int differentValuesCount = possibleValues.stream().filter(n -> Double.isFinite(n.doubleValue()))
            .collect(Collectors.toSet()).size();
    if (differentValuesCount < maximumBinNumber) {
        finalBinNumber = differentValuesCount;
    } else {//from w w  w.  j  av a  2 s  .c  o m
        finalBinNumber = maximumBinNumber;
    }

    EmpiricalDistribution distribution = new EmpiricalDistribution(finalBinNumber);

    Double[] values = possibleValues.parallelStream().filter(n -> Double.isFinite(n.doubleValue()))
            .map(v -> v.doubleValue()).sorted()
            //.toArray();
            .toArray(size -> new Double[size]);
    distribution.load(ArrayUtils.toPrimitive(values));

    min = values[0];
    max = values[values.length - 1];
    range = max - min;
    binSize = range / (finalBinNumber - 1);

    //System.out.println(String.format("min = %.0f, max = %.0f, range = %.0f, bin size = %.0f, bin number = %d", min, max, range, binSize, finalBinNumber));

    XYChart.Series<Double, Double> serie = new XYChart.Series<>();
    ArrayList<XYChart.Data<Double, Double>> data = new ArrayList<>();
    double k = min;
    for (SummaryStatistics st : distribution.getBinStats()) {
        data.add(new XYChart.Data<>(k, new Double(st.getN())));
        k += binSize;
    }

    Platform.runLater(() -> {
        serie.getData().addAll(data);
        areaChart.getData().clear();
        areaChart.getData().add(serie);
    });

}

From source file:org.apache.edgent.analytics.math3.stat.JsonOLS.java

@Override
public void result(JsonElement partition, JsonObject result) {
    // If there are no values or only a single
    // value then we cannot calculate tne slope.
    if (values.length <= 2)
        return;/*from w  ww  .  j a  v a2s .c  o m*/

    setSampleData();
    double[] regressionParams = ols.estimateRegressionParameters();
    if (regressionParams.length >= 2) {
        // [0] is the constant (zero'th order)
        // [1] is the first order , which we use as the slope.
        final double slope = regressionParams[1];
        if (Double.isFinite(slope))
            result.addProperty(type.name(), slope);
    }
    values = null;
}