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:gedi.riboseq.inference.codon.ReadsXCodonMatrix.java
public double regularize2(Codon codon) { double deltaLL = 0; HashMap<Read, double[]> rs = M.get(codon); for (Read r : rs.keySet()) { double[] d = rs.get(r); if (d[1] == 0) continue; // try to redistribute d[1] to other codons HashMap<Codon, double[]> cs = I.get(r); double s = 0; for (Codon c : cs.keySet()) { double[] d2 = cs.get(c); if (d2 != d) s += d2[1];/*from w ww . j a va 2 s. c om*/ } if (s == 0) return Double.NEGATIVE_INFINITY; double beforesum = 0; double aftersum = 0; for (Codon c : cs.keySet()) { double[] d2 = cs.get(c); beforesum += c.totalActivity * d2[0]; if (d2 != d) { aftersum += (c.totalActivity + d[1] * d2[1] / s) * d2[0]; d2[1] += d[1] * d2[1] / s; } } deltaLL += Math.log(aftersum) - Math.log(beforesum); d[1] = 0; } // int deltaparam = -rs.keySet().size(); // return 2*deltaparam-2*deltaLL; // == AIC_after - AIC_before, i.e. regularization is successful if this is negative return deltaLL; }
From source file:org.jfree.data.time.TimeSeries.java
/** * Finds the range of y-values that fall within the specified range of * x-values (where the x-values are interpreted as milliseconds since the * epoch and converted to time periods using the specified timezone). * //w ww.ja v a2s. com * @param xRange the subset of x-values to use (<code>null</code> not * permitted). * @param xAnchor the anchor point for the x-values (<code>null</code> * not permitted). * @param zone the time zone (<code>null</code> not permitted). * * @return The range of y-values. * * @since 1.0.18 */ public Range findValueRange(Range xRange, TimePeriodAnchor xAnchor, TimeZone zone) { ParamChecks.nullNotPermitted(xRange, "xRange"); ParamChecks.nullNotPermitted(xAnchor, "xAnchor"); ParamChecks.nullNotPermitted(zone, "zone"); if (this.data.isEmpty()) { return null; } Calendar calendar = Calendar.getInstance(zone); // since the items are ordered, we could be more clever here and avoid // iterating over all the data double lowY = Double.POSITIVE_INFINITY; double highY = Double.NEGATIVE_INFINITY; for (int i = 0; i < this.data.size(); i++) { TimeSeriesDataItem item = (TimeSeriesDataItem) this.data.get(i); long millis = item.getPeriod().getMillisecond(xAnchor, calendar); if (xRange.contains(millis)) { Number n = item.getValue(); if (n != null) { double v = n.doubleValue(); lowY = Math.min(lowY, v); highY = Math.max(highY, v); } } } if (Double.isInfinite(lowY) && Double.isInfinite(highY)) { if (lowY < highY) { return new Range(lowY, highY); } else { return new Range(Double.NaN, Double.NaN); } } return new Range(lowY, highY); }
From source file:ddf.catalog.source.opensearch.OpenSearchSiteUtil.java
/** * Takes in an array of coordinates and converts it to a (rough approximation) bounding box. * <p/>/*from w w w . j av a 2 s. com*/ * Note: Searches being performed where the polygon goes through the international date line may * return a bad bounding box. * * @param polyAry array of coordinates (lon,lat,lon,lat,lon,lat..etc) * @return Array of bounding box coordinates in the following order: West South East North. Also * described as minX, minY, maxX, maxY (where longitude is the X-axis, and latitude is * the Y-axis). */ public static double[] createBBoxFromPolygon(String[] polyAry) { double minX = Double.POSITIVE_INFINITY; double minY = Double.POSITIVE_INFINITY; double maxX = Double.NEGATIVE_INFINITY; double maxY = Double.NEGATIVE_INFINITY; double curX, curY; for (int i = 0; i < polyAry.length - 1; i += 2) { LOGGER.debug("polyToBBox: lon - {} lat - {}", polyAry[i], polyAry[i + 1]); curX = Double.parseDouble(polyAry[i]); curY = Double.parseDouble(polyAry[i + 1]); if (curX < minX) { minX = curX; } if (curX > maxX) { maxX = curX; } if (curY < minY) { minY = curY; } if (curY > maxY) { maxY = curY; } } return new double[] { minX, minY, maxX, maxY }; }
From source file:com.cognitect.transit.TransitTest.java
public void testSpecialNumbers() throws Exception { assertEquals(scalar("\"~zNaN\""), writeJson(Double.NaN)); assertEquals(scalar("\"~zINF\""), writeJson(Double.POSITIVE_INFINITY)); assertEquals(scalar("\"~z-INF\""), writeJson(Double.NEGATIVE_INFINITY)); assertEquals(scalar("\"~zNaN\""), writeJson(Float.NaN)); assertEquals(scalar("\"~zINF\""), writeJson(Float.POSITIVE_INFINITY)); assertEquals(scalar("\"~z-INF\""), writeJson(Float.NEGATIVE_INFINITY)); assertEquals(scalarVerbose("\"~zNaN\""), writeJsonVerbose(Double.NaN)); assertEquals(scalarVerbose("\"~zINF\""), writeJsonVerbose(Double.POSITIVE_INFINITY)); assertEquals(scalarVerbose("\"~z-INF\""), writeJsonVerbose(Double.NEGATIVE_INFINITY)); assertEquals(scalarVerbose("\"~zNaN\""), writeJsonVerbose(Float.NaN)); assertEquals(scalarVerbose("\"~zINF\""), writeJsonVerbose(Float.POSITIVE_INFINITY)); assertEquals(scalarVerbose("\"~z-INF\""), writeJsonVerbose(Float.NEGATIVE_INFINITY)); }
From source file:afest.datastructures.tree.decision.erts.grower.AERTGrower.java
/** * Return the best split according to the scoring function used by the ERTGrower. * @param <T> Type of ITrainingPoints used by the Extra Trees. * @param set set of points to compute the score with. * @param splits set of splits to compute the score for. * @return the best split according to the scoring function used by the ERTGrower. */// w ww.j a va 2s.co m private <T extends ITrainingPoint<R, O>> ERTSplit<R> getBestSplit(Collection<T> set, ArrayList<ERTSplit<R>> splits) { double maxScore = Double.NEGATIVE_INFINITY; ERTSplit<R> bestSplit = null; for (ERTSplit<R> split : splits) { double score = fScore.getScore(set, split); if (score > maxScore || bestSplit == null) { maxScore = score; bestSplit = split; } } return bestSplit; }
From source file:edu.harvard.iq.dataverse.dataaccess.TabularSubsetGenerator.java
public static Double[] subsetDoubleVector(InputStream in, int column, int numCases) { Double[] retVector = new Double[numCases]; Scanner scanner = new Scanner(in); scanner.useDelimiter("\\n"); for (int caseIndex = 0; caseIndex < numCases; caseIndex++) { if (scanner.hasNext()) { String[] line = (scanner.next()).split("\t", -1); // Verified: new Double("nan") works correctly, // resulting in Double.NaN; // Double("[+-]Inf") doesn't work however; // (the constructor appears to be expecting it // to be spelled as "Infinity", "-Infinity", etc. if ("inf".equalsIgnoreCase(line[column]) || "+inf".equalsIgnoreCase(line[column])) { retVector[caseIndex] = java.lang.Double.POSITIVE_INFINITY; } else if ("-inf".equalsIgnoreCase(line[column])) { retVector[caseIndex] = java.lang.Double.NEGATIVE_INFINITY; } else if (line[column] == null || line[column].equals("")) { // missing value: retVector[caseIndex] = null; } else { try { retVector[caseIndex] = new Double(line[column]); } catch (NumberFormatException ex) { retVector[caseIndex] = null; // missing value }/* ww w. j a v a2 s. c o m*/ } } else { scanner.close(); throw new RuntimeException("Tab file has fewer rows than the stored number of cases!"); } } int tailIndex = numCases; while (scanner.hasNext()) { String nextLine = scanner.next(); if (!"".equals(nextLine)) { scanner.close(); throw new RuntimeException( "Column " + column + ": tab file has more nonempty rows than the stored number of cases (" + numCases + ")! current index: " + tailIndex + ", line: " + nextLine); } tailIndex++; } scanner.close(); return retVector; }
From source file:edu.cmu.tetrad.search.Lofs2.java
private void ruleR1(Graph skeleton, Graph graph, List<Node> nodes) { List<DataSet> centeredData = DataUtils.center(this.dataSets); setDataSets(centeredData);//from w w w. ja v a2 s . c om for (Node node : nodes) { SortedMap<Double, String> scoreReports = new TreeMap<Double, String>(); List<Node> adj = new ArrayList<Node>(); for (Node _node : skeleton.getAdjacentNodes(node)) { if (knowledge.isForbidden(_node.getName(), node.getName())) { continue; } adj.add(_node); } DepthChoiceGenerator gen = new DepthChoiceGenerator(adj.size(), adj.size()); int[] choice; double maxScore = Double.NEGATIVE_INFINITY; List<Node> parents = null; while ((choice = gen.next()) != null) { List<Node> _parents = GraphUtils.asList(choice, adj); double score = score(node, _parents); scoreReports.put(-score, _parents.toString()); if (score > maxScore) { maxScore = score; parents = _parents; } } double p = pValue(node, parents); if (p > alpha) { continue; } for (double score : scoreReports.keySet()) { TetradLogger.getInstance().log("score", "For " + node + " parents = " + scoreReports.get(score) + " score = " + -score); } TetradLogger.getInstance().log("score", ""); if (parents == null) { continue; } for (Node _node : adj) { if (parents.contains(_node)) { Edge parentEdge = Edges.directedEdge(_node, node); if (!graph.containsEdge(parentEdge)) { graph.addEdge(parentEdge); } } } } for (Edge edge : skeleton.getEdges()) { if (!graph.isAdjacentTo(edge.getNode1(), edge.getNode2())) { graph.addUndirectedEdge(edge.getNode1(), edge.getNode2()); } } }
From source file:beast.evolution.tree.ConstrainedClusterTree.java
/** go through MRCAPriors * Since we can easily scale a clade, start with the highest MRCAPrior, then process the nested ones * @throws MathException **///ww w .j a va 2 s . c o m static public void handlebounds(Node node, Map<Node, MRCAPrior> nodeToBoundMap, double EPSILON) throws MathException { if (!node.isLeaf()) { if (nodeToBoundMap.containsKey(node)) { MRCAPrior calibration = nodeToBoundMap.get(node); if (calibration.distInput.get() != null) { ParametricDistribution distr = calibration.distInput.get(); distr.initAndValidate(); double lower = distr.inverseCumulativeProbability(0.0) + distr.offsetInput.get(); double upper = distr.inverseCumulativeProbability(1.0) + distr.offsetInput.get(); // make sure the timing fits the constraint double height = node.getHeight(); double newHeight = Double.NEGATIVE_INFINITY; if (height < lower) { if (Double.isFinite(upper)) { newHeight = (lower + upper) / 2.0; } else { newHeight = lower; } } if (height > upper) { if (Double.isFinite(lower)) { newHeight = (lower + upper) / 2.0; } else { newHeight = upper; } } if (Double.isFinite(newHeight)) { double scale = newHeight / height; // scale clade node.scale(scale); // adjust parents if necessary Node node2 = node; Node parent = node2.getParent(); while (parent != null && parent.getHeight() < node2.getHeight()) { parent.setHeight(node2.getHeight() + EPSILON); node2 = node2.getParent(); parent = node2.getParent(); } } } } for (Node child : node.getChildren()) { handlebounds(child, nodeToBoundMap, EPSILON); } } }
From source file:fxts.stations.core.TradeDesk.java
/** * This method is used to format double values with pips precision * (price, rate, interest etc) to string representation * that will be shown in tables, dialogs and other UI controls. * * @param aCurrency currency pair/* w w w . j a v a2 s .c o m*/ * @param aPrice price to format * * @return formatted string of adPrice according to asCurrency */ public static String formatPrice(String aCurrency, double aPrice) { if (aCurrency == null) { return null; } try { TradingSessionStatus sessionStatus = TradingServerSession.getInstance().getTradingSessionStatus(); TradingSecurity security = sessionStatus.getSecurity(aCurrency); int precision = security.getFXCMSymPrecision(); return PRICE_FORMATS.get(precision).format(aPrice); } catch (Exception e) { //checks for infinity if (aPrice == Double.POSITIVE_INFINITY || aPrice == Double.NEGATIVE_INFINITY) { return "Infinity"; } if (isCurrencyInThePair("JPY", aCurrency)) { return PRICE_FORMATS.get(3).format(aPrice); } else { return PRICE_FORMATS.get(5).format(aPrice); } } }
From source file:gdsc.core.ij.Utils.java
/** * Calculate a histogram given the provided data * /* w w w .j a v a2 s . c o m*/ * @param data * @param numBins * The number of histogram bins between min and max * @return The histogram as a pair of arrays: { value[], frequency[] } */ public static double[][] calcHistogram(double[] data, int numBins) { double min = Double.POSITIVE_INFINITY; double max = Double.NEGATIVE_INFINITY; for (double f : data) { if (min > f) min = f; if (max < f) max = f; } return calcHistogram(data, min, max, numBins); }