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:de.bund.bfr.math.VectorFunction.java

@Override
public double[] value(double[] point) throws IllegalArgumentException {
    List<Double> result = new ArrayList<>();

    for (int i = 0; i < parameters.size(); i++) {
        parser.setVarValue(parameters.get(i), point[i]);
    }// w  ww.j  a  va  2  s . co m

    int n = variableValues.values().stream().findAny().get().size();

    for (int i = 0; i < n; i++) {
        for (Map.Entry<String, List<Double>> entry : variableValues.entrySet()) {
            parser.setVarValue(entry.getKey(), entry.getValue().get(i));
        }

        try {
            double value = parser.evaluate(function);

            result.add(Double.isFinite(value) ? value : Double.NaN);
        } catch (ParseException e) {
            e.printStackTrace();
            result.add(Double.NaN);
        }
    }

    return Doubles.toArray(result);
}

From source file:com.facebook.presto.operator.aggregation.TestDoubleRegrSlopeAggregation.java

private void testNonTrivialAggregation(Double[] y, Double[] x) {
    SimpleRegression regression = new SimpleRegression();
    for (int i = 0; i < x.length; i++) {
        regression.addData(x[i], y[i]);/*from   w w w .j  a va  2 s.  c  o  m*/
    }
    double expected = regression.getSlope();
    checkArgument(Double.isFinite(expected) && expected != 0.0, "Expected result is trivial");
    testAggregation(expected, createDoublesBlock(y), createDoublesBlock(x));
}

From source file:com.facebook.presto.operator.aggregation.TestDoubleRegrInterceptAggregation.java

private void testNonTrivialAggregation(Double[] y, Double[] x) {
    SimpleRegression regression = new SimpleRegression();
    for (int i = 0; i < x.length; i++) {
        regression.addData(x[i], y[i]);//from  w w w  .j a v  a 2 s.  c o m
    }
    double expected = regression.getIntercept();
    checkArgument(Double.isFinite(expected) && expected != 0., "Expected result is trivial");
    testAggregation(expected, createDoublesBlock(y), createDoublesBlock(x));
}

From source file:objenome.op.Numeric1.java

@Override
public Node normalize() {

    double a = getChildConstantValue(0);
    if (Double.isFinite(a))
        return new Doubliteral(value(a));

    return super.normalize();
}

From source file:com.facebook.presto.operator.aggregation.TestCorrelationAggregation.java

private void testNonTrivialAggregation(double[] y, double[] x) {
    PearsonsCorrelation corr = new PearsonsCorrelation();
    double expected = corr.correlation(x, y);
    checkArgument(Double.isFinite(expected) && expected != 0.0 && expected != 1.0,
            "Expected result is trivial");
    testAggregation(expected, createDoublesBlock(box(y)), createDoublesBlock(box(x)));
}

From source file:de.bund.bfr.math.LodFunction.java

@Override
public double value(double[] point) {
    double sd = Double.NaN;

    for (int ip = 0; ip < nParams; ip++) {
        if (parameters.get(ip).equals(sdParam)) {
            sd = Math.abs(point[ip]);
        } else {/*from  w w  w. j  a  v a  2s.  c o m*/
            parser.setVarValue(parameters.get(ip), point[ip]);
        }
    }

    if (sd == 0.0) {
        return Double.NaN;
    }

    double logLikelihood = 0.0;

    for (int iv = 0; iv < nValues; iv++) {
        for (Map.Entry<String, List<Double>> entry : variableValues.entrySet()) {
            parser.setVarValue(entry.getKey(), entry.getValue().get(iv));
        }

        try {
            double value = parser.evaluate(function);

            if (!Double.isFinite(value)) {
                return Double.NaN;
            }

            NormalDistribution normDist = new NormalDistribution(value, sd);

            logLikelihood += targetValues.get(iv) > levelOfDetection
                    ? Math.log(normDist.density(targetValues.get(iv)))
                    : Math.log(normDist.cumulativeProbability(levelOfDetection));
        } catch (ParseException e) {
            e.printStackTrace();
            return Double.NaN;
        }
    }

    return logLikelihood;
}

From source file:com.bodybuilding.argos.discovery.HystrixCommandMetrics.java

