Example usage for java.lang Double isInfinite

List of usage examples for java.lang Double isInfinite

Introduction

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

Prototype

public static boolean isInfinite(double v) 

Source Link

Document

Returns true if the specified number is infinitely large in magnitude, false otherwise.

Usage

From source file:playground.johannes.coopsim.analysis.InfiniteScoresTask.java

@Override
public void analyze(Set<Trajectory> trajectories, Map<String, DescriptiveStatistics> results) {
    int count = 0;
    for (Trajectory t : trajectories) {
        Plan p = t.getPerson().getSelectedPlan();
        if (Double.isInfinite(p.getScore()))
            count++;/*from  w ww  .  j  a va 2  s .com*/
    }

    if (count > 0)
        logger.warn(String.format("There are %1$s plans with infinite score.", count));

}

From source file:gdsc.smlm.ij.utils.Utils.java

/**
 * Round the double to the specified significant digits
 * //from   ww w  . ja v a  2 s  . com
 * @param d
 * @param significantDigits
 * @return
 */
public static String rounded(double d, int significantDigits) {
    if (Double.isInfinite(d) || Double.isNaN(d))
        return "" + d;
    BigDecimal bd = new BigDecimal(d);
    bd = bd.round(new MathContext(significantDigits));
    return "" + bd.doubleValue();
}

From source file:com.opengamma.analytics.math.interpolation.PiecewiseCubicHermiteSplineInterpolatorWithSensitivity.java

@Override
public PiecewisePolynomialResultsWithSensitivity interpolateWithSensitivity(final double[] xValues,
        final double[] yValues) {

    ArgumentChecker.notNull(xValues, "xValues");
    ArgumentChecker.notNull(yValues, "yValues");

    ArgumentChecker.isTrue(xValues.length == yValues.length, "xValues length = yValues length");
    ArgumentChecker.isTrue(xValues.length > 1, "Data points should be more than 1");

    final int nDataPts = xValues.length;

    for (int i = 0; i < nDataPts; ++i) {
        ArgumentChecker.isFalse(Double.isNaN(xValues[i]), "xData containing NaN");
        ArgumentChecker.isFalse(Double.isInfinite(xValues[i]), "xData containing Infinity");
        ArgumentChecker.isFalse(Double.isNaN(yValues[i]), "yData containing NaN");
        ArgumentChecker.isFalse(Double.isInfinite(yValues[i]), "yData containing Infinity");
    }//from ww w  . ja va 2  s.  c o m

    double[] xValuesSrt = Arrays.copyOf(xValues, nDataPts);
    double[] yValuesSrt = Arrays.copyOf(yValues, nDataPts);
    ParallelArrayBinarySort.parallelBinarySort(xValuesSrt, yValuesSrt);

    for (int i = 1; i < nDataPts; ++i) {
        ArgumentChecker.isFalse(xValuesSrt[i - 1] == xValuesSrt[i], "xValues should be distinct");
    }

    final DoubleMatrix2D[] temp = solve(xValuesSrt, yValuesSrt);

    // check the matrices
    // TODO remove some of these tests
    ArgumentChecker.noNulls(temp, "error in solve - some matrices are null");
    int n = temp.length;
    ArgumentChecker.isTrue(n == nDataPts, "wrong number of matricies");
    for (int k = 0; k < n; k++) {
        DoubleMatrix2D m = temp[k];
        final int rows = m.getNumberOfRows();
        final int cols = m.getNumberOfColumns();
        for (int i = 0; i < rows; ++i) {
            for (int j = 0; j < cols; ++j) {
                ArgumentChecker.isTrue(Doubles.isFinite(m.getEntry(i, j)), "Matrix contains a NaN or infinite");
            }
        }
    }

    DoubleMatrix2D coefMatrix = temp[0];
    DoubleMatrix2D[] coefMatrixSense = new DoubleMatrix2D[n - 1];
    System.arraycopy(temp, 1, coefMatrixSense, 0, n - 1);

    return new PiecewisePolynomialResultsWithSensitivity(new DoubleMatrix1D(xValuesSrt), coefMatrix, 4, 1,
            coefMatrixSense);
}

From source file:net.sourceforge.jabm.evolution.FitnessProportionateBreeder.java

