List of usage examples for java.lang Double compareTo
public int compareTo(Double anotherDouble)
From source file:gov.nih.nci.ncicb.cadsr.bulkloader.util.excel.DBExcelUtility.java
public boolean compareExcelRow(ExcelRow erow, ArrayList cmp, String coltype[]) throws Exception { int numberOfColumns = coltype.length; short col = 0; boolean nodata = true; Object data[] = erow.getData(); for (int i = 0; i < numberOfColumns; i++) { Object odata = (Object) cmp.get(i); if (data[i] == null && odata == null) { continue; }// ww w . ja va 2 s . com if ((data[i] == null && odata != null) || (data[i] != null && odata == null)) { return false; } if (coltype[i].equalsIgnoreCase(DataType.TYPE_STRING)) { String cdata = (String) cmp.get(i); if (!cdata.equalsIgnoreCase((String) data[i])) { return false; } } else if (coltype[i].equalsIgnoreCase(DataType.TYPE_INTEGER)) { Integer idata = (Integer) cmp.get(i); Integer cidata = (Integer) data[i]; if (idata.compareTo(cidata) != 0) { return false; } } else if (coltype[i].equalsIgnoreCase(DataType.TYPE_DOUBLE)) { Double ddata = (Double) cmp.get(i); Double cddata = (Double) data[i]; if (ddata.compareTo(cddata) != 0) { return false; } } else if (coltype[i].equalsIgnoreCase(DataType.TYPE_BOOLEAN)) { Boolean bdata = (Boolean) cmp.get(i); Boolean cbdata = (Boolean) data[i]; if (bdata.booleanValue() != cbdata.booleanValue()) { return false; } } else if (coltype[i].equalsIgnoreCase(DataType.TYPE_DATE)) { Date dtval = (Date) cmp.get(i); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); //Date cdtval = sdf.parse(data[i]); Date cdtval = (Date) data[i]; Calendar cal1 = Calendar.getInstance(); Calendar cal2 = Calendar.getInstance(); cal1.setTime(dtval); cal2.setTime(cdtval); if (cal1.get(Calendar.YEAR) != cal2.get(Calendar.YEAR) || cal1.get(Calendar.MONTH) != cal2.get(Calendar.MONTH) || cal1.get(Calendar.DATE) != cal2.get(Calendar.DATE)) { return false; } } } return true; }
From source file:com.intuit.tank.runner.method.RequestRunner.java
private int compare(String actualValue, String expected) { if (NumberUtils.isNumber(actualValue) && NumberUtils.isNumber(expected)) { Double a = NumberUtils.toDouble(actualValue); Double e = NumberUtils.toDouble(expected); return a.compareTo(e); }//from w ww .ja va 2s . c o m return actualValue.compareTo(expected); }
From source file:org.mrgeo.colorscale.ColorScale.java
public boolean equals(final ColorScale cs) { if (min == null && cs.min != null || min != null && cs.min == null) { return false; }// w ww . ja va2 s .com if ((min != null && cs.min != null) && Double.compare(min, cs.min) != 0) { return false; } if (max == null && cs.max != null || max != null && cs.max == null) { return false; } if ((max != null && cs.max != null) && Double.compare(max, cs.max) != 0) { return false; } if (!scaling.equals(cs.scaling)) { return false; } if (interpolate != cs.interpolate) { return false; } if (forceValuesIntoRange != cs.forceValuesIntoRange) { return false; } if (reliefShading != cs.reliefShading) { return false; } if (nullColor.length != cs.nullColor.length) { return false; } for (int i = 0; i < nullColor.length; i++) { if (nullColor[i] != cs.nullColor[i]) { return false; } } if (size() != cs.size()) { return false; } final Iterator<Double> iterator1 = cs.keySet().iterator(); for (final Double d1 : this.keySet()) { final Double d2 = iterator1.next(); if (d1.compareTo(d2) != 0) { return false; } final Color value1 = get(d1); final Color value2 = get(d2); if (!value1.equals(value2)) { return false; } } return true; }
From source file:org.fao.geonet.kernel.search.LuceneSearcher.java
/** * Create an XML summary from the search facets collector. * /*from ww w.ja va2 s . c om*/ * @param elSummary The element in which to add the facet report * @param summaryConfigValues The summary configuration * @param facetCollector * @param langCode * @throws IOException */ private static void buildFacetSummary(Element elSummary, Map<String, FacetConfig> summaryConfigValues, FacetsCollector facetCollector, String langCode) throws IOException { DecimalFormat doubleFormat = new DecimalFormat("0"); try { for (Iterator<FacetResult> iterator = facetCollector.getFacetResults().iterator(); iterator .hasNext();) { FacetResult result = (FacetResult) iterator.next(); String label = result.getFacetResultNode().getLabel().toString(); FacetConfig config = summaryConfigValues.get(label); String facetName = config.getPlural(); Translator translator; if (ServiceContext.get() != null) { try { ServiceContext context = ServiceContext.get(); translator = config.getTranslator(context, langCode); } catch (Exception e) { throw new RuntimeException(e); } } else { translator = Translator.NULL_TRANSLATOR; } Element facets = new Element(facetName); FacetResultNode frn = result.getFacetResultNode(); if (frn.getNumSubResults() != 0) { Map<String, Double> facetValues = new LinkedHashMap<String, Double>(); // facetValues = new TreeMap<String, Double>(comparator) for (Iterator subresults = frn.getSubResults().iterator(); subresults.hasNext();) { FacetResultNode node = (FacetResultNode) subresults.next(); facetValues.put(node.getLabel().components[node.getLabel().length - 1], node.getValue()); } List<Entry<String, Double>> entries = new ArrayList<Entry<String, Double>>( facetValues.entrySet()); if (Log.isDebugEnabled(Geonet.FACET_ENGINE)) { Log.debug(Geonet.FACET_ENGINE, facetName + ":\tSorting facet by " + config.getSortBy().toString() + " (" + config.getSortOrder().toString() + ")"); } // No need for a custom comparator Lucene facet request is // made by count descending order if (Facet.SortBy.COUNT != config.getSortBy()) { Comparator c = null; if (Facet.SortBy.NUMVALUE == config.getSortBy()) { // Create a numeric comparator c = new Comparator<Entry<String, Double>>() { public int compare(final Entry<String, Double> e1, final Entry<String, Double> e2) { try { Double d1 = Double.valueOf(e1.getKey()); Double d2 = Double.valueOf(e2.getKey()); return d1.compareTo(d2); } catch (NumberFormatException e) { // String comparison Log.warning(Geonet.FACET_ENGINE, "Failed to compare numeric values (" + e1.getKey() + " / " + e2.getKey() + ") for facet. Check sortBy option in summary configuration."); return e1.getKey().compareTo(e2.getKey()); } } }; } else { c = new Comparator<Entry<String, Double>>() { public int compare(final Entry<String, Double> e1, final Entry<String, Double> e2) { return e1.getKey().compareTo(e2.getKey()); } }; } Collections.sort(entries, c); if (Facet.SortOrder.DESCENDING == config.getSortOrder()) { Collections.reverse(entries); } } for (Entry<String, Double> entry : entries) { String facetValue = entry.getKey(); String facetCount = doubleFormat.format(entry.getValue()); if (Log.isDebugEnabled(Geonet.FACET_ENGINE)) { Log.debug(Geonet.FACET_ENGINE, " - " + facetValue + " (" + facetCount + ")"); } String translatedValue = translator.translate(facetValue); Element facet = new Element(config.getName()); facet.setAttribute("count", facetCount); facet.setAttribute("name", facetValue); if (translatedValue != null) { facet.setAttribute("label", translatedValue); } facets.addContent(facet); } } elSummary.addContent(facets); } } catch (ArrayIndexOutOfBoundsException e) { Log.error(Geonet.FACET_ENGINE, "Check facet configuration. This may happen when a facet is configured" + " but does not exist in the taxonomy index. Error is: " + e.getMessage(), e); e.printStackTrace(); } }
From source file:org.geworkbench.engine.ccm.ComponentConfigurationManager.java
public void removeOutVersionedFoldersFromCwbFileList() { List<File> tmpCwbFiles = new ArrayList<File>(); boolean foundNewerVersion = false; for (int i = 0; i < cwbFile.size(); i++) { foundNewerVersion = false;/*from w ww.ja va 2s . com*/ File file1 = cwbFile.get(i); String cwbFileName1 = file1.getName(); for (int j = 0; j < cwbFile.size(); j++) { if (i == j) { continue; } File file2 = cwbFile.get(j); String cwbFileName2 = file2.getName(); if (cwbFileName1.equals(cwbFileName2)) { String folder1 = resourceFolder(file1); int versionIndex1 = folder1.indexOf("."); Double version1 = new Double(0.0); int folder1length = folder1.length(); if (versionIndex1 > -1 && folder1length >= versionIndex1 + 1) { try { version1 = new Double(folder1.substring(versionIndex1 + 1)); } catch (Exception e) { version1 = new Double(0.0); } } String folder2 = resourceFolder(file2); int versionIndex2 = folder2.indexOf("."); Double version2 = new Double(0.0); int folder2length = folder2.length(); if (versionIndex2 > -1 && folder2length >= versionIndex2 + 1) { try { String ver = folder2.substring(versionIndex2 + 1); version2 = new Double(ver); } catch (Exception e) { version2 = new Double(0.0); } } if (version2.compareTo(version1) > 0) { foundNewerVersion = true; break; } } } if (foundNewerVersion) { continue; } tmpCwbFiles.add(file1); } cwbFile = tmpCwbFiles; }
From source file:org.geworkbench.engine.ccm.ComponentConfigurationManagerWindow2.java
private void findAvailableUpdatesFromTomcat() { installedRow = initialRow;/*from w w w . ja v a2 s. c om*/ // String url = System.getProperty("remote_components_config_url"); //remote_components_config_url=http://califano11.cgc.cpmc.columbia.edu:8080/componentRepository/deploycomponents.txt GlobalPreferences prefs = GlobalPreferences.getInstance(); String url = prefs.getRCM_URL().trim(); if (url == null || url == "") { log.info("No Remote Component Manager URL configured."); return; } url += "/deploycomponents.txt"; HttpClient client = new HttpClient(); client.getHttpConnectionManager().getParams().setConnectionTimeout(3000); GetMethod method = new GetMethod(url); method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false)); method.setFollowRedirects(true); try { int statusCode = client.executeMethod(method); if (statusCode != HttpStatus.SC_OK) { JOptionPane.showMessageDialog(null, "No updates are available at this time.\nPlease try again later.", "Remote Component Update", JOptionPane.PLAIN_MESSAGE); return; } String deploycomponents = method.getResponseBodyAsString(); // String[] rows = deploycomponents.split("\\r\\n"); String[] folderNameVersions = deploycomponents.split("\\r\\n"); for (int i = 0; i < ccmTableModel.getModelRowCount(); i++) { String localFolderName = ccmTableModel.getResourceFolder(i); String localVersion = ((String) ccmTableModel.getModelValueAt(i, CCMTableModel2.VERSION_INDEX)); Double dLocalVersion = new Double(localVersion); for (int j = 0; j < folderNameVersions.length; j++) { String[] cols = folderNameVersions[j].split(","); String remoteFolderName = cols[0]; String remoteVersion = cols[1]; Double dRemoteVersion = new Double(remoteVersion); if (localFolderName.equalsIgnoreCase(remoteFolderName)) { if (dRemoteVersion.compareTo(dLocalVersion) > 0) { ccmTableModel.setModelValueAt(remoteVersion, i, CCMTableModel2.AVAILABLE_UPDATE_INDEX, CCMTableModel2.NO_VALIDATION); } } } } } catch (HttpException e) { JOptionPane.showMessageDialog(null, "No updates are available at this time.\nPlease try again later.", "Remote Component Update", JOptionPane.PLAIN_MESSAGE); //e.printStackTrace(); return; } catch (IOException e) { JOptionPane.showMessageDialog(null, e.getMessage() + ".\n(" + e.getClass().getName() + ")\nPlease try again later.", "No Update Available", JOptionPane.PLAIN_MESSAGE); //e.printStackTrace(); return; } catch (Exception e) { // IllegalArgumentException JOptionPane.showMessageDialog(null, e.getMessage() + ".", "No Update Available", JOptionPane.PLAIN_MESSAGE); } }
From source file:org.apache.carbondata.core.scan.filter.FilterUtil.java
private static int compareFilterMembersBasedOnActualDataType(String filterMember1, String filterMember2, DataType dataType) {// w w w .ja v a 2s . c om try { if (dataType == DataTypes.SHORT || dataType == DataTypes.INT || dataType == DataTypes.LONG || dataType == DataTypes.DOUBLE) { if (CarbonCommonConstants.MEMBER_DEFAULT_VAL.equals(filterMember1)) { return 1; } Double d1 = Double.parseDouble(filterMember1); Double d2 = Double.parseDouble(filterMember2); return d1.compareTo(d2); } else if (DataTypes.isDecimal(dataType)) { if (CarbonCommonConstants.MEMBER_DEFAULT_VAL.equals(filterMember1)) { return 1; } java.math.BigDecimal val1 = new BigDecimal(filterMember1); java.math.BigDecimal val2 = new BigDecimal(filterMember2); return val1.compareTo(val2); } else if (dataType == DataTypes.DATE || dataType == DataTypes.TIMESTAMP) { if (CarbonCommonConstants.MEMBER_DEFAULT_VAL.equals(filterMember1)) { return 1; } String format = null; if (dataType == DataTypes.DATE) { format = CarbonProperties.getInstance().getProperty(CarbonCommonConstants.CARBON_DATE_FORMAT, CarbonCommonConstants.CARBON_DATE_DEFAULT_FORMAT); } else { format = CarbonProperties.getInstance().getProperty( CarbonCommonConstants.CARBON_TIMESTAMP_FORMAT, CarbonCommonConstants.CARBON_TIMESTAMP_DEFAULT_FORMAT); } SimpleDateFormat parser = new SimpleDateFormat(format); Date date1 = null; Date date2 = null; date1 = parser.parse(filterMember1); date2 = parser.parse(filterMember2); return date1.compareTo(date2); } else { return filterMember1.compareTo(filterMember2); } } catch (ParseException | NumberFormatException e) { return -1; } }
From source file:be.hogent.tarsos.util.histogram.Histogram.java
/** * Returns the cumulative frequency of values less than or equal to v. * <p>//w w w . j a v a2 s . c o m * Returns 0 if v is not comparable to the values set. * </p> * <p> * Uses code from <a href="http://commons.apache.org/math">Apache Commons * Math"</a> licensed to the Apache Software Foundation (ASF) under one or * more contributor license agreements. * </p> * * @param v * the value to lookup. * @return the proportion of values equal to v */ public long getCumFreq(final Double v) { long cumulativeFreq = -1; if (getSumFreq() == 0) { cumulativeFreq = 0; } else if (v.compareTo(freqTable.firstKey()) < 0) { cumulativeFreq = 0; } else if (v.compareTo(freqTable.lastKey()) >= 0) { cumulativeFreq = getSumFreq(); } else { // the frequency of this key long result = 0; final Long value = freqTable.get(v); if (value != null) { result = value.longValue(); } // add the frequencies of values smaller than this key final Iterator<Double> values = freqTable.keySet().iterator(); while (values.hasNext()) { final Double nextValue = values.next(); if (v.compareTo(nextValue) > 0) { result += getCount(nextValue); } else { cumulativeFreq = result; break; } } } if (cumulativeFreq == -1) { throw new AssertionError("The key is greather than te last key but this is impossible." + " It should have been returned already."); } return cumulativeFreq; }
From source file:ml.shifu.shifu.core.validator.ModelInspector.java
/** * Check the setting for model training. * It will make sure (num_of_layers > 0 * && num_of_layers = hidden_nodes_size * && num_of_layse = active_func_size) * /*from w w w .ja v a 2 s . com*/ * @param train * - @ModelTrainConf to check * @return @ValidateResult */ @SuppressWarnings("unchecked") private ValidateResult checkTrainSetting(ModelConfig modelConfig, ModelTrainConf train) { ValidateResult result = new ValidateResult(true); if (train.getBaggingNum() == null || train.getBaggingNum() < 0) { ValidateResult tmpResult = new ValidateResult(true); tmpResult.setStatus(false); tmpResult.getCauses().add("Bagging number should be greater than zero in train configuration"); result = ValidateResult.mergeResult(result, tmpResult); } if (train.getNumKFold() != null && train.getNumKFold() > 20) { ValidateResult tmpResult = new ValidateResult(true); tmpResult.setStatus(false); tmpResult.getCauses().add("numKFold should be in (0, 20] or <=0 (not dp k-crossValidation)"); result = ValidateResult.mergeResult(result, tmpResult); } if (train.getBaggingSampleRate() == null || train.getBaggingSampleRate().compareTo(Double.valueOf(0)) <= 0 || train.getBaggingSampleRate().compareTo(Double.valueOf(1)) > 0) { ValidateResult tmpResult = new ValidateResult(true); tmpResult.setStatus(false); tmpResult.getCauses().add("Bagging sample rate number should be in (0, 1]."); result = ValidateResult.mergeResult(result, tmpResult); } if (train.getValidSetRate() == null || train.getValidSetRate().compareTo(Double.valueOf(0)) < 0 || train.getValidSetRate().compareTo(Double.valueOf(1)) >= 0) { ValidateResult tmpResult = new ValidateResult(true); tmpResult.setStatus(false); tmpResult.getCauses().add("Validation set rate number should be in [0, 1)."); result = ValidateResult.mergeResult(result, tmpResult); } if (train.getNumTrainEpochs() == null || train.getNumTrainEpochs() <= 0) { ValidateResult tmpResult = new ValidateResult(true); tmpResult.setStatus(false); tmpResult.getCauses().add("Epochs should be larger than 0."); result = ValidateResult.mergeResult(result, tmpResult); } if (train.getEpochsPerIteration() != null && train.getEpochsPerIteration() <= 0) { ValidateResult tmpResult = new ValidateResult(true); tmpResult.setStatus(false); tmpResult.getCauses().add("'epochsPerIteration' should be larger than 0 if set."); result = ValidateResult.mergeResult(result, tmpResult); } if (train.getWorkerThreadCount() != null && (train.getWorkerThreadCount() <= 0 || train.getWorkerThreadCount() > 32)) { ValidateResult tmpResult = new ValidateResult(true); tmpResult.setStatus(false); tmpResult.getCauses().add("'workerThreadCount' should be in (0, 32] if set."); result = ValidateResult.mergeResult(result, tmpResult); } if (train.getConvergenceThreshold() != null && train.getConvergenceThreshold().compareTo(0.0) < 0) { ValidateResult tmpResult = new ValidateResult(true); tmpResult.setStatus(false); tmpResult.getCauses().add("'threshold' should be larger than or equal to 0.0 if set."); result = ValidateResult.mergeResult(result, tmpResult); } if (modelConfig.isClassification() && train.isOneVsAll() && !CommonUtils.isTreeModel(train.getAlgorithm()) && !train.getAlgorithm().equalsIgnoreCase("nn")) { ValidateResult tmpResult = new ValidateResult(true); tmpResult.setStatus(false); tmpResult.getCauses() .add("'one vs all' or 'one vs rest' is only enabled with 'RF' or 'GBT' or 'NN' algorithm"); result = ValidateResult.mergeResult(result, tmpResult); } if (modelConfig.isClassification() && train.getMultiClassifyMethod() == MultipleClassification.NATIVE && train.getAlgorithm().equalsIgnoreCase(CommonConstants.RF_ALG_NAME)) { Object impurity = train.getParams().get("Impurity"); if (impurity != null && !"entropy".equalsIgnoreCase(impurity.toString()) && !"gini".equalsIgnoreCase(impurity.toString())) { ValidateResult tmpResult = new ValidateResult(true); tmpResult.setStatus(false); tmpResult.getCauses() .add("Impurity should be in [entropy,gini] if native mutiple classification in RF."); result = ValidateResult.mergeResult(result, tmpResult); } } GridSearch gs = new GridSearch(train.getParams(), train.getGridConfigFileContent()); // such parameter validation only in regression and not grid search mode if (modelConfig.isRegression() && !gs.hasHyperParam()) { if (train.getAlgorithm().equalsIgnoreCase("nn")) { Map<String, Object> params = train.getParams(); Object loss = params.get("Loss"); if (loss != null && !"log".equalsIgnoreCase(loss.toString()) && !"squared".equalsIgnoreCase(loss.toString()) && !"absolute".equalsIgnoreCase(loss.toString())) { ValidateResult tmpResult = new ValidateResult(true); tmpResult.setStatus(false); tmpResult.getCauses().add("Loss should be in [log,squared,absolute]."); result = ValidateResult.mergeResult(result, tmpResult); } Object TFloss = params.get("TF.loss"); if (TFloss != null && !"squared".equalsIgnoreCase(TFloss.toString()) && !"absolute".equalsIgnoreCase(TFloss.toString()) && !"log".equalsIgnoreCase(TFloss.toString())) { ValidateResult tmpResult = new ValidateResult(true); tmpResult.setStatus(false); tmpResult.getCauses().add("Loss should be in [log,squared,absolute]."); result = ValidateResult.mergeResult(result, tmpResult); } Object TFOptimizer = params.get("TF.optimizer"); if (TFOptimizer != null && !"adam".equalsIgnoreCase(TFOptimizer.toString()) && !"gradientDescent".equalsIgnoreCase(TFOptimizer.toString()) && !"RMSProp".equalsIgnoreCase(TFOptimizer.toString())) { ValidateResult tmpResult = new ValidateResult(true); tmpResult.setStatus(false); tmpResult.getCauses().add("tensorflow optimizer should be in [RMSProp,gradientDescent,adam]."); result = ValidateResult.mergeResult(result, tmpResult); } int layerCnt = (Integer) params.get(CommonConstants.NUM_HIDDEN_LAYERS); if (layerCnt < 0) { ValidateResult tmpResult = new ValidateResult(true); tmpResult.setStatus(false); tmpResult.getCauses().add("The number of hidden layers should be >= 0 in train configuration"); result = ValidateResult.mergeResult(result, tmpResult); } List<Integer> hiddenNode = (List<Integer>) params.get(CommonConstants.NUM_HIDDEN_NODES); List<String> activateFucs = (List<String>) params.get(CommonConstants.ACTIVATION_FUNC); if (hiddenNode.size() != activateFucs.size() || layerCnt != activateFucs.size()) { ValidateResult tmpResult = new ValidateResult(true); tmpResult.setStatus(false); tmpResult.getCauses() .add(CommonConstants.NUM_HIDDEN_LAYERS + "/SIZE(" + CommonConstants.NUM_HIDDEN_NODES + ")" + "/SIZE(" + CommonConstants.ACTIVATION_FUNC + ")" + " should be equal in train configuration"); result = ValidateResult.mergeResult(result, tmpResult); } Double learningRate = Double.valueOf(params.get(CommonConstants.LEARNING_RATE).toString()); if (learningRate != null && (learningRate.compareTo(Double.valueOf(0)) <= 0)) { ValidateResult tmpResult = new ValidateResult(true); tmpResult.setStatus(false); tmpResult.getCauses().add("Learning rate should be larger than 0."); result = ValidateResult.mergeResult(result, tmpResult); } Object learningDecayO = params.get(CommonConstants.LEARNING_DECAY); if (learningDecayO != null) { Double learningDecay = Double.valueOf(learningDecayO.toString()); if (learningDecay != null && ((learningDecay.compareTo(Double.valueOf(0)) < 0) || (learningDecay.compareTo(Double.valueOf(1)) >= 0))) { ValidateResult tmpResult = new ValidateResult(true); tmpResult.setStatus(false); tmpResult.getCauses().add("Learning decay should be in [0, 1) if set."); result = ValidateResult.mergeResult(result, tmpResult); } } Object dropoutObj = params.get(CommonConstants.DROPOUT_RATE); if (dropoutObj != null) { Double dropoutRate = Double.valueOf(dropoutObj.toString()); if (dropoutRate != null && (dropoutRate < 0d || dropoutRate >= 1d)) { ValidateResult tmpResult = new ValidateResult(true); tmpResult.setStatus(false); tmpResult.getCauses().add("Dropout rate should be in [0, 1)."); result = ValidateResult.mergeResult(result, tmpResult); } } Object fixedLayersObj = params.get(CommonConstants.FIXED_LAYERS); if (fixedLayersObj != null) { List<Integer> fixedLayers = (List<Integer>) fixedLayersObj; for (int layer : fixedLayers) { if (layer <= 0 || layer > (layerCnt + 1)) { ValidateResult tmpResult = new ValidateResult(true); tmpResult.setStatus(false); tmpResult.getCauses().add("Fixed layer id " + layer + " is invaild. It should be between 0 and hidden layer cnt + output layer:" + (layerCnt + 1)); result = ValidateResult.mergeResult(result, tmpResult); } } } Object miniBatchsO = params.get(CommonConstants.MINI_BATCH); if (miniBatchsO != null) { Integer miniBatchs = Integer.valueOf(miniBatchsO.toString()); if (miniBatchs != null && (miniBatchs <= 0 || miniBatchs > 1000)) { ValidateResult tmpResult = new ValidateResult(true); tmpResult.setStatus(false); tmpResult.getCauses().add("MiniBatchs should be in (0, 1000] if set."); result = ValidateResult.mergeResult(result, tmpResult); } } Object momentumO = params.get("Momentum"); if (momentumO != null) { Double momentum = Double.valueOf(momentumO.toString()); if (momentum != null && momentum <= 0d) { ValidateResult tmpResult = new ValidateResult(true); tmpResult.setStatus(false); tmpResult.getCauses().add("Momentum should be in (0, ) if set."); result = ValidateResult.mergeResult(result, tmpResult); } } Object adamBeta1O = params.get("AdamBeta1"); if (adamBeta1O != null) { Double adamBeta1 = Double.valueOf(adamBeta1O.toString()); if (adamBeta1 != null && (adamBeta1 <= 0d || adamBeta1 >= 1d)) { ValidateResult tmpResult = new ValidateResult(true); tmpResult.setStatus(false); tmpResult.getCauses().add("AdamBeta1 should be in (0, 1) if set."); result = ValidateResult.mergeResult(result, tmpResult); } } Object adamBeta2O = params.get("AdamBeta2"); if (adamBeta2O != null) { Double adamBeta2 = Double.valueOf(adamBeta2O.toString()); if (adamBeta2 != null && (adamBeta2 <= 0d || adamBeta2 >= 1d)) { ValidateResult tmpResult = new ValidateResult(true); tmpResult.setStatus(false); tmpResult.getCauses().add("AdamBeta2 should be in (0, 1) if set."); result = ValidateResult.mergeResult(result, tmpResult); } } } if (train.getAlgorithm().equalsIgnoreCase(CommonConstants.GBT_ALG_NAME) || train.getAlgorithm().equalsIgnoreCase(CommonConstants.RF_ALG_NAME) || train.getAlgorithm().equalsIgnoreCase(NNConstants.NN_ALG_NAME)) { Map<String, Object> params = train.getParams(); Object fssObj = params.get("FeatureSubsetStrategy"); if (fssObj == null) { if (train.getAlgorithm().equalsIgnoreCase(CommonConstants.GBT_ALG_NAME) || train.getAlgorithm().equalsIgnoreCase(CommonConstants.RF_ALG_NAME)) { ValidateResult tmpResult = new ValidateResult(true); tmpResult.setStatus(false); tmpResult.getCauses().add("FeatureSubsetStrategy is not set in RF/GBT algorithm."); result = ValidateResult.mergeResult(result, tmpResult); } } else { boolean isNumber = false; double doubleFss = 0; try { doubleFss = Double.parseDouble(fssObj.toString()); isNumber = true; } catch (Exception e) { isNumber = false; } if (isNumber) { // if not in [0, 1] failed if (doubleFss <= 0d || doubleFss > 1d) { ValidateResult tmpResult = new ValidateResult(true); tmpResult.setStatus(false); tmpResult.getCauses().add("FeatureSubsetStrategy if double should be in (0, 1]"); result = ValidateResult.mergeResult(result, tmpResult); } } else { boolean fssInEnum = false; for (FeatureSubsetStrategy fss : FeatureSubsetStrategy.values()) { if (fss.toString().equalsIgnoreCase(fssObj.toString())) { fssInEnum = true; break; } } if (!fssInEnum) { ValidateResult tmpResult = new ValidateResult(true); tmpResult.setStatus(false); tmpResult.getCauses().add( "FeatureSubsetStrategy if string should be in ['ALL', 'HALF', 'ONETHIRD' , 'TWOTHIRDS' , 'AUTO' , 'SQRT' , 'LOG2']"); result = ValidateResult.mergeResult(result, tmpResult); } } } } if (train.getAlgorithm().equalsIgnoreCase(CommonConstants.GBT_ALG_NAME) || train.getAlgorithm().equalsIgnoreCase(CommonConstants.RF_ALG_NAME)) { Map<String, Object> params = train.getParams(); if (train.getAlgorithm().equalsIgnoreCase(CommonConstants.GBT_ALG_NAME)) { Object loss = params.get("Loss"); if (loss != null && !"log".equalsIgnoreCase(loss.toString()) && !"squared".equalsIgnoreCase(loss.toString()) && !"halfgradsquared".equalsIgnoreCase(loss.toString()) && !"absolute".equalsIgnoreCase(loss.toString())) { ValidateResult tmpResult = new ValidateResult(true); tmpResult.setStatus(false); tmpResult.getCauses().add("Loss should be in [log,squared,halfgradsquared,absolute]."); result = ValidateResult.mergeResult(result, tmpResult); } if (loss == null) { ValidateResult tmpResult = new ValidateResult(true); tmpResult.setStatus(false); tmpResult.getCauses() .add("'Loss' parameter isn't being set in train#parameters in GBT training."); result = ValidateResult.mergeResult(result, tmpResult); } } Object maxDepthObj = params.get("MaxDepth"); if (maxDepthObj != null) { int maxDepth = Integer.valueOf(maxDepthObj.toString()); if (maxDepth <= 0 || maxDepth > 20) { ValidateResult tmpResult = new ValidateResult(true); tmpResult.setStatus(false); tmpResult.getCauses().add("MaxDepth should in [1, 20]."); result = ValidateResult.mergeResult(result, tmpResult); } } Object vtObj = params.get("ValidationTolerance"); if (vtObj != null) { double validationTolerance = Double.valueOf(vtObj.toString()); if (validationTolerance < 0d || validationTolerance >= 1d) { ValidateResult tmpResult = new ValidateResult(true); tmpResult.setStatus(false); tmpResult.getCauses().add("ValidationTolerance should in [0, 1)."); result = ValidateResult.mergeResult(result, tmpResult); } } Object maxLeavesObj = params.get("MaxLeaves"); if (maxLeavesObj != null) { int maxLeaves = Integer.valueOf(maxLeavesObj.toString()); if (maxLeaves <= 0) { ValidateResult tmpResult = new ValidateResult(true); tmpResult.setStatus(false); tmpResult.getCauses().add("MaxLeaves should in [1, Integer.MAX_VALUE]."); result = ValidateResult.mergeResult(result, tmpResult); } } if (maxDepthObj == null && maxLeavesObj == null) { ValidateResult tmpResult = new ValidateResult(true); tmpResult.setStatus(false); tmpResult.getCauses().add( "'MaxDepth' or 'MaxLeaves' parameters at least one of both should be set in train#parameters in GBT training."); result = ValidateResult.mergeResult(result, tmpResult); } Object maxStatsMemoryMBObj = params.get("MaxStatsMemoryMB"); if (maxStatsMemoryMBObj != null) { int maxStatsMemoryMB = Integer.valueOf(maxStatsMemoryMBObj.toString()); if (maxStatsMemoryMB <= 0) { ValidateResult tmpResult = new ValidateResult(true); tmpResult.setStatus(false); tmpResult.getCauses().add("MaxStatsMemoryMB should > 0."); result = ValidateResult.mergeResult(result, tmpResult); } } Object dropoutObj = params.get(CommonConstants.DROPOUT_RATE); if (dropoutObj != null) { Double dropoutRate = Double.valueOf(dropoutObj.toString()); if (dropoutRate != null && (dropoutRate < 0d || dropoutRate >= 1d)) { ValidateResult tmpResult = new ValidateResult(true); tmpResult.setStatus(false); tmpResult.getCauses().add("Dropout rate should be in [0, 1)."); result = ValidateResult.mergeResult(result, tmpResult); } } if (train.getAlgorithm().equalsIgnoreCase(CommonConstants.GBT_ALG_NAME)) { Object learningRateObj = params.get(CommonConstants.LEARNING_RATE); if (learningRateObj != null) { Double learningRate = Double.valueOf(learningRateObj.toString()); if (learningRate != null && (learningRate.compareTo(Double.valueOf(0)) <= 0)) { ValidateResult tmpResult = new ValidateResult(true); tmpResult.setStatus(false); tmpResult.getCauses().add("Learning rate should be larger than 0."); result = ValidateResult.mergeResult(result, tmpResult); } } else { ValidateResult tmpResult = new ValidateResult(true); tmpResult.setStatus(false); tmpResult.getCauses().add( "'LearningRate' parameter isn't being set in train#parameters in GBT training."); result = ValidateResult.mergeResult(result, tmpResult); } } Object minInstancesPerNodeObj = params.get("MinInstancesPerNode"); if (minInstancesPerNodeObj != null) { int minInstancesPerNode = Integer.valueOf(minInstancesPerNodeObj.toString()); if (minInstancesPerNode <= 0) { ValidateResult tmpResult = new ValidateResult(true); tmpResult.setStatus(false); tmpResult.getCauses().add("MinInstancesPerNode should > 0."); result = ValidateResult.mergeResult(result, tmpResult); } } else { ValidateResult tmpResult = new ValidateResult(true); tmpResult.setStatus(false); tmpResult.getCauses().add( "'MinInstancesPerNode' parameter isn't be set in train#parameters in GBT/RF training."); result = ValidateResult.mergeResult(result, tmpResult); } Object treeNumObj = params.get("TreeNum"); if (treeNumObj != null) { int treeNum = Integer.valueOf(treeNumObj.toString()); if (treeNum <= 0 || treeNum > 10000) { ValidateResult tmpResult = new ValidateResult(true); tmpResult.setStatus(false); tmpResult.getCauses().add("TreeNum should be in [1, 10000]."); result = ValidateResult.mergeResult(result, tmpResult); } } else { ValidateResult tmpResult = new ValidateResult(true); tmpResult.setStatus(false); tmpResult.getCauses() .add("'TreeNum' parameter isn't being set in train#parameters in GBT/RF training."); result = ValidateResult.mergeResult(result, tmpResult); } Object minInfoGainObj = params.get("MinInfoGain"); if (minInfoGainObj != null) { Double minInfoGain = Double.valueOf(minInfoGainObj.toString()); if (minInfoGain != null && (minInfoGain.compareTo(Double.valueOf(0)) < 0)) { ValidateResult tmpResult = new ValidateResult(true); tmpResult.setStatus(false); tmpResult.getCauses().add("MinInfoGain should be >= 0."); result = ValidateResult.mergeResult(result, tmpResult); } } else { ValidateResult tmpResult = new ValidateResult(true); tmpResult.setStatus(false); tmpResult.getCauses() .add("'MinInfoGain' parameter isn't be set in train#parameters in GBT/RF training."); result = ValidateResult.mergeResult(result, tmpResult); } Object impurityObj = params.get("Impurity"); if (impurityObj == null) { ValidateResult tmpResult = new ValidateResult(true); tmpResult.setStatus(false); tmpResult.getCauses().add("Impurity is not set in RF/GBT algorithm."); result = ValidateResult.mergeResult(result, tmpResult); } else { if (train.getAlgorithm().equalsIgnoreCase(CommonConstants.GBT_ALG_NAME)) { if (impurityObj != null && !"variance".equalsIgnoreCase(impurityObj.toString()) && !"friedmanmse".equalsIgnoreCase(impurityObj.toString())) { ValidateResult tmpResult = new ValidateResult(true); tmpResult.setStatus(false); tmpResult.getCauses().add("GBDT only supports 'variance|friedmanmse' impurity type."); result = ValidateResult.mergeResult(result, tmpResult); } } if (train.getAlgorithm().equalsIgnoreCase(CommonConstants.RF_ALG_NAME)) { if (impurityObj != null && !"friedmanmse".equalsIgnoreCase(impurityObj.toString()) && !"entropy".equalsIgnoreCase(impurityObj.toString()) && !"variance".equalsIgnoreCase(impurityObj.toString()) && !"gini".equalsIgnoreCase(impurityObj.toString())) { ValidateResult tmpResult = new ValidateResult(true); tmpResult.setStatus(false); tmpResult.getCauses() .add("RF supports 'variance|entropy|gini|friedmanmse' impurity types."); result = ValidateResult.mergeResult(result, tmpResult); } } } } } return result; }
From source file:com.clustercontrol.jobmanagement.factory.JobSessionJobImpl.java
/** * ??Double???????//from w w w . ja v a 2 s .c om * @param value1 1 * @param value2 2 * @return ? */ private int checkDecisionValue(String value1, String value2) { Double dValue01 = Double.parseDouble(value1); Double dValue02 = Double.parseDouble(value2); return dValue01.compareTo(dValue02); }