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:org.jfree.data.xy.IntervalXYDelegate.java
/** * Recalculate the minimum width "from scratch". * * @return The minimum width./* w w w .ja va 2 s.co m*/ */ private double recalculateInterval() { double result = Double.POSITIVE_INFINITY; int seriesCount = this.dataset.getSeriesCount(); for (int series = 0; series < seriesCount; series++) { result = Math.min(result, calculateIntervalForSeries(series)); } return result; }
From source file:com.bigml.histogram.Histogram.java
/** * Returns a <code>SumResult</code> object which contains the * density estimate at the point <code>p</code> along * with the density for the targets.//from w w w . j a v a 2 s . c om * * @param p the density estimate point */ @SuppressWarnings("unchecked") public SumResult<T> extendedDensity(double p) { T emptyTarget = (T) _bins.first().getTarget().init(); double countDensity; T targetDensity; Bin<T> exact = _bins.get(p); if (p < _minimum || p > _maximum) { countDensity = 0; targetDensity = (T) emptyTarget.clone(); } else if (p == _minimum && p == _maximum) { countDensity = Double.POSITIVE_INFINITY; targetDensity = emptyTarget; } else if (exact != null) { double higher = Math.nextAfter(p, Double.POSITIVE_INFINITY); double lower = Math.nextAfter(p, Double.NEGATIVE_INFINITY); SumResult<T> lowerResult = extendedDensity(lower); SumResult<T> higherResult = extendedDensity(higher); countDensity = (lowerResult.getCount() + higherResult.getCount()) / 2; targetDensity = (T) lowerResult.getTargetSum().clone().sum(higherResult.getTargetSum()).mult(0.5); } else { Bin<T> lowerBin = _bins.lower(p); if (lowerBin == null) { lowerBin = new Bin<T>(_minimum, 0, (T) emptyTarget.clone()); } Bin<T> higherBin = _bins.higher(p); if (higherBin == null) { higherBin = new Bin<T>(_maximum, 0, (T) emptyTarget.clone()); } double bDiff = p - lowerBin.getMean(); double pDiff = higherBin.getMean() - lowerBin.getMean(); double bpRatio = bDiff / pDiff; NumericTarget countTarget = (NumericTarget) computeDensity(bpRatio, lowerBin.getMean(), higherBin.getMean(), new NumericTarget(lowerBin.getCount()), new NumericTarget(higherBin.getCount())); countDensity = countTarget.getSum(); targetDensity = (T) computeDensity(bpRatio, lowerBin.getMean(), higherBin.getMean(), lowerBin.getTarget(), higherBin.getTarget()); } return new SumResult<T>(countDensity, targetDensity); }
From source file:org.jax.pubarray.server.restful.GraphingResource.java
/** * Create a graph for the given configuration * @param graphConfiguration// w w w .j av a 2s . c o m * the key * @return * the graph */ @SuppressWarnings("unchecked") private JFreeChart createProbeIntensityGraph(ProbeIntensityGraphConfiguration graphConfiguration) { try { Connection connection = this.getConnection(); String[] probeIds = graphConfiguration.getProbeIds(); double[][] probeDataRows = new double[probeIds.length][]; for (int i = 0; i < probeIds.length; i++) { probeDataRows[i] = this.persistenceManager.getDataRowForProbeID(connection, probeIds[i]); } TableColumnMetadata orderBy = graphConfiguration.getOrderProbesBy(); final List<Comparable> orderByItems; if (orderBy != null) { LOG.info("We are ordering by: " + orderBy); orderByItems = this.persistenceManager.getDesignDataColumn(connection, orderBy); } else { orderByItems = null; } TableMetadata metadata = this.persistenceManager.getDataTableMetadata(connection); final CategoryDataset categoryDataset; if (graphConfiguration.getGroupReplicates()) { switch (graphConfiguration.getGroupedGraphType()) { case BOX_PLOT: { categoryDataset = new DefaultBoxAndWhiskerCategoryDataset(); } break; case SCATTER_PLOT: { categoryDataset = new DefaultMultiValueCategoryDataset(); } break; default: throw new IllegalArgumentException( "don't know how to deal with plot type: " + graphConfiguration.getGroupedGraphType()); } } else { categoryDataset = new DefaultCategoryDataset(); } // iterate through all of the selected probesets List<QualifiedColumnMetadata> termsOfInterest = Arrays.asList(graphConfiguration.getTermsOfInterest()); for (int rowIndex = 0; rowIndex < probeDataRows.length; rowIndex++) { double[] currRow = probeDataRows[rowIndex]; assert currRow.length == metadata.getColumnMetadata().length - 1; // should we log2 transform the data? if (graphConfiguration.getLog2TransformData()) { for (int i = 0; i < currRow.length; i++) { currRow[i] = Math.log(currRow[i]) / LOG2_FACTOR; } } // iterate through the columns in the data table (each column // represents a different array) List<ComparableContainer<Double, Comparable>> rowElemList = new ArrayList<ComparableContainer<Double, Comparable>>(); for (int colIndex = 0; colIndex < currRow.length; colIndex++) { // we use +1 indexing here because we want to skip over // the probesetId metadata and get right to the // array intensity metadata TableColumnMetadata colMeta = metadata.getColumnMetadata()[colIndex + 1]; // check to see if we need to skip this data if (!graphConfiguration.getIncludeDataFromAllArrays()) { // if it's one of the "terms of interest" we will keep // it. we're using a brute force search here boolean keepThisOne = false; for (QualifiedColumnMetadata termOfInterest : termsOfInterest) { if (termOfInterest.getTableName().equals(metadata.getTableName()) && termOfInterest.getName().equals(colMeta.getName())) { keepThisOne = true; break; } } if (!keepThisOne) { continue; } } final String columnName = colMeta.getName(); final Comparable columnKey; if (orderByItems == null) { columnKey = columnName; } else { // the ordering will be done on the selected // "order by" design criteria columnKey = new ComparableContainer<String, Comparable>(columnName, orderByItems.get(colIndex), !graphConfiguration.getGroupReplicates()); // TODO remove me!!!! System.out.println("For array " + columnName + " the order by " + "value is: " + orderByItems.get(colIndex)); // end of remove me } rowElemList .add(new ComparableContainer<Double, Comparable>(currRow[colIndex], columnKey, false)); } Collections.sort(rowElemList); if (graphConfiguration.getGroupReplicates()) { switch (graphConfiguration.getGroupedGraphType()) { case BOX_PLOT: { DefaultBoxAndWhiskerCategoryDataset dataset = (DefaultBoxAndWhiskerCategoryDataset) categoryDataset; for (int i = 0; i < rowElemList.size(); i++) { List<Double> groupList = new ArrayList<Double>(); groupList.add(rowElemList.get(i).getElement()); Comparable colKey = rowElemList.get(i).getComparable(); i++; for (; i < rowElemList.size() && rowElemList.get(i).getComparable().equals(colKey); i++) { groupList.add(rowElemList.get(i).getElement()); } i--; dataset.add(groupList, probeIds[rowIndex], colKey); } } break; case SCATTER_PLOT: { DefaultMultiValueCategoryDataset dataset = (DefaultMultiValueCategoryDataset) categoryDataset; for (int i = 0; i < rowElemList.size(); i++) { List<Double> groupList = new ArrayList<Double>(); groupList.add(rowElemList.get(i).getElement()); Comparable colKey = rowElemList.get(i).getComparable(); i++; for (; i < rowElemList.size() && rowElemList.get(i).getComparable().equals(colKey); i++) { groupList.add(rowElemList.get(i).getElement()); } i--; dataset.add(groupList, probeIds[rowIndex], colKey); } } break; } } else { DefaultCategoryDataset dataset = (DefaultCategoryDataset) categoryDataset; for (ComparableContainer<Double, Comparable> rowElem : rowElemList) { dataset.addValue(rowElem.getElement(), probeIds[rowIndex], rowElem.getComparable()); } } } CategoryAxis xAxis = new CategoryAxis(); if (graphConfiguration.getGroupReplicates() && orderBy != null) { xAxis.setLabel(orderBy.getName()); } else { if (orderBy != null) { xAxis.setLabel("Arrays (Ordered By " + orderBy.getName() + ")"); } else { xAxis.setLabel("Arrays"); } } xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); final NumberAxis yAxis; if (graphConfiguration.getLog2TransformData()) { yAxis = new NumberAxis("log2(Intensity)"); } else { yAxis = new NumberAxis("Intensity"); } yAxis.setAutoRange(true); yAxis.setAutoRangeIncludesZero(false); // TODO: this is a HACK to deal with auto-range bug in JFreeChart // which occurs when doing the grouped scatter plot if (graphConfiguration.getGroupReplicates() && graphConfiguration.getGroupedGraphType() == GroupedGraphType.SCATTER_PLOT) { double minVal = Double.POSITIVE_INFINITY; double maxVal = Double.NEGATIVE_INFINITY; for (double[] dataRow : probeDataRows) { for (double datum : dataRow) { if (datum > maxVal) { maxVal = datum; } if (datum < minVal) { minVal = datum; } } if (minVal != Double.POSITIVE_INFINITY && maxVal != Double.NEGATIVE_INFINITY && minVal != maxVal) { yAxis.setAutoRange(false); double margin = (maxVal - minVal) * 0.02; Range yRange = new Range(minVal - margin, maxVal + margin); yAxis.setRange(yRange); } } } // END HACK final CategoryItemRenderer renderer; if (graphConfiguration.getGroupReplicates()) { switch (graphConfiguration.getGroupedGraphType()) { case BOX_PLOT: { BoxAndWhiskerRenderer boxRenderer = new BoxAndWhiskerRenderer(); boxRenderer.setMaximumBarWidth(0.03); renderer = boxRenderer; } break; case SCATTER_PLOT: { renderer = new ScatterRenderer(); } break; default: throw new IllegalArgumentException( "don't know how to deal with plot type: " + graphConfiguration.getGroupedGraphType()); } } else { renderer = new LineAndShapeRenderer(); } Plot plot = new CategoryPlot(categoryDataset, xAxis, yAxis, renderer); return new JFreeChart("Intensity Values", plot); } catch (SQLException ex) { LOG.log(Level.SEVERE, "failed to generate image", ex); return null; } }
From source file:com.cognitect.transit.TransitMPTest.java
public void testWriteReadSpecialNumbers() throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); Writer w = TransitFactory.writer(TransitFactory.Format.MSGPACK, out); w.write(Double.NaN);// www .j a va 2 s. c o m w.write(Float.NaN); w.write(Double.POSITIVE_INFINITY); w.write(Float.POSITIVE_INFINITY); w.write(Double.NEGATIVE_INFINITY); w.write(Float.NEGATIVE_INFINITY); ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); Reader r = TransitFactory.reader(TransitFactory.Format.MSGPACK, in); assert ((Double) r.read()).isNaN(); assert ((Double) r.read()).isNaN(); assertEquals(Double.POSITIVE_INFINITY, (Double) r.read()); assertEquals(Double.POSITIVE_INFINITY, (Double) r.read()); assertEquals(Double.NEGATIVE_INFINITY, (Double) r.read()); assertEquals(Double.NEGATIVE_INFINITY, (Double) r.read()); }
From source file:afest.datastructures.tree.decision.erts.grower.AERTGrower.java
/** * Create a split on the given attribute by choosing a uniformly random threshold in [min, max). * @param <T> Type of ITrainingPoints used by the Extra Trees. * @param set set containing the points in which we choose the threshold. * @param attribute attribute to pick the threshold for. * @return a split on the given attribute by choosing a uniformly random threshold in [min, max). */// w w w .ja v a2s . co m private <T extends ITrainingPoint<R, O>> ERTSplit<R> createSplit(Collection<T> set, R attribute) { double min = Double.POSITIVE_INFINITY; double max = Double.NEGATIVE_INFINITY; for (T aT : set) { double value = aT.getValue(attribute); if (value > max) { max = value; } if (value < min) { min = value; } } if (Double.isInfinite(max)) { max = Double.MAX_VALUE; } if (Double.isInfinite(min)) { min = -Double.MAX_VALUE; } max = max - Double.MIN_VALUE; min = min + Double.MIN_VALUE; double threshold = fRandom.nextDouble() * (max - min) + min; ERTSplit<R> split = new ERTSplit<R>(attribute, threshold); return split; }
From source file:cn.pku.sei.GHRC.MySpectralClusterer.java
/** * Returns the best cut of a graph w.r.t. the degree of dissimilarity * between points of different partitions and the degree of similarity * between points of the same partition. * /*from ww w. j a v a 2 s . c o m*/ * @param W * the weight matrix of the graph * @return an array of two elements, each of these contains the points of a * partition */ protected int[][] bestCut(final DoubleMatrix2D W) { int n = W.columns(); // Builds the diagonal matrices D and D^(-1/2) (represented as their // diagonals) final DoubleMatrix1D d = DoubleFactory1D.dense.make(n); final DoubleMatrix1D d_minus_1_2 = DoubleFactory1D.dense.make(n); for (int i = 0; i < n; i++) { double d_i = W.viewRow(i).zSum(); d.set(i, d_i); d_minus_1_2.set(i, 1 / Math.sqrt(d_i)); } final DoubleMatrix2D D = DoubleFactory2D.sparse.diagonal(d); final DoubleMatrix2D X = D.copy(); // X = D^(-1/2) * (D - W) * D^(-1/2) X.assign(W, Functions.minus); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) X.set(i, j, X.get(i, j) * d_minus_1_2.get(i) * d_minus_1_2.get(j)); // Computes the eigenvalues and the eigenvectors of X final EigenvalueDecomposition e = new EigenvalueDecomposition(X); final DoubleMatrix1D lambda = e.getRealEigenvalues(); // Selects the eigenvector z_2 associated with the second smallest // eigenvalue // Creates a map that contains the pairs <index, eigevalue> final AbstractIntDoubleMap map = new OpenIntDoubleHashMap(n); for (int i = 0; i < n; i++) map.put(i, Math.abs(lambda.get(i))); final IntArrayList list = new IntArrayList(); // Sorts the map on the value map.keysSortedByValue(list); // Gets the index of the second smallest element final int i_2 = list.get(1); // y_2 = D^(-1/2) * z_2 final DoubleMatrix1D y_2 = e.getV().viewColumn(i_2).copy(); y_2.assign(d_minus_1_2, Functions.mult); // Creates a map that contains the pairs <i, y_2[i]> map.clear(); for (int i = 0; i < n; i++) map.put(i, y_2.get(i)); // Sorts the map on the value map.keysSortedByValue(list); // Search the element in the map previuosly ordered that minimizes the // cut of the partition double best_cut = Double.POSITIVE_INFINITY; final int[][] partition = new int[2][]; // The array v contains all the elements of the graph ordered by their // projection on vector y_2 final int[] c = list.elements(); // For each admissible splitting point i for (int i = 1; i < n; i++) { // The array a contains all the elements that have a projection on // vector y_2 less or equal to the one of i-th element // The array b contains the remaining elements final int[] a = new int[i]; final int[] b = new int[n - i]; System.arraycopy(c, 0, a, 0, i); System.arraycopy(c, i, b, 0, n - i); final double cut = Ncut(W, a, b, c); if (cut < best_cut) { best_cut = cut; partition[0] = a; partition[1] = b; } } return partition; }
From source file:com.rapidminer.gui.graphs.TransitionGraphCreator.java
private void updateGraph() { // remove old edges if available Iterator<String> e = edgeLabelMap.keySet().iterator(); while (e.hasNext()) { graph.removeEdge(e.next());/*w w w.j av a 2 s.c o m*/ } edgeLabelMap.clear(); edgeStrengthMap.clear(); // remove old vertices if available Iterator<String> v = vertexLabelMap.keySet().iterator(); while (v.hasNext()) { graph.removeVertex(v.next()); } vertexLabelMap.clear(); String sourceFilterName = null; if (sourceFilter.getSelectedIndex() > 0) { sourceFilterName = ((SourceId) sourceFilter.getSelectedItem()).getId(); } List<SortableEdge> sortableEdges = new LinkedList<SortableEdge>(); if (sourceFilterName == null) { for (Example example : exampleSet) { String source = example.getValueAsString(sourceAttribute); String target = example.getValueAsString(targetAttribute); double strength = 1.0d; if (strengthAttribute != null) { strength = example.getValue(strengthAttribute); } String type = null; if (typeAttribute != null) { type = example.getValueAsString(typeAttribute); } String edgeName = null; if (type != null) { edgeName = type; } else { edgeName = strength + ""; } sortableEdges .add(new SortableEdge(source, target, edgeName, strength, SortableEdge.DIRECTION_INCREASE)); } } else { List<String> sources = new LinkedList<String>(); sources.add(sourceFilterName); int hop = 1; int maxHops = (Integer) numberOfHops.getValue(); do { List<String> newSources = new LinkedList<String>(); for (String currentSourceFilterName : sources) { for (Example example : exampleSet) { String source = example.getValueAsString(sourceAttribute); if (currentSourceFilterName != null) { if (!currentSourceFilterName.equals(source)) { continue; } } String target = example.getValueAsString(targetAttribute); double strength = 1.0d; if (strengthAttribute != null) { strength = example.getValue(strengthAttribute); } String type = null; if (typeAttribute != null) { type = example.getValueAsString(typeAttribute); } String edgeName = null; if (type != null) { edgeName = type; } else { edgeName = strength + ""; } sortableEdges.add(new SortableEdge(source, target, edgeName, strength, SortableEdge.DIRECTION_INCREASE)); newSources.add(target); } } sources.clear(); hop++; if (hop > maxHops) { sources = null; } else { sources = newSources; } } while (sources != null); } Collections.sort(sortableEdges); // determine used vertices Set<String> allVertices = new HashSet<String>(); int numberOfEdges = edgeSlider.getValue(); int counter = 0; for (SortableEdge sortableEdge : sortableEdges) { if (counter > numberOfEdges) { break; } allVertices.add(sortableEdge.getFirstVertex()); allVertices.add(sortableEdge.getSecondVertex()); counter++; } // add all used vertices to graph for (String vertex : allVertices) { graph.addVertex(vertex); String description = getNodeDescription(vertex); if (description == null) { vertexLabelMap.put(vertex, vertex); } else { vertexLabelMap.put(vertex, description); } } counter = 0; double minStrength = Double.POSITIVE_INFINITY; double maxStrength = Double.NEGATIVE_INFINITY; Map<String, Double> strengthMap = new HashMap<String, Double>(); for (SortableEdge sortableEdge : sortableEdges) { if (counter > numberOfEdges) { break; } String idString = edgeFactory.create(); graph.addEdge(idString, sortableEdge.getFirstVertex(), sortableEdge.getSecondVertex(), EdgeType.DIRECTED); edgeLabelMap.put(idString, Tools.formatIntegerIfPossible(sortableEdge.getEdgeValue())); double strength = sortableEdge.getEdgeValue(); minStrength = Math.min(minStrength, strength); maxStrength = Math.max(maxStrength, strength); strengthMap.put(idString, strength); counter++; } for (Entry<String, Double> entry : strengthMap.entrySet()) { edgeStrengthMap.put(entry.getKey(), (strengthMap.get(entry.getKey()) - minStrength) / (maxStrength - minStrength)); } }
From source file:io.horizondb.model.core.fields.DecimalField.java
/** * Converts the specified decimal into a double. * /*from www.j av a2s . c o m*/ * @param mantissa the decimal mantissa * @param exponent the decimal exponent * @return the double corresponding to the specified decimal */ private static double toDouble(long mantissa, int exponent) { if (isNaN(mantissa, exponent)) { return Double.NaN; } if (isPositiveInfinity(mantissa, exponent)) { return Double.POSITIVE_INFINITY; } if (isNegativeInfinity(mantissa, exponent)) { return Double.NEGATIVE_INFINITY; } if (exponent > 0) { return mantissa * pow10(exponent); } return mantissa / pow10(-exponent); }
From source file:info.debatty.java.datasets.sift.Matrix.java
public static double min(final double[] A) { double minval = Double.POSITIVE_INFINITY; for (double val : A) { if (val < minval) { minval = val; }/*from www .j a va 2 s. c o m*/ } return minval; }
From source file:org.jfree.data.xy.IntervalXYDelegate.java
/** * Calculates the interval width for a given series. * * @param series the series index./*from ww w. ja va 2s . c om*/ * * @return The interval width. */ private double calculateIntervalForSeries(int series) { double result = Double.POSITIVE_INFINITY; int itemCount = this.dataset.getItemCount(series); if (itemCount > 1) { double prev = this.dataset.getXValue(series, 0); for (int item = 1; item < itemCount; item++) { double x = this.dataset.getXValue(series, item); result = Math.min(result, x - prev); prev = x; } } return result; }