List of usage examples for java.util TreeMap put
public V put(K key, V value)
From source file:it.uniroma2.sag.kelp.learningalgorithm.clustering.kernelbasedkmeans.KernelBasedKMeansEngine.java
/** * Count the reassignment as a stopping criteria for the algorithm * //w w w . ja v a2s .c o m * @param exampleIdToClusterMap * The map of assignment for the previous iteration * @param clusterList * The actual clusters * @return */ private int countReassigment(TreeMap<Long, Integer> exampleIdToClusterMap, List<Cluster> clusterList) { int reassignment = 0; TreeMap<Long, Integer> currentExampleIdToClusterMap = new TreeMap<Long, Integer>(); int clusterId = 0; for (Cluster cluster : clusterList) { for (ClusterExample clusterExample : cluster.getExamples()) { currentExampleIdToClusterMap.put(clusterExample.getExample().getId(), clusterId); } clusterId++; } for (Long currentExId : currentExampleIdToClusterMap.keySet()) { if (exampleIdToClusterMap.get(currentExId).intValue() != currentExampleIdToClusterMap.get(currentExId) .intValue()) reassignment++; } return reassignment; }
From source file:com.joliciel.jochre.boundaries.SplitCandidateFinderImpl.java
@Override public List<Split> findSplitCandidates(Shape shape) { List<Split> splitCandidates = new ArrayList<Split>(); // generate a list giving the total distance from the top and bottom to the shape's edge // the hypothesis is that splits almost always occur at x-coordinates // where there's a summit in the distance to the shape's edge, between two valleys int[] edgeDistances = new int[shape.getWidth()]; int[][] verticalContour = shape.getVerticalContour(); for (int x = 0; x < shape.getWidth(); x++) { int edgeDistance = verticalContour[x][0] + ((shape.getHeight() - 1) - verticalContour[x][1]); if (edgeDistance > shape.getHeight() - 1) edgeDistance = shape.getHeight() - 1; edgeDistances[x] = edgeDistance; }//from www.ja v a 2 s . co m int[] maximaMinima = new int[shape.getWidth()]; int lastDistance = -1; boolean rising = true; int i = 0; for (int edgeDistance : edgeDistances) { if (lastDistance >= 0) { if (edgeDistance < lastDistance && rising) { maximaMinima[i - 1] = 1; } if (edgeDistance > lastDistance && !rising) { maximaMinima[i - 1] = -1; } } if (edgeDistance > lastDistance) { rising = true; } else if (edgeDistance < lastDistance) { rising = false; } lastDistance = edgeDistance; i++; } maximaMinima[0] = 1; if (rising) maximaMinima[shape.getWidth() - 1] = 1; else maximaMinima[shape.getWidth() - 1] = -1; for (int x = 0; x < shape.getWidth(); x++) { String maxMin = ""; if (maximaMinima[x] < 0) maxMin = " min"; if (maximaMinima[x] > 0) maxMin = " max"; LOG.trace("edgeDistance[" + x + "]: " + edgeDistances[x] + maxMin); } boolean haveMinimum = false; int lastMaximum = -1; int lastMinValue = 0; int lastMaxValue = 0; TreeSet<SplitCandidateValue> splitCandidateValues = new TreeSet<SplitCandidateFinderImpl.SplitCandidateValue>(); for (i = 0; i < shape.getWidth(); i++) { if (maximaMinima[i] < 0) { haveMinimum = true; if (lastMaximum > 0) { double diff = (double) ((lastMaxValue - lastMinValue) + (lastMaxValue - edgeDistances[i])) / 2.0; splitCandidateValues.add(new SplitCandidateValue(lastMaximum, diff)); } lastMinValue = edgeDistances[i]; } if (maximaMinima[i] > 0) { if (haveMinimum) { lastMaximum = i; lastMaxValue = edgeDistances[i]; } haveMinimum = false; } } List<SplitCandidateValue> candidatesToRemove = new ArrayList<SplitCandidateFinderImpl.SplitCandidateValue>(); for (SplitCandidateValue thisValue : splitCandidateValues) { if (candidatesToRemove.contains(thisValue)) continue; for (SplitCandidateValue otherValue : splitCandidateValues) { if (candidatesToRemove.contains(otherValue)) continue; if (otherValue.equals(thisValue)) break; int distance = thisValue.getPosition() - otherValue.getPosition(); if (distance < 0) distance = 0 - distance; if (distance < this.minDistanceBetweenSplits) { LOG.trace("Removing candidate " + otherValue.getPosition() + ", distance=" + distance); candidatesToRemove.add(otherValue); } } } splitCandidateValues.removeAll(candidatesToRemove); TreeMap<Integer, Split> splitCandidateMap = new TreeMap<Integer, Split>(); for (SplitCandidateValue candidateValue : splitCandidateValues) { Split splitCandidate = boundaryServiceInternal.getEmptySplit(shape); splitCandidate.setPosition(candidateValue.getPosition()); splitCandidateMap.put(candidateValue.getPosition(), splitCandidate); } for (Split split : splitCandidateMap.values()) splitCandidates.add(split); return splitCandidates; }
From source file:com.activequant.server.web.MainController.java
@RequestMapping("/server") public String server(Map<String, Object> map) { Properties properties = new Properties(); try {//from w w w .j ava 2 s. c o m properties.load(new FileInputStream("framework.properties")); } catch (IOException e) { e.printStackTrace(); } TreeMap<String, Object> tmap2 = new TreeMap<String, Object>(); for (Object s : properties.keySet()) { String key = (String) s; tmap2.put(key, properties.get(key)); } properties = new Properties(); try { properties.load(new FileInputStream("aq2server.properties")); } catch (IOException e) { e.printStackTrace(); } TreeMap<String, Object> tmap = new TreeMap<String, Object>(); for (Object s : properties.keySet()) { String key = (String) s; tmap.put(key, properties.get(key)); } map.put("framework", tmap2); map.put("aq2server", tmap); return "server"; }
From source file:com.uber.hoodie.common.model.HoodieTableMetadata.java
/** * Returns all the commit metadata for this table. Reads all the commit files from HDFS. * Expensive operation, use with caution. * * @return SortedMap of CommitTime,HoodieCommitMetadata *//*ww w. j av a 2 s .c o m*/ public SortedMap<String, HoodieCommitMetadata> getAllCommitMetadata() { try { TreeMap<String, HoodieCommitMetadata> metadataMap = new TreeMap<>(); for (String commitTs : commits.getCommitList()) { metadataMap.put(commitTs, getCommitMetadata(commitTs)); } return Collections.unmodifiableSortedMap(metadataMap); } catch (IOException e) { throw new HoodieIOException("Could not load all commits for table " + getTableName(), e); } }
From source file:ANNFileDetect.EncogTestClass.java
private void createReport(TreeMap<Double, Integer> ht, String file) throws IOException { TreeMap<Integer, ArrayList<Double>> tm = new TreeMap<Integer, ArrayList<Double>>(); for (Map.Entry<Double, Integer> entry : ht.entrySet()) { if (tm.containsKey(entry.getValue())) { ArrayList<Double> al = (ArrayList<Double>) tm.get(entry.getValue()); al.add(entry.getKey());/*from w ww.ja v a 2 s . c om*/ tm.put(entry.getValue(), al); } else { ArrayList<Double> al = new ArrayList<Double>(); al.add(entry.getKey()); tm.put(entry.getValue(), al); } } String[] tmpfl = file.split("/"); if (tmpfl.length < 2) tmpfl = file.split("\\\\"); String crp = tmpfl[tmpfl.length - 1]; String[] actfl = crp.split("\\."); FileWriter fstream = new FileWriter("tempTrainingFiles/" + actfl[1].toUpperCase() + actfl[0] + ".txt"); BufferedWriter fileto = new BufferedWriter(fstream); int size = tm.size(); int cnt = 0; for (Map.Entry<Integer, ArrayList<Double>> entry : tm.entrySet()) { if (cnt > (size - 10) && entry.getKey() > 2 && entry.getValue().size() < 20) { double tmpval = ((double) entry.getKey()) / filebytes; fileto.write("Times: " + tmpval + " Values: "); for (Double dbl : entry.getValue()) { fileto.write(dbl + " "); } fileto.write("\n"); } cnt++; } fileto.close(); }
From source file:be.cytomine.client.HttpClient.java
public void authorize(String action, String url, String contentType, String accept) throws IOException { url = url.replace(host, ""); url = url.replace("http://" + host, ""); url = url.replace("https://" + host, ""); TreeMap<String, String> headers = new TreeMap<String, String>(); headers.put("accept", accept); headers.put("date", getActualDateStr()); log.debug("AUTHORIZE: " + action + "\\n\\n" + contentType + "\\n" + headers.get("date") + "\n"); String canonicalHeaders = action + "\n\n" + contentType + "\n" + headers.get("date") + "\n"; String messageToSign = canonicalHeaders + url; log.debug("publicKey=" + publicKey); log.debug("privateKey=" + privateKey); log.debug("messageToSign=" + messageToSign); SecretKeySpec privateKeySign = new SecretKeySpec(privateKey.getBytes(), "HmacSHA1"); try {//w w w.j a v a2 s . c o m Mac mac = Mac.getInstance("HmacSHA1"); mac.init(privateKeySign); byte[] rawHmac = mac.doFinal(new String(messageToSign.getBytes(), "UTF-8").getBytes()); byte[] signatureBytes = Base64.encodeBase64(rawHmac); String signature = new String(signatureBytes); String authorization = "CYTOMINE " + publicKey + ":" + signature; log.debug("signature=" + signature); log.debug("authorization=" + authorization); headers.put("authorization", authorization); for (String key : headers.keySet()) { addHeader(key, headers.get(key)); } } catch (GeneralSecurityException e) { throw new IOException(e); } }
From source file:org.powertac.accounting.AccountingServiceTests.java
@Test public void testInterestInitialization() { TreeMap<String, String> map = new TreeMap<String, String>(); map.put("accounting.accountingService.minInterest", "0.01"); map.put("accounting.accountingService.maxInterest", "0.20"); map.put("accounting.accountingService.bankInterest", "0.008"); Configuration mapConfig = new MapConfiguration(map); config.setConfiguration(mapConfig);/*from w w w . ja v a 2 s. com*/ accountingService.initialize(comp, new ArrayList<String>()); assertEquals("correct bank interest", 0.008, accountingService.getBankInterest(), 1e-6); }
From source file:gsn.wrappers.general.CSVHandler.java
public TreeMap<String, Serializable> convertTo(String[] formats, String[] fields, String nullValues[], String[] values, char separator) { TreeMap<String, Serializable> streamElement = new TreeMap<String, Serializable>( new CaseInsensitiveComparator()); for (String field : fields) streamElement.put(field, null); HashMap<String, String> timeStampFormats = new HashMap<String, String>(); for (int i = 0; i < Math.min(fields.length, values.length); i++) { if (isNull(nullValues, values[i])) { continue; } else if (formats[i].equalsIgnoreCase("numeric")) { try { streamElement.put(fields[i], Double.parseDouble(values[i])); } catch (java.lang.NumberFormatException e) { logger.error("Parsing to Numeric failed: Value to parse=" + values[i]); throw e; }/*w w w .j av a 2 s .c om*/ } else if (formats[i].equalsIgnoreCase("string")) { streamElement.put(fields[i], values[i]); } else if (formats[i].equalsIgnoreCase("bigint")) { try { streamElement.put(fields[i], Long.parseLong(values[i])); } catch (java.lang.NumberFormatException e) { logger.error("Parsing to BigInt failed: Value to parse=" + values[i]); throw e; } } else if (isTimeStampFormat(formats[i])) { String value = ""; String format = ""; if (streamElement.get(fields[i]) != null) { value = (String) streamElement.get(fields[i]); format = timeStampFormats.get(fields[i]); value += separator; format += separator; } if (isTimeStampLeftPaddedFormat(formats[i])) values[i] = StringUtils.leftPad(values[i], getTimeStampFormat(formats[i]).length(), '0'); value += values[i]; format += getTimeStampFormat(formats[i]); streamElement.put(fields[i], value); timeStampFormats.put(fields[i], format); } } for (String timeField : timeStampFormats.keySet()) { String timeFormat = timeStampFormats.get(timeField); String timeValue = (String) streamElement.get(timeField); try { DateTime x = DateTimeFormat.forPattern(timeFormat).withZone(getTimeZone()).parseDateTime(timeValue); streamElement.put(timeField, x.getMillis()); } catch (IllegalArgumentException e) { logger.error("Parsing error: TimeFormat=" + timeFormat + " , TimeValue=" + timeValue); logger.error(e.getMessage(), e); throw e; } } return streamElement; }
From source file:io.pravega.client.stream.mock.MockController.java
private StreamSegments getCurrentSegments(Stream stream) { List<Segment> segmentsInStream = getSegmentsForStream(stream); TreeMap<Double, Segment> segments = new TreeMap<>(); double increment = 1.0 / segmentsInStream.size(); for (int i = 0; i < segmentsInStream.size(); i++) { segments.put((i + 1) * increment, new Segment(stream.getScope(), stream.getStreamName(), i)); }/*from w w w.j av a2 s . c o m*/ return new StreamSegments(segments); }
From source file:org.powertac.accounting.AccountingServiceTests.java
@Test public void testMaxMinInitialization() { TreeMap<String, String> map = new TreeMap<String, String>(); map.put("accounting.accountingService.minInterest", "0.01"); map.put("accounting.accountingService.maxInterest", "0.20"); Configuration mapConfig = new MapConfiguration(map); config.setConfiguration(mapConfig);/*www. jav a 2 s . com*/ String result = accountingService.initialize(comp, new ArrayList<String>()); assertEquals("correct return value", "AccountingService", result); assertEquals("correct min value", 0.01, accountingService.getMinInterest(), 1e-6); assertEquals("correct max value", 0.20, accountingService.getMaxInterest(), 1e-6); assertTrue("correct bank interest", accountingService.getMinInterest() <= accountingService.getBankInterest()); assertTrue("correct bank interest", accountingService.getMaxInterest() >= accountingService.getBankInterest()); }