List of usage examples for java.util Collections max
public static <T extends Object & Comparable<? super T>> T max(Collection<? extends T> coll)
From source file:cfa.vo.iris.sed.ExtSed.java
public void checkChar() { for (int i = 0; i < this.getNumberOfSegments(); i++) { Segment segment = this.getSegment(i); List<Double> spectral; try {/* w w w .j a v a2s .c o m*/ spectral = Arrays.asList(ArrayUtils.toObject(segment.getSpectralAxisValues())); double min = Collections.min(spectral); double max = Collections.max(spectral); segment.createChar().createSpectralAxis().createCoverage().createBounds().createRange().createMin() .setValue(min); segment.createChar().createSpectralAxis().createCoverage().createBounds().createRange().createMax() .setValue(max); segment.createChar().createSpectralAxis().createCoverage().createBounds().createExtent() .setValue(max - min); } catch (SedNoDataException ex) { Logger.getLogger(ExtSed.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:reader.ArgumentUnitTCReader.java
@Override public void initialize(UimaContext context) throws ResourceInitializationException { super.initialize(context); // read input file with texts (= argument units) and labels labels = new ArrayList<String>(); texts = new ArrayList<String>(); Iterator<Map<String, Object>> documentsIterator; try {/*ww w.ja v a 2 s . com*/ String inputString = FileUtils.readFileToString(this.inputFile); JSONParser jsonParser = new JSONParser(); @SuppressWarnings("unchecked") ArrayList<Map<String, Object>> jsonTexts = new ArrayList<Map<String, Object>>( (List<Map<String, Object>>) jsonParser.parse(inputString)); documentsIterator = jsonTexts.iterator(); while (documentsIterator.hasNext()) { Map<String, Object> jsonData = documentsIterator.next(); @SuppressWarnings("unchecked") List<Map<String, Object>> userAnnotations = (List<Map<String, Object>>) jsonData .get(JsonCorpusUtil.USER_ANNOTATIONS); for (Map<String, Object> userAnnotation : userAnnotations) { String annotator = (String) userAnnotation.get(JsonCorpusUtil.ANNOTATOR); if (annotator.equals(this.annotator)) { String htmlText = (String) jsonData.get(JsonCorpusUtil.TEXT); org.jsoup.nodes.Document cleanedText = Jsoup.parse(htmlText); String rawDocumentText = cleanedText.text(); Map<Integer, Token> idxToTokenMapping = this.createIndexToTokenMapping(rawDocumentText); @SuppressWarnings("unchecked") List<String> argUnits = (List<String>) userAnnotation .get(JsonCorpusUtil.ARGUMENTATION_UNITS); for (String argUnit : argUnits) { //System.out.println("au: " +argUnit); String cleanedArgUnit = argUnit.replaceAll("\\s+", ""); Matcher matcher = JsonCorpusUtil.getRecognitionPattern().matcher(cleanedArgUnit); if (!matcher.matches()) { this.getLogger() .warn(String.format( "argument unit %s does not match the expected pattern %s", cleanedArgUnit, JsonCorpusUtil.getRecognitionPattern().pattern())); } else { // ************************************************** // coordinates of an argument unit: String label = matcher.group(1); String stringIndices = matcher.group(3).replaceAll("^,", ""); List<Integer> indices = CollectionUtils.parseIntList(stringIndices, ","); int firstIndex = Collections.min(indices); Token firstToken = idxToTokenMapping.get(firstIndex); int lastIndex = Collections.max(indices); Token lastToken = idxToTokenMapping.get(lastIndex); //String text = getArgunitText(firstIndex, lastIndex); // ***************************************************** String generalizedLabel = getGeneralizedLabel(label); // Read argument unit as dummy Paragraph annotation to get the text JCas dummyJCas = JCasFactory.createJCas(); dummyJCas.setDocumentText(rawDocumentText); Paragraph para = new Paragraph(dummyJCas, firstToken.getBegin(), lastToken.getEnd()); //System.out.println("argument unit text: " +para.getCoveredText()); texts.add(para.getCoveredText()); labels.add(generalizedLabel); //System.out.println("annotator: " +annotator); System.out.println("label: " + label + " general label: " + generalizedLabel); } // matching was ok } // for argUnit : argUnits } // if annotator.equals(this.annotator) } // for user annotation } // while hasNext } catch (final IOException e) { throw new ResourceInitializationException(e); } catch (final ParseException e) { throw new ResourceInitializationException(e); } catch (UIMAException e) { throw new ResourceInitializationException(e); } offset = 0; System.out.println("number of AUs: " + texts.size()); }
From source file:hu.ppke.itk.nlpg.purepos.decoder.BeamedViterbi.java
private HashMap<NGram<Integer>, Node> prune(final HashMap<NGram<Integer>, Node> beam) { HashMap<NGram<Integer>, Node> ret = new HashMap<NGram<Integer>, Node>(); // System.err.println(beam); // try {//from w w w.ja v a 2 s. c om Node maxNode = Collections.max(beam.values()); Double max = maxNode.getWeight(); for (NGram<Integer> key : beam.keySet()) { Node actNode = beam.get(key); Double actVal = actNode.getWeight(); if (!(actVal < max - logTheta)) { ret.put(key, actNode); } } // } catch (Exception e) { // e.printStackTrace(); // System.err.println(beam); // } return ret; }
From source file:com.mycompany.complexity.tool.mvn.TreeLayoutDois.java
private int calculateDimensionY(Collection<V> roots) { int size = 0; List<Integer> maxSize = new ArrayList<>(); for (V v : roots) { int childrenNum = graph.getSuccessors(v).size(); if (childrenNum != 0) { for (V element : graph.getSuccessors(v)) { if (!alreadyCalculatedY.contains(element)) { alreadyCalculatedY.add(element); size += calculateDimensionY(element) + distY; }/*w w w . java2 s . c om*/ } } size = Math.max(0, size - distY); maxSize.add(size); } return Collections.max(maxSize); }
From source file:be.ugent.maf.cellmissy.analysis.singlecell.preprocessing.impl.SingleCellConditionPreProcessorImpl.java
@Override public void generateRawCoordinatesRanges(SingleCellConditionDataHolder singleCellConditionDataHolder) { singleCellConditionDataHolder.getSingleCellWellDataHolders().stream() .forEach((singleCellWellDataHolder) -> { singleCellWellPreProcessor.generateRawCoordinatesRanges(singleCellWellDataHolder); });//from w w w. jav a 2 s. c o m Double[][] transposedMatrix = AnalysisUtils .transpose2DArray(singleCellConditionDataHolder.getRawTrackCoordinatesMatrix()); // compute the min and the max coordinates Double xMin = Collections.min(Arrays.asList(transposedMatrix[0])); Double xMax = Collections.max(Arrays.asList(transposedMatrix[0])); Double yMin = Collections.min(Arrays.asList(transposedMatrix[1])); Double yMax = Collections.max(Arrays.asList(transposedMatrix[1])); Double[][] rawCoordinatesRanges = new Double[2][2]; rawCoordinatesRanges[0] = new Double[] { xMin, xMax }; rawCoordinatesRanges[1] = new Double[] { yMin, yMax }; singleCellConditionDataHolder.setRawCoordinatesRanges(rawCoordinatesRanges); }
From source file:org.apache.accumulo.server.master.tableOps.CompactionDriver.java
@Override public long isReady(long tid, Master master) throws Exception { String zCancelID = Constants.ZROOT + "/" + HdfsZooInstance.getInstance().getInstanceID() + Constants.ZTABLES + "/" + tableId + Constants.ZTABLE_COMPACT_CANCEL_ID; IZooReaderWriter zoo = ZooReaderWriter.getRetryingInstance(); if (Long.parseLong(new String(zoo.getData(zCancelID, null))) >= compactId) { // compaction was canceled throw new ThriftTableOperationException(tableId, null, TableOperation.COMPACT, TableOperationExceptionType.OTHER, "Compaction canceled"); }/*www. j a v a2s.c o m*/ MapCounter<TServerInstance> serversToFlush = new MapCounter<TServerInstance>(); Connector conn = master.getConnector(); Scanner scanner = new IsolatedScanner(conn.createScanner(MetadataTable.NAME, Authorizations.EMPTY)); Range range = new KeyExtent(new Text(tableId), null, startRow == null ? null : new Text(startRow)) .toMetadataRange(); if (tableId.equals(MetadataTable.ID)) range = range.clip(new Range(RootTable.EXTENT.getMetadataEntry(), false, null, true)); scanner.setRange(range); TabletsSection.ServerColumnFamily.COMPACT_COLUMN.fetch(scanner); TabletsSection.ServerColumnFamily.DIRECTORY_COLUMN.fetch(scanner); scanner.fetchColumnFamily(TabletsSection.CurrentLocationColumnFamily.NAME); long t1 = System.currentTimeMillis(); RowIterator ri = new RowIterator(scanner); int tabletsToWaitFor = 0; int tabletCount = 0; while (ri.hasNext()) { Iterator<Entry<Key, Value>> row = ri.next(); long tabletCompactID = -1; TServerInstance server = null; Entry<Key, Value> entry = null; while (row.hasNext()) { entry = row.next(); Key key = entry.getKey(); if (TabletsSection.ServerColumnFamily.COMPACT_COLUMN.equals(key.getColumnFamily(), key.getColumnQualifier())) tabletCompactID = Long.parseLong(entry.getValue().toString()); if (TabletsSection.CurrentLocationColumnFamily.NAME.equals(key.getColumnFamily())) server = new TServerInstance(entry.getValue(), key.getColumnQualifier()); } if (tabletCompactID < compactId) { tabletsToWaitFor++; if (server != null) serversToFlush.increment(server, 1); } tabletCount++; Text tabletEndRow = new KeyExtent(entry.getKey().getRow(), (Text) null).getEndRow(); if (tabletEndRow == null || (endRow != null && tabletEndRow.compareTo(new Text(endRow)) >= 0)) break; } long scanTime = System.currentTimeMillis() - t1; Instance instance = master.getInstance(); Tables.clearCache(instance); if (tabletCount == 0 && !Tables.exists(instance, tableId)) throw new ThriftTableOperationException(tableId, null, TableOperation.COMPACT, TableOperationExceptionType.NOTFOUND, null); if (serversToFlush.size() == 0 && Tables.getTableState(instance, tableId) == TableState.OFFLINE) throw new ThriftTableOperationException(tableId, null, TableOperation.COMPACT, TableOperationExceptionType.OFFLINE, null); if (tabletsToWaitFor == 0) return 0; for (TServerInstance tsi : serversToFlush.keySet()) { try { final TServerConnection server = master.getConnection(tsi); if (server != null) server.compact(master.getMasterLock(), tableId, startRow, endRow); } catch (TException ex) { Logger.getLogger(CompactionDriver.class).error(ex.toString()); } } long sleepTime = 500; if (serversToFlush.size() > 0) sleepTime = Collections.max(serversToFlush.values()) * sleepTime; // make wait time depend on the server with the most to // compact sleepTime = Math.max(2 * scanTime, sleepTime); sleepTime = Math.min(sleepTime, 30000); return sleepTime; }
From source file:wef.articulab.view.ui.BNXYPlot.java
public void setDataset(ArrayList<Double>[] behaviors, double threshhold, String nameBehActivated, double activation) { this.behaviors = behaviors; this.thresholds.add(threshhold); this.activations.add(new Object[] { nameBehActivated, activation }); maxThreshold = Collections.max(thresholds); minThreshold = Collections.min(thresholds); if (activation > maxActivation) { maxActivation = activation;/*from ww w . j a va 2s .c om*/ } double portion = (maxThreshold - minThreshold) / 6; if ((portion * 6) > (maxActivation / 4)) { maxThreshold = threshhold + portion > maxThreshold ? maxThreshold : threshhold + portion; minThreshold = threshhold - portion < minThreshold ? minThreshold : threshhold - portion; } refreshDataset(); chart.fireChartChanged(); }
From source file:Simulator.PerformanceCalculation.java
JPanel minmaxwaitTime2(boolean minCheck) { LinkedHashSet no = new LinkedHashSet(); LinkedHashMap<Integer, ArrayList<Double>> wait1 = new LinkedHashMap<>(); for (Map.Entry<Integer, TraceObject> entry : l.getLocalTrace().entrySet()) { TraceObject traceObject = entry.getValue(); if (wait1.get(traceObject.getSurgeonId()) == null) { ArrayList details = new ArrayList(); details.add(traceObject.getWaitTime2()); wait1.put(traceObject.getSurgeonId(), details); } else {// ww w . ja v a 2 s . c o m wait1.get(traceObject.getSurgeonId()).add(traceObject.getWaitTime2()); } no.add(traceObject.getSurgeonId()); } XYSeriesCollection dataset = new XYSeriesCollection(); LinkedHashMap<Integer, Double> average = new LinkedHashMap<>(); for (Map.Entry<Integer, ArrayList<Double>> entry : wait1.entrySet()) { Integer integer = entry.getKey(); ArrayList<Double> arrayList = entry.getValue(); double value = 0; if (minCheck) { value = Collections.min(arrayList); value = value / 600; } else { value = Collections.max(arrayList); value = value / 600; } average.put(integer, value); } XYSeries series = new XYSeries("Surgeon Minimum Wait Time 2"); for (int i = 1; i <= average.size(); i++) { series.add(i, average.get(i)); } dataset.addSeries(series); String name; if (minCheck) { name = "Minimum"; } else { name = "Maximum"; } // Generate the graph JFreeChart chart = ChartFactory.createXYLineChart(name + " Wait Time 2 For Patients", // Title "Surgeon ID", // x-axis Label "Time (Days)", // y-axis Label dataset, // Dataset PlotOrientation.VERTICAL, // Plot Orientation true, // Show Legend true, // Use tooltips false // Configure chart to generate URLs? ); XYPlot xyPlot = (XYPlot) chart.getPlot(); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) xyPlot.getRenderer(); renderer.setBaseShapesVisible(true); NumberAxis domain = (NumberAxis) xyPlot.getDomainAxis(); domain.setVerticalTickLabels(true); return new ChartPanel(chart); }
From source file:org.wso2.carbon.ml.model.internal.SparkModelService.java
/** * @param algorithmType Type of the machine learning algorithm - e.g. Classification * @param userResponse User's response to a questionnaire about machine learning task * @return Map containing names of recommended machine learning algorithms and * recommendation scores (out of 5) for each algorithm */// w ww. j a v a2 s. c om public Map<String, Double> getRecommendedAlgorithms(String algorithmType, Map<String, String> userResponse) { Map<String, Double> recommendations = new HashMap<String, Double>(); List<MLAlgorithm> algorithms = new ArrayList(); for (MLAlgorithm mlAlgorithm : mlAlgorithms.getAlgorithms()) { if (algorithmType.equals(mlAlgorithm.getType())) { algorithms.add(mlAlgorithm); } } for (MLAlgorithm mlAlgorithm : algorithms) { if (HIGH.equals(userResponse.get(INTERPRETABILITY))) { mlAlgorithm.setInterpretability(mlAlgorithm.getInterpretability() * 5); } else if (MEDIUM.equals(userResponse.get(INTERPRETABILITY))) { mlAlgorithm.setInterpretability(mlAlgorithm.getInterpretability() * 3); } else { mlAlgorithm.setInterpretability(5); } if (LARGE.equals(userResponse.get(DATASET_SIZE))) { mlAlgorithm.setScalability(mlAlgorithm.getScalability() * 5); } else if (MEDIUM.equals(userResponse.get(DATASET_SIZE))) { mlAlgorithm.setScalability(mlAlgorithm.getScalability() * 3); } else if (SMALL.equals(userResponse.get(DATASET_SIZE))) { mlAlgorithm.setScalability(5); } if (YES.equals(userResponse.get(TEXTUAL))) { mlAlgorithm.setDimensionality(mlAlgorithm.getDimensionality() * 3); } else { mlAlgorithm.setDimensionality(5); } recommendations.put(mlAlgorithm.getName(), (double) (mlAlgorithm.getDimensionality() + mlAlgorithm.getInterpretability() + mlAlgorithm.getScalability())); } Double max = Collections.max(recommendations.values()); DecimalFormat ratingNumberFormat = new DecimalFormat(DECIMAL_FORMAT); Double scaledRating; for (Map.Entry<String, Double> recommendation : recommendations.entrySet()) { scaledRating = ((recommendation.getValue()) / max) * 5; scaledRating = Double.valueOf(ratingNumberFormat.format(scaledRating)); recommendations.put(recommendation.getKey(), scaledRating); } return recommendations; }
From source file:org.mifos.customers.client.business.ClientPerformanceHistoryEntity.java
public Short getMaxLoanCycleForProduct(final PrdOfferingBO prdOffering) { {//from www .j a va2s. c om Set<LoanCounter> clientLoanCounters = getLoanCounters(); try { Collection<Short> loanCyclesForProduct = select(clientLoanCounters, new Predicate<LoanCounter>() { @Override public boolean evaluate(LoanCounter counter) { return counter.isOfSameProduct(prdOffering); } }, TRANSFORM_LOAN_COUNTER_TO_LOAN_CYCLE); return loanCyclesForProduct.isEmpty() ? SHORT_ZERO : Collections.max(loanCyclesForProduct); } catch (Exception e) { return SHORT_ZERO; } } }