List of usage examples for org.apache.commons.math3.stat.descriptive DescriptiveStatistics addValue
public void addValue(double v)
From source file:knop.psfj.BeadFrameList.java
/** * Gets the delta z statistics.// w w w .ja v a2s.c o m * * @return the delta z statistics */ public DescriptiveStatistics getDeltaZStatistics() { DescriptiveStatistics stats = new DescriptiveStatistics(); for (BeadFrame f : this) { if (f.isValid() == false) continue; stats.addValue(f.getDeltaZ()); } return stats; }
From source file:knop.psfj.BeadAverager.java
/** * Average bead.// w w w . ja va2s . co m * * @param frameList the frame list * @return the image plus */ public ImagePlus averageBead(ArrayList<BeadFrame> frameList) { ImagePlus result; DescriptiveStatistics centerX = new DescriptiveStatistics(); DescriptiveStatistics centerY = new DescriptiveStatistics(); DescriptiveStatistics centerZ = new DescriptiveStatistics(); int originalStackSize = frameList.get(0).getSliceNumber(); setTotalBeads(frameList.size()); //frameList = filter(frameList); ArrayList<ImageStack> centeredStacks = new ArrayList<ImageStack>(); for (BeadFrame frame : frameList) { System.out.println(frame.getCentroidXAsInt()); centerX.addValue(frame.getCentroidXAsInt()); centerY.addValue(frame.getCentroidYAsInt()); centerZ.addValue(frame.getCentroidZAsInt()); } int chosenCenter = MathUtils.round(centerZ.getPercentile(50)); int maxUp = chosenCenter - MathUtils.round(chosenCenter - centerZ.getMin()); int maxDown = originalStackSize - MathUtils.round(centerZ.getMax()); System.out.println(maxUp); System.out.println(maxDown); for (BeadFrame frame : frameList) { ImageStack subStack = new ImageStack(frame.getSubstack().getWidth(), frame.getSubstack().getHeight()); int center = frame.getCentroidZAsInt(); int begin = center - maxUp; int end = center + maxDown; System.out.println(String.format(" Groing from %d to %d with a center at %d", begin, end, center)); for (int i = begin; i != end; i++) { subStack.addSlice(frame.getSubstack().getImageStack().getProcessor(i + 1)); } centeredStacks.add(subStack); //new ImagePlus("",subStack).show(); } System.out.println(centerX); System.out.println(centerY); System.out.println(centerZ); return new ImagePlus("", averageStacks(centeredStacks)); }
From source file:classifiers.ComplexClassifier.java
/** * * @throws Exception/*from w w w .ja v a2s . c o m*/ */ @Override public void BewertunginProzent() throws Exception { double count = 0; double[][] bestergeb = new double[1][2]; double[][] hilf; double[][] hilf2; for (int i = 0; i < anzahldurchlauf; i++) { Bootstrap(Modelmenge); train(this.traindaten); hilf = new double[1][2]; hilf2 = new double[1][2]; hilf = test(traindaten); this.trainergebnisse[0][0] = hilf[0][0]; this.trainergebnisse[0][1] = hilf[0][1]; //System.out.println("Fehlerquote Training:" + (double) (int) (this.trainergebnisse[0][0] * 100) / 100 + "%" + " " + "Dauer:" + " " + (int) (this.trainergebnisse[0][1]) + "ms"); hilf2 = test(testdaten); this.testergebnisse[0][0] = hilf2[0][0]; this.testergebnisse[0][1] = hilf2[0][1]; /* if(testergebnisse[i][0]<=max) { max=testergebnisse[i][0]; bestemodel=Model; bestergeb[0][0]=testergebnisse[i][0]; bestergeb[0][1]=testergebnisse[i][1]; }*/ //System.out.println("Validierung:"); //System.out.println("Validierungsngsdaten:"); // System.out.println("Fehlerquote Validierungs:" + " " + (double) (int) (this.testergebnisse[0][0] * 100) / 100 + "%" + " " + "Dauer:" + " " + (int) (this.testergebnisse[0][1]) + "ms"); // System.out.println("----------------------------------------------------------------------------------------"); } DescriptiveStatistics stats1 = new DescriptiveStatistics(); DescriptiveStatistics stat1 = new DescriptiveStatistics(); for (int i = 0; i < trainergebnisse.length; i++) { stats1.addValue(trainergebnisse[0][0]); stat1.addValue(trainergebnisse[0][1]); } double mean1 = stats1.getMean(); double std1 = stats1.getStandardDeviation(); double meanzeit1 = stat1.getMean(); double stdzeit1 = stat1.getStandardDeviation(); // System.out.println("Mittlere Felehrquote des Tainings:" + " " + (double) (int) (mean1 * 100) / 100 + "%" + "(" + (double) (int) ((std1 / Math.sqrt(anzahldurchlauf)) * 100) / 100 + "%)"); //System.out.println("Mittlere Dauer des trainings:" + " " + (int) (meanzeit1) + " " + "ms" + "(" + (int) ((stdzeit1 / Math.sqrt(anzahldurchlauf))) + "ms)"); //System.out.println("--------------------------------------------------------------------------------------"); DescriptiveStatistics stats = new DescriptiveStatistics(); DescriptiveStatistics stat = new DescriptiveStatistics(); // Add the data from the array for (int i = 0; i < testergebnisse.length; i++) { stats.addValue(testergebnisse[i][0]); stat.addValue(testergebnisse[i][1]); } this.Mittlerevalidierungsquote = stats.getMean(); this.stadartdeviationvalidierung = (int) (stats.getStandardDeviation() / Math.sqrt(anzahldurchlauf)); this.Mittlerezeit = stat.getMean(); this.standartdeviationtime = (int) (stat.getStandardDeviation() / Math.sqrt(anzahldurchlauf)); // System.out.println("Mittlere Fehlerquote der Validierungsmengen:" + " " + (double) (int) (Mittlerevalidierungsquote * 100) / 100 + "%" + "(" + (double) (int) ((stadartdeviationvalidierung / Math.sqrt(anzahldurchlauf)) * 100) / 100 + "%)"); // System.out.println("Mittlere Dauer der Validierung :" + " " + (int) (Mittlerezeit) + " " + "ms" + "(" + (int) ((standartdeviationtime / Math.sqrt(anzahldurchlauf))) + "ms)"); erg[1] = (double) (int) (Mittlerevalidierungsquote * 100) / 100; erg[2] = Mittlerezeit; erg[3] = (double) (int) ((stadartdeviationvalidierung / Math.sqrt(anzahldurchlauf)) * 100) / 100; erg[4] = (int) ((standartdeviationtime / Math.sqrt(anzahldurchlauf))); struct.setErgebnisse(erg); train(this.Modelmenge); hilf = test(Modelmenge); this.Modelergebnisse[0][0] = hilf[0][0]; this.Modelergebnisse[0][1] = hilf[0][1]; hilf = test(validierungsmenge); validierungsergebnisse[0][0] = hilf[0][0]; validierungsergebnisse[0][1] = hilf[0][1]; /* System.out.println("---------------------------------------------------------------------------------------");*/ // System.out.println("Fehlerquote der training auf dem Datensatz:" + " " + (double) (int) (Modelergebnisse[0][0] * 100) / 100 + "%"); //System.out.println("Zeit des trainings (Datensatz):" + " " + (int) (Modelergebnisse[0][1]) + " " + "ms"); //System.out.println("---------------------------------------------------------------------------------------"); //System.out.println("Fehlerquote der Test:" + " " + (double) (int) (validierungsergebnisse[0][0] * 100) / 100 + "%"); //System.out.println("Zeit der Test:" + " " + (int) (validierungsergebnisse[0][1]) + " " + "ms"); //System.out.println(); /* System.out.println("Beste Struktur:"+" "+"Validierung:"+" "+(int)bestergeb[0][0]+"%"+" "+"Zeit:"+" "+(int)bestergeb[0][1]+"ms"); System.out.println("---------------------------------------------------------------------------------------"); if(bestemodel!=null) bestemodel.ToString();*/ }
From source file:classifiers.Simpleclassifier.java
@Override public void BewertunginProzent() throws Exception { System.out.println("Parameter:" + "Anzahldurchlauf:" + this.anzahldurchlauf); //System.out.println("----------------------------------------------------------------------------------------"); double count = 0; double max = 0; double[][] hilf = new double[1][2]; double[][] hilf2 = new double[1][2]; for (int i = 0; i < anzahldurchlauf; i++) { Bootstrap(Modelmenge);//from w w w .j a v a2 s. c o m train(this.traindaten); // System.out.println("training NR" + " " + i + ":"); // System.out.println("trainingsdeaten:"); hilf = test(traindaten); this.trainergebnisse[i][0] = hilf[0][0]; this.trainergebnisse[i][1] = hilf[0][1]; //System.out.println("Fehlerquote TrainingNR" + " " + i + ":" + " " + (double)(int) (hilf[0][0]*100)/100 + "%" + " " + "Dauer:" + " " + (int) hilf[0][1] + "ms"); hilf2 = test(testdaten); this.testergebnisse[i][0] = hilf2[0][0]; this.testergebnisse[i][1] = hilf2[0][1]; // System.out.println("Validierung NR" + " " + i + ":"); //System.out.println("Validierungsngsdaten:"); // System.out.println("Fehlerquote Validierungs NR" + " " + i + ":" + " " + (double)(int) (hilf2[0][0]*100)/100 + "%" + " " + "Dauer:" + " " + (int) hilf2[0][1] + "ms"); //System.out.println("----------------------------------------------------------------------------------------"); } DescriptiveStatistics stats1 = new DescriptiveStatistics(); DescriptiveStatistics stat1 = new DescriptiveStatistics(); // Add the data from the array for (int i = 0; i < trainergebnisse.length; i++) { stats1.addValue(trainergebnisse[i][0]); stat1.addValue(trainergebnisse[i][1]); } double mean1 = stats1.getMean(); double std1 = stats1.getStandardDeviation(); double meanzeit1 = stat1.getMean(); double stdzeit1 = stat1.getStandardDeviation(); // System.out.println("Mittlere Felehrquote des Tainings:" + " " + (double)(int) (mean1*100)/100 + "%" + "(" + (double)(int) ((std1 / Math.sqrt(anzahldurchlauf))*100)/100 + "%)"); //System.out.println("Mittlere Dauer des trainings:" + " " + (int) meanzeit1 + " " + "ms" + "(" + (int) ((stdzeit1 / Math.sqrt(anzahldurchlauf)) ) + "ms)"); //System.out.println("--------------------------------------------------------------------------------------"); DescriptiveStatistics stats = new DescriptiveStatistics(); DescriptiveStatistics stat = new DescriptiveStatistics(); // Add the data from the array for (int i = 0; i < testergebnisse.length; i++) { stats.addValue(testergebnisse[i][0]); stat.addValue(testergebnisse[i][1]); } this.Mittlerevalidierungsquote = stats.getMean(); this.stadartdeviationvalidierung = (int) (stats.getStandardDeviation() / Math.sqrt(anzahldurchlauf)); this.Mittlerezeit = stat.getMean(); this.standartdeviationtime = (int) (stat.getStandardDeviation() / Math.sqrt(anzahldurchlauf)); ergb[1] = Mittlerevalidierungsquote; ergb[2] = Mittlerezeit; ergb[3] = (double) (int) ((stadartdeviationvalidierung / Math.sqrt(anzahldurchlauf)) * 100) / 100; ergb[4] = (int) ((standartdeviationtime / Math.sqrt(anzahldurchlauf))); struct.setErgebnisse(ergb); /* System.out.println("Durchnittliche Fehlerquote der Validierungsmengen:" + " " + (int) Mittlerevalidierungsquote + "%" + "(" + (int) (stadartdeviationvalidierung / Math.sqrt(anzahldurchlauf)) + "%)"); System.out.println("durchnittliche Dauer der Validierung :" + " " + (int) (Mittlerezeit) + " " + "ms" + "(" + (int) ((standartdeviationtime / Math.sqrt(anzahldurchlauf)) ) + "ms)");*/ train(this.Modelmenge); hilf = test(Modelmenge); this.Modelergebnisse[0][0] = hilf[0][0]; this.Modelergebnisse[0][1] = hilf[0][1]; hilf = test(validierungsmenge); validierungsergebnisse[0][0] = hilf[0][0]; validierungsergebnisse[0][1] = hilf[0][1]; /* System.out.println("---------------------------------------------------------------------------------------");*/ // System.out.println("Fehlerquote der training auf dem Datensatz:" + " " + (double)(int) (Modelergebnisse[0][0]*100)/100 + "%"); // System.out.println("Zeit des trainings (Datensatz):" + " " + (int) (Modelergebnisse[0][1] ) + " " + "ms"); // System.out.println("---------------------------------------------------------------------------------------"); // System.out.println("Fehlerquote der Test:" + " " + (double)(int) (validierungsergebnisse[0][0]*100)/100 + "%"); // System.out.println("Zeit der Test:" + " " + (int) (validierungsergebnisse[0][1] ) + " " + "ms"); /* Instances bestmodel=new Instances(Modelmenge,bestmodelindexen.length); double result; for(int i=0;i<bestmodelindexen.length;i++) { bestmodel.add(Modelmenge.instance(bestmodelindexen[i])); } train(bestmodel); result= test(validierungsmenge); System.out.println(); System.out.println("der Beste Model ist:"); System.out.println("-----------------------------------------"); System.out.println(bestmodel); System.out.println("mit eine Leistung von:"+" "+result+"%"); return result; }*/ }
From source file:io.hops.leaderElection.experiments.ExperimentDriver.java
private void calculateNumbers(int numProcesses, String outputFileName) throws FileNotFoundException, IOException { if (!new File(outputFileName).exists()) { LOG.error("File " + outputFileName + " does not exists"); return;/*from ww w . j ava 2 s. c om*/ } String marker = "DataPoints: "; String line; DescriptiveStatistics failOverStats = new DescriptiveStatistics(); DescriptiveStatistics tpStats = new DescriptiveStatistics(); BufferedReader br = new BufferedReader(new FileReader(outputFileName)); while ((line = br.readLine()) != null) { if (!line.startsWith(marker)) { continue; } boolean tpStatRecorded = false; String numbers = line.substring(marker.length(), line.length()); StringTokenizer st = new StringTokenizer(numbers, ",[] "); while (st.hasMoreElements()) { double point = Double.parseDouble(st.nextToken()); if (!tpStatRecorded) { tpStats.addValue(point); tpStatRecorded = true; } else { failOverStats.addValue(point); } } } br.close(); writeMessageToFile(numProcesses, failOverStats, tpStats); }
From source file:ec.coevolve.MultiPopCoevolutionaryEvaluatorExtra.java
protected Individual[] behaviourElite(EvolutionState state, int subpop) { // Generate the dataset ArrayList<IndividualClusterable> points = new ArrayList<IndividualClusterable>(); if (novelChampionsOrigin == NovelChampionsOrigin.halloffame) { for (int i = 0; i < hallOfFame[subpop].size(); i++) { points.add(new IndividualClusterable(hallOfFame[subpop].get(i), i)); }/* w w w . j ava 2 s.com*/ } else if (novelChampionsOrigin == NovelChampionsOrigin.archive) { for (ArchiveEntry ae : archives[subpop]) { points.add(new IndividualClusterable(ae.getIndividual(), ae.getGeneration())); } } // Cap -- only use the individuals with the highest fitness scores if (novelChampionsCap > 0) { // calculate the percentile DescriptiveStatistics ds = new DescriptiveStatistics(); for (IndividualClusterable ic : points) { ds.addValue(ic.getFitness()); } double percentile = ds.getPercentile(novelChampionsCap); // remove those below the percentile Iterator<IndividualClusterable> iter = points.iterator(); while (iter.hasNext()) { IndividualClusterable next = iter.next(); if (next.getFitness() < percentile) { iter.remove(); } } } // Check if there are enough points for clustering if (points.size() <= novelChampions) { Individual[] elite = new Individual[points.size()]; for (int i = 0; i < elite.length; i++) { elite[i] = points.get(i).getIndividual(); } return elite; } // Do the k-means clustering KMeansPlusPlusClusterer<IndividualClusterable> clusterer = new KMeansPlusPlusClusterer<IndividualClusterable>( novelChampions, 100); List<CentroidCluster<IndividualClusterable>> clusters = clusterer.cluster(points); // Return one from each cluster Individual[] elite = new Individual[novelChampions]; for (int i = 0; i < clusters.size(); i++) { CentroidCluster<IndividualClusterable> cluster = clusters.get(i); List<IndividualClusterable> clusterPoints = cluster.getPoints(); if (novelChampionsMode == NovelChampionsMode.random) { int randIndex = state.random[0].nextInt(clusterPoints.size()); elite[i] = clusterPoints.get(randIndex).getIndividual(); } else if (novelChampionsMode == NovelChampionsMode.last) { IndividualClusterable oldest = null; for (IndividualClusterable ic : clusterPoints) { if (oldest == null || ic.age > oldest.age) { oldest = ic; } } elite[i] = oldest.getIndividual(); } else if (novelChampionsMode == NovelChampionsMode.centroid) { DistanceMeasure dm = clusterer.getDistanceMeasure(); double[] centroid = cluster.getCenter().getPoint(); IndividualClusterable closest = null; double closestDist = Double.MAX_VALUE; for (IndividualClusterable ic : clusterPoints) { double dist = dm.compute(centroid, ic.getPoint()); if (dist < closestDist) { closestDist = dist; closest = ic; } } elite[i] = closest.getIndividual(); } else if (novelChampionsMode == NovelChampionsMode.best) { IndividualClusterable best = null; float highestFit = Float.NEGATIVE_INFINITY; for (IndividualClusterable ic : clusterPoints) { if (ic.getFitness() > highestFit) { best = ic; highestFit = ic.getFitness(); } } elite[i] = best.getIndividual(); } } return elite; }
From source file:edu.snu.leader.hierarchy.simple.DefaultReporter.java
/** * Report the final results of the simulation * * @see edu.snu.leader.hierarchy.simple.Reporter#reportFinalResults() *///w ww . j a v a 2 s . c o m @Override public void reportFinalResults() { // Create some handy variables long firstActiveTimestep = Long.MAX_VALUE; long lastActiveTimestep = Long.MIN_VALUE; int initiatorCount = 0; // Gather some statistics DescriptiveStatistics immediateFollowerStats = new DescriptiveStatistics(); DescriptiveStatistics initiatorDistanceStats = new DescriptiveStatistics(); DescriptiveStatistics activeTimestepStats = new DescriptiveStatistics(); // Iterate through all the individuals Iterator<Individual> indIter = _simState.getAllIndividuals().iterator(); while (indIter.hasNext()) { Individual ind = indIter.next(); // Get some statistics immediateFollowerStats.addValue(ind.getImmediateFollowerCount()); initiatorDistanceStats.addValue(ind.getDistanceToInitiator()); activeTimestepStats.addValue(ind.getActiveTimestep()); // Build the prefix String prefix = "individual." + ind.getID() + "."; // Log out important information _writer.println(prefix + "group-id = " + ind.getGroupID()); _writer.println(prefix + "active-timestep = " + ind.getActiveTimestep()); _writer.println(prefix + "immediate-follower-count = " + ind.getImmediateFollowerCount()); _writer.println(prefix + "total-follower-count = " + ind.getTotalFollowerCount()); _writer.println(prefix + "distance-to-initiator = " + ind.getDistanceToInitiator()); _writer.println(prefix + "location = " + ind.getLocation().getX() + " " + ind.getLocation().getY()); _writer.println(prefix + "threshold = " + ind.getThreshold()); _writer.println(prefix + "skill = " + ind.getSkill()); _writer.println(prefix + "confidence = " + ind.getConfidence()); _writer.println(prefix + "reputation = " + ind.getReputation()); _writer.println(prefix + "boldness = " + ind.getBoldness()); // Get the leader's ID, if it exists Object leaderID = ""; if (null != ind.getLeader()) { leaderID = ind.getLeader().getIndividual().getID(); } else { ++initiatorCount; } _writer.println(prefix + "leader = " + leaderID); // Build the list of neighbor ID's StringBuilder builder = new StringBuilder(); Iterator<Neighbor> neighborIter = ind.getNearestNeighbors().iterator(); while (neighborIter.hasNext()) { builder.append(neighborIter.next().getIndividual().getID()); builder.append(" "); } _writer.println(prefix + "nearest-neighbors = " + builder.toString()); // Build the list of follower ID's builder = new StringBuilder(); neighborIter = ind.getFollowers().iterator(); while (neighborIter.hasNext()) { builder.append(neighborIter.next().getIndividual().getID()); builder.append(" "); } _writer.println(prefix + "immediate-followers = " + builder.toString()); // Check the activity time if (firstActiveTimestep > ind.getActiveTimestep()) { firstActiveTimestep = ind.getActiveTimestep(); } if (lastActiveTimestep < ind.getActiveTimestep()) { lastActiveTimestep = ind.getActiveTimestep(); } _writer.println(); } // Log the simulation information _writer.println("simulation.first-active-timestep = " + firstActiveTimestep); _writer.println("simulation.last-active-timestep = " + lastActiveTimestep); _writer.println("simulation.initiator-count = " + initiatorCount); // Log the stats _writer.println("statistics.immediate-followers.mean = " + immediateFollowerStats.getMean()); _writer.println( "statistics.immediate-followers.std-dev = " + immediateFollowerStats.getStandardDeviation()); _writer.println("statistics.immediate-followers.min = " + immediateFollowerStats.getMin()); _writer.println("statistics.immediate-followers.max = " + immediateFollowerStats.getMax()); _writer.println("statistics.initiator-distance.mean = " + initiatorDistanceStats.getMean()); _writer.println("statistics.initiator-distance.std-dev = " + initiatorDistanceStats.getStandardDeviation()); _writer.println("statistics.initiator-distance.min = " + initiatorDistanceStats.getMin()); _writer.println("statistics.initiator-distance.max = " + initiatorDistanceStats.getMax()); _writer.println("statistics.active-timestep.mean = " + activeTimestepStats.getMean()); _writer.println("statistics.active-timestep.std-dev = " + activeTimestepStats.getStandardDeviation()); _writer.println("statistics.active-timestep.min = " + activeTimestepStats.getMin()); _writer.println("statistics.active-timestep.max = " + activeTimestepStats.getMax()); // Log out the stop time _writer.println(); _writer.println(_STATS_SPACER); _writer.println("# Finished: " + (new Date())); // Close out the writer _writer.close(); }
From source file:de.tudarmstadt.ukp.experiments.argumentation.sequence.evaluation.thirdparty.SegEvalEvaluator.java
/** * Takes each file from the {@code predictionsFolder} and evaluate it against its counterpart * from the {@code goldFolder} using boundary similarity metric. * * @param goldFolder gold data * @param predictionsFolder predictions (or any other data, ie. from annotators) * @param argumentComponentClass which argument component should be considered * @return statistics/*from w w w . j av a2 s.c o m*/ * @throws Exception */ public DescriptiveStatistics evaluateFolders(File goldFolder, File predictionsFolder, Class<ArgumentComponent> argumentComponentClass) throws Exception { DescriptiveStatistics statistics = new DescriptiveStatistics(); File[] files = predictionsFolder.listFiles(JCasIOHelper.XMI_FILTER); // System.out.println("Predicted files size: " + files.length); for (File predicted : files) { File gold = new File(goldFolder, predicted.getName()); if (!gold.exists()) { throw new IOException("Gold file " + gold + " does not exist!"); } JCas goldJCas = JCasIOHelper.loadJCasFromFile(gold); JCas predictedJCas = JCasIOHelper.loadJCasFromFile(predicted); double boundarySimilarity = evaluate(goldJCas, predictedJCas, argumentComponentClass); statistics.addValue(boundarySimilarity); } return statistics; }
From source file:fr.inria.eventcloud.benchmarks.load_balancing.LoadBalancingBenchmark.java
public StatsRecorder execute() { this.logParameterValues(); // creates and runs micro benchmark MicroBenchmark microBenchmark = new MicroBenchmark(this.nbRuns, new MicroBenchmarkService() { private EventCloudsRegistry registry; private BenchmarkStatsCollector collector; private String collectorURL; private NodeProvider nodeProvider; private EventCloudDeployer deployer; private CustomPublishProxy publishProxies; private Event[] events; @Override/* w w w . j av a2 s. c om*/ public void setup() throws Exception { LOG.info("Loading events from {}", LoadBalancingBenchmark.this.inputFile); this.events = LoadBalancingBenchmark.this.loadEvents(LoadBalancingBenchmark.this.inputFile); LOG.info("{} compound events loaded", this.events.length); this.collector = PAActiveObject.newActive(BenchmarkStatsCollector.class, new Object[] { LoadBalancingBenchmark.this.nbPeers - 1 }); this.collectorURL = PAActiveObject.registerByName(this.collector, BENCHMARK_STATS_COLLECTOR_NAME); this.nodeProvider = LoadBalancingBenchmark.this.createNodeProvider(); LoadBalancingBenchmark.this.componentsManager = EventCloudComponentsManagerFactory .newComponentsManager(this.nodeProvider, 1, LoadBalancingBenchmark.this.nbPeers, 1, 1, 0); LoadBalancingBenchmark.this.componentsManager.start(); EventCloudDeploymentDescriptor descriptor = this.createDeploymentDescriptor(this.nodeProvider, this.collectorURL); this.deployer = new EventCloudDeployer(new EventCloudDescription(), descriptor, LoadBalancingBenchmark.this.componentsManager); this.deployer.deploy(1, 1); this.registry = LoadBalancingBenchmark.this.deployRegistry(this.deployer, this.nodeProvider); String registryURL = null; try { registryURL = this.registry.register("registry"); } catch (ProActiveException e) { throw new IllegalStateException(e); } EventCloudId eventCloudId = this.deployer.getEventCloudDescription().getId(); this.publishProxies = LoadBalancingBenchmark.this.createPublishProxies(this.nodeProvider, registryURL, eventCloudId); } private EventCloudDeploymentDescriptor createDeploymentDescriptor(NodeProvider nodeProvider, String benchmarkStatsCollectorURL) { Criterion[] criteria = new Criterion[1]; criteria[0] = new QuadrupleCountCriterion(); LoadBalancingConfiguration configuration = null; if (LoadBalancingBenchmark.this.strategy != null) { configuration = new LoadBalancingConfiguration(criteria, LoadBalancingBenchmark.this.componentsManager, LoadBalancingBenchmark.this.strategy); } EventCloudDeploymentDescriptor descriptor = new EventCloudDeploymentDescriptor( new CustomSemanticOverlayProvider(configuration, this.collectorURL, LoadBalancingBenchmark.this.nbQuadruplesPublished, LoadBalancingBenchmark.this.inMemoryDatastore)); return descriptor; } @Override public void run(StatsRecorder recorder) throws TimeoutException { LOG.info("Assigning events"); this.publishProxies.assignEvents(this.events); LOG.info("Publishing events to trigger load balancing"); this.publishProxies.publish(); this.collector.waitCondition(3600000); try { Thread.sleep(10000); } catch (InterruptedException e) { e.printStackTrace(); } LOG.info("Distribution on peers is:"); Map<OverlayId, Integer> results = new HashMap<OverlayId, Integer>(); for (Peer peer : this.collector.getPeers()) { @SuppressWarnings("unchecked") GenericResponseOperation<Integer> result = (GenericResponseOperation<Integer>) PAFuture .getFutureValue(peer.receive(new CountQuadruplesOperation(false))); results.put(peer.getId(), result.getValue()); } // Proxy proxy = // org.objectweb.proactive.extensions.p2p.structured.factories.ProxyFactory.newProxy(this.deployer.getTrackers()); // CountQuadrupleResponse response = // (CountQuadrupleResponse) // PAFuture.getFutureValue(proxy.send(new // CountQuadrupleRequest())); // // Map<OverlayId, Long> results = response.getResult(); DescriptiveStatistics stats = new DescriptiveStatistics(); int count = 0; for (Entry<OverlayId, Integer> entry : results.entrySet()) { LOG.info("{} {}", entry.getKey(), entry.getValue()); count += entry.getValue(); stats.addValue(entry.getValue()); } LOG.info( "{} peers manage a total of {} quadruples, standard deviation is {}, variability (stddev/average * 100) is {}%", results.size(), count, stats.getStandardDeviation(), (stats.getStandardDeviation() / stats.getMean()) * 100); System.exit(1); } @Override public void clear() throws Exception { LOG.info("Clearing previously recorded information before to start benchmark"); List<ResponseOperation> futures = new ArrayList<ResponseOperation>(); for (Peer p : this.deployer.getRandomTracker().getPeers()) { futures.add(p.receive(new ClearOperation())); } PAFuture.waitForAll(futures); this.collector.clear(); } @Override public void teardown() throws Exception { LoadBalancingBenchmark.this.undeploy(this.nodeProvider, this.deployer, this.registry, this.collectorURL); } }); microBenchmark.discardFirstRuns(this.discardFirstRuns); microBenchmark.showProgress(); microBenchmark.execute(); return microBenchmark.getStatsRecorder(); }
From source file:gdsc.smlm.ij.plugins.SpotInspector.java
public void run(String arg) { if (MemoryPeakResults.countMemorySize() == 0) { IJ.error(TITLE, "No localisations in memory"); return;/*from w ww. j a v a2s . co m*/ } if (!showDialog()) return; // Load the results results = ResultsManager.loadInputResults(inputOption, false); if (results == null || results.size() == 0) { IJ.error(TITLE, "No results could be loaded"); IJ.showStatus(""); return; } // Check if the original image is open ImageSource source = results.getSource(); if (source == null) { IJ.error(TITLE, "Unknown original source image"); return; } source = source.getOriginal(); if (!source.open()) { IJ.error(TITLE, "Cannot open original source image: " + source.toString()); return; } final float stdDevMax = getStandardDeviation(results); if (stdDevMax < 0) { // TODO - Add dialog to get the initial peak width IJ.error(TITLE, "Fitting configuration (for initial peak width) is not available"); return; } // Rank spots rankedResults = new ArrayList<PeakResultRank>(results.size()); final double a = results.getNmPerPixel(); final double gain = results.getGain(); final boolean emCCD = results.isEMCCD(); for (PeakResult r : results.getResults()) { float[] score = getScore(r, a, gain, emCCD, stdDevMax); rankedResults.add(new PeakResultRank(r, score[0], score[1])); } Collections.sort(rankedResults); // Prepare results table. Get bias if necessary if (showCalibratedValues) { // Get a bias if required Calibration calibration = results.getCalibration(); if (calibration.bias == 0) { GenericDialog gd = new GenericDialog(TITLE); gd.addMessage("Calibrated results requires a camera bias"); gd.addNumericField("Camera_bias (ADUs)", calibration.bias, 2); gd.showDialog(); if (!gd.wasCanceled()) { calibration.bias = Math.abs(gd.getNextNumber()); } } } IJTablePeakResults table = new IJTablePeakResults(false, results.getName(), true); table.copySettings(results); table.setTableTitle(TITLE); table.setAddCounter(true); table.setShowCalibratedValues(showCalibratedValues); table.begin(); // Add a mouse listener to jump to the frame for the clicked line textPanel = table.getResultsWindow().getTextPanel(); // We must ignore old instances of this class from the mouse listeners id = ++currentId; textPanel.addMouseListener(this); // Add results to the table int n = 0; for (PeakResultRank rank : rankedResults) { rank.rank = n++; PeakResult r = rank.peakResult; table.add(r.peak, r.origX, r.origY, r.origValue, r.error, r.noise, r.params, r.paramsStdDev); } table.end(); if (plotScore || plotHistogram) { // Get values for the plots float[] xValues = null, yValues = null; double yMin, yMax; int spotNumber = 0; xValues = new float[rankedResults.size()]; yValues = new float[xValues.length]; for (PeakResultRank rank : rankedResults) { xValues[spotNumber] = spotNumber + 1; yValues[spotNumber++] = recoverScore(rank.score); } // Set the min and max y-values using 1.5 x IQR DescriptiveStatistics stats = new DescriptiveStatistics(); for (float v : yValues) stats.addValue(v); if (removeOutliers) { double lower = stats.getPercentile(25); double upper = stats.getPercentile(75); double iqr = upper - lower; yMin = FastMath.max(lower - iqr, stats.getMin()); yMax = FastMath.min(upper + iqr, stats.getMax()); IJ.log(String.format("Data range: %f - %f. Plotting 1.5x IQR: %f - %f", stats.getMin(), stats.getMax(), yMin, yMax)); } else { yMin = stats.getMin(); yMax = stats.getMax(); IJ.log(String.format("Data range: %f - %f", yMin, yMax)); } plotScore(xValues, yValues, yMin, yMax); plotHistogram(yValues, yMin, yMax); } // Extract spots into a stack final int w = source.getWidth(); final int h = source.getHeight(); final int size = 2 * radius + 1; ImageStack spots = new ImageStack(size, size, rankedResults.size()); // To assist the extraction of data from the image source, process them in time order to allow // frame caching. Then set the appropriate slice in the result stack Collections.sort(rankedResults, new Comparator<PeakResultRank>() { public int compare(PeakResultRank o1, PeakResultRank o2) { if (o1.peakResult.peak < o2.peakResult.peak) return -1; if (o1.peakResult.peak > o2.peakResult.peak) return 1; return 0; } }); for (PeakResultRank rank : rankedResults) { PeakResult r = rank.peakResult; // Extract image // Note that the coordinates are relative to the middle of the pixel (0.5 offset) // so do not round but simply convert to int final int x = (int) (r.params[Gaussian2DFunction.X_POSITION]); final int y = (int) (r.params[Gaussian2DFunction.Y_POSITION]); // Extract a region but crop to the image bounds int minX = x - radius; int minY = y - radius; int maxX = FastMath.min(x + radius + 1, w); int maxY = FastMath.min(y + radius + 1, h); int padX = 0, padY = 0; if (minX < 0) { padX = -minX; minX = 0; } if (minY < 0) { padY = -minY; minY = 0; } int sizeX = maxX - minX; int sizeY = maxY - minY; float[] data = source.get(r.peak, new Rectangle(minX, minY, sizeX, sizeY)); // Prevent errors with missing data if (data == null) data = new float[sizeX * sizeY]; ImageProcessor spotIp = new FloatProcessor(sizeX, sizeY, data, null); // Pad if necessary, i.e. the crop is too small for the stack if (padX > 0 || padY > 0 || sizeX < size || sizeY < size) { ImageProcessor spotIp2 = spotIp.createProcessor(size, size); spotIp2.insert(spotIp, padX, padY); spotIp = spotIp2; } int slice = rank.rank + 1; spots.setPixels(spotIp.getPixels(), slice); spots.setSliceLabel(Utils.rounded(rank.originalScore), slice); } source.close(); ImagePlus imp = Utils.display(TITLE, spots); imp.setRoi((PointRoi) null); // Make bigger for (int i = 10; i-- > 0;) imp.getWindow().getCanvas().zoomIn(imp.getWidth() / 2, imp.getHeight() / 2); }