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:com.simiacryptus.mindseye.test.PCAUtil.java

/**
 * Populate pca kernel./*from w w  w . jav  a2 s  . c o  m*/
 *
 * @param kernel              the kernel
 * @param featureSpaceVectors the feature space vectors
 */
public static void populatePCAKernel_1(final Tensor kernel, final Tensor[] featureSpaceVectors) {
    final int outputBands = featureSpaceVectors.length;
    @Nonnull
    final int[] filterDimensions = kernel.getDimensions();
    kernel.setByCoord(c -> {
        final int kband = c.getCoords()[2];
        final int outband = kband % outputBands;
        final int inband = (kband - outband) / outputBands;
        int x = c.getCoords()[0];
        int y = c.getCoords()[1];
        x = filterDimensions[0] - (x + 1);
        y = filterDimensions[1] - (y + 1);
        final double v = featureSpaceVectors[outband].get(x, y, inband);
        return Double.isFinite(v) ? v : kernel.get(c);
    });
}

From source file:com.boozallen.cognition.ingest.storm.spout.StormKafkaSpout.java

public boolean isRateLimited() {
    return Double.isFinite(permitsPerSecond);
}

From source file:delfos.rs.trustbased.WeightedGraph.java

private double[][] makeMatrixFromEdges(Set<PathBetweenNodes<Node>> edges) {
    double[][] matrix = new double[nodesIndex.size()][nodesIndex.size()];
    edges.parallelStream().filter(edge -> Double.isFinite(edge.getLength())).forEach(edge -> {
        Integer fromIndex = nodesIndex.get(edge.from());
        Integer toIndex = nodesIndex.get(edge.to());
        double weight = Objects.equals(fromIndex, toIndex) ? 0 : edge.getFirstWeight();
        matrix[fromIndex][toIndex] = weight;
    });//from w  w  w .j ava 2 s . com

    IntStream.range(0, matrix.length).boxed().parallel().forEach(index -> matrix[index][index] = 1);
    return matrix;
}

From source file:com.simiacryptus.mindseye.test.PCAUtil.java

/**
 * Populate pca kernel.//  w w  w. j a v  a  2 s. c om
 *
 * @param kernel              the kernel
 * @param featureSpaceVectors the feature space vectors
 */
public static void populatePCAKernel_2(final Tensor kernel, final Tensor[] featureSpaceVectors) {
    final int outputBands = featureSpaceVectors.length;
    @Nonnull
    final int[] filterDimensions = kernel.getDimensions();
    kernel.setByCoord(c -> {
        final int kband = c.getCoords()[2];
        final int outband = kband % outputBands;
        final int inband = (kband - outband) / outputBands;
        int x = c.getCoords()[0];
        int y = c.getCoords()[1];
        x = filterDimensions[0] - (x + 1);
        y = filterDimensions[1] - (y + 1);
        final double v = featureSpaceVectors[inband].get(x, y, outband);
        return Double.isFinite(v) ? v : kernel.get(c);
    });
}

From source file:de.bund.bfr.knime.gis.views.canvas.CanvasUtils.java

public static double toPositiveDouble(Object value) {
    if (value instanceof Number) {
        double d = ((Number) value).doubleValue();

        return Double.isFinite(d) && d >= 0.0 ? d : 0.0;
    }/*from  ww w  .j a  v a 2 s. co  m*/

    return 0.0;
}

From source file:net.rptools.image.listeners.TransformHandler.java

/**
 * @see #transform(String, String, boolean, String, Point2D)
 * @param phase phase we are in/*from  ww  w  . j  a v a2 s  .c o m*/
 * @param fix fixed point
 * @param transformType transform type
 * @param constraints contraints
 * @param newDrag new transform end point
 */