@JsonCreator
HystrixCommandMetrics(@JsonProperty("name") String name, @JsonProperty("reportingHosts") Integer reportingHosts,
        @JsonProperty("rollingCountTimeout") Integer timedOut,
        @JsonProperty("rollingCountFailure") Integer failed,
        @JsonProperty("rollingCountSuccess") Integer success,
        @JsonProperty("rollingCountShortCircuited") Integer shortCircuited,
        @JsonProperty("rollingCountThreadPoolRejected") Integer threadPoolRejected,
        @JsonProperty("rollingCountSemaphoreRejected") Integer semaphoreRejected,
        @JsonProperty("propertyValue_metricsRollingStatisticalWindowInMilliseconds") Double rollingWindowMs) {

    this.name = name;
    this.reportingHosts = reportingHosts;
    this.timedOut = timedOut;
    this.failed = failed;
    this.success = success;
    this.shortCircuited = shortCircuited;
    this.rejected = threadPoolRejected;
    this.rejected += semaphoreRejected;

    // see https://github.com/Netflix/Hystrix/blob/master/hystrix-core/src/main/java/com/netflix/hystrix/HystrixCommandMetrics.java
    this.requests = this.failed + this.success + this.timedOut + this.rejected + this.shortCircuited;
    long errorCount = this.failed + this.timedOut + this.rejected + this.shortCircuited;

    if (this.requests > 0) {
        this.errorPercentage = (double) errorCount / this.requests * 100;
    }//from  ww w .  j a va 2s . c o  m

    double numberSeconds = Math.floor(rollingWindowMs / this.reportingHosts) / 1000;

    if (numberSeconds > 0) {
        this.requestRate = this.requests / numberSeconds;
    }

    if (!Double.isFinite(this.requestRate)) {
        this.requestRate = 0D;
    }
    if (!Double.isFinite(this.errorPercentage)) {
        this.errorPercentage = 0D;
    }

}

From source file:org.rhwlab.segmentation.GaussianMixtureEM.java

License:asdf

private void E_Step() {
    for (int n = 0; n < source.getN(); ++n) {
        double x = source.get(n).getIntensity();
        r[n][0] = Utils.elnMult(lnpi[0], normal[0].logDensity(x));
        double sum = r[n][0];
        for (int k = 1; k < K; ++k) {
            double v = Utils.elnMult(lnpi[k], normal[k].logDensity(x));
            sum = Utils.elnsum(sum, v);/* ww  w.ja va  2s.c  om*/
            r[n][k] = v;
        }
        for (int k = 0; k < K; ++k) {
            r[n][k] = Math.exp(r[n][k] - sum);
            if (!Double.isFinite(r[n][k])) {
                int asf = 0;
            }
        }
        int uisahdfuisd = 0;
    }
}

From source file:net.tradelib.core.TradeSummaryBuilder.java

public void add(Trade ts) {
    ++numTrades;//from w w  w .  j  a  v  a2  s.c o m
    if (ts.pnl < 0.0) {
        ++nonZero;
        ++negative;
        averageLossTrade.add(ts.pnl);
        grossLosses += ts.pnl;
    } else if (ts.pnl > 0.0) {
        ++nonZero;
        ++positive;
        averageWinTrade.add(ts.pnl);
        grossProfits += ts.pnl;
    }

    pnlStats.addValue(ts.pnl);

    maxWin = Math.max(maxWin, ts.pnl);
    maxLoss = Math.min(maxLoss, ts.pnl);

    // Set the PnL to zero until the current trade begins
    while (pnlId < pnl.size() && pnl.getTimestamp(pnlId).isBefore(ts.start)) {
        pnl.set(pnlId, 0.0);
        ++pnlId;
    }

    // Keep the PnL as it is inside the current trade
    while (pnlId < pnl.size() && !pnl.getTimestamp(pnlId).isAfter(ts.end)) {
        equity += pnl.get(pnlId);
        maxEquity = Math.max(maxEquity, equity);
        minEquity = Math.min(minEquity, equity);
        maxDD = Math.min(maxDD, equity - maxEquity);
        double prev = maxDDPct;
        maxDDPct = Math.min(maxDDPct, equity / maxEquity - 1);
        if (Double.isNaN(maxDDPct) || !Double.isFinite(maxDDPct)) {
            maxDDPct = Double.MAX_VALUE;
        }

        if (pnl.get(pnlId) != 0.0) {
            dailyPnlStats.addValue(pnl.get(pnlId));
        }

        ++pnlId;
    }
}

From source file:org.bonej.ops.ellipsoid.EllipsoidPoints.java

@Override
public boolean conforms() {
    final double[] radii = in1();
    final Long n = in2();
    return n >= 0 && radii.length == 3 && Arrays.stream(radii).allMatch(r -> r > 0 && Double.isFinite(r));
}