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.talend.dq.indicators.preview.table.ChartDataEntity.java

public String getPersent() {
    if (percent != null) {
        // MOD qiongli 2011-4-25 bug 20670:if it is infinite,return N/A.
        if (Double.isNaN(percent) || Double.isInfinite(percent)) {
            return PluginConstant.NA_STRING;
        } else {/*from  w ww .j  a  v  a2 s .c o m*/
            return StringFormatUtil.format(percent, StringFormatUtil.PERCENT).toString();
        }
    } else {
        return null;
    }
}

From source file:etomica.models.co2.PNGCPM.java

public double energy(IMoleculeList atoms) {
    double sum = 0;
    if (component != Component.INDUCTION) {
        for (int i = 0; i < atoms.getMoleculeCount() - 1; i++) {
            pair.atom0 = atoms.getMolecule(i);
            for (int j = i + 1; j < atoms.getMoleculeCount(); j++) {
                pair.atom1 = atoms.getMolecule(j);
                sum += getNonPolarizationEnergy(pair);
                if (Double.isInfinite(sum)) {
                    return sum;
                }/*from w  ww . j a  v  a 2  s  . co m*/
            }
        }
    }

    if (component != Component.TWO_BODY) {
        sum += getPolarizationEnergy(atoms);
    }
    if (!oops && Double.isNaN(sum)) {
        oops = true;
        energy(atoms);
        throw new RuntimeException("oops NaN");
    }
    return sum;
}

From source file:org.opentox.jaqpot3.qsar.util.WekaInstancesProcess.java

public static Map<String, Double> getInstanceAttributeValues(Instance inst, int numAttributes) {
    //numAttributes need to be set before adding the new attributes
    Map<String, Double> featureMap = new HashMap();
    if (numAttributes > 0) {
        double res;
        for (int i = 0; i < numAttributes; ++i) {
            res = (!Double.isNaN(inst.value(i))) ? inst.value(i) : 0;
            res = (!Double.isInfinite(res)) ? res : 0;
            featureMap.put(inst.attribute(i).name(), res);
        }// ww  w .j  av a  2  s  .  c  o  m
    }
    return featureMap;
}

From source file:org.renjin.MathExt.java

public static double round(double x, int digits) {
    // adapted from the nmath library, fround.c
    /* = 308 (IEEE); was till R 0.99: (DBL_DIG - 1) */
    /* Note that large digits make sense for very small numbers */
    double sgn;/*  w w  w .j a  v a  2s  .  c o m*/
    int dig;

    if (Double.isNaN(x) || Double.isNaN(digits)) {
        return x + digits;
    }
    if (Double.isInfinite(x)) {
        return x;
    }

    if (digits == Double.POSITIVE_INFINITY) {
        return x;
    } else if (digits == Double.NEGATIVE_INFINITY) {
        return 0.0;
    }

    if (digits > MAX_DIGITS) {
        digits = MAX_DIGITS;
    }
    dig = (int) Math.floor(digits + 0.5);

    if (x < 0.) {
        sgn = -1.;
        x = -x;
    } else {
        sgn = 1.;
    }
    if (dig == 0) {
        return sgn * Math.rint(x);
    } else if (dig > 0) {
        double pow10 = Math.pow(10., dig);
        double intx = Math.floor(x);
        return sgn * (intx + Math.rint((x - intx) * pow10) / pow10);
    } else {
        double pow10 = Math.pow(10., -dig);
        return sgn * Math.rint(x / pow10) * pow10;
    }
}

From source file:de.tudarmstadt.ukp.dkpro.wsd.graphconnectivity.iterative.wikipedia.algorithm.LinkInformationSequentialDisambiguation.java

private double computeLinkMeasureSimilarity(String target0, String target1) throws SimilarityException {
    if (target0.equals(target1)) {
        return 1.0;
    }/*from   ww  w  .j  a v  a  2 s. co  m*/

    List<String> linksA;
    List<String> linksB;
    try {
        linksA = getIncomingLinks(target0);
        linksB = getIncomingLinks(target1);
    } catch (Exception e) {
        throw new SimilarityException();
    }

    int linksBoth = ListUtils.intersection(linksA, linksB).size();

    double a = Math.log(linksA.size());
    double b = Math.log(linksB.size());
    double ab = Math.log(linksBoth);
    double m = Math.log(linkInformationReader.getNumberOfSenses());

    double sr = (Math.max(a, b) - ab) / (m - Math.min(a, b));

    if (Double.isNaN(sr) || Double.isInfinite(sr) || sr > 1) {
        sr = 1;
    }

    sr = 1 - sr;

    return sr;

}

From source file:mulavito.gui.components.LayerViewer.java

public static void autoZoomViewer(VisualizationViewer<?, ?> vv, LayerViewer<?, ?> home, Directions direction) {
    if (vv == null || home == null)
        return;//from   ww  w  .  j av a2  s  .co m

    // reset transforms
    MutableTransformer layoutTrans = vv.getRenderContext().getMultiLayerTransformer()
            .getTransformer(edu.uci.ics.jung.visualization.Layer.LAYOUT);
    layoutTrans.setToIdentity();
    MutableTransformer viewTrans = vv.getRenderContext().getMultiLayerTransformer()
            .getTransformer(edu.uci.ics.jung.visualization.Layer.VIEW);
    viewTrans.setToIdentity();

    Dimension dim = vv.getSize();
    Rectangle2D.Double graphBounds = home.getGraphBoundsCache();

    CrossoverScalingControl scaler = new CrossoverScalingControl();

    // Scale using crossover scaler, so vertices will not grow
    // larger than they are in original
    double factor = Double.POSITIVE_INFINITY;

    if (direction == Directions.HORIZONTAL || direction == Directions.BOTH)
        factor = dim.getWidth() / graphBounds.width;
    if (direction == Directions.VERTICAL || direction == Directions.BOTH || Double.isInfinite(factor))
        factor = Math.min(factor, dim.getHeight() / graphBounds.height);
    scaler.scale(vv, (float) factor, vv.getCenter());

    // Translate center of graph to center of vv.
    Point2D lvc = vv.getRenderContext().getMultiLayerTransformer().inverseTransform(vv.getCenter());
    double dx = (lvc.getX() - graphBounds.getCenterX());
    double dy = (lvc.getY() - graphBounds.getCenterY());
    layoutTrans.translate(dx, dy);
}