@ThreadPolicy(ThreadPolicy.ThreadId.JFX)
private void resizeIntern(final String phase, final Point2D fix, final String transformType,
        final String constraints, final Point2D newDrag) {
    if (phase.equals(START)) {
        previousDrag = newDrag;
    }

    if (previousDrag == null) {
        return;
    }

    double scalex = Math.abs((fix.getX() - newDrag.getX()) / (fix.getX() - previousDrag.getX()));
    if (!Double.isFinite(scalex) || scalex < SANITY_SCALE || scalex > 1 / SANITY_SCALE) {
        scalex = 1;
    }
    double scaley = Math.abs((fix.getY() - newDrag.getY()) / (fix.getY() - previousDrag.getY()));
    if (!Double.isFinite(scaley) || scaley < SANITY_SCALE || scaley > 1 / SANITY_SCALE) {
        scaley = 1;
    }
    final double oldRad = Math.atan2(fix.getY() - previousDrag.getY(), fix.getX() - previousDrag.getX());
    final double newRad = Math.atan2(fix.getY() - newDrag.getY(), fix.getX() - newDrag.getX());

    if (constraints.equals(ISO)) {
        final double tmp = Math.max(scalex, scaley);
        scalex = tmp;
        scaley = tmp;
    }

    String transform = "1.0;0.0;0.0;0.0;1.0;0.0";
    switch (transformType) {
    case "rotate":
        transform = GeometryHelper.createTransform(fix, newRad - oldRad);
        break;
    case "scalex":
        transform = GeometryHelper.createTransform(fix, scalex, 1);
        break;
    case "scaley":
        transform = GeometryHelper.createTransform(fix, 1, scaley);
        break;
    case "scalexy":
        transform = GeometryHelper.createTransform(fix, scalex, scaley);
        break;
    default:
        break;
    }
    LOGGER.info("transform={}", transform);

    previousDrag = newDrag;

    for (ModelViewBinding binding : getSelection().getBindings()) {
        binding.prependTransform(transform);
    }

    if (phase.equals(END)) {
        previousDrag = null;
    }
}

From source file:kishida.cnn.NeuralNetwork.java

public float[] forward(float[] readData, float[] correctData) {
    ((InputLayer) layers.get(0)).setInput(readData);
    for (int i = 1; i < layers.size(); ++i) {
        layers.get(i).forward();/*from   w  w w.  ja v a 2s .c o m*/
    }
    float[] output = layers.get(layers.size() - 1).getResult();
    if (!FloatUtil.toDoubleStream(output).allMatch(d -> Double.isFinite(d))) {
        throw new RuntimeException("there are some infinite value");
    }

    //?
    float[] delta = new float[output.length];
    for (int idx = 0; idx < output.length; ++idx) {
        delta[idx] = correctData[idx] - output[idx];
    }
    //?
    for (int i = layers.size() - 1; i >= 1; --i) {
        delta = layers.get(i).backward(delta);
    }

    return output;
}

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

public TradeSummary summarize() {
    TradeSummary summary = new TradeSummary();
    summary.numTrades = numTrades;//from ww  w.j  ava  2s. c o m

    if (numTrades > 0) {
        summary.grossLosses = grossLosses;
        summary.grossProfits = grossProfits;

        if (grossLosses != 0.0) {
            summary.profitFactor = Math.abs(grossProfits / grossLosses);
        } else {
            summary.profitFactor = Math.abs(grossProfits);
        }

        summary.averageTradePnl = pnlStats.getMax();
        summary.tradePnlStdDev = pnlStats.getStandardDeviation();
        if (numTrades > 0) {
            summary.pctNegative = (double) negative / numTrades * 100.0;
            summary.pctPositive = (double) positive / numTrades * 100.0;
        } else {
            summary.pctNegative = 0.0;
            summary.pctPositive = 0.0;
        }

        summary.maxLoss = maxLoss;
        summary.maxWin = maxWin;
        summary.averageLoss = averageLossTrade.get();
        summary.averageWin = averageWinTrade.get();

        if (summary.averageLoss != 0.0) {
            summary.averageWinLoss = summary.averageWin / (summary.averageLoss * (-1.0));
        } else {
            summary.averageWinLoss = summary.averageWin;
        }

        summary.equityMin = minEquity;
        summary.equityMax = maxEquity;
        summary.maxDD = maxDD;
        summary.maxDDPct = maxDDPct * 100;
        if (Double.isNaN(summary.maxDDPct) || !Double.isFinite(summary.maxDDPct)) {
            Logger.getLogger("").warning(String.format("Fixing a bad maximum drawdown [%f]", summary.maxDDPct));
            summary.maxDDPct = Double.MAX_VALUE;
        }

        summary.averageDailyPnl = dailyPnlStats.getMean();
        summary.dailyPnlStdDev = dailyPnlStats.getStandardDeviation();
        if (summary.dailyPnlStdDev == 0) {
            summary.dailyPnlStdDev = 1e-10;
        }
        summary.sharpeRatio = Functions.sharpeRatio(summary.averageDailyPnl, summary.dailyPnlStdDev, 252);
    }

    return summary;
}

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

