List of usage examples for java.lang Double NEGATIVE_INFINITY
double NEGATIVE_INFINITY
To view the source code for java.lang Double NEGATIVE_INFINITY.
Click Source Link
From source file:com.cognitect.transit.TransitTest.java
public void testReadSpecialNumbers() throws IOException { assertEquals(Double.NaN, reader("\"~zNaN\"").read()); assertEquals(Double.POSITIVE_INFINITY, reader("\"~zINF\"").read()); assertEquals(Double.NEGATIVE_INFINITY, reader("\"~z-INF\"").read()); }
From source file:net.triptech.metahive.model.KeyValue.java
@PrePersist @PreUpdate//from w w w . ja v a 2s .c o m protected void preCreateOrUpdate() { if (doubleValue != null) { if (doubleValue == Double.NaN || doubleValue == Double.POSITIVE_INFINITY || doubleValue == Double.NEGATIVE_INFINITY) { doubleValue = null; } } // Update the modified date modified = new Date(); }
From source file:com.insightml.math.optimization.AbstractOptimizable.java
@Override public final Triple<double[], Double, Double> max(final MultivariateFunction test, final double[] initial) { Check.size(initial, 1, 999);/*from w ww.jav a2 s .c om*/ final double initialTrain = value(initial); final double initialTest = test == null ? Double.NEGATIVE_INFINITY : test.value(initial); PointValuePair result = new PointValuePair(initial, initialTrain); Triple<double[], Double, Double> bestTrain = Triple.create(initial, initialTrain, initialTest); Triple<double[], Double, Double> bestTest = Triple.create(initial, initialTrain, initialTest); while (true) { result = iteration(result); if (result.getSecond() < bestTrain.getSecond() + convergence.getAbsoluteThreshold()) { log("RESULT", result); break; } final double testScore = test == null ? 0 : test.value(result.getFirst()); bestTrain = Triple.create(result.getFirst(), result.getSecond(), testScore); if (test != null && testScore > bestTest.getThird()) { bestTest = bestTrain; } // todo: prevent doing NM twice if (bounds == null) { break; } } if (test == null) { return bestTrain; } final double improveTrain = bestTrain.getSecond() - bestTest.getSecond(); final double improveTest = bestTest.getThird() - bestTrain.getThird(); if (improveTest > improveTrain) { logger.info(bestTrain + " vs. " + bestTest); } return improveTest > improveTrain ? bestTest : bestTrain; }
From source file:org.jfree.data.statistics.BoxAndWhiskerCalculator.java
/** * Calculates the statistics required for a {@link BoxAndWhiskerItem} * from a list of <code>Number</code> objects. Any items in the list * that are <code>null</code>, not an instance of <code>Number</code>, or * equivalent to <code>Double.NaN</code>, will be ignored. * * @param values a list of numbers (a <code>null</code> list is not * permitted).// w w w . j ava2s . co m * @param stripNullAndNaNItems a flag that controls the handling of null * and NaN items. * * @return A box-and-whisker item. * * @since 1.0.3 */ public static BoxAndWhiskerItem calculateBoxAndWhiskerStatistics(List values, boolean stripNullAndNaNItems) { ParamChecks.nullNotPermitted(values, "values"); List vlist; if (stripNullAndNaNItems) { vlist = new ArrayList(values.size()); Iterator iterator = values.listIterator(); while (iterator.hasNext()) { Object obj = iterator.next(); if (obj instanceof Number) { Number n = (Number) obj; double v = n.doubleValue(); if (!Double.isNaN(v)) { vlist.add(n); } } } } else { vlist = values; } Collections.sort(vlist); double mean = Statistics.calculateMean(vlist, false); double median = Statistics.calculateMedian(vlist, false); double q1 = calculateQ1(vlist); double q3 = calculateQ3(vlist); double interQuartileRange = q3 - q1; double upperOutlierThreshold = q3 + (interQuartileRange * 1.5); double lowerOutlierThreshold = q1 - (interQuartileRange * 1.5); double upperFaroutThreshold = q3 + (interQuartileRange * 2.0); double lowerFaroutThreshold = q1 - (interQuartileRange * 2.0); double minRegularValue = Double.POSITIVE_INFINITY; double maxRegularValue = Double.NEGATIVE_INFINITY; double minOutlier = Double.POSITIVE_INFINITY; double maxOutlier = Double.NEGATIVE_INFINITY; List outliers = new ArrayList(); Iterator iterator = vlist.iterator(); while (iterator.hasNext()) { Number number = (Number) iterator.next(); double value = number.doubleValue(); if (value > upperOutlierThreshold) { outliers.add(number); if (value > maxOutlier && value <= upperFaroutThreshold) { maxOutlier = value; } } else if (value < lowerOutlierThreshold) { outliers.add(number); if (value < minOutlier && value >= lowerFaroutThreshold) { minOutlier = value; } } else { minRegularValue = Math.min(minRegularValue, value); maxRegularValue = Math.max(maxRegularValue, value); } minOutlier = Math.min(minOutlier, minRegularValue); maxOutlier = Math.max(maxOutlier, maxRegularValue); } return new BoxAndWhiskerItem(new Double(mean), new Double(median), new Double(q1), new Double(q3), new Double(minRegularValue), new Double(maxRegularValue), new Double(minOutlier), new Double(maxOutlier), outliers); }
From source file:eu.amidst.core.utils.Utils.java
/** * Returns the index of the maximum element in a given array of doubles. * @param vals an {@code array} of {@code double}. * @return an {@code int} that represents the index of the maximum element in the array. */// w w w .j a va 2 s . co m public static int maxIndex(double[] vals) { double max = Double.NEGATIVE_INFINITY; int index = -1; for (int i = 0; i < vals.length; i++) { if (vals[i] > max) { max = vals[i]; index = i; } } return index; }
From source file:mase.spec.BasicHybridExchangerDunn.java
private double dunnIndex(double[][] distances) { double maxIntraCluster = Double.NEGATIVE_INFINITY; double minInterCluster = Double.POSITIVE_INFINITY; for (int i = 0; i < distances.length; i++) { maxIntraCluster = Math.max(distances[i][i], maxIntraCluster); for (int j = 0; j < distances.length; j++) { if (i != j) { minInterCluster = Math.min(minInterCluster, distances[i][j]); }/* w w w. jav a 2 s. c o m*/ } } return minInterCluster / maxIntraCluster; }
From source file:de.tudarmstadt.ukp.dkpro.core.langdect.LanguageDetector.java
@Override public void process(JCas jcas) throws AnalysisEngineProcessException { List<String> words = JCasUtil.toText(JCasUtil.select(jcas, Token.class)); if (words.size() < 1) { return;/*from w w w . j av a2s. c om*/ } List<String> ngrams = new ArrayList<String>(); if (words.size() > 1) { ngrams.add(getNgram(BOS, words.get(0), words.get(1))); } for (String ngram : new NGramStringIterable(words, 1, 3)) { ngrams.add(ngram); } try { Map<String, Double> langProbs = getLanguageProbabilities(ngrams); String maxLanguage = "x-unspecified"; double maxLogProb = Double.NEGATIVE_INFINITY; for (String lang : langProbs.keySet()) { double prob = langProbs.get(lang); if (prob > maxLogProb) { maxLogProb = prob; maxLanguage = lang; } System.out.println(lang + " - " + prob); } jcas.setDocumentLanguage(maxLanguage); } catch (Exception e) { throw new AnalysisEngineProcessException(e); } }
From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.util.weights.RandomGenerator.java
/** * Returns the weights for problems of arbitrary dimension. * /*from ww w .j a va 2 s . com*/ * @return the weights */ private List<double[]> initializeWeightsND() { int N = 50; List<double[]> candidates = new ArrayList<double[]>(numberOfPoints * N); // create random weights for (int i = 0; i < numberOfPoints * N; i++) { double[] weight = new double[numberOfObjectives]; for (int j = 0; j < numberOfObjectives; j++) { weight[j] = PRNG.nextDouble(); } double sum = StatUtils.sum(weight); for (int j = 0; j < numberOfObjectives; j++) { weight[j] /= sum; } candidates.add(weight); } List<double[]> weights = new ArrayList<double[]>(numberOfPoints * N); // add boundary weights (1,0,...,0), (0,1,...,0), ..., (0,...,0,1) for (int i = 0; i < numberOfObjectives; i++) { double[] weight = new double[numberOfObjectives]; weight[i] = 1.0; weights.add(weight); } // fill in remaining weights with the weight vector with the largest // distance from the assigned weights while (weights.size() < numberOfPoints) { double[] weight = null; double distance = Double.NEGATIVE_INFINITY; for (int i = 0; i < candidates.size(); i++) { double d = Double.POSITIVE_INFINITY; for (int j = 0; j < weights.size(); j++) { d = Math.min(d, MathArrays.distance(candidates.get(i), weights.get(j))); } if (d > distance) { weight = candidates.get(i); distance = d; } } weights.add(weight); candidates.remove(weight); } return weights; }
From source file:org.jfree.chart.demo.SampleXYDataset2.java
/** * Creates a sample dataset.// w w w .ja v a 2s . c o m * * @param seriesCount the number of series. * @param itemCount the number of items. */ public SampleXYDataset2(final int seriesCount, final int itemCount) { this.xValues = new Double[seriesCount][itemCount]; this.yValues = new Double[seriesCount][itemCount]; this.seriesCount = seriesCount; this.itemCount = itemCount; double minX = Double.POSITIVE_INFINITY; double maxX = Double.NEGATIVE_INFINITY; double minY = Double.POSITIVE_INFINITY; double maxY = Double.NEGATIVE_INFINITY; for (int series = 0; series < seriesCount; series++) { for (int item = 0; item < itemCount; item++) { final double x = (Math.random() - 0.5) * DEFAULT_RANGE; this.xValues[series][item] = new Double(x); if (x < minX) { minX = x; } if (x > maxX) { maxX = x; } final double y = (Math.random() + 0.5) * 6 * x + x; this.yValues[series][item] = new Double(y); if (y < minY) { minY = y; } if (y > maxY) { maxY = y; } } } this.domainMin = new Double(minX); this.domainMax = new Double(maxX); this.domainRange = new Range(minX, maxX); this.rangeMin = new Double(minY); this.rangeMax = new Double(maxY); this.range = new Range(minY, maxY); }
From source file:beast.math.distributions.GammaDistribution.java
/** * the natural log of the probability density function of the distribution * * @param x argument//from ww w .j a v a 2 s . co m * @param shape shape parameter * @param scale scale parameter * @return log pdf value */ public static double logPdf(double x, double shape, double scale) { // double a = Math.pow(scale,-shape) * Math.pow(x, shape-1.0); // double b = x/scale + GammaFunction.lnGamma(shape); // return Math.log(a) - b; // AR - changed this to return -ve inf instead of throwing an // exception... This makes things // much easier when using this to calculate log likelihoods. // if (x < 0) throw new IllegalArgumentException(); if (x < 0) return Double.NEGATIVE_INFINITY; if (x == 0) { if (shape == 1.0) return Math.log(1.0 / scale); else return Double.NEGATIVE_INFINITY; } if (shape == 1.0) { return (-x / scale) - Math.log(scale); } if (shape == 0.0) // uninformative return -Math.log(x); /*return ((shape - 1.0) * Math.log(x/scale) - x / scale - GammaFunction .lnGamma(shape)) - Math.log(scale);*/ return ((shape - 1.0) * (Math.log(x) - Math.log(scale)) - x / scale - GammaFunction.lnGamma(shape)) - Math.log(scale); }