List of usage examples for java.util Collections min
public static <T extends Object & Comparable<? super T>> T min(Collection<? extends T> coll)
From source file:com.compomics.cell_coord.computation.impl.TrackOperatorImpl.java
@Override public void computeShiftedCoordinatesRanges(Track track) { Double[][] shiftedCoordinates = track.getShiftedCoordinates(); Double[][] transpCoord = ComputationUtils.transpose2DArray(shiftedCoordinates); List<Double> xCoordAsList = Arrays.asList(transpCoord[0]); List<Double> yCoordAsList = Arrays.asList(transpCoord[1]); Double xMin = Collections.min(xCoordAsList); Double xMax = Collections.max(xCoordAsList); Double yMin = Collections.min(yCoordAsList); Double yMax = Collections.max(yCoordAsList); Double[][] shiftedCoordRanges = new Double[][] { { xMin, xMax }, { yMin, yMax } }; track.setShiftedCoordinateRanges(shiftedCoordRanges); }
From source file:edu.cornell.mannlib.vitro.webapp.visualization.coprincipalinvestigator.CoPIVisCodeGenerator.java
/** * This method is used to setup parameters for the sparkline value object. These parameters * will be used in the template to construct the actual html/javascript code. * @param visMode/*from w w w.java 2 s .com*/ * @param visContainer */ private SparklineData setupSparklineParameters(String visMode, String providedVisContainerID) { SparklineData sparklineData = new SparklineData(); int numOfYearsToBeRendered = 0; /* * It was decided that to prevent downward curve that happens if there are no publications * in the current year seems a bit harsh, so we consider only publications from the last 10 * complete years. * */ int currentYear = Calendar.getInstance().get(Calendar.YEAR) - 1; int shortSparkMinYear = currentYear - VisConstants.MINIMUM_YEARS_CONSIDERED_FOR_SPARKLINE + 1; /* * This is required because when deciding the range of years over which * the vis was rendered we dont want to be influenced by the * "DEFAULT_GRANT_YEAR". */ Set<String> investigatedYears = new HashSet<String>(yearToUniqueCoPIs.keySet()); investigatedYears.remove(VOConstants.DEFAULT_GRANT_YEAR); /* * We are setting the default value of minGrantYear to be 10 years * before the current year (which is suitably represented by the * shortSparkMinYear), this in case we run into invalid set of investigated * years. */ int minGrantYear = shortSparkMinYear; String visContainerID = null; if (yearToUniqueCoPIs.size() > 0) { try { minGrantYear = Integer.parseInt(Collections.min(investigatedYears)); } catch (NoSuchElementException e1) { log.debug("vis: " + e1.getMessage() + " error occurred for " + yearToUniqueCoPIs.toString()); } catch (NumberFormatException e2) { log.debug("vis: " + e2.getMessage() + " error occurred for " + yearToUniqueCoPIs.toString()); } } int minGrantYearConsidered = 0; /* * There might be a case that the person investigated his first grant * within the last 10 years but we want to make sure that the sparkline * is representative of at least the last 10 years, so we will set the * minGrantYearConsidered to "currentYear - 10" which is also given by * "shortSparkMinYear". */ if (minGrantYear > shortSparkMinYear) { minGrantYearConsidered = shortSparkMinYear; } else { minGrantYearConsidered = minGrantYear; } numOfYearsToBeRendered = currentYear - minGrantYearConsidered + 1; sparklineData.setNumOfYearsToBeRendered(numOfYearsToBeRendered); int uniqueCoPICounter = 0; Set<Collaborator> allCoPIsWithKnownGrantShipYears = new HashSet<Collaborator>(); List<YearToEntityCountDataElement> yearToUniqueInvestigatorsCountDataTable = new ArrayList<YearToEntityCountDataElement>(); for (int grantYear = minGrantYearConsidered; grantYear <= currentYear; grantYear++) { String grantYearAsString = String.valueOf(grantYear); Set<Collaborator> currentCoPIs = yearToUniqueCoPIs.get(grantYearAsString); Integer currentUniqueCoPIs = null; if (currentCoPIs != null) { currentUniqueCoPIs = currentCoPIs.size(); allCoPIsWithKnownGrantShipYears.addAll(currentCoPIs); } else { currentUniqueCoPIs = 0; } yearToUniqueInvestigatorsCountDataTable.add( new YearToEntityCountDataElement(uniqueCoPICounter, grantYearAsString, currentUniqueCoPIs)); uniqueCoPICounter++; } /* * For the purpose of this visualization I have come up with a term * "Sparks" which essentially means data points. Sparks that will be * rendered in full mode will always be the one's which have any year * associated with it. Hence. */ sparklineData.setRenderedSparks(allCoPIsWithKnownGrantShipYears.size()); sparklineData.setYearToEntityCountDataTable(yearToUniqueInvestigatorsCountDataTable); /* * This is required only for the sparklines which convey collaborationships like * coinvestigatorships and coauthorship. There are edge cases where a collaborator can be * present for in a collaboration with known & unknown year. We do not want to repeat the * count for this collaborator when we present it in the front-end. * */ Set<Collaborator> totalUniqueCoInvestigators = new HashSet<Collaborator>(allCoPIsWithKnownGrantShipYears); /* * Total grants will also consider grants that have no year * associated with them. Hence. */ Integer unknownYearGrants = 0; if (yearToUniqueCoPIs.get(VOConstants.DEFAULT_GRANT_YEAR) != null) { unknownYearGrants = yearToUniqueCoPIs.get(VOConstants.DEFAULT_GRANT_YEAR).size(); totalUniqueCoInvestigators.addAll(yearToUniqueCoPIs.get(VOConstants.DEFAULT_GRANT_YEAR)); } sparklineData.setTotalCollaborationshipCount(totalUniqueCoInvestigators.size()); sparklineData.setUnknownYearGrants(unknownYearGrants); if (providedVisContainerID != null) { visContainerID = providedVisContainerID; } else { visContainerID = DEFAULT_VISCONTAINER_DIV_ID; } sparklineData.setVisContainerDivID(visContainerID); /* * By default these represents the range of the rendered sparks. Only in * case of "short" sparkline mode we will set the Earliest * RenderedGrant year to "currentYear - 10". */ sparklineData.setEarliestYearConsidered(minGrantYearConsidered); sparklineData.setEarliestRenderedGrantYear(minGrantYear); sparklineData.setLatestRenderedGrantYear(currentYear); /* * The Full Sparkline will be rendered by default. Only if the url has * specific mention of SHORT_SPARKLINE_MODE_KEY then we render the short * sparkline and not otherwise. */ if (VisualizationFrameworkConstants.SHORT_SPARKLINE_VIS_MODE.equalsIgnoreCase(visMode)) { sparklineData.setEarliestRenderedGrantYear(shortSparkMinYear); sparklineData.setShortVisMode(true); } else { sparklineData.setShortVisMode(false); } if (yearToUniqueCoPIs.size() > 0) { sparklineData.setFullTimelineNetworkLink(UtilityFunctions.getCollaboratorshipNetworkLink(individualURI, VisualizationFrameworkConstants.PERSON_LEVEL_VIS, VisualizationFrameworkConstants.COPI_VIS_MODE)); sparklineData.setDownloadDataLink( UtilityFunctions.getCSVDownloadURL(individualURI, VisualizationFrameworkConstants.CO_PI_VIS, VisualizationFrameworkConstants.COPIS_COUNT_PER_YEAR_VIS_MODE)); Map<String, Integer> yearToUniqueCoPIsCount = new HashMap<String, Integer>(); for (Map.Entry<String, Set<Collaborator>> currentYearToUniqueCoPIsCount : yearToUniqueCoPIs .entrySet()) { yearToUniqueCoPIsCount.put(currentYearToUniqueCoPIsCount.getKey(), currentYearToUniqueCoPIsCount.getValue().size()); } sparklineData.setYearToActivityCount(yearToUniqueCoPIsCount); } return sparklineData; }
From source file:com.noterik.bart.fs.fscommand.dynamic.playlist.util.SBFile.java
public float getMin(int iCol) { List<Float> b = Arrays.asList(ArrayUtils.toObject(signals.get(iCol))); float min = Collections.min(b); b = null;//from w w w.ja v a2s .c o m return min; }
From source file:be.ugent.maf.cellmissy.gui.controller.analysis.doseresponse.generic.GenericDRNormalizedController.java
/** * Initialize view./*from w ww . j a v a2s . c o m*/ */ @Override protected void initDRNormalizedPanel() { dRNormalizedPlotPanel = new DRNormalizedPlotPanel(); //init chart panel normalizedChartPanel = new ChartPanel(null); normalizedChartPanel.setOpaque(false); /** * Action listeners for buttons */ /** * The combo box determines how the normalization is done. Bottom combo * box defines what the value for 0% response is. */ dRNormalizedPlotPanel.getBottomComboBox().addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String value = (String) dRNormalizedPlotPanel.getBottomComboBox().getSelectedItem(); switch (value) { case "Smallest Mean Value": dRNormalizedPlotPanel.getBottomTextField().setEditable(false); dRNormalizedPlotPanel.getBottomTextField() .setText(AnalysisUtils .roundTwoDecimals(Collections.min(computeMeans(getAllResponses( doseResponseController.getdRAnalysisGroup().getDoseResponseData())))) .toString()); break; case "Smallest Median Value": dRNormalizedPlotPanel.getBottomTextField().setEditable(false); dRNormalizedPlotPanel.getBottomTextField() .setText(AnalysisUtils .roundTwoDecimals(Collections.min(computeMedians(getAllResponses( doseResponseController.getdRAnalysisGroup().getDoseResponseData())))) .toString()); break; case "Other Value": dRNormalizedPlotPanel.getBottomTextField().setText(""); dRNormalizedPlotPanel.getBottomTextField().setEditable(true); break; } } }); /** * The combo box determines how the normalization is done. Top combo box * defines what the value for 100% response is. */ dRNormalizedPlotPanel.getTopComboBox().addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String choice = (String) dRNormalizedPlotPanel.getTopComboBox().getSelectedItem(); switch (choice) { case "Largest Mean Value": dRNormalizedPlotPanel.getTopTextField().setEditable(false); dRNormalizedPlotPanel.getTopTextField() .setText(AnalysisUtils .roundTwoDecimals(Collections.max(computeMeans(getAllResponses( doseResponseController.getdRAnalysisGroup().getDoseResponseData())))) .toString()); break; case "Largest Median Value": dRNormalizedPlotPanel.getTopTextField().setEditable(false); dRNormalizedPlotPanel.getTopTextField() .setText(AnalysisUtils .roundTwoDecimals(Collections.max(computeMedians(getAllResponses( doseResponseController.getdRAnalysisGroup().getDoseResponseData())))) .toString()); break; case "Other Value": dRNormalizedPlotPanel.getTopTextField().setText(""); dRNormalizedPlotPanel.getTopTextField().setEditable(true); break; } } }); /** * If selected, the curve fit 'bottom' parameter will be constrained to * zero. This zero is defined by the text field value during * normalization. * */ dRNormalizedPlotPanel.getBottomConstrainCheckBox().addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { bottomConstrainValue = 0.0; } else { bottomConstrainValue = null; } } }); /** * If selected, the curve fit 'top' parameter will be constrained to * 100. This is defined by the text field value during normalization. * */ dRNormalizedPlotPanel.getTopConstrainCheckBox().addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { topConstrainValue = 100.0; } else { topConstrainValue = null; } } }); /** * Re-normalize and plot new dose-response graph, taking into account * any choices made by the user. */ dRNormalizedPlotPanel.getPlotGraphButton().addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dataToFit = prepareFittingData(doseResponseController.getdRAnalysisGroup().getDoseResponseData(), doseResponseController.getLogTransform()); setTableModel(doseResponseController.updateTableModel(createTableModel(dataToFit))); doseResponseController.updateModelInTable(tableModel); doseResponseController .performFitting( dataToFit, doseResponseController.getdRAnalysisGroup() .getDoseResponseAnalysisResults().getFittingResults(true), bottomConstrainValue, topConstrainValue); doseResponseController.plotDoseResponse(normalizedChartPanel, dRNormalizedPlotPanel.getDoseResponseChartParentPanel(), dataToFit, doseResponseController.getdRAnalysisGroup(), true); //Calculate new statistics doseResponseController.calculateStatistics(); } }); }
From source file:com.opengamma.util.test.DbTest.java
protected static Object[][] getParametersForSeparateMasters(int prevVersionCount) { String databaseType = System.getProperty("test.database.type"); if (databaseType == null) { databaseType = "all"; }//from w w w . j a v a 2s . c om Collection<String> databaseTypes = TestProperties.getDatabaseTypes(databaseType); ArrayList<Object[]> parameters = new ArrayList<Object[]>(); for (String dbType : databaseTypes) { DbTool dbtool = TestProperties.getDbTool(dbType); dbtool.setJdbcUrl(dbtool.getTestDatabaseUrl()); if (isScriptPublished()) { dbtool.addDbScriptDirectory(SCRIPT_INSTALL_DIR.getAbsolutePath()); } else { dbtool.addDbScriptDirectory(DbTool.getWorkingDirectory()); } for (String masterDB : dbtool.getScriptDirs().keySet()) { Set<Integer> versions = dbtool.getScriptDirs().get(masterDB).keySet(); int max = Collections.max(versions); int min = Collections.min(versions); for (int v = max; v >= Math.max(max - prevVersionCount, min); v--) { parameters.add(new Object[] { dbType, masterDB, "" + max /*target_version*/, "" + v /*migrate_from_version*/ }); } } } Object[][] array = new Object[parameters.size()][]; parameters.toArray(array); return array; }
From source file:com.linkedin.drelephant.tez.heuristics.GenericMemoryHeuristic.java
public HeuristicResult apply(TezApplicationData data) { if (!data.getSucceeded()) { return null; }// ww w. j av a 2 s.c om TezTaskData[] tasks = getTasks(data); List<Long> totalPhysicalMemory = new LinkedList<Long>(); List<Long> totalVirtualMemory = new LinkedList<Long>(); List<Long> runTime = new LinkedList<Long>(); for (TezTaskData task : tasks) { if (task.isSampled()) { totalPhysicalMemory.add(task.getCounters().get(TezCounterData.CounterName.PHYSICAL_MEMORY_BYTES)); totalVirtualMemory.add(task.getCounters().get(TezCounterData.CounterName.VIRTUAL_MEMORY_BYTES)); runTime.add(task.getTotalRunTimeMs()); } } long averagePMem = Statistics.average(totalPhysicalMemory); long averageVMem = Statistics.average(totalVirtualMemory); long maxPMem; long minPMem; try { maxPMem = Collections.max(totalPhysicalMemory); minPMem = Collections.min(totalPhysicalMemory); } catch (Exception exception) { maxPMem = 0; minPMem = 0; } long averageRunTime = Statistics.average(runTime); String containerSizeStr; if (!Strings.isNullOrEmpty(data.getConf().getProperty(_containerMemConf))) { containerSizeStr = data.getConf().getProperty(_containerMemConf); } else { containerSizeStr = getContainerMemDefaultMBytes(); } long containerSize = Long.valueOf(containerSizeStr) * FileUtils.ONE_MB; double averageMemMb = (double) ((averagePMem) / FileUtils.ONE_MB); double ratio = averageMemMb / ((double) (containerSize / FileUtils.ONE_MB)); Severity severity; if (tasks.length == 0) { severity = Severity.NONE; } else { severity = getMemoryRatioSeverity(ratio); } HeuristicResult result = new HeuristicResult(_heuristicConfData.getClassName(), _heuristicConfData.getHeuristicName(), severity, Utils.getHeuristicScore(severity, tasks.length)); result.addResultDetail("Number of tasks", Integer.toString(tasks.length)); result.addResultDetail("Maximum Physical Memory (MB)", tasks.length == 0 ? "0" : Long.toString(maxPMem / FileUtils.ONE_MB)); result.addResultDetail("Minimum Physical memory (MB)", tasks.length == 0 ? "0" : Long.toString(minPMem / FileUtils.ONE_MB)); result.addResultDetail("Average Physical Memory (MB)", tasks.length == 0 ? "0" : Long.toString(averagePMem / FileUtils.ONE_MB)); result.addResultDetail("Average Virtual Memory (MB)", tasks.length == 0 ? "0" : Long.toString(averageVMem / FileUtils.ONE_MB)); result.addResultDetail("Average Task RunTime", tasks.length == 0 ? "0" : Statistics.readableTimespan(averageRunTime)); result.addResultDetail("Requested Container Memory (MB)", (tasks.length == 0 || containerSize == 0 || containerSize == -1) ? "0" : String.valueOf(containerSize / FileUtils.ONE_MB)); return result; }
From source file:com.noterik.bart.fs.fscommand.dynamic.playlist.util.SBFile.java
public float[] getMinMax(int iCol) { List<Float> b = Arrays.asList(ArrayUtils.toObject(signals.get(iCol))); float[] minmax = new float[2]; minmax[0] = Collections.min(b); minmax[1] = Collections.max(b); b = null;/* w w w .ja v a 2 s .c o m*/ return minmax; }
From source file:dkpro.similarity.algorithms.lsr.aggregate.MCS06AggregateComparator.java
private double getDirectionalRelatedness(Collection<String> stringList1, Collection<String> stringList2) throws SimilarityException { double weightedSum = 0.0; double idfSum = 0.0; for (String w1 : stringList1) { try {/*from w w w . j a v a 2s . co m*/ w1 = w1.toLowerCase(); } catch (NullPointerException e) { // Ignore continue; } Set<Double> subscores = new HashSet<Double>(); for (String w2 : stringList2) { try { w2 = w2.toLowerCase(); Set<String> wordset = new HashSet<String>(); wordset.add(w1); wordset.add(w2); double score; if (cache.containsKey(wordset)) { score = cache.get(wordset); } else { score = measure.getSimilarity(w1, w2); cache.put(wordset, score); } subscores.add(score); } catch (NullPointerException e) { // Ignore } } // Get best score for the pair (w1, w2) double bestSubscore = 0.0; if (stringList2.size() > 0) { if (measure.isDistanceMeasure()) { bestSubscore = Collections.min(subscores); } else { bestSubscore = Collections.max(subscores); } // Handle error cases such as "not found" if (bestSubscore < 0.0) { bestSubscore = 0.0; } } // Weight double weightedScore; if (idfValues.containsKey(w1)) { weightedScore = bestSubscore * idfValues.get(w1); weightedSum += weightedScore; idfSum += idfValues.get(w1); } else { // Well, ignore this token. //System.out.println("Ignoring token: \"" + w1 + "\""); } } return weightedSum / idfSum; }
From source file:be.ugent.maf.cellmissy.gui.controller.analysis.doseresponse.area.AreaDRNormalizedController.java
/** * Initialize view//from w ww . j av a 2s . com */ @Override protected void initDRNormalizedPanel() { dRNormalizedPlotPanel = new DRNormalizedPlotPanel(); //init chart panel normalizedChartPanel = new ChartPanel(null); normalizedChartPanel.setOpaque(false); /** * Action listeners for buttons */ /** * The combo box determines how the normalization is done. Bottom combo * box defines what the value for 0% response is. */ dRNormalizedPlotPanel.getBottomComboBox().addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String value = (String) dRNormalizedPlotPanel.getBottomComboBox().getSelectedItem(); switch (value) { case "Smallest Mean Value": dRNormalizedPlotPanel.getBottomTextField().setEditable(false); dRNormalizedPlotPanel.getBottomTextField().setText(AnalysisUtils .roundTwoDecimals(Collections.min(computeMeans( doseResponseController.getdRAnalysisGroup().getVelocitiesMap().values()))) .toString()); break; case "Smallest Median Value": dRNormalizedPlotPanel.getBottomTextField().setEditable(false); dRNormalizedPlotPanel.getBottomTextField().setText(AnalysisUtils .roundTwoDecimals(Collections.min(computeMedians( doseResponseController.getdRAnalysisGroup().getVelocitiesMap().values()))) .toString()); break; case "Other Value": dRNormalizedPlotPanel.getBottomTextField().setText(""); dRNormalizedPlotPanel.getBottomTextField().setEditable(true); break; } } }); /** * The combo box determines how the normalization is done. Top combo box * defines what the value for 100% response is. */ dRNormalizedPlotPanel.getTopComboBox().addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String choice = (String) dRNormalizedPlotPanel.getTopComboBox().getSelectedItem(); switch (choice) { case "Largest Mean Value": dRNormalizedPlotPanel.getTopTextField().setEditable(false); dRNormalizedPlotPanel.getTopTextField().setText(AnalysisUtils .roundTwoDecimals(Collections.max(computeMeans( doseResponseController.getdRAnalysisGroup().getVelocitiesMap().values()))) .toString()); break; case "Largest Median Value": dRNormalizedPlotPanel.getTopTextField().setEditable(false); dRNormalizedPlotPanel.getTopTextField().setText(AnalysisUtils .roundTwoDecimals(Collections.max(computeMedians( doseResponseController.getdRAnalysisGroup().getVelocitiesMap().values()))) .toString()); break; case "Other Value": dRNormalizedPlotPanel.getTopTextField().setText(""); dRNormalizedPlotPanel.getTopTextField().setEditable(true); break; } } }); /** * If selected, the curve fit 'bottom' parameter will be constrained to * zero. This zero is defined by the text field value during * normalization. * */ dRNormalizedPlotPanel.getBottomConstrainCheckBox().addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { bottomConstrainValue = 0.0; } else { bottomConstrainValue = null; } } }); /** * If selected, the curve fit 'top' parameter will be constrained to * 100. This is defined by the text field value during normalization. * */ dRNormalizedPlotPanel.getTopConstrainCheckBox().addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { topConstrainValue = 100.0; } else { topConstrainValue = null; } } }); /** * Re-normalize and plot new dose-response graph, taking into account * any choices made by the user. */ dRNormalizedPlotPanel.getPlotGraphButton().addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dataToFit = prepareFittingData(doseResponseController.getdRAnalysisGroup()); setTableModel(createTableModel(dataToFit)); doseResponseController.updateModelInTable(tableModel); doseResponseController .performFitting( dataToFit, doseResponseController.getdRAnalysisGroup() .getDoseResponseAnalysisResults().getFittingResults(true), bottomConstrainValue, topConstrainValue); doseResponseController.plotDoseResponse(normalizedChartPanel, dRNormalizedPlotPanel.getDoseResponseChartParentPanel(), dataToFit, doseResponseController.getdRAnalysisGroup(), true); //Calculate new statistics doseResponseController.calculateStatistics(); } }); }
From source file:it.unifi.rcl.chess.traceanalysis.Trace.java
public double getMin() { return Collections.min(data); }