List of usage examples for org.apache.commons.math.stat.descriptive SummaryStatistics SummaryStatistics
public SummaryStatistics()
From source file:boa.aggregators.ConfidenceIntervalAggregator.java
/** {@inheritDoc} */ @Override/* w w w . j a va2 s . c o m*/ public void finish() throws IOException, InterruptedException { if (this.isCombining()) { String s = ""; for (final Long key : map.keySet()) s += key + ":" + map.get(key) + ";"; this.collect(s, null); return; } try { final SummaryStatistics summaryStatistics = new SummaryStatistics(); for (final Long key : map.keySet()) for (int i = 0; i < map.get(key); i++) summaryStatistics.addValue(key); final double a = new TDistributionImpl(summaryStatistics.getN() - 1) .inverseCumulativeProbability(1.0 - n / 200.0); this.collect(a * summaryStatistics.getStandardDeviation() / Math.sqrt(summaryStatistics.getN())); } catch (final MathException e) { } }
From source file:geogebra.common.kernel.statistics.AlgoNormalQuantilePlot.java
private GeoSegment getQQLineSegment() { SummaryStatistics stats = new SummaryStatistics(); for (int i = 0; i < sortedData.length; i++) { stats.addValue(sortedData[i]);//w w w.j ava 2 s.co m } double sd = stats.getStandardDeviation(); double mean = stats.getMean(); double min = stats.getMin(); double max = stats.getMax(); // qq line: y = (1/sd)x - mean/sd GeoPoint startPoint = new GeoPoint(cons); startPoint.setCoords(min, (min / sd) - mean / sd, 1.0); GeoPoint endPoint = new GeoPoint(cons); endPoint.setCoords(max, (max / sd) - mean / sd, 1.0); GeoSegment seg = new GeoSegment(cons, startPoint, endPoint); seg.calcLength(); return seg; }
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 w w w . j a va2s . c o m * * @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:boa.aggregators.StatisticsAggregator.java
/** {@inheritDoc} */ @Override/*from w ww . ja va 2 s. co m*/ public void finish() throws IOException, InterruptedException { if (this.isCombining()) { String s = ""; for (final Long key : map.keySet()) s += key + ":" + map.get(key) + ";"; this.collect(s, null); return; } float median = 0; long medianPos = count / 2L; long curPos = 0; long prevPos = 0; long prevKey = 0; for (final Long key : map.keySet()) { curPos = prevPos + map.get(key); if (prevPos <= medianPos && medianPos < curPos) { if (curPos % 2 == 0 && prevPos == medianPos) median = (float) (key + prevKey) / 2.0f; else median = key; break; } prevKey = key; prevPos = curPos; } double s1 = 0; double s2 = 0; double s3 = 0; double s4 = 0; final SummaryStatistics summaryStatistics = new SummaryStatistics(); for (final Long key : map.keySet()) { s1 += key * map.get(key); s2 += key * key * map.get(key); s3 += key * key * key * map.get(key); s4 += key * key * key * key * map.get(key); for (int i = 0; i < map.get(key); i++) summaryStatistics.addValue(key); } final double mean = s1 / (double) count; final double var = s2 / (double) (count - 1) - s1 * s1 / (double) (count * (count - 1)); final double stdev = Math.sqrt(var); final double skewness = (s3 - 3 * s1 * s2 / (double) count + s1 * s1 * s1 * 2 / (count * count)) / (count * stdev * var); final double kurtosis = (s4 - s3 * s1 * 4 / count + s2 * s1 * s1 * 6 / (double) (count * count) - s1 * s1 * s1 * s1 * 3 / (double) (count * count * count)) / (count * var * var); double ci = 0.0; try { final TDistributionImpl tDist = new TDistributionImpl(summaryStatistics.getN() - 1); final double a = tDist.inverseCumulativeProbability(1.0 - 0.025); ci = a * summaryStatistics.getStandardDeviation() / Math.sqrt(summaryStatistics.getN()); } catch (final MathException e) { } this.collect(s1 + ", " + mean + ", " + median + ", " + stdev + ", " + var + ", " + kurtosis + ", " + skewness + ", " + ci); }
From source file:geogebra.kernel.statistics.AlgoTMeanEstimate.java
protected final void compute() { try {/*ww w .ja v a 2 s. com*/ // get statistics from sample data input if (input.length == 2) { int size = geoList.size(); if (!geoList.isDefined() || size < 2) { result.setUndefined(); return; } val = new double[size]; for (int i = 0; i < size; i++) { GeoElement geo = geoList.get(i); if (geo.isNumberValue()) { NumberValue num = (NumberValue) geo; val[i] = num.getDouble(); } else { result.setUndefined(); return; } } stats = new SummaryStatistics(); for (int i = 0; i < val.length; i++) { stats.addValue(val[i]); } n = stats.getN(); sd = stats.getStandardDeviation(); mean = stats.getMean(); } else { mean = geoMean.getDouble(); sd = geoSD.getDouble(); n = geoN.getDouble(); } level = geoLevel.getDouble(); // validate statistics if (level < 0 || level > 1 || sd < 0 || n < 1) { result.setUndefined(); return; } // get interval estimate me = getMarginOfError(sd, n, level); // return list = {low limit, high limit, mean, margin of error, df } result.clear(); boolean oldSuppress = cons.isSuppressLabelsActive(); cons.setSuppressLabelCreation(true); result.add(new GeoNumeric(cons, mean - me)); result.add(new GeoNumeric(cons, mean + me)); //result.add(new GeoNumeric(cons, mean)); //result.add(new GeoNumeric(cons, me)); //result.add(new GeoNumeric(cons, n-1)); // df cons.setSuppressLabelCreation(oldSuppress); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (MathException e) { e.printStackTrace(); } }
From source file:gsn.tests.performance.Queries.java
private void runQueries() { ArrayList<Future<QueryResult>> futures = new ArrayList<Future<QueryResult>>(); long startTime = System.currentTimeMillis(); for (int i = 0; i < nbQueries; i++) { // Pick the next vs //int index = (int) (Math.random() * mapping.size()); int index = i; Map.Entry<String, ArrayList<DataField>> entry = (Map.Entry<String, ArrayList<DataField>>) mapping .entrySet().toArray()[index]; String vsName = entry.getKey(); int nbFields = entry.getValue().size(); // Build the query StringBuilder query = new StringBuilder(gsnUrl).append("/multidata?vs[0]=").append(vsName) .append("&field[0]=All").append("&download_mode=inline").append("&download_format=csv") .append("&nb=SPECIFIED&nb_value=").append(maxQuerySize); // TODO Extend with Conditions, aggregations. futures.add(executor.submit(new QueryTask(query.toString(), nbFields, vsName))); }/*from w ww . ja v a2 s .co m*/ // Go through the results and compute the stats SummaryStatistics execTime = new SummaryStatistics(); SummaryStatistics tuples = new SummaryStatistics(); SummaryStatistics fields = new SummaryStatistics(); SummaryStatistics datas = new SummaryStatistics(); SummaryStatistics tuplesRate = new SummaryStatistics(); SummaryStatistics fieldsRate = new SummaryStatistics(); SummaryStatistics datasRate = new SummaryStatistics(); //int rowsSum = 0; //int fieldsSum = 0; //int dataSizeSum = 0; for (Future<QueryResult> result : futures) { try { QueryResult r = result.get(); double deltaInSec = r.delta / 1000.0d; double dataInMeg = r.dataSize * 8.0d / (1024.0d * 1024.0d); System.out.println(r); execTime.addValue(deltaInSec); // s tuples.addValue(r.rows); fields.addValue(r.nbFields); datas.addValue(dataInMeg); // MB // tuplesRate.addValue(r.rows / deltaInSec); // tuple/s fieldsRate.addValue(r.nbFields / deltaInSec); // field/s datasRate.addValue(dataInMeg / deltaInSec); //MB/s } catch (Exception e) { System.err.println(e.getMessage()); } } long endTime = System.currentTimeMillis(); // // float evalDuration = (endTime - startTime) / 1000.0f; // s System.out.println(new StringBuilder().append("\n------ GSN Queries Result --------").append("\n") .append("| URL: ").append(gsnUrl).append("\n").append("| Eval duration: ") .append(format(evalDuration)).append(" [s]\n").append("| Nb Queries : ").append(nbQueries) .append("\n").append("| Tuples : ").append(printStats(tuples, "no unit")).append("\n") .append("| Fields : ").append(printStats(fields, "no unit")).append("\n") .append("| Raw Data : ").append(printStats(datas, "MB")).append("\n") .append("| Download time: ").append(printStats(execTime, "s")).append("\n") .append("| Tuple Rate : ").append(printStats(tuplesRate, "tuple/s")).append("\n") .append("| Field Rate : ").append(printStats(fieldsRate, "field/s")).append("\n") .append("| Data Rate : ").append(printStats(datasRate, "MB/s")).append("\n") .append("-----------------------------------\n")); executor.shutdown(); }
From source file:geogebra.common.kernel.statistics.AlgoTMeanEstimate.java
@Override public final void compute() { try {//www . j ava 2 s . co m // get statistics from sample data input if (input.length == 2) { int size = geoList.size(); if (!geoList.isDefined() || size < 2) { result.setUndefined(); return; } val = new double[size]; for (int i = 0; i < size; i++) { GeoElement geo = geoList.get(i); if (geo instanceof NumberValue) { NumberValue num = (NumberValue) geo; val[i] = num.getDouble(); } else { result.setUndefined(); return; } } stats = new SummaryStatistics(); for (int i = 0; i < val.length; i++) { stats.addValue(val[i]); } n = stats.getN(); sd = stats.getStandardDeviation(); mean = stats.getMean(); } else { mean = geoMean.getDouble(); sd = geoSD.getDouble(); n = geoN.getDouble(); } level = geoLevel.getDouble(); // validate statistics if (level < 0 || level > 1 || sd < 0 || n < 1) { result.setUndefined(); return; } // get interval estimate me = getMarginOfError(sd, n, level); // return list = {low limit, high limit, mean, margin of error, df } result.clear(); boolean oldSuppress = cons.isSuppressLabelsActive(); cons.setSuppressLabelCreation(true); result.add(new GeoNumeric(cons, mean - me)); result.add(new GeoNumeric(cons, mean + me)); // result.add(new GeoNumeric(cons, mean)); // result.add(new GeoNumeric(cons, me)); // result.add(new GeoNumeric(cons, n-1)); // df cons.setSuppressLabelCreation(oldSuppress); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (MathException e) { e.printStackTrace(); } }
From source file:com.yahoo.ycsb.measurements.SeriesUnit.java
public OneMeasurementTimeSeries(String name, Properties props) { super(name);// ww w. j a v a 2 s. c o m _granularity = Integer.parseInt(props.getProperty(GRANULARITY, GRANULARITY_DEFAULT)); _measurements = new Vector<SeriesUnit>(); returncodes = new HashMap<Integer, int[]>(); tputstats = new SummaryStatistics(); }
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 {/* ww w. j a v a 2 s. 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:net.sf.maltcms.chromaui.project.spi.runnables.CondensePeakAnnotationsRunnable.java
@Override public void run() { try {//from ww w. j a v a2s. c om progressHandle.start(3); progressHandle.progress("Retrieving Tool Descriptors", 1); Collection<? extends IToolDescriptor> selectedTools = Dialogs.showAndSelectDescriptors( project.getToolsForPeakContainers(), Lookups.singleton(project), true, IToolDescriptor.class, "Condense Peaks", "Check Peak Tool Results to Condense"); if (!selectedTools.isEmpty()) { progressHandle.progress("Retrieving Peak Containers for " + selectedTools.size() + " Tools", 2); List<Peak1DContainer> peakContainers = new ArrayList<>(); for (IChromatogramDescriptor chrom : project.getChromatograms()) { for (Peak1DContainer container : project.getPeaks(chrom)) { if (selectedTools.contains(container.getTool())) { peakContainers.add(container); } } } File basedir = project.getImportLocation(this); for (Peak1DContainer container : peakContainers) { if (isCancel()) { return; } SummaryStatistics stats = new SummaryStatistics(); HistogramDataset hd = new HistogramDataset(); ArrayDouble.D2 pwd = new ArrayDouble.D2(container.getMembers().size(), container.getMembers().size()); int i = 0, j; ArrayList<IPeakAnnotationDescriptor> al = new ArrayList<>(container.getMembers()); HashMap<PeakFeatureVector, Clique<PeakFeatureVector>> cliques = new LinkedHashMap<>(); for (IPeakAnnotationDescriptor ipad1 : al) { Clique<PeakFeatureVector> c = new Clique<>(new PeakFeatureVectorComparator(), new PeakCliqueRTDiffMemberCriterion(), new PeakCliqueUpdater()); PeakFeatureVector pfv = new PeakFeatureVector(ipad1); c.add(pfv); cliques.put(pfv, c); } boolean done = false; while (!done) { for (Clique<PeakFeatureVector> pfv1 : cliques.values()) { for (Clique<PeakFeatureVector> pfv2 : cliques.values()) { Clique<PeakFeatureVector> jointClique = new Clique<>( new PeakFeatureVectorComparator(), new PeakCliqueRTDiffMemberCriterion(), new PeakCliqueUpdater()); Set<PeakFeatureVector> vectors = new LinkedHashSet<>(); } } } for (Clique<PeakFeatureVector> pfv1 : cliques.values()) { for (Clique<PeakFeatureVector> pfv2 : cliques.values()) { Clique<PeakFeatureVector> jointClique = new Clique<>(new PeakFeatureVectorComparator(), new PeakCliqueRTDiffMemberCriterion(), new PeakCliqueUpdater()); Set<PeakFeatureVector> vectors = new LinkedHashSet<>(); for (PeakFeatureVector p1 : pfv1.getFeatureVectorList()) { vectors.add(p1); for (PeakFeatureVector p2 : pfv2.getFeatureVectorList()) { vectors.add(p2); if (pfv1.add(p2)) { jointClique.add(p2); } else { vectors.remove(p2); } if (pfv2.add(p1)) { jointClique.add(p1); } else { vectors.remove(p1); } } } //jointClique.add } } System.out.println(stats); double snr = stats.getMean() / stats.getStandardDeviation(); Logger.getLogger(getClass().getName()).log(Level.INFO, "SNR: {0}", snr); // for (int u = 0; u < pwd.getShape()[0]; u++) { // for (int v = 0; v < pwd.getShape()[1]; v++) { // } // } saveHistogramChart(hd, new File(basedir, container.getChromatogram().getDisplayName() + "-" + container.getDisplayName() + "-similarity-histogram.png")); BufferedImage bi = ImageTools.makeImage2D(pwd, 256); ImageIO.write(bi, "PNG", new File(basedir, container.getChromatogram().getDisplayName() + "-" + container.getDisplayName() + ".png")); } progressHandle.progress("Calculating pairwise peak RTs", 3); project.refresh(); } else { Logger.getLogger(CondensePeakAnnotationsRunnable.class.getName()).log(Level.INFO, "IToolDescriptor selection was empty!"); } } catch (IllegalArgumentException | IOException e) { Exceptions.printStackTrace(e); } finally { progressHandle.finish(); } }