List of usage examples for org.apache.commons.math3.stat.descriptive SummaryStatistics SummaryStatistics
public SummaryStatistics()
From source file:gdsc.smlm.ij.plugins.CreateData.java
/** * Create an image from the localisations using the configured PSF width. Draws a new stack * image.//w w w .j a v a 2s. c om * <p> * Note that the localisations are filtered using the signal. The input list of localisations will be updated. * * @param localisationSets * @return The localisations */ private List<LocalisationModel> drawImage(final List<LocalisationModelSet> localisationSets) { if (localisationSets.isEmpty()) return null; // Create a new list for all localisation that are drawn (i.e. pass the signal filters) List<LocalisationModelSet> newLocalisations = Collections .synchronizedList(new ArrayList<LocalisationModelSet>(localisationSets.size())); photonsRemoved = new AtomicInteger(); t1Removed = new AtomicInteger(); tNRemoved = new AtomicInteger(); photonStats = new SummaryStatistics(); // Add drawn spots to memory results = new MemoryPeakResults(); Calibration c = new Calibration(settings.pixelPitch, (float) settings.getTotalGain(), settings.exposureTime); c.emCCD = (settings.getEmGain() > 1); c.bias = settings.bias; c.readNoise = settings.readNoise * ((settings.getCameraGain() > 0) ? settings.getCameraGain() : 1); results.setCalibration(c); results.setSortAfterEnd(true); results.begin(); maxT = localisationSets.get(localisationSets.size() - 1).getTime(); // Display image ImageStack stack = new ImageStack(settings.size, settings.size, maxT); final double psfSD = getPsfSD(); if (psfSD <= 0) return null; ImagePSFModel imagePSFModel = null; if (imagePSF) { // Create one Image PSF model that can be copied imagePSFModel = createImagePSF(localisationSets); if (imagePSFModel == null) return null; } IJ.showStatus("Drawing image ..."); // Multi-thread for speed // Note that the default Executors.newCachedThreadPool() will continue to make threads if // new tasks are added. We need to limit the tasks that can be added using a fixed size // blocking queue. // http://stackoverflow.com/questions/1800317/impossible-to-make-a-cached-thread-pool-with-a-size-limit // ExecutorService threadPool = Executors.newCachedThreadPool(); ExecutorService threadPool = Executors.newFixedThreadPool(Prefs.getThreads()); List<Future<?>> futures = new LinkedList<Future<?>>(); // Count all the frames to process frame = 0; totalFrames = maxT; // Collect statistics on the number of photons actually simulated // Process all frames int i = 0; int lastT = -1; for (LocalisationModelSet l : localisationSets) { if (Utils.isInterrupted()) break; if (l.getTime() != lastT) { lastT = l.getTime(); futures.add(threadPool.submit(new ImageGenerator(localisationSets, newLocalisations, i, lastT, createPSFModel(imagePSFModel), results, stack, poissonNoise))); } i++; } // Finish processing data Utils.waitForCompletion(futures); futures.clear(); if (Utils.isInterrupted()) { IJ.showProgress(1); return null; } // Do all the frames that had no localisations for (int t = 1; t <= maxT; t++) { if (Utils.isInterrupted()) break; if (stack.getPixels(t) == null) { futures.add(threadPool.submit(new ImageGenerator(localisationSets, newLocalisations, maxT, t, null, results, stack, poissonNoise))); } } // Finish Utils.waitForCompletion(futures); threadPool.shutdown(); IJ.showProgress(1); if (Utils.isInterrupted()) { return null; } results.end(); if (photonsRemoved.get() > 0) Utils.log("Removed %d localisations with less than %.1f photons", photonsRemoved.get(), settings.minPhotons); if (t1Removed.get() > 0) Utils.log("Removed %d localisations with no neighbours @ SNR %.2f", t1Removed.get(), settings.minSNRt1); if (tNRemoved.get() > 0) Utils.log("Removed %d localisations with valid neighbours @ SNR %.2f", tNRemoved.get(), settings.minSNRtN); if (photonStats.getN() > 0) Utils.log("Average photons rendered = %s +/- %s", Utils.rounded(photonStats.getMean()), Utils.rounded(photonStats.getStandardDeviation())); //System.out.printf("rawPhotons = %f\n", rawPhotons.getMean()); //System.out.printf("drawPhotons = %f\n", drawPhotons.getMean()); //Utils.showHistogram("draw photons", drawPhotons, "photons", true, 0, 1000); // Update with all those localisation that have been drawn localisationSets.clear(); localisationSets.addAll(newLocalisations); IJ.showStatus("Displaying image ..."); ImageStack newStack = stack; if (!settings.rawImage) { // Get the global limits and ensure all values can be represented Object[] imageArray = stack.getImageArray(); float[] limits = Maths.limits((float[]) imageArray[0]); for (int j = 1; j < imageArray.length; j++) limits = Maths.limits(limits, (float[]) imageArray[j]); limits[0] = 0; // Leave bias in place // Check if the image will fit in a 16-bit range if ((limits[1] - limits[0]) < 65535) { // Convert to 16-bit newStack = new ImageStack(stack.getWidth(), stack.getHeight(), stack.getSize()); // Account for rounding final float min = (float) (limits[0] - 0.5); for (int j = 0; j < imageArray.length; j++) { float[] image = (float[]) imageArray[j]; short[] pixels = new short[image.length]; for (int k = 0; k < pixels.length; k++) { pixels[k] = (short) (image[k] - min); } newStack.setPixels(pixels, j + 1); } } else { // Keep as 32-bit but round to whole numbers for (int j = 0; j < imageArray.length; j++) { float[] pixels = (float[]) imageArray[j]; for (int k = 0; k < pixels.length; k++) { pixels[k] = Math.round(pixels[k]); } } } } // Show image ImagePlus imp = Utils.display(CREATE_DATA_IMAGE_TITLE, newStack); ij.measure.Calibration cal = new ij.measure.Calibration(); String unit = "nm"; double unitPerPixel = settings.pixelPitch; if (unitPerPixel > 100) { unit = "um"; unitPerPixel /= 1000.0; } cal.setUnit(unit); cal.pixelHeight = cal.pixelWidth = unitPerPixel; imp.setCalibration(cal); imp.setDimensions(1, 1, newStack.getSize()); imp.resetDisplayRange(); imp.updateAndDraw(); saveImage(imp); results.setSource(new IJImageSource(imp)); results.setName(CREATE_DATA_IMAGE_TITLE + " (" + TITLE + ")"); results.setConfiguration(createConfiguration((float) psfSD)); results.setBounds(new Rectangle(0, 0, settings.size, settings.size)); MemoryPeakResults.addResults(results); if (benchmarkMode && benchmarkParameters != null) benchmarkParameters.setPhotons(results); List<LocalisationModel> localisations = toLocalisations(localisationSets); savePulses(localisations, results, CREATE_DATA_IMAGE_TITLE); // Saved the fixed and moving localisations into different datasets saveFixedAndMoving(results, CREATE_DATA_IMAGE_TITLE); return localisations; }
From source file:gov.llnl.lc.infiniband.opensm.plugin.data.OSM_FabricDeltaAnalyzer.java
public double getPathUtilization(RT_Path path, PFM_Port.PortCounterName pcn) { // walk the path, and return the maximum utilization number for any leg SummaryStatistics linkStats = new SummaryStatistics(); ArrayList<RT_PathLeg> legs = path.getLegs(); // iterate through the legs for (RT_PathLeg leg : legs) { OSM_Port p1 = leg.getFromPort(); String portId = PFM_PortChange.getPFM_PortChangeKey(p1.getNodeGuid(), p1.getPortNumber()); PFM_PortRate pr = PortRates.get(portId); linkStats.addValue(getPortUtilization(pr, pcn)); }//from w ww .j ava 2s .com return linkStats.getMax(); }
From source file:gov.llnl.lc.infiniband.opensm.plugin.data.OSM_FabricDeltaAnalyzer.java
private BinList<PFM_PortRate> getFabricRateUtilizationBins(int numBins, OSM_NodeType includeTypes) { // assume I have a Delta, and I want to compute the BW's and put them // in a fixed number of bins. // only include the ports from the specified node types. if unknown, include all // the object to return, should be the specified number of bins BinList<PFM_PortRate> UtilizationBins = new BinList<PFM_PortRate>(); PortRates = new LinkedHashMap<String, PFM_PortRate>(); // enforce min/max numBins = numBins < 1 ? 1 : numBins; numBins = numBins > DEFAULT_NUM_BINS ? DEFAULT_NUM_BINS : numBins; // create the bin keys, from 0 to 100 %, linear, whole numbers // divide the max link rate up into the desired bins (0 - 100%) BinSize = 100 / numBins;/*from w ww. j a v a 2s .c o m*/ RateStats = new SummaryStatistics(); if ((ActiveTrafficPorts == null) || (ActiveTrafficPorts.entrySet() == null)) { logger.severe("WHAT THE HECK!"); if (ActiveTrafficPorts == null) { logger.severe("I have no idea why, but the active Traffic Ports from TOP seem to be null!"); } else { logger.severe("Hmmm, the Active Traffic Ports is not null, but the entry set is, check out top!"); } return UtilizationBins; } for (Map.Entry<String, PFM_PortChange> eMapEntry : ActiveTrafficPorts.entrySet()) { PFM_PortChange pc = eMapEntry.getValue(); String key = eMapEntry.getKey(); // what type of node is this port from?? boolean sPortType = isSwitchPort(getDelta(), pc.getPort1()); // only add this value if the port change is from the desired type (or no desired type specified) if (includeThisPort(getDelta(), pc.getPort1(), includeTypes)) { PFM_PortRate pr = new PFM_PortRate(pc); PortRates.put(key, pr); // FIXME - decide which way is more correct // use xmit data by default or Max ?? double U = getPortUtilization(pr, PFM_Port.PortCounterName.xmit_data); //double U = getMaxPortUtilization(pr); RateStats.addValue(U); // put this PortChange in the desired bin for (int k = BinSize; k < 100; k += BinSize) { if (U < (double) k) { UtilizationBins.add(pr, Integer.toString(k)); break; } } } } return UtilizationBins; }
From source file:net.tradelib.core.TradeSummaryBuilder.java
public TradeSummaryBuilder(Series pnl) { numTrades = 0;//from ww w. j av a 2s. c o m grossProfits = 0.0; grossLosses = 0.0; dailyPnlStats = new SummaryStatistics(); pnlStats = new SummaryStatistics(); nonZero = 0; positive = 0; negative = 0; maxWin = 0.0; maxLoss = 0.0; averageWinTrade = new Average(); averageLossTrade = new Average(); this.pnl = pnl; pnlId = 0; equity = 0.0; minEquity = Double.MAX_VALUE; maxEquity = Double.MIN_VALUE; maxDD = Double.MAX_VALUE; maxDDPct = Double.MAX_VALUE; }
From source file:net.tradelib.ratio.SharpeRatio.java
/** * @brief Computes the Sharpe ratio for a list of returns. * //from www. j av a 2s . co m * @param returns The returns * @param rf The risk free average return * * @return The Sharpe ratio */ public static double value(List<Double> returns, double rf) { SummaryStatistics ss = new SummaryStatistics(); returns.forEach((xx) -> ss.addValue(xx - rf)); return ss.getMean() / ss.getStandardDeviation(); }
From source file:net.tradelib.ratio.SortinoRatio.java
/** * @brief Computes the Sortino ratio for a list of returns. * /*from ww w .ja va 2s. co m*/ * @param returns The returns * @param rf The risk free average return * @param multiplier Mainly used to compute the Sortino ratio * for the opposite returns, i.e. short strategy. * * @return The Sortino ratio. Double.MAX_VALUE is returned if there * are no negative returns after applying the multiplier (i.e. * the divisor is 0). */ public static double value(List<Double> returns, double rf, double multiplier) { SummaryStatistics fullStats = new SummaryStatistics(); SummaryStatistics downStats = new SummaryStatistics(); for (int ii = 0; ii < returns.size(); ++ii) { double dd = (returns.get(ii) - rf) * multiplier; fullStats.addValue(dd); if (dd < rf) downStats.addValue(dd); else downStats.addValue(0); } if (downStats.getN() == 0) return Double.MAX_VALUE; return fullStats.getMean() / downStats.getStandardDeviation(); }
From source file:nl.detoren.ijsco.data.Groep.java
public double getStandDev() { SummaryStatistics stats = new SummaryStatistics(); for (int i = 0; i < aantalspelers; ++i) { if (!spelers[i].isBye()) { stats.addValue(spelers[i].getRating()); }//from ww w.j a va2s. com } return stats.getStandardDeviation(); }
From source file:objenome.solver.evolve.Population.java
public SummaryStatistics getStatistics() { SummaryStatistics s = new SummaryStatistics(); for (I i : this) { double d = ((DoubleFitness) i.getFitness()).getValue(); s.addValue(d);/*from w w w. j av a 2s . c om*/ } return s; }
From source file:org.alfresco.bm.report.ResultSummary.java
public ResultSummary(String name) { this.name = name; this.statsSuccess = new SummaryStatistics(); this.statsFailure = new SummaryStatistics(); }
From source file:org.alfresco.repo.cache.TransactionStats.java
public SummaryStatistics getTimings(OpType op) { SummaryStatistics opTimings = timings.get(op); if (opTimings == null) { opTimings = new SummaryStatistics(); timings.put(op, opTimings);//ww w.j av a 2 s . co m } return opTimings; }