public AgentList reproduce(AgentList currentGeneration) {

    int n = currentGeneration.size();
    AgentList nextGeneration = new AgentList(currentGeneration);

    double[] cummulativeFitnesses = cummulativeFitnesses(currentGeneration);

    if (!Double.isNaN(totalFitness) && !Double.isInfinite(totalFitness)) {
        for (int i = 0; i < n; i++) {
            int j = choose(cummulativeFitnesses);
            reproduce(nextGeneration.get(i), currentGeneration.get(j));
        }/*  w w  w .  j  a va  2 s  . co m*/
    } else {
        logger.warn("Not reproducing because fitness is undefined");
    }

    return nextGeneration;
}

From source file:net.sf.json.JSONUtils.java

/**
 * Produce a string from a double. The string "null" will be returned if the
 * number is not finite./*from   www.  j  a v  a  2s .c  o  m*/
 *
 * @param d A double.
 * @return A String.
 */
public static String doubleToString(double d) {
    if (Double.isInfinite(d) || Double.isNaN(d)) {
        return "null";
    }

    // Shave off trailing zeros and decimal point, if possible.
    String s = Double.toString(d);

    if ((s.indexOf('.') > 0) && (s.indexOf('e') < 0) && (s.indexOf('E') < 0)) {
        while (s.endsWith("0")) {
            s = s.substring(0, s.length() - 1);
        }

        if (s.endsWith(".")) {
            s = s.substring(0, s.length() - 1);
        }
    }

    return s;
}

From source file:dr.math.distributions.TruncatedDistribution.java

public TruncatedDistribution(Distribution source, double lower, double upper) {
    this.source = source;

    if (lower == upper) {
        throw new IllegalArgumentException("upper equals lower");
    }//from w  w  w  .  j a va  2s. co  m

    if (source.getProbabilityDensityFunction().getLowerBound() > lower) {
        lower = source.getProbabilityDensityFunction().getLowerBound();
    }

    if (source.getProbabilityDensityFunction().getUpperBound() < upper) {
        upper = source.getProbabilityDensityFunction().getUpperBound();
    }

    this.lower = lower;
    this.upper = upper;

    if (!Double.isInfinite(this.lower)) {
        this.lowerCDF = source.cdf(lower);
    } else {
        this.lowerCDF = 0;
    }

    if (!Double.isInfinite(this.upper)) {
        this.normalization = source.cdf(upper) - lowerCDF;
    } else {
        this.normalization = 1.0 - lowerCDF;
    }
}

From source file:sadl.integration.MonteCarloIntegration.java

public void preprocess(ContinuousDistribution d, double stepSize, double xMin, double xMax) {
    if (d instanceof SingleValueDistribution) {
        singleValueDis = true;/*from w w w  . j  a  v  a 2 s. c o m*/
        preprocessed = true;
        return;
    }
    if (Double.isInfinite(xMin)) {
        xMin = Double.MIN_VALUE;
    }
    if (Double.isInfinite(xMax)) {
        xMax = Double.MAX_VALUE;
    }
    final Pair<Double, Double> minMax = findExtreme(d, xMin, xMax, stepSize);
    final double yMin = minMax.getLeft().doubleValue();
    final double yMax = minMax.getRight().doubleValue();
    final double xDiff = xMax - xMin;
    final double yDiff = yMax - yMin;

    int pointsFound = 0;
    int pointsRejected = 0;
    integral = new MonteCarloPoint[pointsToStore];
    while (pointsFound < pointsToStore) {
        final double xSampled = xMin + (xDiff * xRandom.nextDouble());
        final double ySampled = yMin + (yDiff * yRandom.nextDouble());
        final double pdfValue = d.pdf(xSampled);
        if (pdfValue > 0 && ySampled <= pdfValue) {
            // store the point because the sampled y value is smaller than the pdf value at the x value
            integral[pointsFound] = new MonteCarloPoint(xSampled, pdfValue);
            pointsFound++;
        } else {
            pointsRejected++;
        }
    }
    logger.debug("Rejected {} points", pointsRejected);
    logger.debug("Accepted {} points", pointsFound);
    if (Settings.isParallel()) {
        Arrays.parallelSort(integral, new MonteCarloPointComparator());
    } else {
        Arrays.sort(integral, new MonteCarloPointComparator());
    }

    // Collections.sort(integral2);
    // integral2.sort((m1, m2) -> Double.compare(m1.getX(), m2.getX()));
    preprocessed = true;
}

From source file:com.opengamma.analytics.math.interpolation.ShapePreservingCubicSplineInterpolator.java

