List of usage examples for java.lang Double POSITIVE_INFINITY
double POSITIVE_INFINITY
To view the source code for java.lang Double POSITIVE_INFINITY.
Click Source Link
From source file:net.triptech.metahive.model.KeyValue.java
@PrePersist @PreUpdate/*w ww . j a v a 2s .co 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:beast.evomodel.speciation.BirthDeathModel.java
public BirthDeathModel(String modelName, Parameter birthDiffRateParameter, Parameter relativeDeathRateParameter, Parameter sampleProbability, Parameter originHeightParameter, TreeType type, Type units, boolean conditionalOnRoot) { super(modelName, units); this.birthDiffRateParameter = birthDiffRateParameter; addVariable(birthDiffRateParameter); birthDiffRateParameter.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, 0.0, 1)); this.relativeDeathRateParameter = relativeDeathRateParameter; if (relativeDeathRateParameter != null) { addVariable(relativeDeathRateParameter); relativeDeathRateParameter.addBounds(new Parameter.DefaultBounds(1.0, 0.0, 1)); }// w w w . j ava 2 s . c om this.sampleProbability = sampleProbability; if (sampleProbability != null) { addVariable(sampleProbability); sampleProbability.addBounds(new Parameter.DefaultBounds(1.0, 0.0, 1)); } this.originHeightParameter = originHeightParameter; conditionOnOrigin = originHeightParameter != null; if (conditionOnOrigin) addVariable(originHeightParameter); this.conditionalOnRoot = conditionalOnRoot; if (conditionalOnRoot && conditionOnOrigin) { throw new IllegalArgumentException("Cannot condition on both root and origin!"); } this.type = type; }
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 av a 2s.c o 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:com.joptimizer.util.MPSParserTest.java
/** * This is the PILOT4 netlib problem./*from w ww .j a va 2s. c o m*/ */ public void testMps3() throws Exception { log.debug("testMps3"); String problemId = "3"; File f = Utils .getClasspathResourceAsFile("lp" + File.separator + "mps" + File.separator + problemId + ".mps"); double unboundedLBValue = Double.NEGATIVE_INFINITY; double unboundedUBValue = Double.POSITIVE_INFINITY; double unspecifiedLBValue = 0; double unspecifiedUBValue = unboundedUBValue; MPSParser p = new MPSParser(unspecifiedLBValue, unspecifiedUBValue, unboundedLBValue, unboundedUBValue); p.parse(f); int n = p.getN(); int meq = p.getMeq(); int mieq = p.getMieq(); log.debug("name: " + p.getName()); log.debug("n : " + n); log.debug("meq : " + meq); log.debug("mieq: " + mieq); log.debug("rows: " + (meq + mieq)); log.debug("lb : " + ArrayUtils.toString(p.getLb().toArray())); log.debug("ub : " + ArrayUtils.toString(p.getUb().toArray())); assertEquals(n, 1000); assertEquals(meq, 287); assertEquals(mieq, 123); List<String> unboundedVariables = Arrays.asList(new String[] { "XCRO01", "XROP01", "XGAS01", "XELE01", "XAGR01", "XMNG01", "XCMP01", "XFDS01", "XPPR01", "XSCG01", "XMET01", "XTEX01", "XLUM01", "XFAP01", "XMFG01", "XTAW01", "XTRD01", "XFIN01", "XSVC01", "XTRE01", "XMAC01" }); List<String> variablesNames = p.getVariablesNames(); for (int i = 0; i < n; i++) { String variable = variablesNames.get(i); if (unboundedVariables.contains(variable)) { //this variables are stated to be unbounded in this mps model assertEquals(unboundedLBValue, p.getLb().getQuick(i)); assertEquals(unboundedUBValue, p.getUb().getQuick(i)); } else if ("PLWU01".equalsIgnoreCase(variable)) { //this variables has not explicit bounds in this mps model assertEquals(unspecifiedLBValue, p.getLb().getQuick(i)); assertEquals(unspecifiedUBValue, p.getUb().getQuick(i)); } } }
From source file:edu.jhuapl.bsp.detector.OpenMath.java
public static double max(double[] in) { if (in != null) { double minvalue = Double.NEGATIVE_INFINITY; for (int i = 0; i < in.length; i++) { minvalue = Math.max(in[i], minvalue); }/*from ww w. j a va 2 s . c o m*/ return minvalue; } return Double.POSITIVE_INFINITY; }
From source file:edu.uci.ics.jung.algorithms.shortestpath.DijkstraDistance.java
/** * <p>Creates an instance of <code>DijkstraShortestPath</code> for * the specified graph and the specified method of extracting weights * from edges, which caches results locally if and only if * <code>cached</code> is <code>true</code>. * //w w w .j a v a2 s . c om * @param g the graph on which distances will be calculated * @param nev the class responsible for returning weights for edges * @param cached specifies whether the results are to be cached */ public DijkstraDistance(Hypergraph<V, E> g, Transformer<E, ? extends Number> nev, boolean cached) { this.g = g; this.nev = nev; this.sourceMap = new HashMap<V, SourceData>(); this.cached = cached; this.max_distance = Double.POSITIVE_INFINITY; this.max_targets = Integer.MAX_VALUE; }
From source file:com.analog.lyric.dimple.solvers.gibbs.samplers.generic.SuwaTodoSampler.java
@Override public void nextSample(DiscreteValue sampleValue, double[] energy, double minEnergy, IDiscreteSamplerClient samplerClient) { RandomGenerator rand = activeRandom(); final int length = sampleValue.getDomain().size(); // energy may be longer than domain size int sampleIndex; // Special-case length 2 for speed // This case is equivalent to MH if (length == 2) { final int previousIndex = sampleValue.getIndex(); final double pdf0 = Math.exp(minEnergy - energy[0]); final double pdf1 = Math.exp(minEnergy - energy[1]); if (previousIndex == 0) { double rejectProb = pdf0 - pdf1; if (rejectProb < 0) sampleIndex = 1; // Flip else if (rand.nextDouble() < rejectProb) sampleIndex = 0;/* w w w . j av a 2 s .c om*/ else sampleIndex = 1; // Flip } else { double rejectProb = pdf1 - pdf0; if (rejectProb < 0) sampleIndex = 0; // Flip if (rand.nextDouble() < rejectProb) sampleIndex = 1; else sampleIndex = 0; // Flip } } else // For all other lengths { // Calculate cumulative conditional probability (unnormalized) double sum = 0; final double[] samplerScratch = _samplerScratch; final int previousIndex = sampleValue.getIndex(); double previousIntervalValue = 0; samplerScratch[0] = 0; for (int m = 1; m < length; m++) { final int mm1 = m - 1; final double unnormalizedValue = Math.exp(minEnergy - energy[mm1]); if (mm1 == previousIndex) previousIntervalValue = unnormalizedValue; sum += unnormalizedValue; samplerScratch[m] = sum; } final int lm1 = length - 1; final double unnormalizedValue = Math.exp(minEnergy - energy[lm1]); if (previousIndex == lm1) previousIntervalValue = unnormalizedValue; sum += unnormalizedValue; for (int m = length; m < _lengthRoundedUp; m++) samplerScratch[m] = Double.POSITIVE_INFINITY; // Sample from a range circularly shifted by the largest interval with size of the previous value interval // In this scale, the largest interval is always 1 double randomValue = samplerScratch[previousIndex] + 1 + previousIntervalValue * rand.nextDouble(); randomValue = randomValue % sum; // Circularly wrap // Sample from the CDF using a binary search final int half = _lengthRoundedUp >> 1; sampleIndex = 0; for (int bitValue = half; bitValue > 0; bitValue >>= 1) { final int testIndex = sampleIndex | bitValue; if (randomValue > samplerScratch[testIndex]) sampleIndex = testIndex; } } samplerClient.setNextSampleIndex(sampleIndex); }
From source file:mase.mason.world.DistanceSensorArcs.java
/** * Very efficient implementation using an ordered TreeMap Should ensure * scalability when large numbers of objects are present, as there is no * need to check angles with objects that are farther than the closest * object in the given cone. Potential limitation (unlikely): if there are * two objects at exactly the same distance but at different angles, only * one of them will be considered, as the distance is used as key in the * TreeMap//from w w w . j a va2 s .com */ @Override public double[] readValues() { lastDistances = new double[valueCount()]; Arrays.fill(lastDistances, Double.POSITIVE_INFINITY); Arrays.fill(closestObjects, null); if (range < 0.001) { return lastDistances; } double rangeNoiseAbs = Double.isInfinite(range) ? rangeNoise * fieldDiagonal : range * rangeNoise; WorldObject[] candidates = getCandidates(); // TODO: replace treemap with collection-sort Pair<Double, WorldObject>[] distances = new Pair[candidates.length]; int index = 0; for (WorldObject o : candidates) { if (!centerToCenter && o.isInside(ag.getLocation())) { Arrays.fill(lastDistances, 0); Arrays.fill(closestObjects, o); return lastDistances; } double dist = centerToCenter ? ag.getLocation().distance(o.getLocation()) : Math.max(0, ag.distanceTo(o)); if (rangeNoiseAbs > 0) { dist += rangeNoiseAbs * (noiseType == UNIFORM ? state.random.nextDouble() * 2 - 1 : state.random.nextGaussian()); dist = Math.max(dist, 0); } if (dist <= range) { distances[index++] = Pair.of(dist, o); } } if (index < distances.length) { distances = Arrays.copyOf(distances, index); } Arrays.sort(distances, new Comparator<Pair<Double, WorldObject>>() { @Override public int compare(Pair<Double, WorldObject> a, Pair<Double, WorldObject> b) { return Double.compare(a.getLeft(), b.getLeft()); } }); int filled = 0; for (Pair<Double, WorldObject> e : distances) { if (filled == arcStart.length) { break; } double angle = ag.angleTo(e.getRight().getLocation()); if (orientationNoise > 0) { angle += orientationNoise * (noiseType == UNIFORM ? state.random.nextDouble() * 2 - 1 : state.random.nextGaussian()); angle = EmboddiedAgent.normalizeAngle(angle); } for (int a = 0; a < arcStart.length; a++) { if (Double.isInfinite(lastDistances[a]) && ((angle >= arcStart[a] && angle <= arcEnd[a]) || (arcStart[a] > arcEnd[a] && (angle >= arcStart[a] || angle <= arcEnd[a])))) { filled++; lastDistances[a] = e.getKey(); closestObjects[a] = e.getValue(); } } } return lastDistances; }
From source file:com.opengamma.analytics.financial.credit.creditdefaultswap.pricing.vanilla.isdanew.SimpleCreditCurveBuilder.java
/** * {@inheritDoc}//ww w. j a va 2 s . co m */ @Override public ISDACompliantCreditCurve calibrateCreditCurve(final CDSAnalytic[] cds, final double[] premiums, final ISDACompliantYieldCurve yieldCurve, final double[] pointsUpfront) { ArgumentChecker.noNulls(cds, "cds"); ArgumentChecker.notEmpty(premiums, "empty fractionalSpreads"); ArgumentChecker.notNull(yieldCurve, "null yieldCurve"); final int n = cds.length; ArgumentChecker.isTrue(n == premiums.length, "Number of CDSs does not match number of spreads"); final double proStart = cds[0].getProtectionStart(); for (int i = 1; i < n; i++) { ArgumentChecker.isTrue(proStart == cds[i].getProtectionStart(), "all CDSs must has same protection start"); ArgumentChecker.isTrue(cds[i].getProtectionEnd() > cds[i - 1].getProtectionEnd(), "protection end must be ascending"); } // use continuous premiums as initial guess final double[] guess = new double[n]; final double[] t = new double[n]; for (int i = 0; i < n; i++) { guess[i] = premiums[i] / cds[i].getLGD(); t[i] = cds[i].getProtectionEnd(); } ISDACompliantCreditCurve creditCurve = new ISDACompliantCreditCurve(t, guess); for (int i = 0; i < n; i++) { final CDSPricer func = new CDSPricer(i, cds[i], premiums[i], creditCurve, yieldCurve, pointsUpfront[i]); final double[] bracket = BRACKER.getBracketedPoints(func, 0.8 * guess[i], 1.25 * guess[i], 0.0, Double.POSITIVE_INFINITY); final double zeroRate = ROOTFINDER.getRoot(func, bracket[0], bracket[1]); creditCurve = creditCurve.withRate(zeroRate, i); } return creditCurve; }
From source file:beast.math.distributions.InverseGammaDistribution.java
/** * mean of the Gamma distribution//from ww w. j a v a2 s . c om * * @param shape shape parameter * @param scale scale parameter * @return mean */ public static double mean(double shape, double scale) { if (shape > 1) { return scale / (shape - 1); } return Double.POSITIVE_INFINITY; }