public double logDPMLikelihood(int n) throws ArithmeticException {
    LogNode stdLeft = (LogNode) left;//  ww w.  j  a v  a 2s . c o m
    LogNode stdRight = (LogNode) right;
    if (left != null && right != null) {
        lngn = Gamma.logGamma(n);

        if (!Double.isFinite(lngn)) {
            System.exit(111);
        }
        Double lnagn = Utils.elnMult(lnAlpha, lngn);
        if (!Double.isFinite(lnagn)) {
            System.exit(112);
        }
        double lndd = Utils.elnMult(stdLeft.lnd, stdRight.lnd);
        lnd = Utils.elnsum(lnagn, Utils.elnMult(stdLeft.lnd, stdRight.lnd));
        if (lnd == 0.0) {
            int aisohdfni = 0;
        }
        if (!Double.isFinite(lnd)) {
            System.exit(222);
        }

        lnPi = Utils.elnMult(lnagn, -lnd);
        if (lnPi == 0.0) {
            int isafduis = 0;
            lnd = Utils.elnsum(lnagn, Utils.elnMult(stdLeft.lnd, stdRight.lnd));
        }
        if (!Double.isFinite(lnPi)) {
            System.exit(223);
        }
        lnonePi = Utils.eln(1.0 - Math.exp(lnPi));

        Double lnFirst = Utils.elnMult(lnPi, lnLike);
        Double prod = Utils.elnMult(stdLeft.lnDPM, stdRight.lnDPM);
        Double lnSecond = Utils.elnMult(lnonePi, prod);

        return Utils.elnsum(lnFirst, lnSecond);
    }
    return lnLike;
}

From source file:sphericalGeo.RelaxedSphericalDiffusionModel.java

public double getLogLikelihood(double[] start, double[] stop, double time) {
    if (start[0] == stop[0] && start[1] == stop[1]) {
        return -1e100;
    }//from  www  .  j  a  v a 2 s  .com

    if (recompute) {
        // this must be synchronized to avoid being called simultaneously by
        // two different likelihood threads
        synchronized (this) {
            prepare();
            recompute = false;
        }
    }
    // assumes start = {latitude, longitude}
    // assumes stop = {latitude, longitude}
    // and -90 < latitude < 90, -180 < longitude < 180

    double latitude1 = start[0];
    double longitude1 = start[1];
    final double DEG2RAD = Math.PI / 180.0;
    final double theta1 = (latitude1) * DEG2RAD;
    if (longitude1 < 0)
        longitude1 += 360;
    //final double phi1 = longitude1 * DEG2RAD;

    double latitude2 = stop[0];
    double longitude2 = stop[1];
    final double theta2 = (latitude2) * DEG2RAD;
    if (longitude2 < 0)
        longitude2 += 360;
    //final double phi2 = longitude2 * DEG2RAD;

    final double deltaLambda = (longitude2 - longitude1) * DEG2RAD; //phi2 - phi1, in radians;

    // Use trigonometric equalities to reduce cost of computing both sin(x)*sin(y) and cos(x)*cos(y)
    // to two cos() calls and 4 +/- and one '/2'.
    final double cosplus = cos(theta1 + theta2);
    final double cosminus = cos(theta1 - theta2);
    final double twicecoscos = (cosminus + cosplus);
    final double twicesinsin = (cosminus - cosplus);
    final double x = (twicesinsin + twicecoscos * cos(deltaLambda)) / 2;
    //        final double x = FastMath.sin(theta1) * FastMath.sin(theta2) +
    //                FastMath.cos(theta1) * FastMath.cos(theta2) * FastMath.cos(deltaLambda);
    final double angle;
    if (fast) {
        angle = (abs(x) > .9 ? acos_parts_fast7(x) : acos(x));
    } else {
        angle = acos(x);
    }

    double precision0 = precision.getValue(0);
    double invVariance = precision0 / time;
    double cachedResult = getCachedResult(angle, invVariance);
    if (Double.isFinite(cachedResult)) {
        return cachedResult;
    }
    return calc(angle, invVariance);

}