List of usage examples for java.lang Double compare
public static int compare(double d1, double d2)
From source file:edu.rice.cs.bioinfo.programs.phylonet.algos.network.InferMLNetworkFromSequences.java
private Comparator<Double> getDoubleScoreComparator() { return new Comparator<Double>() { public int compare(Double o1, Double o2) { return Double.compare(o1, o2); }/*from w w w . j av a 2 s . c o m*/ }; }
From source file:smodelkit.util.Helper.java
public static <T extends Comparable<T>> int indexOfMaxElement(double[] array) { if (array.length == 0) { throw new IllegalArgumentException("There is no maximum element of an empty list."); }/*from ww w . java 2 s . com*/ int maxIndex = 0; for (int i : new Range(1, array.length)) { if (Double.compare(array[i], array[maxIndex]) > 0) { maxIndex = i; } } return maxIndex; }
From source file:eu.hansolo.tilesfx.tools.Location.java
public String getCardinalDirectionFromBearing(final double BEARING) { double bearing = BEARING % 360.0; for (CardinalDirection cardinalDirection : CardinalDirection.values()) { if (Double.compare(bearing, cardinalDirection.from) >= 0 && Double.compare(bearing, cardinalDirection.to) < 0) { return cardinalDirection.direction; }//from w w w . ja va2 s .c om } return ""; }
From source file:com.joptimizer.algebra.CholeskySparseFactorization.java
/** * Solves Q.X = B//from ww w .j a va2 s .c o m */ public DoubleMatrix2D solve(DoubleMatrix2D B) { if (B.rows() != dim) { log.error("wrong dimension of vector b: expected " + dim + ", actual " + B.rows()); throw new RuntimeException("wrong dimension of vector b: expected " + dim + ", actual " + B.rows()); } // with scaling, we must solve U.Q.U.z = U.b, after that we have x = U.z if (this.rescaler != null) { // B = ALG.mult(this.U, B); B = ColtUtils.diagonalMatrixMult(this.U, B); } int nOfColumns = B.columns(); // copy final double[][] Y = B.copy().toArray(); // Solve LY = B (same as L.Yc = Bc for every column of Y and B) for (int j = 0; j < dim; j++) { final double[] LTJ = LcolumnsValues[j]; for (int col = 0; col < nOfColumns; col++) { Y[j][col] /= LTJ[0];// the diagonal of the matrix L final double YJCol = Y[j][col]; if (Double.compare(YJCol, 0.) != 0) { for (int i = j + 1; i < dim; i++) { Y[i][col] -= YJCol * LTJ[i - j]; } } } } // Solve L[T].X = Y (same as L[T].Xc = Yc for every column of X and Y) final DoubleMatrix2D X = F2.make(dim, nOfColumns); for (int i = dim - 1; i > -1; i--) { final double[] LTI = LcolumnsValues[i]; double[] sum = new double[nOfColumns]; for (int col = 0; col < nOfColumns; col++) { for (int j = dim - 1; j > i; j--) { sum[col] += LTI[j - i] * X.getQuick(j, col); } X.setQuick(i, col, (Y[i][col] - sum[col]) / LTI[0]); } } if (this.rescaler != null) { // return ALG.mult(this.U, X); return ColtUtils.diagonalMatrixMult(this.U, X); } else { return X; } }
From source file:com.rascarlo.aurdroid.ui.SearchResultFragment.java
private List<SearchResult> getSortedList(List<SearchResult> searchResultList) { switch (sortOder) { case AurdroidConstants.SORT_BY_PACKAGE_NAME: Collections.sort(searchResultList, (o1, o2) -> o1.getName().compareToIgnoreCase(o2.getName())); break;//from w w w . ja v a 2 s . co m case AurdroidConstants.SORT_BY_VOTES: Collections.sort(searchResultList, (o1, o2) -> Long.compare(Long.parseLong(o2.getNumVotes()), Long.parseLong(o1.getNumVotes()))); break; case AurdroidConstants.SORT_BY_POPULARITY: Collections.sort(searchResultList, (o1, o2) -> Double.compare(Double.parseDouble(o2.getPopularity()), Double.parseDouble(o1.getPopularity()))); break; case AurdroidConstants.SORT_BY_LAST_UPDATED: Collections.sort(searchResultList, (o1, o2) -> Long.compare(Long.parseLong(o2.getLastModified()), Long.parseLong(o1.getLastModified()))); break; case AurdroidConstants.SORT_BY_FIRST_SUBMITTED: Collections.sort(searchResultList, (o1, o2) -> Long.compare(Long.parseLong(o1.getFirstSubmitted()), Long.parseLong(o2.getFirstSubmitted()))); break; default: Collections.sort(searchResultList, (o1, o2) -> o1.getName().compareToIgnoreCase(o2.getName())); break; } return searchResultList; }
From source file:com.google.android.apps.location.gps.gnsslogger.PlotFragment.java
private List<GnssMeasurement> sortByCarrierToNoiseRatio(List<GnssMeasurement> measurements) { Collections.sort(measurements, new Comparator<GnssMeasurement>() { @Override/*from w w w. j ava2 s. c om*/ public int compare(GnssMeasurement o1, GnssMeasurement o2) { return Double.compare(o2.getCn0DbHz(), o1.getCn0DbHz()); } }); return measurements; }
From source file:csci310.parkhere.controller.ClientController.java
public SearchResults sortSearchResultByPrice() { if (searchResults != null) { // ArrayList<ParkingSpot> searchResultList Collections.sort(searchResults.searchResultList, new Comparator<ParkingSpot>() { public int compare(ParkingSpot p1, ParkingSpot p2) { return Double.compare(p1.search_price, p2.search_price); }//from www. ja v a2 s . com }); } return searchResults; }
From source file:edu.byu.nlp.dataset.BasicSparseFeatureVector.java
public static Comparator<Entry> valueComparator() { return new Comparator<Entry>() { @Override// w ww. j av a2s. c o m public int compare(Entry entry1, Entry entry2) { return Double.compare(entry1.getValue(), entry2.getValue()); } }; }
From source file:ml.shifu.shifu.core.dtrain.wdl.WDLWorker.java
/** * Logic to load data into memory list which includes float array for numerical features and sparse object array for * categorical features./*from w w w . j ava 2s . co m*/ */ @Override public void load(GuaguaWritableAdapter<LongWritable> currentKey, GuaguaWritableAdapter<Text> currentValue, WorkerContext<WDLParams, WDLParams> context) { if ((++this.count) % 5000 == 0) { LOG.info("Read {} records.", this.count); } // hashcode for fixed input split in train and validation long hashcode = 0; float[] inputs = new float[this.numInputs]; this.cateInputs = (int) this.columnConfigList.stream().filter(ColumnConfig::isCategorical).count(); SparseInput[] cateInputs = new SparseInput[this.cateInputs]; float ideal = 0f, significance = 1f; int index = 0, numIndex = 0, cateIndex = 0; // use guava Splitter to iterate only once for (String input : this.splitter.split(currentValue.getWritable().toString())) { if (index == this.columnConfigList.size()) { significance = getWeightValue(input); break; // the last field is significance, break here } else { ColumnConfig config = this.columnConfigList.get(index); if (config != null && config.isTarget()) { ideal = getFloatValue(input); } else { // final select some variables but meta and target are not included if (validColumn(config)) { if (config.isNumerical()) { inputs[numIndex] = getFloatValue(input); this.inputIndexMap.putIfAbsent(config.getColumnNum(), numIndex++); } else if (config.isCategorical()) { cateInputs[cateIndex] = new SparseInput(config.getColumnNum(), getCateIndex(input, config)); this.inputIndexMap.putIfAbsent(config.getColumnNum(), cateIndex++); } hashcode = hashcode * 31 + input.hashCode(); } } } index += 1; } // output delimiter in norm can be set by user now and if user set a special one later changed, this exception // is helped to quick find such issue. validateInputLength(context, inputs, numIndex); // sample negative only logic here if (sampleNegOnly(hashcode, ideal)) { return; } // up sampling logic, just add more weights while bagging sampling rate is still not changed if (modelConfig.isRegression() && isUpSampleEnabled() && Double.compare(ideal, 1d) == 0) { // ideal == 1 means positive tags; sample + 1 to avoid sample count to 0 significance = significance * (this.upSampleRng.sample() + 1); } Data data = new Data(inputs, cateInputs, significance, ideal); // split into validation and training data set according to validation rate boolean isInTraining = this.addDataPairToDataSet(hashcode, data, context.getAttachment()); // update some positive or negative selected count in metrics this.updateMetrics(data, isInTraining); }
From source file:nz.co.senanque.sandbox.ObjectTest.java
@Test public void testDefaults() throws Exception { ValidationSession validationSession = m_validationEngine.createSession(); // create a customer Customer customer = m_customerDAO.createCustomer(); assertEquals("400", customer.getAmountstr()); assertEquals(0, Double.compare(400D, customer.getAmount())); customer.setName("aaaab"); assertEquals(true, customer.getMetadata().isUnknown("address")); validationSession.bind(customer);//www . ja va 2 s . co m assertEquals(true, customer.getMetadata().isUnknown("address")); customer.setAddress("whatever"); assertEquals(false, customer.getMetadata().isUnknown("address")); assertEquals(true, customer.getMetadata().getProxyField("amountstr").isRequired()); validationSession.close(); }