From source file:org.immutables.gson.stream.JsonGeneratorWriter.java

@Override
public JsonWriter value(Number value) throws IOException {
    if (value == null) {
        return nullValue();
    }// w w w.j a v a 2s .c  o m
    double d = value.doubleValue();
    if (!isLenient()) {
        if (Double.isNaN(d) || Double.isInfinite(d)) {
            throw new IllegalArgumentException("JSON forbids NaN and infinities: " + value);
        }
    }
    generator.writeNumber(d);
    return this;
}

From source file:org.matsim.contrib.socnetgen.sna.graph.analysis.Centrality.java

public DescriptiveStatistics closenessDistribution() {
    DescriptiveStatistics ds = new DescriptiveStatistics();

    if (sources == null) {
        for (double val : mCentrality.getVertexCloseness()) {
            if (!Double.isInfinite(val))
                ds.addValue(val);
        }//from   ww w  . j  ava2s  .  c  om
    } else {
        for (Vertex v : sources) {
            int idx = y.getIndex(v);
            double val = mCentrality.getVertexCloseness()[idx];
            if (!Double.isInfinite(val))
                ds.addValue(val);
        }
    }
    return ds;
}

From source file:mase.spec.HybridStat.java

@Override
public void postPreBreedingExchangeStatistics(EvolutionState state) {
    super.postPreBreedingExchangeStatistics(state);
    AbstractHybridExchanger exc = (AbstractHybridExchanger) state.exchanger;
    // generation, evaluations, and number of metapops
    state.output.print(state.generation + " " + ((MaseProblem) state.evaluator.p_problem).getTotalEvaluations()
            + " " + exc.metaPops.size(), log);

    DescriptiveStatistics ds = new DescriptiveStatistics();
    for (MetaPopulation mp : exc.metaPops) {
        ds.addValue(mp.agents.size());//from  w  w w  .j  a  v a 2  s . c  o m
    }
    // metapop size (min, mean, max)
    state.output.print(" " + ds.getMin() + " " + ds.getMean() + " " + ds.getMax(), log);

    // metapop mean and max age
    ds.clear();
    for (MetaPopulation mp : exc.metaPops) {
        ds.addValue(mp.age);
    }
    state.output.print(" " + ds.getMean() + " " + ds.getMax(), log);

    // number of splits and merges in this generation + total number of splits and merges
    totalMerges += exc.merges;
    totalSplits += exc.splits;
    state.output.print(" " + exc.merges + " " + exc.splits + " " + totalMerges + " " + totalSplits, log);

    if (exc instanceof StochasticHybridExchanger) {
        StochasticHybridExchanger she = (StochasticHybridExchanger) exc;
        // metapop difference to others
        ds.clear();
        for (int i = 0; i < she.distanceMatrix.length; i++) {
            for (int j = i + 1; j < she.distanceMatrix.length; j++) {
                if (!Double.isInfinite(she.distanceMatrix[i][j]) && !Double.isNaN(she.distanceMatrix[i][j])) {
                    ds.addValue(she.distanceMatrix[i][j]);
                }
            }
        }
        if (ds.getN() > 0) {
            state.output.print(" " + ds.getN() + " " + ds.getMin() + " " + ds.getMean() + " " + ds.getMax(),
                    log);
        } else {
            state.output.print(" 0 0 0 0", log);
        }

        //printMatrix(she.distanceMatrix, state);
    }

    state.output.println("", log);

    /*for(MetaPopulation mp : exc.metaPops) {
    StringBuilder sb = new StringBuilder();
    sb.append(String.format("%3d", mp.age)).append(" - ").append(mp.toString());
    if(!mp.foreigns.isEmpty()) {
        sb.append(" - Foreigns:");
    }
    for(Foreign f : mp.foreigns) {
        sb.append(" ").append(f.origin).append("(").append(f.age).append(")");
    }
    state.output.message(sb.toString());
    }*/

    /*for(MetaPopulation mp : exc.metaPops) {
    state.output.message(mp.age + "/" + mp.lockDown);
    }*/
}

From source file:org.onebusaway.nyc.vehicle_tracking.impl.inference.CategoricalDist.java

/**
 * Adds a LOG value to the distribution.
 * //  ww w.  j av a 2  s. c o m
 * @param logProb
 * @param object
 */
public void logPut(double logProb, T object) {

    Preconditions.checkNotNull(object);

    if (Double.isInfinite(logProb))
        return;

    _logCumulativeProb = LogMath.add(_logCumulativeProb, logProb);
    final double lastVal = _entriesToLogProbs.putIfAbsent(object, logProb);
    if (_entriesToLogProbs.getNoEntryValue() != lastVal)
        _entriesToLogProbs.put(object, LogMath.add(lastVal, logProb));

    /*
     * reset the underlying distribution for lazy reloading
     */
    _emd = null;
    _objIdx.clear();
}