List of usage examples for java.lang Double isInfinite
public static boolean isInfinite(double v)
From source file:net.sf.mzmine.modules.visualization.twod.TwoDXYPlot.java
public boolean render(final Graphics2D g2, final Rectangle2D dataArea, int index, PlotRenderingInfo info, CrosshairState crosshairState) { // if this is not TwoDDataSet if (index != 0) return super.render(g2, dataArea, index, info, crosshairState); // prepare some necessary constants final int x = (int) dataArea.getX(); final int y = (int) dataArea.getY(); final int width = (int) dataArea.getWidth(); final int height = (int) dataArea.getHeight(); final double imageRTMin = (double) getDomainAxis().getRange().getLowerBound(); final double imageRTMax = (double) getDomainAxis().getRange().getUpperBound(); final double imageRTStep = (imageRTMax - imageRTMin) / width; final double imageMZMin = (double) getRangeAxis().getRange().getLowerBound(); final double imageMZMax = (double) getRangeAxis().getRange().getUpperBound(); final double imageMZStep = (imageMZMax - imageMZMin) / height; if ((zoomOutBitmap != null) && (imageRTMin == totalRTRange.getMin()) && (imageRTMax == totalRTRange.getMax()) && (imageMZMin == totalMZRange.getMin()) && (imageMZMax == totalMZRange.getMax()) && (zoomOutBitmap.getWidth() == width) && (zoomOutBitmap.getHeight() == height)) { g2.drawImage(zoomOutBitmap, x, y, null); return true; }//from w ww. ja va 2s .c o m // Save current time Date renderStartTime = new Date(); // prepare a double array of summed intensities double values[][] = new double[width][height]; maxValue = 0; // now this is an instance variable Random r = new Random(); for (int i = 0; i < width; i++) for (int j = 0; j < height; j++) { double pointRTMin = imageRTMin + (i * imageRTStep); double pointRTMax = pointRTMin + imageRTStep; double pointMZMin = imageMZMin + (j * imageMZStep); double pointMZMax = pointMZMin + imageMZStep; double lv = dataset.getMaxIntensity(new Range(pointRTMin, pointRTMax), new Range(pointMZMin, pointMZMax), plotMode); if (logScale) { lv = Math.log10(lv); if (lv < 0 || Double.isInfinite(lv)) lv = 0; values[i][j] = lv; //values[r.nextInt(width)][r.nextInt(height)] = lv; } else { values[i][j] = lv; } if (lv > maxValue) maxValue = lv; } // This should never happen, but just for correctness if (maxValue == 0) return false; // Normalize all values for (int i = 0; i < width; i++) for (int j = 0; j < height; j++) { values[i][j] /= maxValue; } // prepare a bitmap of required size BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); // draw image points for (int i = 0; i < width; i++) for (int j = 0; j < height; j++) { Color pointColor = paletteType.getColor(values[i][j]); image.setRGB(i, height - j - 1, pointColor.getRGB()); } // if we are zoomed out, save the values if ((imageRTMin == totalRTRange.getMin()) && (imageRTMax == totalRTRange.getMax()) && (imageMZMin == totalMZRange.getMin()) && (imageMZMax == totalMZRange.getMax())) { zoomOutBitmap = image; } // Paint image g2.drawImage(image, x, y, null); Date renderFinishTime = new Date(); logger.finest("Finished rendering 2D visualizer, " + (renderFinishTime.getTime() - renderStartTime.getTime()) + " ms"); return true; }
From source file:de.jfachwert.pruefung.NumberValidator.java
/** * Verifiziert die uebergebene Nummer, ob sie eine gueltige Nummer und * nicht unendlich oder 'NaN' ist. Falls die Nummer unendlich oder 'NaN' * ist, wird eine {@link ArithmeticException} geworfen. * * @param number zu pruefende Nummer//from w w w .j a v a 2 s.c om * @return die Nummer selbst zur Weiterverarbeitung */ public Number verifyNumber(Number number) { if ((number instanceof Double) || (number instanceof Float)) { double dValue = number.doubleValue(); if (Double.isNaN(dValue) || Double.isInfinite(dValue)) { throw new LocalizedArithmeticException(dValue, NUMBER); } } return number; }
From source file:edu.jhuapl.bsp.detector.OpenMath.java
public static double mean(int[] in) { if (in != null && in.length > 0) { double sum = 0; for (int i = 0; i < in.length; i++) { sum += in[i];/*from ww w . j av a2 s . com*/ } double result = sum / in.length; if (Double.isNaN(result) || Double.isInfinite(result)) { return 0; } else { return result; } } return 0; }
From source file:com.joptimizer.optimizers.LPOptimizationRequest.java
public void setLb(DoubleMatrix1D lb) { for (int i = 0; i < lb.size(); i++) { double lbi = lb.getQuick(i); if (Double.isNaN(lbi) || Double.isInfinite(lbi)) { throw new IllegalArgumentException( "The lower bounds can not be set to Double.NaN or Double.INFINITY"); }/* w w w . ja v a 2s. com*/ } this.lb = lb; }
From source file:beast.math.distributions.NormalDistribution.java
/** * A more accurate and faster implementation of the cdf (taken from function pnorm in the R statistical language) * This implementation has discrepancies depending on the programming language and system architecture * In Java, returned values become zero once z reaches -37.5193 exactly on the machine tested * In the other implementation, the returned value 0 at about z = -8 * In C, this 0 value is reached approximately z = -37.51938 * <p/>/*from w w w . j av a2 s. c o m*/ * Will later need to be optimised for BEAST * * @param x argument * @param mu mean * @param sigma standard deviation * @param log_p is p logged * @return cdf at x */ public static double cdf(double x, double mu, double sigma, boolean log_p) { if (Double.isNaN(x) || Double.isNaN(mu) || Double.isNaN(sigma)) { return Double.NaN; } if (Double.isInfinite(x) && mu == x) { /* x-mu is NaN */ return Double.NaN; } if (sigma <= 0) { if (sigma < 0) { return Double.NaN; } return (x < mu) ? 0.0 : 1.0; } double p = (x - mu) / sigma; if (Double.isInfinite(p)) { return (x < mu) ? 0.0 : 1.0; } return standardCDF(p, log_p); }
From source file:org.matsim.contrib.socnetgen.sna.snowball.analysis.DegreeGrowth.java
private void dump(Sampler<?, ?, ?> sampler) { DescriptiveStatistics stats = ObservedDegree.getInstance() .statistics(sampler.getSampledGraph().getVertices()); if (prevStats != null) { TDoubleDoubleHashMap hist = Histogram.createHistogram(stats, discretizer, false); TDoubleDoubleHashMap prevHist = Histogram.createHistogram(prevStats, discretizer, false); TDoubleDoubleHashMap growth = new TDoubleDoubleHashMap(); TDoubleDoubleIterator it = hist.iterator(); for (int i = 0; i < hist.size(); i++) { it.advance();// w w w .jav a 2 s .c o m double g = it.value() / prevHist.get(it.key()); if (Double.isInfinite(g)) g = 0.0; growth.put(it.key(), g); } growthTable.put(sampler.getIteration() - 1, growth); } prevStats = stats; }
From source file:com.stewel.dataflow.assocrules.AlgoAgrawalFaster94.java
/** * Run the algorithm for generating association rules from a set of itemsets. * * @return the set of rules found if the user chose to save the result to memory * @throws IOException exception if error while writting to file *///from w w w. ja v a 2 s . co m public void runAlgorithm() throws IOException { // For each frequent itemset of size >=2 that we will name "lk" for (int k = 2; k < patterns.getLevels().size(); k++) { for (Itemset lk : patterns.getLevels().get(k)) { // create a variable H1 for recursion List<int[]> H1_for_recursion = new ArrayList<int[]>(); // For each itemset "itemsetSize1" of size 1 that is member of lk for (int item : lk.getItems()) { int itemsetHm_P_1[] = new int[] { item }; // make a copy of lk without items from hm_P_1 int[] itemset_Lk_minus_hm_P_1 = Itemset.cloneItemSetMinusOneItem(lk.getItems(), item); // Now we will calculate the support and confidence // of the rule: itemset_Lk_minus_hm_P_1 ==> hm_P_1 long support = itemsetSupportCalculator.calculateSupport(itemset_Lk_minus_hm_P_1); // THIS COULD BE // OPTIMIZED ? double supportAsDouble = (double) support; // calculate the confidence of the rule : itemset_Lk_minus_hm_P_1 ==> hm_P_1 double conf = lk.getAbsoluteSupport() / supportAsDouble; // if the confidence is lower than minimumConfidence if (conf < minimumConfidence || Double.isInfinite(conf)) { continue; } double lift = 0; long supportHm_P_1 = 0; // if the user is using the minimumLift threshold, we will need // to also calculate the lift of the rule: itemset_Lk_minus_hm_P_1 ==> hm_P_1 if (usingLift) { // if we want to calculate the lift, we need the support of hm_P_1 supportHm_P_1 = itemsetSupportCalculator.calculateSupport(itemsetHm_P_1); // if we want to calculate the lift, we need to add this. // calculate the lift double term1 = ((double) lk.getAbsoluteSupport()) / databaseSize; double term2 = supportAsDouble / databaseSize; double term3 = ((double) supportHm_P_1 / databaseSize); lift = term1 / (term2 * term3); // if the lift is not enough if (lift < minimumLift) { continue; } } // If we are here, it means that the rule respect the minimumConfidence and minimumLift parameters. // Therefore, we output the rule. associationRuleWriter.write(ImmutableAssociationRule.builder() .antecedent(itemset_Lk_minus_hm_P_1).consequent(itemsetHm_P_1).coverage(support) .transactionCount(lk.getAbsoluteSupport()).confidence(conf).lift(lift).build()); // Then we keep the itemset hm_P_1 to find more rules using this itemset and lk. H1_for_recursion.add(itemsetHm_P_1); // ================ END OF WHAT I HAVE ADDED } // Finally, we make a recursive call to continue explores rules that can be made with "lk" apGenrules(k, 1, lk, H1_for_recursion); } } }
From source file:etomica.models.co2.PNCO2GCPM.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 ww w .j a v a2s . c o 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:geogebra.kernel.AlgoIntegralDefinite.java
protected final void compute() { if (!f.isDefined() || !ageo.isDefined() || !bgeo.isDefined()) { n.setUndefined();//from ww w . jav a 2 s. c om return; } // check for equal bounds double lowerLimit = a.getDouble(); double upperLimit = b.getDouble(); if (Kernel.isEqual(lowerLimit, upperLimit)) { n.setValue(0); return; } // check if f(a) and f(b) are defined double fa = f.evaluate(lowerLimit); double fb = f.evaluate(upperLimit); if (Double.isNaN(fa) || Double.isInfinite(fa) || Double.isNaN(fb) || Double.isInfinite(fb)) { n.setUndefined(); return; } // return if it should not be evaluated (i.e. is shade-only) if (evaluate != null && !evaluate.getBoolean()) { n.setValue(0); return; } /* * Try to use symbolic integral * * We only do this for functions that do NOT include divisions by their variable. * Otherwise there might be problems like: * Integral[ 1/x, -2, -1 ] would be undefined (log(-1) - log(-2)) * Integral[ 1/x^2, -1, 1 ] would be defined (-2) */ if (symbIntegral != null && symbIntegral.isDefined() && !f.includesDivisionByVar()) { double val = symbIntegral.evaluate(upperLimit) - symbIntegral.evaluate(lowerLimit); n.setValue(val); if (n.isDefined()) return; } // numerical integration // max_error = ACCURACY; // current maximum error //maxstep = 0; double integral = numericIntegration(f, lowerLimit, upperLimit); n.setValue(integral); /* Application.debug("***\nsteps: " + maxstep); Application.debug("max_error: " + max_error); */ }
From source file:es.udc.gii.common.eaf.plugin.parameter.jade.JADECRAdaptiveParameter.java
@Override public double get(EvolutionaryAlgorithm algorithm) { double meana_cr; double cr_i;//from w w w . j a v a 2 s. c o m List<Individual> individuals; int cr_individuals; double cr_ind; //Hay que "chequear" que los individuos sean del tipo JADE: if (algorithm.getGenerations() > this.alg_generation) { //Calculamos mu; individuals = algorithm.getPopulation().getIndividuals(); meana_cr = 0.0; cr_individuals = 0; for (Individual i : individuals) { if (i instanceof JADEIndividual) { cr_ind = ((JADEIndividual) i).getCR(); if (cr_ind != -Double.MAX_VALUE) { meana_cr += cr_ind; cr_individuals++; } } else { throw new ConfigurationException( "JADECRAdaptiveParameter requires individuals of type JADEIndividual"); } } meana_cr /= cr_individuals; if (!Double.isNaN(meana_cr) && !Double.isInfinite(meana_cr)) { this.mu_cr = (1.0 - this.c) * this.mu_cr + this.c * meana_cr; this.mu_cr = (this.mu_cr > 1.0 ? 1.0 : (this.mu_cr < 0.0 ? 0.0 : this.mu_cr)); } this.alg_generation++; //System.out.println(this.mu_cr); } cr_i = 0.0; NormalDistributionImpl n = new NormalDistributionImpl(this.mu_cr, this.std_cr); try { double r = EAFRandom.nextDouble(); cr_i = n.inverseCumulativeProbability(r); cr_i = (cr_i > 1.0 ? 1.0 : (cr_i < 0.0 ? 0.0 : cr_i)); } catch (MathException ex) { Logger.getLogger(JADECRAdaptiveParameter.class.getName()).log(Level.SEVERE, null, ex); } return cr_i; }