@Override
public PiecewisePolynomialResult interpolate(final double[] xValues, final double[] yValues) {

    ArgumentChecker.notNull(xValues, "xValues");
    ArgumentChecker.notNull(yValues, "yValues");

    ArgumentChecker.isTrue(xValues.length == yValues.length, "xValues length = yValues length");
    ArgumentChecker.isTrue(xValues.length > 2, "Data points should be more than 1");

    final int nDataPts = xValues.length;

    for (int i = 0; i < nDataPts; ++i) {
        ArgumentChecker.isFalse(Double.isNaN(xValues[i]), "xData containing NaN");
        ArgumentChecker.isFalse(Double.isInfinite(xValues[i]), "xData containing Infinity");
        ArgumentChecker.isFalse(Double.isNaN(yValues[i]), "yData containing NaN");
        ArgumentChecker.isFalse(Double.isInfinite(yValues[i]), "yData containing Infinity");
    }/*from  w w w  . ja  va2 s. co m*/

    for (int i = 0; i < nDataPts; ++i) {
        for (int j = i + 1; j < nDataPts; ++j) {
            ArgumentChecker.isFalse(xValues[i] == xValues[j], "xValues should be distinct");
        }
    }

    final double[] xValuesSrt = Arrays.copyOf(xValues, nDataPts);
    final double[] yValuesSrt = Arrays.copyOf(yValues, nDataPts);
    ParallelArrayBinarySort.parallelBinarySort(xValuesSrt, yValuesSrt);

    final double[] intervals = intervalsCalculator(xValuesSrt);
    final double[] slopes = slopesCalculator(yValuesSrt, intervals);
    final double[] beta = betaCalculator(slopes);
    double[] first = firstDiffFinder(intervals, slopes);
    double[] rValues = rValuesCalculator(slopes, first);

    boolean correctSign = false;
    int it = 0;

    while (correctSign == false) {
        correctSign = signChecker(beta, rValues);
        if (correctSign == false) {
            first = firstDiffSweep(intervals, slopes, beta, first);
            rValues = rValuesCalculator(slopes, first);
        }
        ++it;
        if (it > 10) {
            throw new IllegalArgumentException("Spline is not found!");
        }
    }

    final double[] second = secondDiffFinder(intervals, beta, rValues);
    final double[] tau = tauFinder(intervals, slopes, beta, first, second);
    final double[] knots = knotsProvider(xValuesSrt, intervals, tau);

    final double[][] coefMatrix = solve(yValuesSrt, intervals, slopes, first, second, tau);

    for (int i = 0; i < coefMatrix.length; ++i) {
        double ref = 0.;
        final double interval = knots[i + 1] - knots[i];
        for (int j = 0; j < 4; ++j) {
            ref += coefMatrix[i][j] * Math.pow(interval, 3 - j);
            ArgumentChecker.isFalse(Double.isNaN(coefMatrix[i][j]), "Too large input");
            ArgumentChecker.isFalse(Double.isInfinite(coefMatrix[i][j]), "Too large input");
        }
        final double yVal = i == coefMatrix.length - 1 ? yValues[nDataPts - 1] : coefMatrix[i + 1][3];
        final double bound = Math.max(Math.abs(ref) + Math.abs(yVal), 1.e-1);
        ArgumentChecker.isTrue(Math.abs(ref - yVal) < ERROR * bound,
                "Input is too large/small or data points are too close");
    }

    return new PiecewisePolynomialResult(new DoubleMatrix1D(knots), new DoubleMatrix2D(coefMatrix), 4, 1);
}

From source file:org.jactr.core.runtime.profile.ProfilingModelRunner.java

@Override
protected void startUp() {
    super.startUp();
    _simulatedClockStartTime = ACTRRuntime.getRuntime().getClock(_model).getTime();
    if (Double.isInfinite(_simulatedClockStartTime) || Double.isNaN(_simulatedClockStartTime))
        _simulatedClockStartTime = 0;/*from w  w  w.  j  av  a2 s . c om*/
}

From source file:org.eclipse.recommenders.commons.bayesnet.Node.java

public boolean isValid() {
    if (parents.length > 0) {
        int parentStates = 1;
        for (final Node parent : parents) {
            parentStates *= parent.numberOfStates();
        }//  ww  w .  j  a  v  a  2  s  . c om
        if (probabilities.length != parentStates * states.length) {
            return false;
        }
    } else if (probabilities.length != states.length) {
        return false;
    }

    for (int i = 0; i < probabilities.length; i++) {
        if (Double.isInfinite(probabilities[i])) {
            return false;
        }
        if (Double.isNaN(probabilities[i])) {
            return false;
        }
    }

    return true;
}