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.RangeTest.java
/** * Tests the constrain() method for various values. *//*from w ww . j ava 2s. c om*/ @Test public void testConstrain() { Range r1 = new Range(0.0, 1.0); double d = r1.constrain(0.5); assertEquals(0.5, d, 0.0000001); d = r1.constrain(0.0); assertEquals(0.0, d, 0.0000001); d = r1.constrain(1.0); assertEquals(1.0, d, 0.0000001); d = r1.constrain(-1.0); assertEquals(0.0, d, 0.0000001); d = r1.constrain(2.0); assertEquals(1.0, d, 0.0000001); d = r1.constrain(Double.POSITIVE_INFINITY); assertEquals(1.0, d, 0.0000001); d = r1.constrain(Double.NEGATIVE_INFINITY); assertEquals(0.0, d, 0.0000001); d = r1.constrain(Double.NaN); assertTrue(Double.isNaN(d)); }
From source file:ch.epfl.leb.sass.models.fluorophores.commands.internal.FluorophoreReceiverIT.java
/** * Test of generateFluorophoresRandom2D method, of class FluorophoreReceiver. *///from w ww .j av a 2 s. c o m @Test public void testGenerateFluorophoresRandom2D() { GenerateFluorophoresRandom2D.Builder fluorBuilder = new GenerateFluorophoresRandom2D.Builder(); fluorBuilder.numFluors(25); // Number of fluorophores // Create the set of fluorophores. fluorBuilder.camera(camera).psfBuilder(psfBuilder).fluorDynamics(fluorDynamics).illumination(illumination); FluorophoreCommand fluorCommand = fluorBuilder.build(); List<Fluorophore> fluorophores = fluorCommand.generateFluorophores(); assertEquals(25, fluorophores.size()); double minX = Double.POSITIVE_INFINITY; double maxX = Double.NEGATIVE_INFINITY; double minY = Double.POSITIVE_INFINITY; double maxY = Double.NEGATIVE_INFINITY; for (Fluorophore f : fluorophores) { if (f.getX() < minX) minX = f.getX(); if (f.getX() > maxX) maxX = f.getX(); if (f.getY() < minY) minY = f.getY(); if (f.getY() > maxY) maxY = f.getY(); } assertTrue(maxX <= 32); assertTrue(minX >= 0.0); assertTrue(maxY <= 32); assertTrue(minY >= 0.0); }
From source file:com.rapidminer.gui.plotter.RangeablePlotterAdapter.java
@Override public List<ParameterType> getAdditionalParameterKeys(InputPort inputPort) { List<ParameterType> types = super.getAdditionalParameterKeys(inputPort); boolean inputDeliversAttributes = false; if (inputPort != null) { MetaData metaData = inputPort.getMetaData(); if (metaData != null && (metaData instanceof ExampleSetMetaData || metaData instanceof ModelMetaData)) { inputDeliversAttributes = true; }//w w w . ja va 2s.co m } if (inputDeliversAttributes) { types.add(new ParameterTypeList(PARAMETER_PREFIX_RANGE_LIST, "Defines the ranges for the given attribute", new ParameterTypeAttribute(PARAMETER_DIMENSION_NAME, "This is the name of the dimension, the range should be applied onto.", inputPort), new ParameterTypeTupel(PARAMETER_PREFIX_RANGE, "Defines the range of the corresponding axis.", new ParameterTypeDouble(PARAMETER_PREFIX_RANGE_MIN, "Defines the lower bound of the axis.", Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY), new ParameterTypeDouble(PARAMETER_PREFIX_RANGE_MAX, "Defines the upper bound of the axis.", Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY)))); } else { types.add(new ParameterTypeList(PARAMETER_PREFIX_RANGE_LIST, "Defines the ranges for the given attribute", new ParameterTypeString(PARAMETER_DIMENSION_NAME, "This is the name of the dimension, the range should be applied onto."), new ParameterTypeTupel(PARAMETER_PREFIX_RANGE, "Defines the range of the corresponding axis.", new ParameterTypeDouble(PARAMETER_PREFIX_RANGE_MIN, "Defines the lower bound of the axis.", Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY), new ParameterTypeDouble(PARAMETER_PREFIX_RANGE_MAX, "Defines the upper bound of the axis.", Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY)))); } return types; }
From source file:visualizer.graph.scalar.DistanceScalar.java
public Scalar scalarFromDistanceMarix(String filename, Vertex vertex) throws IOException { DistanceMatrix dmat = new DistanceMatrix(filename); List<String> filenames = dmat.getIds(); //defining the index int index = -1; for (int i = 0; i < filenames.size(); i++) { if (filenames.get(i).equals(vertex.getUrl())) { index = i;/*w w w . ja v a2s . com*/ break; } } if (index == -1) { throw new IOException("Query data instance not found on the points file."); } //creating the scalar values double[] scalar = new double[dmat.getElementCount()]; double min = Double.POSITIVE_INFINITY; for (int i = 0; i < dmat.getElementCount(); i++) { scalar[i] = dmat.getDistance(i, index); if (min > scalar[i] && i != index) { min = scalar[i]; } } scalar[index] = min; return this.createScalar(scalar, filenames, vertex); }
From source file:Tsne.java
/** * Convert data to probability/* ww w. ja v a2 s . c o m*/ * co-occurrences (aka calculating the kernel) * @param d the data to convert * @param u the perplexity of the model * @return the probabilities of co-occurrence */ public INDArray computeGaussianPerplexity(final INDArray d, double u) { int n = d.rows(); final INDArray p = zeros(n, n); final INDArray beta = ones(n, 1); final double logU = Math.log(u); log.info("Calculating probabilities of data similarities.."); for (int i = 0; i < n; i++) { if (i % 500 == 0 && i > 0) log.info("Handled " + i + " records"); double betaMin = Double.NEGATIVE_INFINITY; double betaMax = Double.POSITIVE_INFINITY; NDArrayIndex[] range = new NDArrayIndex[] { NDArrayIndex.concat(NDArrayIndex.interval(0, i), NDArrayIndex.interval(i + 1, d.columns())) }; INDArray row = d.slice(i).get(range); Pair<INDArray, INDArray> pair = hBeta(row, beta.getDouble(i)); INDArray hDiff = pair.getFirst().sub(logU); int tries = 0; //while hdiff > tolerance while (BooleanIndexing.and(abs(hDiff), Conditions.greaterThan(tolerance)) && tries < 50) { //if hdiff > 0 if (BooleanIndexing.and(hDiff, Conditions.greaterThan(0))) { if (Double.isInfinite(betaMax)) beta.putScalar(i, beta.getDouble(i) * 2.0); else beta.putScalar(i, (beta.getDouble(i) + betaMax) / 2.0); betaMin = beta.getDouble(i); } else { if (Double.isInfinite(betaMin)) beta.putScalar(i, beta.getDouble(i) / 2.0); else beta.putScalar(i, (beta.getDouble(i) + betaMin) / 2.0); betaMax = beta.getDouble(i); } pair = hBeta(row, beta.getDouble(i)); hDiff = pair.getFirst().subi(logU); tries++; } p.slice(i).put(range, pair.getSecond()); } //dont need data in memory after log.info("Mean value of sigma " + sqrt(beta.rdiv(1)).mean(Integer.MAX_VALUE)); BooleanIndexing.applyWhere(p, Conditions.isNan(), new Value(realMin)); //set 0 along the diagonal INDArray permute = p.transpose(); INDArray pOut = p.add(permute); pOut.divi(pOut.sum(Integer.MAX_VALUE)); BooleanIndexing.applyWhere(pOut, Conditions.lessThan(Nd4j.EPS_THRESHOLD), new Value(Nd4j.EPS_THRESHOLD)); //ensure no nans return pOut; }
From source file:org.matsim.pt.analysis.RouteTimeDiagram.java
public void createGraph(final String filename, final TransitRoute route) { HashMap<Id, Integer> stopIndex = new HashMap<Id, Integer>(); int idx = 0;//w ww .jav a 2 s. c o m for (TransitRouteStop stop : route.getStops()) { stopIndex.put(stop.getStopFacility().getId(), idx); idx++; } HashSet<Id> vehicles = new HashSet<Id>(); for (Departure dep : route.getDepartures().values()) { vehicles.add(dep.getVehicleId()); } XYSeriesCollection dataset = new XYSeriesCollection(); int numSeries = 0; double earliestTime = Double.POSITIVE_INFINITY; double latestTime = Double.NEGATIVE_INFINITY; for (Map.Entry<Id, List<Tuple<Id, Double>>> entry : this.positions.entrySet()) { if (vehicles.contains(entry.getKey())) { XYSeries series = new XYSeries("t", false, true); for (Tuple<Id, Double> pos : entry.getValue()) { Integer stopIdx = stopIndex.get(pos.getFirst()); if (stopIdx != null) { double time = pos.getSecond().doubleValue(); series.add(stopIdx.intValue(), time); if (time < earliestTime) { earliestTime = time; } if (time > latestTime) { latestTime = time; } } } dataset.addSeries(series); numSeries++; } } JFreeChart c = ChartFactory.createXYLineChart("Route-Time Diagram, Route = " + route.getId(), "stops", "time", dataset, PlotOrientation.VERTICAL, false, // legend? false, // tooltips? false // URLs? ); c.setBackgroundPaint(new Color(1.0f, 1.0f, 1.0f, 1.0f)); XYPlot p = (XYPlot) c.getPlot(); p.getRangeAxis().setInverted(true); p.getRangeAxis().setRange(earliestTime, latestTime); XYItemRenderer renderer = p.getRenderer(); for (int i = 0; i < numSeries; i++) { renderer.setSeriesPaint(i, Color.black); } try { ChartUtilities.saveChartAsPNG(new File(filename), c, 1024, 768, null, true, 9); } catch (IOException e) { e.printStackTrace(); } }
From source file:lu.lippmann.cdb.ext.hydviga.data.StationsDataProvider.java
public String findNearestStation(final String stationName, final Collection<String> attrNames) { if (getCoordinates(stationName) == null) { throw new IllegalArgumentException(stationName + " not in coordinates map!"); }// w w w . j av a 2 s .c om final double[] coords = this.coordinatesMap.get(stationName); double mindist = Double.POSITIVE_INFINITY; String nearestStation = null; for (final String k : attrNames) { if (k.equals(stationName)) continue; if (!this.coordinatesMap.containsKey(k)) throw new IllegalStateException(k + " not in coordinates map!"); final double dist = MathsUtil.distance(coords, this.coordinatesMap.get(k)); if (dist < 0000.1d) continue; if (dist < mindist) { mindist = dist; nearestStation = k; } } return nearestStation; }
From source file:org.gvsig.symbology.fmap.symbols.BarChart3DSymbol.java
protected Plot getOutlinePlot() { outlinePlot = null; // <- delete this if (outlinePlot == null) { CategoryPlot myOutlinePlot;/*from w ww . jav a 2 s. c o m*/ DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.addValue(23D, "Series 1", "London"); // dataset.addValue(14D, "Series 1", "New York"); // dataset.addValue(14D, "Series 1", "Istanbul"); // dataset.addValue(14D, "Series 1", "Cairo"); dataset.addValue(13D, "Series 2", "London"); // dataset.addValue(19D, "Series 2", "New York"); // dataset.addValue(19D, "Series 2", "Istanbul"); // dataset.addValue(19D, "Series 2", "Cairo"); dataset.addValue(7D, "Series 3", "London"); // dataset.addValue(9D, "Series 3", "New York"); // dataset.addValue(9D, "Series 3", "Istanbul"); // dataset.addValue(9D, "Series 3", "Cairo"); CategoryAxis categoryAxis = new CategoryAxis3D(categoryAxisLabel); ValueAxis valueAxis = new NumberAxis3D(valueAxisLabel); BarRenderer3D renderer = new BarRenderer3D(); myOutlinePlot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer); double min = Double.POSITIVE_INFINITY; double max = Double.NEGATIVE_INFINITY; // for (int i = 0; values != null && i < values.length; i++) { // min = Math.min(min, values[i]); // max = Math.min(max, values[i]); // dataset.addValue(values[i], rowKeys[i], columnKeys[i]); // } myOutlinePlot.setDataset(dataset); myOutlinePlot.setOrientation(vertical ? PlotOrientation.VERTICAL : PlotOrientation.HORIZONTAL); outlinePlot = myOutlinePlot; } return outlinePlot; }
From source file:com.analog.lyric.dimple.solvers.core.parameterizedMessages.MultivariateNormalParameters.java
/** * Multivariate normal with specified number of dimensions, zero mean, and infinite covariance. * @param dimensions a positive number//from ww w.j a v a2 s. com * @since 0.08 */ public MultivariateNormalParameters(int dimensions) { this(new double[dimensions], arrayOf(dimensions, Double.POSITIVE_INFINITY)); }
From source file:com.cloudera.oryx.kmeans.computation.cluster.KSketchIndex.java
public Distance getDistance(RealVector vec, int id, boolean approx) { double distance = Double.POSITIVE_INFINITY; int closestPoint = -1; if (approx) { if (updated) { rebuildIndices();//from w ww . j a v a2 s.c o m } BitSet q = index(vec); List<BitSet> index = indices.get(id); SortedSet<Idx> lookup = Sets.newTreeSet(); for (int j = 0; j < index.size(); j++) { Idx idx = new Idx(hammingDistance(q, index.get(j)), j); if (lookup.size() < projectionSamples) { lookup.add(idx); } else if (idx.compareTo(lookup.last()) < 0) { lookup.add(idx); lookup.remove(lookup.last()); } } List<RealVector> p = points.get(id); List<Double> lsq = lengthSquared.get(id); for (Idx idx : lookup) { double lenSq = lsq.get(idx.getIndex()); double length = vec.getNorm(); double d = length * length + lenSq - 2 * vec.dotProduct(p.get(idx.getIndex())); if (d < distance) { distance = d; closestPoint = idx.getIndex(); } } } else { // More expensive exact computation List<RealVector> px = points.get(id); List<Double> lsq = lengthSquared.get(id); for (int j = 0; j < px.size(); j++) { RealVector p = px.get(j); double lenSq = lsq.get(j); double length = vec.getNorm(); double d = length * length + lenSq - 2 * vec.dotProduct(p); if (d < distance) { distance = d; closestPoint = j; } } } return new Distance(distance, closestPoint); }