List of usage examples for java.lang Double compare
public static int compare(double d1, double d2)
From source file:org.directwebremoting.dwrunit.Verify.java
/** * Asserts that two doubles or floats are equal to within a positive delta. If they * are not, an {@link AssertionError} is thrown with the given message. If the * expected value is infinity then the delta value is ignored. NaNs are * considered equal://ww w.j av a2 s . com * <code>assertEquals(Double.NaN, Double.NaN, *)</code> passes * @param message the identifying message or <code>null</code> for the {@link AssertionError} * @param expected expected value * @param actual the value to check against <code>expected</code> * @param delta the maximum delta between <code>expected</code> and <code>actual</code> for which * both numbers are still considered equal. */ public void equals(String message, double expected, double actual, double delta) { if (Double.compare(expected, actual) == 0) { return; } if (!(Math.abs(expected - actual) <= delta)) { failNotEquals(message, new Double(expected), new Double(actual)); } }
From source file:ml.shifu.shifu.core.dtrain.lr.LogisticRegressionWorker.java
@Override public void init(WorkerContext<LogisticRegressionParams, LogisticRegressionParams> context) { loadConfigFiles(context.getProps()); int[] inputOutputIndex = DTrainUtils.getInputOutputCandidateCounts(modelConfig.getNormalizeType(), this.columnConfigList); this.inputNum = inputOutputIndex[0] == 0 ? inputOutputIndex[2] : inputOutputIndex[0]; this.outputNum = inputOutputIndex[1]; this.candidateNum = inputOutputIndex[2]; this.isSpecificValidation = (modelConfig.getValidationDataSetRawPath() != null && !"".equals(modelConfig.getValidationDataSetRawPath())); this.isStratifiedSampling = this.modelConfig.getTrain().getStratifiedSample(); this.trainerId = Integer.valueOf(context.getProps().getProperty(CommonConstants.SHIFU_TRAINER_ID, "0")); Integer kCrossValidation = this.modelConfig.getTrain().getNumKFold(); if (kCrossValidation != null && kCrossValidation > 0) { isKFoldCV = true;/*from w ww.ja v a 2s . c o m*/ } if (this.inputNum == 0) { throw new IllegalStateException( "No any variables are selected, please try variable select step firstly."); } this.rng = new PoissonDistribution(1.0d); Double upSampleWeight = modelConfig.getTrain().getUpSampleWeight(); if (Double.compare(upSampleWeight, 1d) != 0) { // set mean to upSampleWeight -1 and get sample + 1 to make sure no zero sample value LOG.info("Enable up sampling with weight {}.", upSampleWeight); this.upSampleRng = new PoissonDistribution(upSampleWeight - 1); } double memoryFraction = Double.valueOf(context.getProps().getProperty("guagua.data.memoryFraction", "0.6")); LOG.info("Max heap memory: {}, fraction: {}", Runtime.getRuntime().maxMemory(), memoryFraction); double crossValidationRate = this.modelConfig.getValidSetRate(); String tmpFolder = context.getProps().getProperty("guagua.data.tmpfolder", "tmp"); if (StringUtils.isNotBlank(modelConfig.getValidationDataSetRawPath())) { // fixed 0.6 and 0.4 of max memory for trainingData and validationData this.trainingData = new BytableMemoryDiskList<Data>( (long) (Runtime.getRuntime().maxMemory() * memoryFraction * 0.6), tmpFolder + File.separator + "train-" + System.currentTimeMillis(), Data.class.getName()); this.validationData = new BytableMemoryDiskList<Data>( (long) (Runtime.getRuntime().maxMemory() * memoryFraction * 0.4), tmpFolder + File.separator + "test-" + System.currentTimeMillis(), Data.class.getName()); } else { this.trainingData = new BytableMemoryDiskList<Data>( (long) (Runtime.getRuntime().maxMemory() * memoryFraction * (1 - crossValidationRate)), tmpFolder + File.separator + "train-" + System.currentTimeMillis(), Data.class.getName()); this.validationData = new BytableMemoryDiskList<Data>( (long) (Runtime.getRuntime().maxMemory() * memoryFraction * crossValidationRate), tmpFolder + File.separator + "test-" + System.currentTimeMillis(), Data.class.getName()); } // create Splitter String delimiter = context.getProps().getProperty(Constants.SHIFU_OUTPUT_DATA_DELIMITER); this.splitter = MapReduceUtils.generateShifuOutputSplitter(delimiter); // cannot find a good place to close these two data set, using Shutdown hook Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { @Override public void run() { LogisticRegressionWorker.this.validationData.close(); LogisticRegressionWorker.this.trainingData.close(); } })); }
From source file:com.opengamma.analytics.financial.commodity.definition.CommodityForwardDefinition.java
@Override public boolean equals(Object obj) { if (this == obj) { return true; }//w ww .java 2 s .co m if (!(obj instanceof CommodityForwardDefinition)) { return false; } final CommodityForwardDefinition<?> other = (CommodityForwardDefinition<?>) obj; if (!ObjectUtils.equals(_expiryDate, other._expiryDate)) { return false; } if (!ObjectUtils.equals(_underlying, other._underlying)) { return false; } if (!ObjectUtils.equals(_firstDeliveryDate, other._firstDeliveryDate)) { return false; } if (!ObjectUtils.equals(_lastDeliveryDate, other._lastDeliveryDate)) { return false; } if (!ObjectUtils.equals(_unitName, other._unitName)) { return false; } if (!ObjectUtils.equals(_settlementType, other._settlementType)) { return false; } if (!ObjectUtils.equals(_currency, other._currency)) { return false; } if (!ObjectUtils.equals(_settlementDate, other._settlementDate)) { return false; } if (Double.compare(_amount, other._amount) != 0) { return false; } if (Double.compare(_unitAmount, other._unitAmount) != 0) { return false; } if (Double.compare(_referencePrice, other._referencePrice) != 0) { return false; } return true; }
From source file:br.com.OCTur.view.InfograficoController.java
private BufferedImage participacao() { DefaultPieDataset dpdDados = new DefaultPieDataset(); hoteis = new ArrayList<>(); for (Hotel hotel : new HotelDAO().pegarTodos()) { List<Reserva> reservas = new ReservaDAO().pegarPorHotelInicioFim(hotel, inicio, fim); double total = 0; for (Reserva reserva : reservas) { long dias = (reserva.getFim().getTime() - reserva.getInicio().getTime()) / 1000 / 60 / 60 / 24; if (dias <= 0) { dias = 1;/* w ww.j a v a2 s .c o m*/ } total += (reserva.getQuarto().getOrcamento().getPreco() * dias); } hoteis.add(new EntidadeGrafico<>(hotel, total)); } hoteis.sort((EntidadeGrafico<Hotel> o1, EntidadeGrafico<Hotel> o2) -> Double.compare(o1.getValue(), o2.getValue()) * -1); for (EntidadeGrafico<Hotel> entidadeGrafico : hoteis.subList(0, hoteis.size() > 4 ? 4 : hoteis.size())) { dpdDados.setValue(entidadeGrafico.toString(), entidadeGrafico.getValue()); } if (hoteis.size() > 4) { dpdDados.setValue("Outros", hoteis.subList(4, hoteis.size()).stream().mapToDouble(EntidadeGrafico::getValue).sum()); } JFreeChart jFreeChart = ChartFactory.createRingChart("", dpdDados, true, false, Locale.ROOT); PiePlot piePlot = (PiePlot) jFreeChart.getPlot(); piePlot.setLabelGenerator(new StandardPieSectionLabelGenerator("{2}")); return jFreeChart.createBufferedImage(175, 252); }
From source file:ca.mymenuapp.ui.activities.MainActivity.java
@OnClick({ R.id.sort_distance, R.id.sort_rating, R.id.sort_cuisine }) void onSortButtonClicked(TextView button) { switch (button.getId()) { case R.id.sort_distance: sortRestaurants(new Comparator<Restaurant>() { @Override//from w w w. ja va2s . c om public int compare(Restaurant lhs, Restaurant rhs) { return Double.compare(SphericalUtil.computeDistanceBetween(lastLatLng, lhs.getPosition()), SphericalUtil.computeDistanceBetween(lastLatLng, rhs.getPosition())); } }); break; case R.id.sort_rating: sortRestaurants(new Comparator<Restaurant>() { @Override public int compare(Restaurant lhs, Restaurant rhs) { // sort descending return Double.compare(rhs.rating, lhs.rating); } }); break; case R.id.sort_cuisine: sortRestaurants(new Comparator<Restaurant>() { @Override public int compare(Restaurant lhs, Restaurant rhs) { return lhs.category.compareTo(rhs.category); } }); break; default: throw new IllegalArgumentException("Not handled!"); } }
From source file:com.opengamma.analytics.financial.commodity.definition.CommodityFutureDefinition.java
@Override public boolean equals(final Object obj) { if (this == obj) { return true; }//from w w w . j a v a 2s. c o m if (!(obj instanceof CommodityFutureDefinition)) { return false; } final CommodityFutureDefinition<?> other = (CommodityFutureDefinition<?>) obj; if (!ObjectUtils.equals(_expiryDate, other._expiryDate)) { return false; } if (!ObjectUtils.equals(_underlying, other._underlying)) { return false; } if (!ObjectUtils.equals(_firstDeliveryDate, other._firstDeliveryDate)) { return false; } if (!ObjectUtils.equals(_lastDeliveryDate, other._lastDeliveryDate)) { return false; } if (!ObjectUtils.equals(_unitName, other._unitName)) { return false; } if (!ObjectUtils.equals(_settlementType, other._settlementType)) { return false; } if (!ObjectUtils.equals(_currency, other._currency)) { return false; } if (!ObjectUtils.equals(_settlementDate, other._settlementDate)) { return false; } if (Double.compare(_amount, other._amount) != 0) { return false; } if (Double.compare(_unitAmount, other._unitAmount) != 0) { return false; } if (Double.compare(_referencePrice, other._referencePrice) != 0) { return false; } return true; }
From source file:com.userweave.module.methoden.iconunderstandability.service.IconMatchingStatistics.java
public List<TermAssignment> getRoundedTermAssignments(ITMImage image) { List<TermAssignment> termAssignments = termAssignmentMap.get(image); if (termAssignments == null) { termAssignments = new ArrayList<TermAssignment>(); for (ItmTerm term : getTerms()) { termAssignments.add(//from www . j a va2 s . c om new TermAssignment(term.getValue(), FormatUtils.round(getAssignmentRate(term, image), 0))); } // sort by assignment Collections.sort(termAssignments, new Comparator<TermAssignment>() { @Override public int compare(TermAssignment termAssignment1, TermAssignment termAssignment2) { return -Double.compare(termAssignment1.getAssignment(), termAssignment2.getAssignment()); } }); termAssignmentMap.put(image, termAssignments); } return termAssignments; }
From source file:org.apache.metron.common.math.stats.OnlineStatisticsProvider.java
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; OnlineStatisticsProvider that = (OnlineStatisticsProvider) o; if (n != that.n) return false; if (Double.compare(that.sum, sum) != 0) return false; if (Double.compare(that.sumOfSquares, sumOfSquares) != 0) return false; if (Double.compare(that.sumOfLogs, sumOfLogs) != 0) return false; if (Double.compare(that.M1, M1) != 0) return false; if (Double.compare(that.M2, M2) != 0) return false; if (Double.compare(that.M3, M3) != 0) return false; if (Double.compare(that.M4, M4) != 0) return false; if (digest != null ? !digest.equals(that.digest) : that.digest != null) return false; if (min != null ? !min.equals(that.min) : that.min != null) return false; return max != null ? max.equals(that.max) : that.max == null; }
From source file:org.geoserver.wcs.GetCoverageTest.java
@Test public void testReproject() throws Exception { // add the target code to the supported ones Catalog catalog = getCatalog();/*w ww . java 2 s. c o m*/ final String layerId = getLayerId(TASMANIA_BM); CoverageInfo ci = catalog.getCoverageByName(layerId); ci.getResponseSRS().add("EPSG:3857"); catalog.save(ci); // do the request Map<String, Object> raw = baseMap(); raw.put("identifier", layerId); raw.put("format", "image/geotiff"); raw.put("BoundingBox", "-80,-180,80,180,urn:ogc:def:crs:EPSG:6.6:4326"); raw.put("GridBaseCRS", "EPSG:3857"); GridCoverage[] coverages = executeGetCoverageKvp(raw); // System.out.println(coverages[0]); // check the envelope Envelope envelope = coverages[0].getEnvelope(); // System.out.println(envelope); CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:3857"); assertEquals(targetCRS, envelope.getCoordinateReferenceSystem()); ReferencedEnvelope nativeBounds = ci.getNativeBoundingBox(); ReferencedEnvelope expected = nativeBounds.transform(targetCRS, true); assertEquals(0, Double.compare(expected.getMinimum(0), envelope.getMinimum(0))); assertEquals(0, Double.compare(expected.getMaximum(0), envelope.getMaximum(0))); assertEquals(0, Double.compare(expected.getMinimum(1), envelope.getMinimum(1))); assertEquals(0, Double.compare(expected.getMaximum(1), envelope.getMaximum(1))); // check we did not get a massive raster out (GEOS-5346) GridEnvelope range = coverages[0].getGridGeometry().getGridRange(); assertEquals(360, range.getSpan(0)); assertEquals(499, range.getSpan(1)); }
From source file:org.orekit.propagation.events.GroundMaskElevationDetector.java
/** Checking and ordering the azimuth-elevation tabulation. * @param azimelev azimuth-elevation tabulation to be checked and ordered * @return ordered azimuth-elevation tabulation ordered *//*from w ww.j a v a2 s. c om*/ private static double[][] checkMask(final double[][] azimelev) { /* Copy of the given mask */ final double[][] mask = new double[azimelev.length + 2][azimelev[0].length]; for (int i = 0; i < azimelev.length; i++) { System.arraycopy(azimelev[i], 0, mask[i + 1], 0, azimelev[i].length); /* Reducing azimuth between 0 and 2*Pi */ mask[i + 1][0] = MathUtils.normalizeAngle(mask[i + 1][0], FastMath.PI); } /* Sorting the mask with respect to azimuth */ Arrays.sort(mask, 1, mask.length - 1, new Comparator<double[]>() { public int compare(final double[] d1, final double[] d2) { return Double.compare(d1[0], d2[0]); } }); /* Extending the mask in order to cover [0, 2PI] in azimuth */ mask[0][0] = mask[mask.length - 2][0] - MathUtils.TWO_PI; mask[0][1] = mask[mask.length - 2][1]; mask[mask.length - 1][0] = mask[1][0] + MathUtils.TWO_PI; mask[mask.length - 1][1] = mask[1][1]; /* Checking the sorted mask: same azimuth modulo 2PI must have same elevation */ for (int i = 1; i < mask.length; i++) { if (Double.compare(mask[i - 1][0], mask[i][0]) == 0) { if (Double.compare(mask[i - 1][1], mask[i][1]) != 0) { throw OrekitException.createIllegalArgumentException( OrekitMessages.UNEXPECTED_TWO_ELEVATION_VALUES_FOR_ONE_AZIMUTH, mask[i - 1][1], mask[i][1], mask[i][0]); } } } return mask; }