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.sf.eventgraphj.analysis.InverseDistanceCentralityScorer.java
/** * Calculates the score for the specified vertex. Returns {@code null} if * there are missing distances and such are not ignored by this instance. *//* www . jav a2 s. c o m*/ @Override public Double getVertexScore(V v) { Double value = this.output.get(v); if (value != null) { if (value < 0) { return null; } return value; } Map<V, Number> v_distances = new HashMap<V, Number>(this.distance.getDistanceMap(v)); if (this.ignore_self_distances) { v_distances.remove(v); } // if we don't ignore missing distances and there aren't enough // distances, output null (shortcut) if (!this.ignore_missing) { int num_dests = this.graph.getVertexCount() - (this.ignore_self_distances ? 1 : 0); if (v_distances.size() != num_dests) { this.output.put(v, -1.0); return null; } } Double sum = 0.0; int count = 0; for (V w : this.graph.getVertices()) { if (w.equals(v) && this.ignore_self_distances) { continue; } Number w_distance = v_distances.get(w); if (w_distance == null) { if (this.ignore_missing) { w_distance = Double.POSITIVE_INFINITY;// graph.getVertexCount(); } else { this.output.put(v, -1.0); return null; } } sum += 1 / w_distance.doubleValue(); count++; } value = sum; if (this.averaging && count > 0) { value /= count; } this.output.put(v, value); if (Double.isNaN(value)) { System.err.println(value); } // assert (!Double.isNaN(value)); return value; }
From source file:org.jfree.data.xy.IntervalXYDelegate.java
/** * Creates a new delegate for the specified dataset. * * @param dataset the underlying dataset (<code>null</code> not permitted). * @param autoWidth a flag that controls whether the interval width is * calculated automatically. *///from w ww . ja v a2s. c o m public IntervalXYDelegate(XYDataset dataset, boolean autoWidth) { ParamChecks.nullNotPermitted(dataset, "dataset"); this.dataset = dataset; this.autoWidth = autoWidth; this.intervalPositionFactor = 0.5; this.autoIntervalWidth = Double.POSITIVE_INFINITY; this.fixedIntervalWidth = 1.0; }
From source file:net.myrrix.online.eval.ParameterOptimizer.java
/** * @return a {@link Map} between the values of the given {@link System} properties and the best value found * during search//from ww w .j av a2 s . c om * @throws ExecutionException if an error occurs while calling {@code evaluator}; the cause is the * underlying exception */ public Map<String, Number> findGoodParameterValues() throws ExecutionException { int numProperties = parameterRanges.size(); String[] propertyNames = new String[numProperties]; Number[][] parameterValuesToTry = new Number[numProperties][]; int index = 0; for (Map.Entry<String, ParameterRange> entry : parameterRanges.entrySet()) { propertyNames[index] = entry.getKey(); parameterValuesToTry[index] = entry.getValue().buildSteps(numSteps); index++; } int numTests = 1; for (Number[] toTry : parameterValuesToTry) { numTests *= toTry.length; } List<Pair<Double, String>> testResultLinesByValue = Lists.newArrayListWithCapacity(numTests); Map<String, Number> bestParameterValues = Maps.newHashMap(); double bestValue = minimize ? Double.POSITIVE_INFINITY : Double.NEGATIVE_INFINITY; for (int test = 0; test < numTests; test++) { StringBuilder testResultLine = new StringBuilder(); for (int prop = 0; prop < numProperties; prop++) { String property = propertyNames[prop]; Number parameterValue = getParameterValueToTry(parameterValuesToTry, test, prop); String propertyString = parameterValue.toString(); log.info("Setting {}={}", property, propertyString); System.setProperty(property, propertyString); testResultLine.append('[').append(property).append('=').append(propertyString).append("] "); } Number evaluatorResult; try { evaluatorResult = evaluator.call(); } catch (Exception e) { throw new ExecutionException(e); } if (evaluatorResult == null) { continue; } double testValue = evaluatorResult.doubleValue(); testResultLine.append("= ").append(testValue); testResultLinesByValue.add(new Pair<Double, String>(testValue, testResultLine.toString())); log.info("{}", testResultLine); if (minimize ? testValue < bestValue : testValue > bestValue) { log.info("New best value {}", testValue); bestValue = testValue; for (int prop = 0; prop < numProperties; prop++) { String property = propertyNames[prop]; Number parameterValue = getParameterValueToTry(parameterValuesToTry, test, prop); bestParameterValues.put(property, parameterValue); } } Collections.sort(testResultLinesByValue, new Comparator<Pair<Double, String>>() { @Override public int compare(Pair<Double, String> a, Pair<Double, String> b) { if (a.getFirst() > b.getFirst()) { return -1; } if (a.getFirst() < b.getFirst()) { return 1; } return 0; } }); for (Pair<Double, String> result : testResultLinesByValue) { log.info("{}", result.getSecond()); } log.info("Best parameter values so far are {}", bestParameterValues); } log.info("Final best parameter values are {}", bestParameterValues); return bestParameterValues; }
From source file:com.wwidesigner.modelling.PlotPlayingRanges.java
/** * Collect the data necessary to graph the predicted tuning for an instrument. * Following this call, use plotGraph() to display the graph. * @param calculator - an impedance calculator for the instrument * @param target - target tuning//from w ww.j av a 2 s . c o m * @param predicted - predicted tuning from the specified calculator, * for each note in target tuning. */ public void buildGraph(InstrumentCalculator calculator, Tuning target, Tuning predicted) { if (mName == null) { if (calculator.instrument.getName() != null) { mName = calculator.instrument.getName(); } else { mName = "Instrument"; } } chart = new Chart(); chart.setTitle("Impedance Pattern"); chart.setAutoRanging(true); chart.getXAxis().setLabel("Frequency"); chart.getYAxis().setLabel(Y_VALUE_NAME); // Legend legend = new Legend(chart); // chart.addDrawable(legend); // legend.setLocation(200, 50); int idx; // Index into notes of target and predicted. // Find bounds of graph quantities. double lowestF = Double.POSITIVE_INFINITY; // Frequency of lowest target note. Fingering predFingering; // Predicted fingering at index idx. Note tgt; // Target note at index idx. Note pred; // Predicted note at index idx. double f; // Frequency. Double frequencyMax; // Maximum frequency in current playing range. Double frequencyMin; // Minimum frequency in current playing range. double y; // y (vertical axis) value at a particular frequency. double minY = 0.0; // Minimum y value. double maxY = 0.0; // Maximum y value. for (idx = 0; idx < target.getFingering().size(); idx++) { tgt = target.getFingering().get(idx).getNote(); predFingering = predicted.getFingering().get(idx); pred = predFingering.getNote(); if (tgt.getFrequency() != null && tgt.getFrequency() < lowestF) { lowestF = tgt.getFrequency(); } if (useActuals && tgt.getFrequencyMax() != null) { frequencyMax = tgt.getFrequencyMax(); } else { frequencyMax = pred.getFrequencyMax(); } if (useActuals && tgt.getFrequencyMin() != null) { frequencyMin = tgt.getFrequencyMin(); } else { frequencyMin = pred.getFrequencyMin(); } if (frequencyMin != null) { y = yValue(calculator, frequencyMin, predFingering); if (y < minY) { minY = y; } if (y > maxY) { maxY = y; } } if (frequencyMax != null) { y = yValue(calculator, frequencyMax, predFingering); if (y < minY) { minY = y; } if (y > maxY) { maxY = y; } } } if (maxY > minY) { // Add a 10% margin outside of the bounds found. double range = maxY - minY; maxY += 0.10 * range; minY -= 0.10 * range; } ChartStyle styleTarget = new ChartStyle(darkGreen, PointShape.DISC, 7); ChartStyle styleTargetOver = new ChartStyle(Color.red, PointShape.UP_TRIANGLE, 9); ChartStyle styleTargetHigh = new ChartStyle(darkYellow, PointShape.UP_TRIANGLE, 9); ChartStyle styleTargetLow = new ChartStyle(darkYellow, PointShape.DOWN_TRIANGLE, 9); ChartStyle styleTargetUnder = new ChartStyle(Color.red, PointShape.DOWN_TRIANGLE, 9); ChartStyle styleNominal = new ChartStyle(Color.blue, PointShape.CIRCLE); ChartStyle styleMinmax = new ChartStyle(Color.black, PointShape.DIAMOND); ChartStyle styleRange = new ChartStyle(Color.black, false, true); ChartStyle styleMinmaxMarked = new ChartStyle(Color.blue, PointShape.DIAMOND); ChartStyle styleRangeMarked = new ChartStyle(Color.blue, false, true); DefaultChartModel targetModel = new DefaultChartModel(); DefaultChartModel targetModelOver = new DefaultChartModel(); DefaultChartModel targetModelHigh = new DefaultChartModel(); DefaultChartModel targetModelLow = new DefaultChartModel(); DefaultChartModel targetModelUnder = new DefaultChartModel(); DefaultChartModel nominalModel = new DefaultChartModel(); DefaultChartModel minmaxModel = new DefaultChartModel(); DefaultChartModel minmaxModelMarked = new DefaultChartModel(); boolean isMarkerNote; // True if target note is tonic or dominant. for (idx = 0; idx < target.getFingering().size(); idx++) { tgt = target.getFingering().get(idx).getNote(); predFingering = predicted.getFingering().get(idx); pred = predFingering.getNote(); if (useActuals && tgt.getFrequencyMax() != null) { frequencyMax = tgt.getFrequencyMax(); } else { frequencyMax = pred.getFrequencyMax(); } if (useActuals && tgt.getFrequencyMin() != null) { frequencyMin = tgt.getFrequencyMin(); } else { frequencyMin = pred.getFrequencyMin(); } if (tgt.getFrequency() != null) { f = tgt.getFrequency(); y = yValue(calculator, f, predFingering); y = clamp(y, minY, maxY); if (frequencyMax != null && f > frequencyMax) { targetModelOver.addPoint(f, y); } else if (frequencyMin != null && f < frequencyMin) { targetModelUnder.addPoint(f, y); } else if (frequencyMin != null && frequencyMax != null) { double ratio = (f - frequencyMin) / (frequencyMax - frequencyMin); if (ratio > 0.9) { targetModelHigh.addPoint(f, y); } else if (ratio < 0.1) { targetModelLow.addPoint(f, y); } else { targetModel.addPoint(f, y); } } else { targetModel.addPoint(f, y); } isMarkerNote = isMarker(f, lowestF); } else { isMarkerNote = false; } if (pred.getFrequency() != null && (tgt.getFrequency() == null || pred.getFrequency() != tgt.getFrequency())) { y = yValue(calculator, pred.getFrequency(), predFingering); y = clamp(y, minY, maxY); nominalModel.addPoint(pred.getFrequency(), y); } if (frequencyMin != null) { f = frequencyMin; y = yValue(calculator, f, predFingering); y = clamp(y, minY, maxY); if (isMarkerNote) { minmaxModelMarked.addPoint(f, y); } else { minmaxModel.addPoint(f, y); } } if (frequencyMax != null) { f = frequencyMax; y = yValue(calculator, f, predFingering); y = clamp(y, minY, maxY); if (isMarkerNote) { minmaxModelMarked.addPoint(f, y); } else { minmaxModel.addPoint(f, y); } } if (frequencyMin != null && frequencyMax != null) { DefaultChartModel rangeModel = new DefaultChartModel(); double step = (frequencyMax - frequencyMin) / 32.0; f = frequencyMin; for (int i = 0; i <= 32; i++) { y = yValue(calculator, f, predFingering); rangeModel.addPoint(f, y); f += step; } if (isMarkerNote) { chart.addModel(rangeModel, styleRangeMarked); } else { chart.addModel(rangeModel, styleRange); } } else if (tgt.getFrequency() != null && pred.getFrequency() != null && tgt.getFrequency() != pred.getFrequency()) { DefaultChartModel rangeModel = new DefaultChartModel(); double step = (tgt.getFrequency() - pred.getFrequency()) / 32.0; f = pred.getFrequency(); for (int i = 0; i <= 32; i++) { y = yValue(calculator, f, predFingering); y = clamp(y, minY, maxY); rangeModel.addPoint(f, y); f += step; } if (isMarkerNote) { chart.addModel(rangeModel, styleRangeMarked); } else { chart.addModel(rangeModel, styleRange); } } } if (minmaxModel.getPointCount() > 0) { chart.addModel(minmaxModel, styleMinmax); chart.addModel(minmaxModelMarked, styleMinmaxMarked); } if (nominalModel.getPointCount() > 0) { chart.addModel(nominalModel, styleNominal); } if (targetModel.getPointCount() > 0) { chart.addModel(targetModel, styleTarget); } if (targetModelOver.getPointCount() > 0) { chart.addModel(targetModelOver, styleTargetOver); } if (targetModelHigh.getPointCount() > 0) { chart.addModel(targetModelHigh, styleTargetHigh); } if (targetModelLow.getPointCount() > 0) { chart.addModel(targetModelLow, styleTargetLow); } if (targetModelUnder.getPointCount() > 0) { chart.addModel(targetModelUnder, styleTargetUnder); } }
From source file:dkpro.similarity.algorithms.lsr.path.PathBasedComparator.java
/** * @param e1/* www . j a va 2 s . com*/ * @param e2 * @return The path length between the two entites or NO_PATH if no path was found. * @throws LexicalSemanticResourceException */ protected double getShortestPathLength(Entity e1, Entity e2) throws LexicalSemanticResourceException { double minPathLength; // try to use the shortest path length method from the LSR first // catch the exception if the method is not implemented and use the (usually slower) entity graph implementation try { minPathLength = getLexicalSemanticResource().getShortestPathLength(e1, e2); } catch (UnsupportedOperationException e) { log.info("Falling back to the entity graph implementation of shortest path (usually slower)."); minPathLength = entityGraph.getShortestPathLength(e1, e2, DirectionMode.undirected); } if (minPathLength == Double.POSITIVE_INFINITY) { return NO_PATH; } return minPathLength; }
From source file:org.f3.tools.framework.Reporter.java
private String generateImage(String refName, String name, Number changeFactor) { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.addValue(changeFactor, 0, 0); JFreeChart chart = ChartFactory.createBarChart("", "", "%change", dataset, PlotOrientation.HORIZONTAL, false, false, false);/* w ww . j a v a 2 s.c o m*/ try { Color bgcolor = null; double value = changeFactor.doubleValue(); if (value == Double.POSITIVE_INFINITY || value == Double.NEGATIVE_INFINITY) { bgcolor = Color.YELLOW; } else if (value > 5) { bgcolor = Color.GREEN; } else if (value >= -5 && value <= 5) { bgcolor = Color.WHITE; } else { bgcolor = Color.RED; } chart.setBackgroundPaint(bgcolor); File dirFile = new File(IMAGE_DIRNAME); if (!dirFile.exists()) { dirFile.mkdirs(); } File ofile = new File(dirFile, name); ChartUtilities.saveChartAsPNG(ofile, chart, 300, 100); return getImageRef(refName, name); } catch (IOException ioe) { Utils.logger.severe(ioe.getMessage()); } return null; }
From source file:ffx.crystal.CCP4MapWriter.java
/** * write data to file, does not normalize * * @param data map data to write out//from ww w . ja va2 s . com * @param norm should the data be normalized by mean/sd? */ public void write(double data[], boolean norm) { ByteOrder b = ByteOrder.nativeOrder(); FileOutputStream fos; DataOutputStream dos; double min = Double.POSITIVE_INFINITY; double max = Double.NEGATIVE_INFINITY; double mean = 0.0; double sd = 0.0; int n = 0; for (int k = 0; k < extz; k++) { for (int j = 0; j < exty; j++) { for (int i = 0; i < extx; i++) { int index = stride * (i + extx * (j + exty * k)); // int index = k * (exty * (extx + 2)) + j * (extx + 2) + i; n++; if (data[index] < min) { min = data[index]; } if (data[index] > max) { max = data[index]; } mean += (data[index] - mean) / n; } } } n = 0; for (int k = 0; k < extz; k++) { for (int j = 0; j < exty; j++) { for (int i = 0; i < extx; i++) { int index = stride * (i + extx * (j + exty * k)); // int index = k * (exty * (extx + 2)) + j * (extx + 2) + i; sd += pow(data[index] - mean, 2.0); n++; } } } sd = sqrt(sd / n); if (norm) { for (int k = 0; k < extz; k++) { for (int j = 0; j < exty; j++) { for (int i = 0; i < extx; i++) { int index = stride * (i + extx * (j + exty * k)); data[index] = (data[index] - mean) / sd; } } } // recurse write(data, false); } try { if (logger.isLoggable(Level.INFO)) { StringBuilder sb = new StringBuilder(); sb.append(String.format("\nwriting CCP4 map file: \"%s\"\n", filename)); sb.append(String.format("map min: %g max: %g mean: %g standard dev.: %g", min, max, mean, sd)); logger.info(sb.toString()); } fos = new FileOutputStream(filename); dos = new DataOutputStream(fos); byte bytes[] = new byte[2048]; int offset = 0; int imapdata; float fmapdata; String mapstr; // header ByteBuffer bb = ByteBuffer.wrap(bytes); bb.order(b).putInt(extx); bb.order(b).putInt(exty); bb.order(b).putInt(extz); // mode (2 = reals, only one we accept) bb.order(b).putInt(2); bb.order(b).putInt(orix); bb.order(b).putInt(oriy); bb.order(b).putInt(oriz); bb.order(b).putInt(nx); bb.order(b).putInt(ny); bb.order(b).putInt(nz); bb.order(b).putFloat((float) crystal.a); bb.order(b).putFloat((float) crystal.b); bb.order(b).putFloat((float) crystal.c); bb.order(b).putFloat((float) crystal.alpha); bb.order(b).putFloat((float) crystal.beta); bb.order(b).putFloat((float) crystal.gamma); bb.order(b).putInt(1); bb.order(b).putInt(2); bb.order(b).putInt(3); bb.order(b).putFloat((float) min); bb.order(b).putFloat((float) max); bb.order(b).putFloat((float) mean); bb.order(b).putInt(crystal.spaceGroup.number); // bb.order(b).putInt(1); // symmetry bytes - should set this up at some point // imapdata = swap ? ByteSwap.swap(320) : 320; bb.order(b).putInt(80); bb.order(b).putInt(0); for (int i = 0; i < 12; i++) { bb.order(b).putFloat(0.0f); } for (int i = 0; i < 15; i++) { bb.order(b).putInt(0); } dos.write(bytes, offset, 208); bb.rewind(); mapstr = "MAP "; dos.writeBytes(mapstr); // machine code: double, float, int, uchar // 0x4441 for LE, 0x1111 for BE if (ByteOrder.nativeOrder().equals(ByteOrder.LITTLE_ENDIAN)) { imapdata = 0x4441; } else { imapdata = 0x1111; } bb.order(b).putInt(imapdata); bb.order(b).putFloat((float) sd); bb.order(b).putInt(1); dos.write(bytes, offset, 12); StringBuilder sb = new StringBuilder(); sb.append("map data from ffx"); while (sb.length() < 80) { sb.append(" "); } dos.writeBytes(sb.toString()); sb = new StringBuilder(); while (sb.length() < 80) { sb.append(" "); } for (int i = 0; i < 9; i++) { dos.writeBytes(sb.toString()); } sb = new StringBuilder(); sb.append("x,y,z"); while (sb.length() < 80) { sb.append(" "); } dos.writeBytes(sb.toString()); bb.rewind(); for (int k = 0; k < extz; k++) { for (int j = 0; j < exty; j++) { for (int i = 0; i < extx; i++) { int index = stride * (i + extx * (j + exty * k)); // int index = k * (exty * (extx + 2)) + j * (extx + 2) + i; fmapdata = (float) data[index]; bb.order(b).putFloat(fmapdata); if (!bb.hasRemaining()) { dos.write(bytes); bb.rewind(); } } } } if (bb.position() > 0) { dos.write(bytes); bb.rewind(); } dos.close(); } catch (Exception e) { String message = "Fatal exception evaluating structure factors.\n"; logger.log(Level.SEVERE, message, e); System.exit(-1); } }
From source file:org.onebusaway.nyc.vehicle_tracking.impl.inference.BlockStateSamplingStrategyImpl.java
@Override public CDFMap<BlockState> cdfForJourneyInProgress(Observation observation) { CDFMap<BlockState> cdf = _observationCache.getValueForObservation(observation, EObservationCacheKey.JOURNEY_IN_PROGRESS_BLOCK_CDF); if (cdf == null) { Set<BlockInstance> potentialBlocks = _blocksFromObservationService .determinePotentialBlocksForObservation(observation); cdf = new CDFMap<BlockState>(); StringBuilder b = null;//from ww w.ja v a2 s. co m if (_log.isDebugEnabled()) { b = new StringBuilder(); b.append("potential blocks found: " + potentialBlocks.size()); } for (BlockInstance blockInstance : potentialBlocks) { BlockState state = _blockStateService.getBestBlockLocation(observation, blockInstance, 0, Double.POSITIVE_INFINITY); double p = scoreState(state, observation); cdf.put(p, state); if (_log.isDebugEnabled()) { b.append("\n" + state.getBlockLocation().getDistanceAlongBlock() + "\t" + state.getBlockLocation().getScheduledTime() + "\t" + p + "\t" + blockInstance); } } if (_log.isDebugEnabled()) _log.debug(b.toString()); /** * Cache the result */ _observationCache.putValueForObservation(observation, EObservationCacheKey.JOURNEY_IN_PROGRESS_BLOCK_CDF, cdf); } return cdf; }
From source file:org.jfree.data.general.DefaultHeatMapDatasetTest.java
/** * Confirm that cloning works.// w w w. j ava 2 s. com */ @Test public void testCloning() throws CloneNotSupportedException { DefaultHeatMapDataset d1 = new DefaultHeatMapDataset(2, 3, -1.0, 4.0, -2.0, 5.0); d1.setZValue(0, 0, 10.0); d1.setZValue(0, 1, Double.NEGATIVE_INFINITY); d1.setZValue(0, 2, Double.POSITIVE_INFINITY); d1.setZValue(1, 0, Double.NaN); DefaultHeatMapDataset d2 = (DefaultHeatMapDataset) d1.clone(); assertTrue(d1 != d2); assertTrue(d1.getClass() == d2.getClass()); assertTrue(d1.equals(d2)); // simple check for independence d1.setZValue(0, 0, 11.0); assertFalse(d1.equals(d2)); d2.setZValue(0, 0, 11.0); assertTrue(d1.equals(d2)); }
From source file:com.rapidminer.operator.preprocessing.discretization.UserBasedDiscretization.java
@Override public List<ParameterType> getParameterTypes() { List<ParameterType> types = super.getParameterTypes(); ParameterType classType = new ParameterTypeString(PARAMETER_CLASS_NAME, "The name of this range."); ParameterType threshold = new ParameterTypeDouble(PARAMETER_UPPER_LIMIT, "The upper limit.", Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY); List<String[]> defaultList = new LinkedList<String[]>(); defaultList.add(new String[] { "first", Double.NEGATIVE_INFINITY + "" }); defaultList.add(new String[] { "last", Double.POSITIVE_INFINITY + "" }); ParameterType type = new ParameterTypeList(PARAMETER_RANGE_NAMES, "Defines the classes and the upper limits of each class.", classType, threshold, defaultList); type.setExpert(false);/*from ww w . ja v a 2 s. c o m*/ types.add(type); return types; }