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:org.immutables.gson.stream.JsonGeneratorWriter.java

@Override
public JsonWriter value(double value) throws IOException {
    if (!isLenient() && (Double.isNaN(value) || Double.isInfinite(value))) {
        throw new IllegalArgumentException("JSON forbids NaN and infinities: " + value);
    }//  w ww.ja v a2s  .c o  m
    generator.writeNumber(value);
    return this;
}

From source file:pl.edu.icm.cermine.tools.classification.general.FeatureVectorScalerImpl.java

@Override
public <A extends Enum<A>> void calculateFeatureLimits(List<TrainingSample<A>> trainingElements) {
    for (TrainingSample<A> trainingElem : trainingElements) {
        FeatureVector fv = trainingElem.getFeatureVector();
        List<String> names = fv.getFeatureNames();

        int featureIdx = 0;
        for (String name : names) {
            double val = fv.getValue(name);
            if (val > limits[featureIdx].max) {
                limits[featureIdx].setMax(val);
            }/*from  w  w w  .j  a v a2s  .  c om*/
            if (val < limits[featureIdx].min) {
                limits[featureIdx].setMin(val);
            }
            ++featureIdx;
        }
    }
    for (FeatureLimits limit : limits) {
        if (Double.isInfinite(limit.getMin()) || Double.isInfinite(limit.getMax())) {
            throw new RuntimeException("Feature limit is not calculated properly!");
        }
    }
}

From source file:com.davidsoergel.stats.HeatmapSeries.java

public void incrementPoint(double x, double y, double zIncrement) //throws StatsException
//, final double startx, final double endx,final double starty, final double endy) throws StatsException
{
    if (Double.isNaN(x) || Double.isInfinite(x)) {
        //throw new StatsException("Invalid x value in HeatmapSeries: " + x);
        logger.warn("Invalid x value in HeatmapSeries: " + x);
        return;/*from   w ww  . j a  va2s. c  om*/
    }
    if (Double.isNaN(y) || Double.isInfinite(y)) {
        //throw new StatsException("Invalid y value in HeatmapSeries: " + y);
        logger.warn("Invalid y value in HeatmapSeries: " + y);
        return;
    }
    if (Double.isNaN(zIncrement) || Double.isInfinite(zIncrement)) {
        //throw new StatsException("Invalid zIncrement value in SimpleXYZSeries: " + zIncrement);
        logger.warn("Invalid zIncrement value in HeatmapSeries: " + zIncrement);
        return;
    }
    HeatmapPoint currentPoint = points.get(x, y);
    if (currentPoint != null) {
        currentPoint.z += zIncrement;
        updateBounds(x, y, currentPoint.z);
    } else {
        points.put(x, y, new HeatmapPoint(x, y, zIncrement)); //, startx, endx, starty, endy));

        updateBounds(x, y, zIncrement);
    }
}

From source file:de.unijena.bioinf.IsotopePatternAnalysis.scoring.LogNormDistributedIntensityScorer.java

@Override
public double score(Spectrum<Peak> measuredSpectrum, Spectrum<Peak> theoreticalPattern, Normalization norm,
        Ms2Experiment experiment, MeasurementProfile profile) {
    // remove peaks from theoretical pattern until the length of both spectra is equal
    final MutableSpectrum<Peak> theoreticalSpectrum = new SimpleMutableSpectrum(theoreticalPattern);
    while (measuredSpectrum.size() < theoreticalSpectrum.size()) {
        theoreticalSpectrum.removePeakAt(theoreticalSpectrum.size() - 1);
    }//w  ww .j  a  v a 2  s  . c  om
    // re-normalize
    Spectrums.normalize(theoreticalSpectrum, norm);
    // score
    double score = 0d;
    final double intensityDeviation = profile.getIntensityDeviation();
    for (int i = 0; i < measuredSpectrum.size(); ++i) {
        final double intensity = measuredSpectrum.getIntensityAt(i);
        final double thIntensity = theoreticalSpectrum.getIntensityAt(i);
        // TODO: TEST!!!!!!!!!!!
        final double sd = Math.abs(log(intensity)
                - log(intensity + intensityDeviation * intensityDependency.getValueAt(intensity)));//log(1 + intensityDeviation*intensityDependency.getValueAt(intensity));
        final double newScore = log(Erf.erfc(abs(log(thIntensity / intensity) / (root2 * sd))));
        if (Double.isInfinite(newScore))
            return newScore;
        score += newScore;
    }
    return score;
}

From source file:com.xwtec.xwserver.util.json.util.JSONUtils.java

/**
 * Produce a string from a double. The string "null" will be returned if the
 * number is not finite.//from  w  w w . j  a v a2 s  . co 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:org.lenskit.util.math.RowView.java

@Override
public boolean isInfinite() {
    for (int i = 0; i < length; i++) {
        if (Double.isInfinite(getEntry(i))) {
            return true;
        }// w w  w  .  j  av a  2 s.c  om
    }
    return false;
}

From source file:org.deidentifier.arx.risk.Gamma.java

/**
 * Approximates the digamma function. Java port of the
 * "The Lightspeed Matlab toolbox" version 2.7 by Tom Minka see:
 * http://research.microsoft.com/en-us/um/people/minka/software/lightspeed/
 * //w  ww  .  java  2 s  .  c  o m
 * @param x
 *            input value
 * @return approximation of digamma for x
 */
