List of usage examples for java.lang Double isInfinite
public static boolean isInfinite(double v)
From source file:org.eclipse.dataset.Maths.java
private static long toLong(double d) { if (Double.isInfinite(d) || Double.isNaN(d)) return 0; return (long) d; }
From source file:MetaFramework.Bayesian.java
/** * Given a critical value t and degrees of freedom to account for, computes a p-value for a chi-square distribution * * @param t Critical value/test statistics * @param df Degrees of Freedom/*from w ww . ja v a 2 s . co m*/ * @return Returns a p-value */ public double computePValue(double t, int df) { double result = 0.0; if (t < 0 || df < 1) { return 0.0; } double K = ((double) df) * 0.5; double X = t * 0.5; if (df == 2) { return Math.exp(-1.0 * X); } double PValue = igf(K, X); if (Double.isNaN(PValue) || Double.isInfinite(PValue) || PValue <= 1e-8) { return 1e-14; } PValue /= approx_gamma(K); // PValue /= gamma(K); //PValue /= tgamma(K); return (1.0 - PValue); }
From source file:org.broadinstitute.gatk.utils.MathUtils.java
/** * See #normalizeFromLog10 but with the additional option to use an approximation that keeps the calculation always in log-space * * @param array/*from w w w . j av a 2s . c o m*/ * @param takeLog10OfOutput * @param keepInLogSpace * * @return */ public static double[] normalizeFromLog10(final double[] array, final boolean takeLog10OfOutput, final boolean keepInLogSpace) { // for precision purposes, we need to add (or really subtract, since they're // all negative) the largest value; also, we need to convert to normal-space. double maxValue = arrayMax(array); // we may decide to just normalize in log space without converting to linear space if (keepInLogSpace) { for (int i = 0; i < array.length; i++) { array[i] -= maxValue; } return array; } // default case: go to linear space double[] normalized = new double[array.length]; for (int i = 0; i < array.length; i++) normalized[i] = Math.pow(10, array[i] - maxValue); // normalize double sum = 0.0; for (int i = 0; i < array.length; i++) sum += normalized[i]; for (int i = 0; i < array.length; i++) { double x = normalized[i] / sum; if (takeLog10OfOutput) { x = Math.log10(x); if (x < LOG10_P_OF_ZERO || Double.isInfinite(x)) x = array[i] - maxValue; } normalized[i] = x; } return normalized; }
From source file:org.apache.sysml.hops.codegen.template.PlanSelectionFuseCostBased.java
private static double rGetPlanCosts(CPlanMemoTable memo, Hop current, HashSet<Pair<Long, Long>> visited, HashSet<Long> partition, ArrayList<Long> M, boolean[] plan, HashMap<Long, Double> computeCosts, CostVector costsCurrent, TemplateType currentType) { //memoization per hop id and cost vector to account for redundant //computation without double counting materialized results or compute //costs of complex operation DAGs within a single fused operator Pair<Long, Long> tag = Pair.of(current.getHopID(), (costsCurrent == null) ? 0 : costsCurrent.ID); if (visited.contains(tag)) return 0; visited.add(tag);//w w w .ja va 2 s.co m //open template if necessary, including memoization //under awareness of current plan choice MemoTableEntry best = null; boolean opened = false; if (memo.contains(current.getHopID())) { if (currentType == null) { best = memo.get(current.getHopID()).stream().filter(p -> isValid(p, current)) .filter(p -> hasNoRefToMaterialization(p, M, plan)).min(new BasicPlanComparator()) .orElse(null); opened = true; } else { best = memo.get(current.getHopID()).stream() .filter(p -> p.type == currentType || p.type == TemplateType.CellTpl) .filter(p -> hasNoRefToMaterialization(p, M, plan)) .min(Comparator.comparing(p -> 7 - ((p.type == currentType) ? 4 : 0) - p.countPlanRefs())) .orElse(null); } } //create new cost vector if opened, initialized with write costs CostVector costVect = !opened ? costsCurrent : new CostVector(Math.max(current.getDim1(), 1) * Math.max(current.getDim2(), 1)); //add compute costs of current operator to costs vector if (partition.contains(current.getHopID())) costVect.computeCosts += computeCosts.get(current.getHopID()); //process children recursively double costs = 0; for (int i = 0; i < current.getInput().size(); i++) { Hop c = current.getInput().get(i); if (best != null && best.isPlanRef(i)) costs += rGetPlanCosts(memo, c, visited, partition, M, plan, computeCosts, costVect, best.type); else if (best != null && isImplicitlyFused(current, i, best.type)) costVect.addInputSize(c.getInput().get(0).getHopID(), Math.max(c.getDim1(), 1) * Math.max(c.getDim2(), 1)); else { //include children and I/O costs costs += rGetPlanCosts(memo, c, visited, partition, M, plan, computeCosts, null, null); if (costVect != null && c.getDataType().isMatrix()) costVect.addInputSize(c.getHopID(), Math.max(c.getDim1(), 1) * Math.max(c.getDim2(), 1)); } } //add costs for opened fused operator if (partition.contains(current.getHopID())) { if (opened) { if (LOG.isTraceEnabled()) LOG.trace("Cost vector for fused operator (hop " + current.getHopID() + "): " + costVect); costs += costVect.outSize * 8 / WRITE_BANDWIDTH; //time for output write costs += Math.max(costVect.computeCosts * costVect.getMaxInputSize() / COMPUTE_BANDWIDTH, costVect.getSumInputSizes() * 8 / READ_BANDWIDTH); } //add costs for non-partition read in the middle of fused operator else if (hasNonPartitionConsumer(current, partition)) { costs += rGetPlanCosts(memo, current, visited, partition, M, plan, computeCosts, null, null); } } //sanity check non-negative costs if (costs < 0 || Double.isNaN(costs) || Double.isInfinite(costs)) throw new RuntimeException("Wrong cost estimate: " + costs); return costs; }
From source file:net.opentsdb.tsd.GraphHandler.java
/** * Respond to a query that wants the output in ASCII. * <p>//from ww w . j a v a 2 s. c o m * When a query specifies the "ascii" query string parameter, we send the * data points back to the client in plain text instead of sending a PNG. * @param query The query we're currently serving. * @param max_age The maximum time (in seconds) we wanna allow clients to * cache the result in case of a cache hit. * @param basepath The base path used for the Gnuplot files. * @param plot The plot object to generate Gnuplot's input files. */ private static void respondAsciiQuery(final HttpQuery query, final int max_age, final String basepath, final Plot plot) { final String path = basepath + ".txt"; PrintWriter asciifile; try { asciifile = new PrintWriter(path); } catch (IOException e) { query.internalError(e); return; } try { final StringBuilder tagbuf = new StringBuilder(); for (final DataPoints dp : plot.getDataPoints()) { final String metric = dp.metricName(); tagbuf.setLength(0); for (final Map.Entry<String, String> tag : dp.getTags().entrySet()) { tagbuf.append(' ').append(tag.getKey()).append('=').append(tag.getValue()); } for (final DataPoint d : dp) { asciifile.print(metric); asciifile.print(' '); asciifile.print((d.timestamp() / 1000)); asciifile.print(' '); if (d.isInteger()) { asciifile.print(d.longValue()); } else { final double value = d.doubleValue(); if (value != value || Double.isInfinite(value)) { throw new IllegalStateException( "NaN or Infinity:" + value + " d=" + d + ", query=" + query); } asciifile.print(value); } asciifile.print(tagbuf); asciifile.print('\n'); } } } finally { asciifile.close(); } try { query.sendFile(path, max_age); } catch (IOException e) { query.internalError(e); } }
From source file:net.sourceforge.processdash.data.util.ResultSet.java
protected Number asNumber(SimpleData s) { double d = 0.0; if (s instanceof NumberData) { d = ((NumberData) s).getDouble(); if (Double.isNaN(d) || Double.isInfinite(d)) d = 0.0;//from w w w. j a v a 2 s.c om } else if (s instanceof DateData) { d = ((DateData) s).getValue().getTime(); } return new Double(d); }
From source file:org.eclipse.dataset.AbstractCompoundDataset.java
@Override protected void calculateSummaryStats(boolean ignoreNaNs, final boolean ignoreInfs, String name) { IndexIterator iter = getIterator();/* ww w . ja va 2s .c o m*/ SummaryStatistics[] stats = new SummaryStatistics[isize]; for (int i = 0; i < isize; i++) stats[i] = new SummaryStatistics(); double[] vals = new double[isize]; while (iter.hasNext()) { boolean okay = true; for (int i = 0; i < isize; i++) { final double val = getElementDoubleAbs(iter.index + i); if (ignoreNaNs && Double.isNaN(val)) { okay = false; break; } if (ignoreInfs && Double.isInfinite(val)) { okay = false; break; } vals[i] = val; } if (!okay) continue; for (int i = 0; i < isize; i++) stats[i].addValue(vals[i]); } // now all the calculations are done, add the values into store if (storedValues == null) storedValues = new HashMap<String, Object>(); else storedValues.clear(); for (int i = 0; i < isize; i++) storedValues.put(name + i, stats[i]); }
From source file:org.eclipse.dataset.LongDataset.java
@Override public LongDataset ipower(final Object b) { Dataset bds = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b); if (bds.getSize() == 1) { final double vr = bds.getElementDoubleAbs(0); final IndexIterator it = getIterator(); if (bds.isComplex()) { final double vi = bds.getElementDoubleAbs(1); if (vi == 0) { while (it.hasNext()) { final double v = Math.pow(data[it.index], vr); if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE data[it.index] = 0; // INT_USE } else { // INT_USE data[it.index] = (long) v; // PRIM_TYPE_LONG // ADD_CAST } // INT_USE }// ww w.j a va 2 s . com } else { final Complex zv = new Complex(vr, vi); while (it.hasNext()) { Complex zd = new Complex(data[it.index], 0); final double v = zd.pow(zv).getReal(); if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE data[it.index] = 0; // INT_USE } else { // INT_USE data[it.index] = (long) v; // PRIM_TYPE_LONG // ADD_CAST } // INT_USE } } } else {// NAN_OMIT while (it.hasNext()) { final double v = Math.pow(data[it.index], vr); if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE data[it.index] = 0; // INT_USE } else { // INT_USE data[it.index] = (long) v; // PRIM_TYPE_LONG // ADD_CAST } // INT_USE } } } else { final BroadcastIterator it = BroadcastIterator.createIterator(this, bds); it.setOutputDouble(true); if (bds.isComplex()) { while (it.hasNext()) { final Complex zv = new Complex(it.bDouble, bds.getElementDoubleAbs(it.bIndex + 1)); final double v = new Complex(it.aDouble, 0).pow(zv).getReal(); if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE data[it.aIndex] = 0; // INT_USE } else { // INT_USE data[it.aIndex] = (long) v; // PRIM_TYPE_LONG // ADD_CAST } // INT_USE } } else {// NAN_OMIT while (it.hasNext()) { final double v = Math.pow(it.aDouble, it.bDouble); if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE data[it.aIndex] = 0; // INT_USE } else { // INT_USE data[it.aIndex] = (long) v; // PRIM_TYPE_LONG // ADD_CAST } // INT_USE } } } setDirty(); return this; }
From source file:org.eclipse.dataset.ByteDataset.java
@Override public ByteDataset ipower(final Object b) { Dataset bds = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b); if (bds.getSize() == 1) { final double vr = bds.getElementDoubleAbs(0); final IndexIterator it = getIterator(); if (bds.isComplex()) { final double vi = bds.getElementDoubleAbs(1); if (vi == 0) { while (it.hasNext()) { final double v = Math.pow(data[it.index], vr); if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE data[it.index] = 0; // INT_USE } else { // INT_USE data[it.index] = (byte) (long) v; // PRIM_TYPE_LONG // ADD_CAST } // INT_USE }/*from www . j a v a2 s . c o m*/ } else { final Complex zv = new Complex(vr, vi); while (it.hasNext()) { Complex zd = new Complex(data[it.index], 0); final double v = zd.pow(zv).getReal(); if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE data[it.index] = 0; // INT_USE } else { // INT_USE data[it.index] = (byte) (long) v; // PRIM_TYPE_LONG // ADD_CAST } // INT_USE } } } else {// NAN_OMIT while (it.hasNext()) { final double v = Math.pow(data[it.index], vr); if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE data[it.index] = 0; // INT_USE } else { // INT_USE data[it.index] = (byte) (long) v; // PRIM_TYPE_LONG // ADD_CAST } // INT_USE } } } else { final BroadcastIterator it = BroadcastIterator.createIterator(this, bds); it.setOutputDouble(true); if (bds.isComplex()) { while (it.hasNext()) { final Complex zv = new Complex(it.bDouble, bds.getElementDoubleAbs(it.bIndex + 1)); final double v = new Complex(it.aDouble, 0).pow(zv).getReal(); if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE data[it.aIndex] = 0; // INT_USE } else { // INT_USE data[it.aIndex] = (byte) (long) v; // PRIM_TYPE_LONG // ADD_CAST } // INT_USE } } else {// NAN_OMIT while (it.hasNext()) { final double v = Math.pow(it.aDouble, it.bDouble); if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE data[it.aIndex] = 0; // INT_USE } else { // INT_USE data[it.aIndex] = (byte) (long) v; // PRIM_TYPE_LONG // ADD_CAST } // INT_USE } } } setDirty(); return this; }
From source file:org.eclipse.dataset.ShortDataset.java
@Override public ShortDataset ipower(final Object b) { Dataset bds = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b); if (bds.getSize() == 1) { final double vr = bds.getElementDoubleAbs(0); final IndexIterator it = getIterator(); if (bds.isComplex()) { final double vi = bds.getElementDoubleAbs(1); if (vi == 0) { while (it.hasNext()) { final double v = Math.pow(data[it.index], vr); if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE data[it.index] = 0; // INT_USE } else { // INT_USE data[it.index] = (short) (long) v; // PRIM_TYPE_LONG // ADD_CAST } // INT_USE }//from ww w. j a v a 2s .co m } else { final Complex zv = new Complex(vr, vi); while (it.hasNext()) { Complex zd = new Complex(data[it.index], 0); final double v = zd.pow(zv).getReal(); if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE data[it.index] = 0; // INT_USE } else { // INT_USE data[it.index] = (short) (long) v; // PRIM_TYPE_LONG // ADD_CAST } // INT_USE } } } else {// NAN_OMIT while (it.hasNext()) { final double v = Math.pow(data[it.index], vr); if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE data[it.index] = 0; // INT_USE } else { // INT_USE data[it.index] = (short) (long) v; // PRIM_TYPE_LONG // ADD_CAST } // INT_USE } } } else { final BroadcastIterator it = BroadcastIterator.createIterator(this, bds); it.setOutputDouble(true); if (bds.isComplex()) { while (it.hasNext()) { final Complex zv = new Complex(it.bDouble, bds.getElementDoubleAbs(it.bIndex + 1)); final double v = new Complex(it.aDouble, 0).pow(zv).getReal(); if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE data[it.aIndex] = 0; // INT_USE } else { // INT_USE data[it.aIndex] = (short) (long) v; // PRIM_TYPE_LONG // ADD_CAST } // INT_USE } } else {// NAN_OMIT while (it.hasNext()) { final double v = Math.pow(it.aDouble, it.bDouble); if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE data[it.aIndex] = 0; // INT_USE } else { // INT_USE data[it.aIndex] = (short) (long) v; // PRIM_TYPE_LONG // ADD_CAST } // INT_USE } } } setDirty(); return this; }