List of usage examples for java.lang Double compare
public static int compare(double d1, double d2)
From source file:WeakIdentityMap.java
static int compare(double[] a, double[] b) { if (a == b) { return 0; }/*from w w w . ja v a2 s . co m*/ if (a == null) { return 1; } if (b == null) { return -1; } int length = Math.min(a.length, b.length); for (int i = 0; i < length; i++) { int v = Double.compare(a[i], b[i]); if (v != 0) { return v; } } return a.length < b.length ? -1 : (a.length > b.length ? 1 : 0); }
From source file:cs.man.ac.uk.stats.ComputeANOVAStats.java
/** * Gets the value of the Studentized Q distribution given a specified degree of freedom, * the number of groups and an alpha significance level. * @param degressOfFreedom the degrees of freedom. * @param groups the number of groups.// w w w . j a v a 2 s.co m * @param a the alpha value. * @return the critical Studentized Q distribution value. */ private static double getQDist(double degressOfFreedom, double groups, double a) { if (Double.compare(a, 0.01) == 0) return QDist_alpha_0_01[(int) degressOfFreedom - 1][(int) groups - 1]; else if (Double.compare(a, 0.05) == 0) return QDist_alpha_0_05[(int) degressOfFreedom - 1][(int) groups - 1]; else return 0; }
From source file:org.esa.nest.gpf.RangeDopplerGeocodingOp.java
/** * Update metadata in the target product. * @throws OperatorException The exception. *//*w w w . ja v a2s . co m*/ private void updateTargetProductMetadata() throws Exception { final MetadataElement absTgt = AbstractMetadata.getAbstractedMetadata(targetProduct); AbstractMetadata.setAttribute(absTgt, AbstractMetadata.srgr_flag, 1); AbstractMetadata.setAttribute(absTgt, AbstractMetadata.num_output_lines, targetImageHeight); AbstractMetadata.setAttribute(absTgt, AbstractMetadata.num_samples_per_line, targetImageWidth); final GeoPos geoPosFirstNear = targetGeoCoding.getGeoPos(new PixelPos(0, 0), null); final GeoPos geoPosFirstFar = targetGeoCoding.getGeoPos(new PixelPos(targetImageWidth - 1, 0), null); final GeoPos geoPosLastNear = targetGeoCoding.getGeoPos(new PixelPos(0, targetImageHeight - 1), null); final GeoPos geoPosLastFar = targetGeoCoding .getGeoPos(new PixelPos(targetImageWidth - 1, targetImageHeight - 1), null); AbstractMetadata.setAttribute(absTgt, AbstractMetadata.first_near_lat, geoPosFirstNear.getLat()); AbstractMetadata.setAttribute(absTgt, AbstractMetadata.first_far_lat, geoPosFirstFar.getLat()); AbstractMetadata.setAttribute(absTgt, AbstractMetadata.last_near_lat, geoPosLastNear.getLat()); AbstractMetadata.setAttribute(absTgt, AbstractMetadata.last_far_lat, geoPosLastFar.getLat()); AbstractMetadata.setAttribute(absTgt, AbstractMetadata.first_near_long, geoPosFirstNear.getLon()); AbstractMetadata.setAttribute(absTgt, AbstractMetadata.first_far_long, geoPosFirstFar.getLon()); AbstractMetadata.setAttribute(absTgt, AbstractMetadata.last_near_long, geoPosLastNear.getLon()); AbstractMetadata.setAttribute(absTgt, AbstractMetadata.last_far_long, geoPosLastFar.getLon()); AbstractMetadata.setAttribute(absTgt, AbstractMetadata.TOT_SIZE, ReaderUtils.getTotalSize(targetProduct)); AbstractMetadata.setAttribute(absTgt, AbstractMetadata.map_projection, targetCRS.getName().getCode()); if (!useAvgSceneHeight) { AbstractMetadata.setAttribute(absTgt, AbstractMetadata.is_terrain_corrected, 1); if (externalDEMFile != null) { // if external DEM file is specified by user AbstractMetadata.setAttribute(absTgt, AbstractMetadata.DEM, externalDEMFile.getPath()); } else { AbstractMetadata.setAttribute(absTgt, AbstractMetadata.DEM, demName); } } // map projection too AbstractMetadata.setAttribute(absTgt, AbstractMetadata.geo_ref_system, "WGS84"); AbstractMetadata.setAttribute(absTgt, AbstractMetadata.lat_pixel_res, delLat); AbstractMetadata.setAttribute(absTgt, AbstractMetadata.lon_pixel_res, delLon); if (pixelSpacingInMeter > 0.0 && Double.compare(pixelSpacingInMeter, SARGeocoding.getPixelSpacing(sourceProduct)) != 0) { AbstractMetadata.setAttribute(absTgt, AbstractMetadata.range_spacing, pixelSpacingInMeter); AbstractMetadata.setAttribute(absTgt, AbstractMetadata.azimuth_spacing, pixelSpacingInMeter); } // save look directions for 5 range lines final MetadataElement lookDirectionListElem = new MetadataElement("Look_Direction_List"); final int numOfDirections = 5; for (int i = 1; i <= numOfDirections; ++i) { SARGeocoding.addLookDirection("look_direction", lookDirectionListElem, i, numOfDirections, sourceImageWidth, sourceImageHeight, firstLineUTC, lineTimeInterval, nearRangeOnLeft, latitude, longitude); } absTgt.addElement(lookDirectionListElem); }
From source file:malware_classification.Malware_Classification.java
private double[][] svm_rescale(double[][] data_orig) { int num_features = data_orig[0].length; double[][] data_scaled = new double[data_orig.length][num_features]; double[] max_vals = new double[num_features]; double[] min_vals = new double[num_features]; // find max and min vals of all features. Feature 0 is the true class. for (int curr_feature = 1; curr_feature < num_features; curr_feature++) { double max_val = Double.NEGATIVE_INFINITY; double min_val = Double.POSITIVE_INFINITY; for (int curr_vec = 0; curr_vec < data_orig.length; curr_vec++) { double curr_val = data_orig[curr_vec][curr_feature]; if (curr_val > max_val) { max_val = curr_val; }/*from w ww .j a va 2s. c o m*/ if (curr_val < min_val) { min_val = curr_val; } } max_vals[curr_feature] = max_val; min_vals[curr_feature] = min_val; if (Double.compare(max_vals[curr_feature], min_vals[curr_feature]) == 0) { logger.info("All data for feature " + curr_feature + " are the same"); } } //rescale for (int curr_vec = 0; curr_vec < data_orig.length; curr_vec++) { data_scaled[curr_vec][0] = data_orig[curr_vec][0]; data_scaled[curr_vec][1] = data_orig[curr_vec][1]; for (int curr_feature = 2; curr_feature < num_features; curr_feature++) { if (Double.compare(max_vals[curr_feature], min_vals[curr_feature]) != 0) { data_scaled[curr_vec][curr_feature] = (data_orig[curr_vec][curr_feature] - min_vals[curr_feature]) / (max_vals[curr_feature] - min_vals[curr_feature]); } else { data_scaled[curr_vec][curr_feature] = 0; } } } return data_scaled; }
From source file:ml.shifu.shifu.core.dtrain.nn.AbstractNNWorker.java
/** * Only baggingWithReplacement is set and size over NNConstants.NN_BAGGING_THRESHOLD, and random value <= 1/size. We * choose use existing data to add training data set and testing data set. */// w w w . j a v a 2 s .com @SuppressWarnings("unused") private boolean isBaggingReplacementTrigged(final double random) { long trainingSize = this.trainingData.getRecordCount(); long testingSize = this.validationData.getRecordCount(); // size should be equals to sampleCount:) long size = trainingSize + testingSize; return this.modelConfig.isBaggingWithReplacement() && (testingSize > 0) && (trainingSize > 0) && (size > NNConstants.NN_BAGGING_THRESHOLD) && (Double.compare(random, 0.5d) < 0); }
From source file:org.apache.bookkeeper.bookie.CreateNewLogTest.java
@Test public void testEntryLogManagerMetricsFromExpiryAspect() throws Exception { ServerConfiguration conf = TestBKConfiguration.newServerConfiguration(); TestStatsProvider statsProvider = new TestStatsProvider(); TestStatsLogger statsLogger = statsProvider.getStatsLogger(BookKeeperServerStats.ENTRYLOGGER_SCOPE); int entrylogMapAccessExpiryTimeInSeconds = 1; int entryLogPerLedgerCounterLimitsMultFactor = 2; // Creating a new configuration with a number of ledger directories. conf.setLedgerDirNames(ledgerDirs);/*from w w w.j av a 2s .c om*/ // pre-allocation is enabled conf.setEntryLogFilePreAllocationEnabled(true); conf.setEntryLogPerLedgerEnabled(true); conf.setEntrylogMapAccessExpiryTimeInSeconds(entrylogMapAccessExpiryTimeInSeconds); conf.setEntryLogPerLedgerCounterLimitsMultFactor(entryLogPerLedgerCounterLimitsMultFactor); LedgerDirsManager ledgerDirsManager = new LedgerDirsManager(conf, conf.getLedgerDirs(), new DiskChecker(conf.getDiskUsageThreshold(), conf.getDiskUsageWarnThreshold())); EntryLogger entryLogger = new EntryLogger(conf, ledgerDirsManager, null, statsLogger, UnpooledByteBufAllocator.DEFAULT); EntryLogManagerForEntryLogPerLedger entrylogManager = (EntryLogManagerForEntryLogPerLedger) entryLogger .getEntryLogManager(); // set same thread executor for entryLoggerAllocator's allocatorExecutor setSameThreadExecutorForEntryLoggerAllocator(entryLogger.getEntryLoggerAllocator()); Counter numOfWriteLedgersRemovedCacheExpiry = statsLogger .getCounter(BookKeeperServerStats.NUM_OF_WRITE_LEDGERS_REMOVED_CACHE_EXPIRY); TestOpStatsLogger entryLogsPerLedger = (TestOpStatsLogger) statsLogger .getOpStatsLogger(BookKeeperServerStats.ENTRYLOGS_PER_LEDGER); int numOfEntrylogsForLedger1 = 3; createNewLogs(entrylogManager, 1L, numOfEntrylogsForLedger1); Assert.assertEquals("ENTRYLOGS_PER_LEDGER SuccessCount", 0, entryLogsPerLedger.getSuccessCount()); Assert.assertEquals("NUM_OF_WRITE_LEDGERS_REMOVED_CACHE_EXPIRY", 0, numOfWriteLedgersRemovedCacheExpiry.get().intValue()); Thread.sleep(entrylogMapAccessExpiryTimeInSeconds * 1000 + 100); entrylogManager.doEntryLogMapCleanup(); entrylogManager.entryLogsPerLedgerCounter.doCounterMapCleanup(); Assert.assertEquals("NUM_OF_WRITE_LEDGERS_REMOVED_CACHE_EXPIRY", 1, numOfWriteLedgersRemovedCacheExpiry.get().intValue()); Assert.assertEquals("ENTRYLOGS_PER_LEDGER SuccessCount", 0, entryLogsPerLedger.getSuccessCount()); Thread.sleep(entrylogMapAccessExpiryTimeInSeconds * 1000 + 100); entrylogManager.doEntryLogMapCleanup(); entrylogManager.entryLogsPerLedgerCounter.doCounterMapCleanup(); Assert.assertEquals("NUM_OF_WRITE_LEDGERS_REMOVED_CACHE_EXPIRY", 1, numOfWriteLedgersRemovedCacheExpiry.get().intValue()); Assert.assertEquals("ENTRYLOGS_PER_LEDGER SuccessCount", 1, entryLogsPerLedger.getSuccessCount()); Assert.assertTrue("ENTRYLOGS_PER_LEDGER average value", Double.compare(numOfEntrylogsForLedger1, entryLogsPerLedger.getSuccessAverage()) == 0); }
From source file:ml.shifu.shifu.core.dtrain.nn.AbstractNNWorker.java
/** * From Trainer, the logic is to random choose items in master dataset, but I don't want to load data twice for * saving memory. Use this to mock raw random repeat logic. This should be some logic difference because of data are * not loaded into data set, not random. *//*from w w w .j a v a 2 s . c om*/ @SuppressWarnings("unused") private void mockRandomRepeatData(double crossValidationRate, double random) { long trainingSize = this.trainingData.getRecordCount(); long testingSize = this.validationData.getRecordCount(); long size = trainingSize + testingSize; // here we used a strong cast from long to int since it's just a random choosing algorithm int next = RandomUtils.nextInt((int) size); FloatMLDataPair dataPair = new BasicFloatMLDataPair( new BasicFloatMLData(new float[this.subFeatures.size()]), new BasicFloatMLData(new float[this.outputNodeCount])); if (next >= trainingSize) { this.validationData.getRecord(next - trainingSize, dataPair); } else { this.trainingData.getRecord(next, dataPair); } if (Double.compare(random, crossValidationRate) < 0) { this.validationData.add(dataPair); } else { this.trainingData.add(dataPair); } }
From source file:de.iteratec.iteraplan.businesslogic.exchange.visio.VisioBubbleExport.java
private List<Tile> createTiles() { List<Tile> tiles = new ArrayList<Tile>(); Map<BuildingBlock, Weight> mappedBBToWeightXY = createMapBBToWeightXY(); int nrTilesX = bubbleSpace.getXDimension().getMapping().size(); int nrTilesY = bubbleSpace.getYDimension().getMapping().size(); double heightTile = COSY_SIDE / nrTilesY; double widthTile = COSY_SIDE / nrTilesX; for (BuildingBlock block : buildingBlocks) { Tile tile = new Tile(); Weight pairWeightBB = mappedBBToWeightXY.get(block); double xWeightBB = pairWeightBB.getX().doubleValue(); double yWeightBB = pairWeightBB.getY().doubleValue(); double xCorLeftCornerTile; double yCorLeftCornerTile; if (xWeightBB < 0) { xCorLeftCornerTile = COSY_SIDE; } else {//from w w w. j a v a 2 s .c om xCorLeftCornerTile = widthTile * Math.round(xWeightBB * (nrTilesX - 1)); } if (yWeightBB < 0) { yCorLeftCornerTile = COSY_SIDE - heightTile / 2; } else { yCorLeftCornerTile = heightTile * Math.round(yWeightBB * (nrTilesY - 1)); } boolean foundTile = false; for (Tile t : tiles) { if (Double.compare(t.getxPos(), xCorLeftCornerTile) == 0 && Double.compare(t.getyPos(), yCorLeftCornerTile) == 0) { tile = t; tile.getBuildingBlocks().add(block); foundTile = true; break; } } if (!foundTile) { tile.setxPos(xCorLeftCornerTile); tile.setyPos(yCorLeftCornerTile); tile.setWidth(widthTile); tile.setHeight(heightTile); List<BuildingBlock> bBL = new LinkedList<BuildingBlock>(); bBL.add(block); tile.setBuildingBlocks(bBL); tiles.add(tile); } } return tiles; }
From source file:org.orekit.time.AbsoluteDate.java
/** Compare the instance with another date. * @param date other date to compare the instance to * @return a negative integer, zero, or a positive integer as this date * is before, simultaneous, or after the specified date. *//*from w ww . j a v a2s . c o m*/ public int compareTo(final AbsoluteDate date) { return Double.compare(durationFrom(date), 0); }
From source file:org.unitime.timetable.solver.exam.ui.ExamInfoModel.java
public String getRoomTable() { try {/* w w w . j a va 2 s . co m*/ Vector<ExamRoomInfo> rooms = getRooms(); ExamAssignment examAssignment = (iChange == null ? null : iChange.getCurrent(iExam)); Collection<ExamRoomInfo> assigned = (examAssignment != null ? examAssignment.getRooms() : isExamAssigned() ? getExamAssignment().getRooms() : null); Collection<ExamRoomInfo> original = (getExamOldAssignment() != null ? getExamOldAssignment().getRooms() : null); if (rooms == null || rooms.isEmpty()) return ""; Collections.sort(rooms, new Comparator<ExamRoomInfo>() { public int compare(ExamRoomInfo r1, ExamRoomInfo r2) { int cmp = 0; if (ExamInfoForm.sRoomOrdNameAsc.equals(iForm.getRoomOrder())) { cmp = r1.getName().compareTo(r2.getName()); } else if (ExamInfoForm.sRoomOrdNameDesc.equals(iForm.getRoomOrder())) { cmp = -r1.getName().compareTo(r2.getName()); } else if (ExamInfoForm.sRoomOrdSizeAsc.equals(iForm.getRoomOrder())) { cmp = Double.compare(r1.getCapacity(getExam()), r2.getCapacity(getExam())); } else if (ExamInfoForm.sRoomOrdSizeDesc.equals(iForm.getRoomOrder())) { cmp = -Double.compare(r1.getCapacity(getExam()), r2.getCapacity(getExam())); } else { cmp = r1.getName().compareTo(r2.getName()); } if (cmp != 0) return cmp; cmp = r1.getName().compareTo(r2.getName()); ; if (cmp != 0) return cmp; return r1.getLocationId().compareTo(r2.getLocationId()); } }); String ret = ""; ret += "<script language='javascript'>"; ret += "function roomOver(source, id) { "; ret += " document.getElementById('r'+id).style.backgroundColor='rgb(223,231,242)';"; ret += " document.getElementById('c'+id).style.backgroundColor='rgb(223,231,242)';"; ret += " source.style.cursor='hand';source.style.cursor='pointer';"; ret += "}"; ret += "var sCap = -1;"; ret += "var sRooms = '"; if (assigned != null && assigned.size() > 0) { for (ExamRoomInfo room : assigned) { ret += ":" + room.getLocationId() + "@" + room.getCapacity(getExam()); } } ret += "';"; ret += "var sNrRooms = " + (assigned != null ? assigned.size() : 0) + ";"; ret += "function roomSelected(id) {"; ret += " return sRooms.indexOf(':'+id+'@')>=0;"; ret += "}"; ret += "function roomOut(id) { "; ret += " var bg = 'transparent';"; ret += " if (roomSelected(id)) bg='rgb(168,187,225)';"; ret += " document.getElementById('r'+id).style.backgroundColor=bg;"; ret += " document.getElementById('c'+id).style.backgroundColor=bg;"; ret += "}"; ret += "function roomClick(source, id, cap) { "; ret += " if (sCap<0) {"; ret += " sCap = 0; sRooms=''; sNrRooms=0;"; if (assigned != null && assigned.size() > 0) { for (ExamRoomInfo room : assigned) ret += " roomOut(" + room.getLocationId() + ");"; } ret += " }"; ret += " var i = sRooms.indexOf(':'+id+'@');"; ret += " if (i>=0) {"; ret += " var j = sRooms.indexOf(':',i+1);"; ret += " sRooms = sRooms.substring(0, i)+(j>=0?sRooms.substring(j):'');"; ret += " sCap -= cap; sNrRooms--;"; ret += " } else {"; ret += " sRooms = sRooms + ':' + id + '@' + cap;"; ret += " sCap += cap; sNrRooms++;"; ret += " if (sNrRooms>" + getExam().getMaxRooms() + ") {"; ret += " var fid = sRooms.substring(1, sRooms.indexOf('@'));"; ret += " var fcap = sRooms.substring(sRooms.indexOf('@')+1, sRooms.indexOf(':',1));"; ret += " sRooms = sRooms.substring(sRooms.indexOf(':',1));"; ret += " sCap -= fcap; sNrRooms--; roomOut(fid);"; ret += " };"; ret += " }"; ret += " roomOut(id);"; ret += " if (sCap>=" + getExam().getNrStudents() + ") {displayLoading(); document.location='examInfo.do?op=Select&room='+sRooms+'&noCacheTS=" + new Date().getTime() + "';}"; ret += " var c = document.getElementById('roomCapacityCounter');"; ret += " if (c!=null) c.innerHTML = (sCap<" + getExam().getNrStudents() + "?'<font color=\"red\">'+sCap+'</font>':''+sCap);"; ret += "}"; ret += "</script>"; ret += "<table border='0' cellspacing='0' cellpadding='3'>"; int idx = 0; int step = 6; for (ExamRoomInfo room : rooms) { if ((idx % step) == 0) { if (idx > 0) ret += "</tr>"; ret += "<tr>"; } String style = ""; if (assigned != null && assigned.contains(room)) style += "background-color:rgb(168,187,225);"; if (original != null && original.contains(room)) style += "text-decoration:underline;"; String mouse = "onMouseOver=\"roomOver(this," + room.getLocationId() + ");\" " + "onMouseOut=\"roomOut(" + room.getLocationId() + ");\" " + "onClick=\"roomClick(this," + room.getLocationId() + "," + room.getCapacity(getExam()) + ");\""; ret += "<td nowrap id='r" + room.getLocationId() + "' " + (style.length() > 0 ? "style='" + style + "' " : "") + mouse + ">" + room.toString() + "</td>"; if ((idx % step) < step - 1) style += "border-right: #646464 1px dashed;"; ret += "<td id='c" + room.getLocationId() + "' " + (style.length() > 0 ? "style='" + style + "' " : "") + mouse + ">" + room.getCapacity(getExam()) + "</td>"; idx++; } while ((idx % step) != 0) { ret += "<td colspan='2'> </td>"; idx++; } ret += "</tr>"; ret += "</table>"; return ret; } catch (Exception e) { sLog.error(e.getMessage(), e); return ""; } }