static double digamma(double x) {

    /* Illegal arguments */
    if (Double.isInfinite(x) || Double.isNaN(x)) {
        return Double.NaN;
    }

    /* Singularities */
    if (x == 0.0d) {
        return Double.NEGATIVE_INFINITY;
    }

    /* Negative values */
    /*
     * Use the reflection formula (Jeffrey 11.1.6): digamma(-x) =
     * digamma(x+1) + pi*cot(pi*x)
     * 
     * This is related to the identity digamma(-x) = digamma(x+1) -
     * digamma(z) + digamma(1-z) where z is the fractional part of x For
     * example: digamma(-3.1) = 1/3.1 + 1/2.1 + 1/1.1 + 1/0.1 +
     * digamma(1-0.1) = digamma(4.1) - digamma(0.1) + digamma(1-0.1) Then we
     * use digamma(1-z) - digamma(z) = pi*cot(pi*z)
     */
    if (x < 0.0d) {
        return digamma(1.0d - x) + (StrictMath.PI / StrictMath.tan(-StrictMath.PI * x));
    }

    /* Use Taylor series if argument <= small */
    if (x <= SMALL_DIGAMMA) {
        return (DIGAMMA_1 - (1.0d / x)) + (TRIGAMMA_1 * x);
    }

    double result = 0.0d;
    /* Reduce to digamma(X + N) where (X + N) >= large */
    while (x < LARGE_DIGAMMA) {
        result -= 1.0d / x;
        x++;
    }

    /* Use de Moivre's expansion if argument >= C */
    /* This expansion can be computed in Maple via asympt(Psi(x),x) */
    if (x >= LARGE_DIGAMMA) {
        double r = 1.0d / x;
        result += StrictMath.log(x) - (0.5d * r);
        r *= r;
        result -= r * (S3 - (r * (S4 - (r * (S5 - (r * (S6 - (r * S7))))))));
    }

    return result;
}

From source file:com.hp.hpl.jena.sparql.util.Utils.java

static public String stringForm(double d) {
    if (Double.isInfinite(d)) {
        if (d < 0)
            return "-INF";
        return "INF";
    }/*  ww w .j  a  v a  2 s . c  o  m*/

    if (Double.isNaN(d))
        return "NaN";

    // Otherwise, SPARQL form always has "e0"
    String x = Double.toString(d);
    if ((x.indexOf('e') != -1) || (x.indexOf('E') != -1))
        return x;
    // Renormalize?
    return x + "e0";
}

From source file:org.jfree.data.general.DefaultHeatMapDataset.java

/**
 * Creates a new dataset where all the z-values are initially 0.  This is
 * a fixed size array of z-values./*from  ww w .  ja  v  a 2s  .c o  m*/
 *
 * @param xSamples  the number of x-values.
 * @param ySamples  the number of y-values
 * @param minX  the minimum x-value in the dataset.
 * @param maxX  the maximum x-value in the dataset.
 * @param minY  the minimum y-value in the dataset.
 * @param maxY  the maximum y-value in the dataset.
 */
public DefaultHeatMapDataset(int xSamples, int ySamples, double minX, double maxX, double minY, double maxY) {

    if (xSamples < 1) {
        throw new IllegalArgumentException("Requires 'xSamples' > 0");
    }
    if (ySamples < 1) {
        throw new IllegalArgumentException("Requires 'ySamples' > 0");
    }
    if (Double.isInfinite(minX) || Double.isNaN(minX)) {
        throw new IllegalArgumentException("'minX' cannot be INF or NaN.");
    }
    if (Double.isInfinite(maxX) || Double.isNaN(maxX)) {
        throw new IllegalArgumentException("'maxX' cannot be INF or NaN.");
    }
    if (Double.isInfinite(minY) || Double.isNaN(minY)) {
        throw new IllegalArgumentException("'minY' cannot be INF or NaN.");
    }
    if (Double.isInfinite(maxY) || Double.isNaN(maxY)) {
        throw new IllegalArgumentException("'maxY' cannot be INF or NaN.");
    }

    this.xSamples = xSamples;
    this.ySamples = ySamples;
    this.minX = minX;
    this.maxX = maxX;
    this.minY = minY;
    this.maxY = maxY;
    this.zValues = new double[xSamples][];
    for (int x = 0; x < xSamples; x++) {
        this.zValues[x] = new double[ySamples];
    }
}

From source file:dbs_project.util.Utils.java

public static double generateRandomDouble() {
    double d;//from   w  ww.  ja  va 2s. c om
    do {
        d = Double.longBitsToDouble(randomLong());
    } while (Double.isNaN(d) || Double.isInfinite(d));
    return d;
}