List of usage examples for org.apache.commons.math.stat.descriptive SummaryStatistics getMean
public double getMean()
From source file:com.userweave.module.methoden.iconunderstandability.service.IconMatchingStatistics.java
private double getMeanReactionTimeForValues(List<Double> values) { SummaryStatistics stats = SummaryStatistics.newInstance(); for (Double value : values) { if (value != null && isValid(value)) { stats.addValue(value);/*from w w w . ja va 2s .c o m*/ } } return stats.getMean(); }
From source file:edu.cornell.med.icb.geo.BinaryArrayProbesetMinNormalizer.java
public void preSeries(final GEOPlatformIndexed platform) { if (options.tpr != null) { LOGGER.info(String.format("Platform maps to %d transcripts.", options.tpr.getTranscripts().size())); } else {/*from w w w .j a v a2s.c o m*/ // install default mapping from probsetId -> probesetId/asTranscriptId final IndexedIdentifier transcriptIndices = new IndexedIdentifier(); options.tpr = new TranscriptProbesetRelationship(transcriptIndices); final IndexedIdentifier indexOfProbesets = platform.getProbeIds(); for (final MutableString probesetId : indexOfProbesets.keySet()) { options.tpr.addRelationship(probesetId, indexOfProbesets.get(probesetId)); } } projectTo = "tissue"; final double[] sumSignalBySample = sumSignal(platform); final SummaryStatistics statHelper = new SummaryStatistics(); for (final double sumForOneSample : sumSignalBySample) { statHelper.addValue(sumForOneSample); } final double averageSumForSamples = statHelper.getMean(); final float[] minValuesPerProbesets = estimateMinValueForProbesets(sumSignalBySample, platform, 10, averageSumForSamples); writeNormalize(averageSumForSamples, sumSignalBySample, minValuesPerProbesets, platform); System.exit(0); }
From source file:com.netflix.curator.framework.recipes.queue.TestQueueSharder.java
@Test public void testDistribution() throws Exception { final int threshold = 100; final int factor = 10; Timing timing = new Timing(); CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1)); QueueSharder<String, DistributedQueue<String>> sharder = null; try {//from w w w . ja v a 2s. c o m client.start(); final CountDownLatch latch = new CountDownLatch(1); QueueConsumer<String> consumer = new QueueConsumer<String>() { @Override public void consumeMessage(String message) throws Exception { latch.await(); } @Override public void stateChanged(CuratorFramework client, ConnectionState newState) { } }; QueueAllocator<String, DistributedQueue<String>> distributedQueueAllocator = makeAllocator(consumer); QueueSharderPolicies policies = QueueSharderPolicies.builder().newQueueThreshold(threshold) .thresholdCheckMs(1).build(); sharder = new QueueSharder<String, DistributedQueue<String>>(client, distributedQueueAllocator, "/queues", "/leader", policies); sharder.start(); for (int i = 0; i < (factor * threshold); ++i) { sharder.getQueue().put(Integer.toString(i)); Thread.sleep(5); } timing.forWaiting().sleepABit(); SummaryStatistics statistics = new SummaryStatistics(); for (String path : sharder.getQueuePaths()) { int numChildren = client.checkExists().forPath(path).getNumChildren(); Assert.assertTrue(numChildren > 0); Assert.assertTrue(numChildren >= (threshold * .1)); statistics.addValue(numChildren); } latch.countDown(); Assert.assertTrue(statistics.getMean() >= (threshold * .9)); } finally { timing.sleepABit(); // let queue clear Closeables.closeQuietly(sharder); Closeables.closeQuietly(client); } }
From source file:alma.acs.monitoring.blobber.BlobData.java
/** * Calculates the statistics and stores it in {@link #statistics} * if our monitor point data is represented as Number objects; * otherwise this call is ignored./*from www. j a va 2 s. com*/ * * @param inDataList */ void calculateStatistics() { if (getDataSize() > 0) { // We trust that the data is homogeneous and check only the first MonitorPointValue MonitorPointValue sampleMonitorPointValue = mpTs.getDataList().get(0); if (sampleMonitorPointValue.getData().isEmpty()) { logger.finer( "Ignoring calculateStatistics() call for a time series of MonitorPointValue objects that hold no data."); return; } // TODO: Should we also compute statistics for multi-valued properties? // This was not done in the original (= pre-ACS 12.0) implementation of BlobberWorker#calculateStatistics // and so far we keep this behavior. if (sampleMonitorPointValue.isMultiValued()) { logger.finer( "Ignoring calculateStatistics() call for a time series of multi-valued MonitorPointValue objects."); return; } // After the above checks, there should be a single data item in our sampleMonitorPointValue // We now verify that it has one of the expected numeric types. Object sampleData = sampleMonitorPointValue.getData().get(0); if (!(sampleData instanceof Integer || sampleData instanceof Long || sampleData instanceof Float || sampleData instanceof Double)) { logger.finer( "Ignoring calculateStatistics() call for data type " + sampleData.getClass().getName()); return; } // Now we calculate the statistics, // using apache math lib that works only with 'double' type SummaryStatistics stat = new SummaryStatistics(); for (MonitorPointValue blobData : mpTs.getDataList()) { Number value = (Number) blobData.getData().get(0); stat.addValue(value.doubleValue()); } statistics = new ComponentStatistics(); // We store the results in a ComponentStatistics object, // converting to original data types where it makes sense if (sampleData instanceof Integer) { statistics.min = new Integer((int) Math.round(stat.getMin())); statistics.max = new Integer((int) Math.round(stat.getMax())); statistics.mean = new Double(stat.getMean()); // or Float, to indicate lower precision? statistics.stdDev = new Double(stat.getStandardDeviation()); // or Float, to indicate lower precision? } else if (sampleData instanceof Long) { statistics.min = new Long(Math.round(stat.getMin())); statistics.max = new Long(Math.round(stat.getMax())); statistics.mean = new Double(stat.getMean()); statistics.stdDev = new Double(stat.getStandardDeviation()); } else if (sampleData instanceof Float) { statistics.min = new Float(stat.getMin()); statistics.max = new Float(stat.getMax()); statistics.mean = new Float(stat.getMean()); statistics.stdDev = new Float(stat.getStandardDeviation()); } else if (sampleData instanceof Double) { statistics.min = new Double(stat.getMin()); statistics.max = new Double(stat.getMax()); statistics.mean = new Double(stat.getMean()); statistics.stdDev = new Double(stat.getStandardDeviation()); } } }
From source file:edu.cornell.med.icb.geo.BinaryArrayProbesetMinNormalizer.java
private float[] estimateMinValueForProbesets(final double[] sumSignalBySample, final GEOPlatformIndexed platform, final int k, final double averageSumForSamples) { final float[] signal; final int minProbeIndex = 0; final int maxProbeIndex = platform.getNumProbeIds(); try {/* w w w . j a v a 2 s.co m*/ final ArrayReader arrayReader = getReader(platform); signal = arrayReader.allocateSignalArray(); final ObjectList<MutableString> sampleIds; sampleIds = arrayReader.getSampleIdList(); final AnnotationSet annotationSet = readAnnotationSet(platform, sampleIds); progressLogger.expectedUpdates = sampleIds.size(); progressLogger.start("Starting estimateMinValueForProbesets"); final float[] minSignalAveragePerProbeset = new float[maxProbeIndex]; // Create one queue per probeset where the signal values will be enqueued. // Capacity is set to k, and largest values are kept. final ScoredTranscriptBoundedSizeQueue[] smallestSignalValuesForProbesets = new ScoredTranscriptBoundedSizeQueue[maxProbeIndex]; for (int i = 0; i < smallestSignalValuesForProbesets.length; i++) { smallestSignalValuesForProbesets[i] = new ScoredTranscriptBoundedSizeQueue(k); } for (int sampleIndex = 0; sampleIndex < sampleIds.size(); ++sampleIndex) { // load signal for one sample (all probesets) arrayReader.readNextSample(signal); for (int probesetIndex = minProbeIndex; probesetIndex < maxProbeIndex; ++probesetIndex) { final int transcriptIndex = getTranscriptIndex(probesetIndex); if (transcriptIndex != -1 && signal[probesetIndex] != 0) { // probeset maps to a transcript in a non-ambiguous way, and was called 'present' in the sample final double sampleNormalizedSignal = averageSumForSamples * (signal[probesetIndex]) / sumSignalBySample[sampleIndex]; smallestSignalValuesForProbesets[probesetIndex].enqueue(sampleIndex, -sampleNormalizedSignal); } } progressLogger.update(); } arrayReader.close(); for (int probesetIndex = 0; probesetIndex < smallestSignalValuesForProbesets.length; probesetIndex++) { final SummaryStatistics helper = new SummaryStatistics(); while (!smallestSignalValuesForProbesets[probesetIndex].isEmpty()) { final TranscriptScore score = smallestSignalValuesForProbesets[probesetIndex].dequeue(); final double smallestSignalValue = -score.score; helper.addValue(smallestSignalValue); } minSignalAveragePerProbeset[probesetIndex] = (float) helper.getMean(); // System.out.println("estimated "+minSignalAveragePerProbeset[probesetIndex]+" for probeset "+probesetIndex); } progressLogger.stop("Finished estimateMinValueForProbesets."); return minSignalAveragePerProbeset; } catch (IOException e) { System.err.println("Error reading binary information from file"); e.printStackTrace(); System.exit(10); } catch (ClassNotFoundException e) { System.err.println("Could not initialize an array reader."); e.printStackTrace(); System.exit(10); } return null; }
From source file:com.userweave.module.methoden.questionnaire.page.report.question.freeanswer.FreeQuestionReportPanel.java
public FreeQuestionReportPanel(String id, Locale locale, FreeQuestion question, com.userweave.pages.configuration.report.FilterFunctorCallback filterFunctorCallback) { super(id, locale, question); List<FreeAnwer> answers = answerDao.getValidAnswersForQuestion(question, filterFunctorCallback.getFilterFunctor()); List<FreeAnwer> notEmptyAnswers = new ArrayList<FreeAnwer>(); SummaryStatistics summaryStatistics = SummaryStatistics.newInstance(); boolean isNumber = false; if (answers != null) { for (FreeAnwer freeAnwer : answers) { String answerString = getAnswerString(freeAnwer); if (answerString != null && !answerString.isEmpty()) { notEmptyAnswers.add(freeAnwer); if (isFreeNumberAnswer(freeAnwer)) { double number = ((FreeNumberAnswer) freeAnwer).getNumber(); summaryStatistics.addValue(number); isNumber = true;/*from ww w. j av a 2s . co m*/ } } } } boolean isVisible = question.getAnswerType() == FreeQuestion.AnswerType.NUMBER; addNumber("mean", summaryStatistics.getMean(), isNumber, isVisible); addNumber("stdDeviation", summaryStatistics.getStandardDeviation(), isNumber, isVisible); setTotalCount(notEmptyAnswers.size()); add(new ListView("answers", notEmptyAnswers) { @Override protected void populateItem(ListItem item) { item.add(new Label("answer", getAnswerString((FreeAnwer) item.getModelObject()))); } }); }
From source file:ddf.metrics.reporting.internal.rrd4j.RrdMetricsRetriever.java
private double cumulativeRunningAverage(List<Double> values) { if (values.size() == 0) { return 0; }//ww w.j ava 2s . c om SummaryStatistics summaryStatistics = new SummaryStatistics(); for (Double value : values) { summaryStatistics.addValue(value); } return summaryStatistics.getMean(); }
From source file:edu.cornell.med.icb.goby.modes.CompactFileStatsMode.java
/** * Print statistics about an alignment file in the Goby compact form. * * @param file The file to display statistics about * @throws IOException if the file cannot be read *///from w w w. j a v a 2s . c om private void describeCompactAlignment(final File file) throws IOException { final String basename = AlignmentReaderImpl.getBasename(file.toString()); stream.printf("Compact Alignment basename = %s%n", basename); final AlignmentReaderImpl reader = new AlignmentReaderImpl(basename); reader.readHeader(); stream.println("Info from header:"); stream.printf("Alignment written with Goby version=%s %n", reader.getGobyVersion()); stream.printf("Alignment produced by aligner=%s version=%s %n", reader.getAlignerName(), reader.getAlignerVersion()); stream.printf("Sorted: %b%n", reader.isSorted()); stream.printf("Indexed: %b%n", reader.isIndexed()); stream.printf("Number of target sequences = %,d%n", reader.getNumberOfTargets()); final int[] targetLengthsFromHeader = reader.getTargetLength(); stream.printf("Number of target length entries = %,d%n", ArrayUtils.getLength(reader.getTargetLength())); stream.printf("smallestSplitQueryIndex = %d%n", reader.getSmallestSplitQueryIndex()); stream.printf("largestSplitQueryIndex = %d%n", reader.getLargestSplitQueryIndex()); // simple statistics for target lengths final SummaryStatistics targetLengthStats = new SummaryStatistics(); if (targetLengthsFromHeader != null) { for (final double d : targetLengthsFromHeader) { targetLengthStats.addValue(d); } } stream.printf("Min target length = %,d%n", (int) targetLengthStats.getMin()); stream.printf("Max target length = %,d%n", (int) targetLengthStats.getMax()); stream.printf("Mean target length = %,.2f%n", targetLengthStats.getMean()); stream.println(); stream.printf("Number of query sequences = %,d%n", reader.getNumberOfQueries()); final SummaryStatistics queryLengthStats = new SummaryStatistics(); stream.println("Query lengths stored in entries = " + reader.isQueryLengthStoredInEntries()); stream.println("Constant query lengths = " + reader.isConstantQueryLengths()); stream.printf("Has query identifiers = %s%n", reader.getQueryIdentifiers() != null && !reader.getQueryIdentifiers().isEmpty()); final IndexedIdentifier targetIdentifiers = reader.getTargetIdentifiers(); final boolean hasTargetIdentifiers = targetIdentifiers != null && !targetIdentifiers.isEmpty(); stream.printf("Has target identifiers = %s%n", hasTargetIdentifiers); stream.printf("Has query index permutation = %s%n", reader.getQueryIndicesWerePermuted()); stream.printf("Has query index occurrences = %s%n", reader.hasQueryIndexOccurrences()); stream.printf("Has all read quality scores = %s%n", reader.getHasAllReadQualityScores()); stream.printf("Has ambiguity = %s%n", reader.hasAmbiguity()); if (verbose) { if (hasTargetIdentifiers) { for (Map.Entry<MutableString, Integer> entry : targetIdentifiers.entrySet()) { stream.printf(" Target %s=%d with a length of %d%n", entry.getKey(), entry.getValue(), targetLengthsFromHeader[entry.getValue()]); } } else { for (Map.Entry<MutableString, Integer> entry : targetIdentifiers.entrySet()) { stream.printf(" Target %d with a length of %d%n", entry.getValue(), targetLengthsFromHeader[entry.getValue()]); } } } stream.println(); if (reader.getReadOriginInfo().size() > 0) { stream.println("---- Read Origin Info ------"); for (final Alignments.ReadOriginInfo info : reader.getReadOriginInfo().getPbList()) { stream.println("["); stream.print(info.toString()); stream.println("]"); } } else { stream.println("Alignment has no Read Origin Info/Read Groups"); } if (headerOnly) return; // the query indices that aligned. Includes those final DistinctIntValueCounterBitSet alignedQueryIndices = new DistinctIntValueCounterBitSet(); describeAmbigousReads(basename, reader.getNumberOfQueries(), alignedQueryIndices); int maxQueryIndex = -1; int maxTargetIndex = -1; int numEntries = 0; long numLogicalAlignmentEntries = 0; long total = 0; double avgScore = 0; int sumNumVariations = 0; int numPaired = 0; int numProperlyPaired = 0; int numFirstInPair = 0; int numSecondInPair = 0; boolean hasSoftClips = false; for (final Alignments.AlignmentEntry entry : reader) { numberOfReads++; // Across all files numEntries++; // Across this file numLogicalAlignmentEntries += Math.max(entry.getMultiplicity(), 1); total += entry.getQueryAlignedLength(); avgScore += entry.getScore(); maxQueryIndex = Math.max(maxQueryIndex, entry.getQueryIndex()); maxTargetIndex = Math.max(maxTargetIndex, entry.getTargetIndex()); cumulativeReadLength += entry.getQueryAlignedLength(); minReadLength = Math.min(minReadLength, entry.getQueryAlignedLength()); maxReadLength = Math.max(maxReadLength, entry.getQueryAlignedLength()); sumNumVariations += entry.getSequenceVariationsCount(); alignedQueryIndices.observe(entry.getQueryIndex()); hasSoftClips |= entry.hasSoftClippedBasesLeft(); hasSoftClips |= entry.hasSoftClippedBasesRight(); // check entry then header for the query length final double queryLength = entry.getQueryLength(); queryLengthStats.addValue(queryLength); numPaired += EntryFlagHelper.isPaired(entry) ? 1 : 0; numProperlyPaired += EntryFlagHelper.isProperlyPaired(entry) ? 1 : 0; numFirstInPair += EntryFlagHelper.isFirstInPair(entry) ? 1 : 0; numSecondInPair += EntryFlagHelper.isSecondInPair(entry) ? 1 : 0; } avgScore /= (double) numLogicalAlignmentEntries; final int numQuerySequences = reader.getNumberOfQueries(); stream.printf("num query indices = %,d%n", numQuerySequences); final int numTargetSequences = maxTargetIndex + 1; final double avgNumVariationsPerQuery = ((double) sumNumVariations) / (double) numQuerySequences; stream.printf("num target indices = %,d%n", numTargetSequences); stream.printf("Number of alignment entries = %,d%n", numLogicalAlignmentEntries); stream.printf("Number of query indices that matched = %,d%n", alignedQueryIndices.count()); stream.printf("Percent matched = %4.1f %% %n", (double) alignedQueryIndices.count() / (double) ((long) numQuerySequences) * 100.0d); stream.printf("Avg query alignment length = %,f%n", numEntries > 0 ? divide(total, numEntries) : -1); stream.printf("Avg score alignment = %f%n", avgScore); stream.printf("Avg number of variations per query sequence = %3.2f %n", avgNumVariationsPerQuery); // size, the number of bytes in the entries file. final long size = new File(basename + ".entries").length(); stream.printf("Average bytes per entry = %f%n", divide(size, numLogicalAlignmentEntries)); stream.printf("Min query length = %,d%n", (int) queryLengthStats.getMin()); stream.printf("Max query length = %,d%n", (int) queryLengthStats.getMax()); final double meanQueryLength = queryLengthStats.getMean(); stream.printf("Mean query length = %,.2f%n", meanQueryLength); final int averageReadLength = (int) (Math.round(meanQueryLength)); stream.printf("Average bits per read base, assuming average read length %d = %f%n", averageReadLength, divide(size, numLogicalAlignmentEntries * averageReadLength)); stream.printf("Percent paired reads = %,.2f %% %n", divide(numPaired, numQuerySequences * 2) * 100d); stream.printf("Percent properly paired reads = %,.2f %% %n", divide(numProperlyPaired, numQuerySequences * 2) * 100d); stream.printf("Percent first in pair = %,.2f %% %n", divide(numFirstInPair, numEntries) * 100d); stream.printf("Percent second in pair = %,.2f %% %n", divide(numSecondInPair, numEntries) * 100d); stream.printf("Aligment entries have some softClips: %b %n", hasSoftClips); }
From source file:com.netflix.curator.framework.recipes.atomic.TestDistributedAtomicLong.java
@Test public void testSimulation() throws Exception { final int threadQty = 20; final int executionQty = 50; final AtomicInteger optimisticTries = new AtomicInteger(); final AtomicInteger promotedLockTries = new AtomicInteger(); final AtomicInteger failures = new AtomicInteger(); final AtomicInteger errors = new AtomicInteger(); final SummaryStatistics timingStats = new SynchronizedSummaryStatistics(); List<Future<Void>> procs = Lists.newArrayList(); ExecutorService executorService = Executors.newFixedThreadPool(threadQty); for (int i = 0; i < threadQty; ++i) { Callable<Void> proc = new Callable<Void>() { @Override/*from www . j a va 2 s . co m*/ public Void call() throws Exception { doSimulation(executionQty, timingStats, optimisticTries, promotedLockTries, failures, errors); return null; } }; procs.add(executorService.submit(proc)); } for (Future<Void> f : procs) { f.get(); } System.out.println("OptimisticTries: " + optimisticTries.get()); System.out.println("PromotedLockTries: " + promotedLockTries.get()); System.out.println("Failures: " + failures.get()); System.out.println("Errors: " + errors.get()); System.out.println(); System.out.println("Avg time: " + timingStats.getMean()); System.out.println("Max time: " + timingStats.getMax()); System.out.println("Min time: " + timingStats.getMin()); System.out.println("Qty: " + timingStats.getN()); Assert.assertEquals(errors.get(), 0); Assert.assertTrue(optimisticTries.get() > 0); Assert.assertTrue(promotedLockTries.get() > 0); }
From source file:it.univpm.deit.semedia.musicuri.core.MusicURISearch.java
/** * Returns the average separation (distance) between the best and second-best matches for a certain batch of tests. * @param allStats an ArrayList containing PerformanceStatistic objects * @return average separation (distance) between the best and second-best matches *///w w w .ja v a 2 s .c om public double getAvgSeparationOfBestFromSecondBestMatch(ArrayList allStats) { PerformanceStatistic tempStat; SummaryStatistics TPBestMatchSummary = SummaryStatistics.newInstance(); SummaryStatistics TPSecondBestSummary = SummaryStatistics.newInstance(); for (int i = 0; i < allStats.size(); i++) { tempStat = (PerformanceStatistic) allStats.get(i); if (tempStat.isTruePositive()) { TPBestMatchSummary.addValue(tempStat.getBestMatchDistance()); TPSecondBestSummary.addValue(tempStat.getSecondBestMatchDistance()); } } double separation = TPSecondBestSummary.getMean() - TPBestMatchSummary.getMean(); return separation; }