List of usage examples for org.apache.commons.math3.stat.descriptive DescriptiveStatistics addValue
public void addValue(double v)
From source file:com.linkedin.pinot.perf.ForwardIndexReaderBenchmark.java
public static void singleValuedReadBenchMarkV2(File file, int numDocs, int numBits) throws Exception { boolean signed = false; boolean isMmap = false; long start, end; boolean fullScan = true; boolean batchRead = true; boolean singleRead = true; PinotDataBuffer heapBuffer = PinotDataBuffer.fromFile(file, ReadMode.heap, FileChannel.MapMode.READ_ONLY, "benchmarking"); com.linkedin.pinot.core.io.reader.impl.v2.FixedBitSingleValueReader reader = new com.linkedin.pinot.core.io.reader.impl.v2.FixedBitSingleValueReader( heapBuffer, numDocs, numBits, signed); if (fullScan) { DescriptiveStatistics stats = new DescriptiveStatistics(); ByteBuffer buffer = ByteBuffer.allocateDirect((int) file.length()); RandomAccessFile raf = new RandomAccessFile(file, "r"); raf.getChannel().read(buffer);/*from w w w . j a v a 2s .c o m*/ raf.close(); int[] input = new int[numBits]; int[] output = new int[32]; int numBatches = (numDocs + 31) / 32; for (int run = 0; run < MAX_RUNS; run++) { start = System.currentTimeMillis(); for (int i = 0; i < numBatches; i++) { for (int j = 0; j < numBits; j++) { input[j] = buffer.getInt(i * numBits * 4 + j * 4); } BitPacking.fastunpack(input, 0, output, 0, numBits); } end = System.currentTimeMillis(); stats.addValue((end - start)); } System.out.println(" v2 full scan stats for " + file.getName()); System.out.println( stats.toString().replaceAll("\n", ", ") + " raw:" + Arrays.toString(stats.getValues())); } if (singleRead) { DescriptiveStatistics stats = new DescriptiveStatistics(); // sequential read for (int run = 0; run < MAX_RUNS; run++) { start = System.currentTimeMillis(); for (int i = 0; i < numDocs; i++) { int value = reader.getInt(i); } end = System.currentTimeMillis(); stats.addValue((end - start)); } System.out.println(" v2 sequential single read for " + file.getName()); System.out.println( stats.toString().replaceAll("\n", ", ") + " raw:" + Arrays.toString(stats.getValues())); } if (batchRead) { DescriptiveStatistics stats = new DescriptiveStatistics(); int batchSize = Math.min(5000, numDocs); int[] output = new int[batchSize]; int[] rowIds = new int[batchSize]; // sequential read for (int run = 0; run < MAX_RUNS; run++) { start = System.currentTimeMillis(); int rowId = 0; while (rowId < numDocs) { int length = Math.min(batchSize, numDocs - rowId); for (int i = 0; i < length; i++) { rowIds[i] = rowId + i; } reader.getIntBatch(rowIds, output, length); rowId = rowId + length; } end = System.currentTimeMillis(); stats.addValue((end - start)); } System.out.println("v2 sequential batch read stats for " + file.getName()); System.out.println( stats.toString().replaceAll("\n", ", ") + " raw:" + Arrays.toString(stats.getValues())); } reader.close(); }
From source file:cz.cuni.mff.d3s.tools.perfdoc.server.measuring.statistics.Statistics.java
public long computeMedian() { if (measurementResults.isEmpty()) { return -1; }/*from www . ja v a2 s . co m*/ DescriptiveStatistics stats = new DescriptiveStatistics(); for (Long l : measurementResults) { stats.addValue(l); } return (long) stats.getMean(); }
From source file:cz.cuni.mff.d3s.tools.perfdoc.server.measuring.statistics.Statistics.java
public long computeMean() { if (measurementResults.isEmpty()) { return -1; }/*from w w w. ja v a 2 s .c o m*/ DescriptiveStatistics stats = new DescriptiveStatistics(); for (Long l : measurementResults) { stats.addValue(l); } return (long) stats.getPercentile(50); }
From source file:de.tudarmstadt.ukp.dkpro.core.performance.ThroughputTestAE.java
public String getPerformanceaAnalysis() { StringBuilder sb = new StringBuilder(); long sumMillis = 0; for (double timeValue : times) { sumMillis += timeValue;/*from w w w .j a v a2s.c o m*/ } DescriptiveStatistics statTimes = new DescriptiveStatistics(); for (Long timeValue : times) { statTimes.addValue((double) timeValue / 1000); } sb.append("Estimate after processing " + times.size() + " documents."); sb.append(LF); Formatter formatter = new Formatter(sb, Locale.US); formatter.format("Time / Document: %,.3f (%,.3f)\n", statTimes.getMean(), statTimes.getStandardDeviation()); formatter.format("Time / 10^4 Token: %,.3f\n", getNormalizedTime(sumMillis, nrofTokens, 1000)); formatter.format("Time / 10^4 Sentences: %,.3f\n", getNormalizedTime(sumMillis, nrofSentences, 1000)); formatter.close(); return sb.toString(); }
From source file:gr.iti.mklab.reveal.forensics.util.Util.java
public static double[][] blockNoiseVar(double[][] inputMap, int blockSize) { // Calculate the block variance of a noise map int blockedWidth = (int) Math.floor(inputMap.length / blockSize) * blockSize; int blockedHeight = (int) Math.floor(inputMap[0].length / blockSize) * blockSize; double[][] blockedIm = new double[blockedWidth / blockSize][blockedHeight / blockSize]; DescriptiveStatistics blockValues; for (int ii = 0; ii < blockedWidth; ii = ii + blockSize) { for (int jj = 0; jj < blockedHeight; jj = jj + blockSize) { blockValues = new DescriptiveStatistics(); for (int B_ii = ii; B_ii < ii + blockSize; B_ii++) { for (int B_jj = jj; B_jj < jj + blockSize; B_jj++) { blockValues.addValue(Math.abs(inputMap[B_ii][B_jj])); }// ww w. j a v a 2 s . co m } blockedIm[ii / blockSize][jj / blockSize] = Math.sqrt(blockValues.getPercentile(50) / 0.6745); } } return blockedIm; }
From source file:gr.iti.mklab.reveal.forensics.util.Util.java
public static double[][] blockVar(double[][] inputIm, int blockSize) { // block variance of input int image int blockedWidth = (int) Math.floor(inputIm.length / blockSize) * blockSize; int blockedHeight = (int) Math.floor(inputIm[0].length / blockSize) * blockSize; double[][] blockedIm = new double[blockedWidth / blockSize][blockedHeight / blockSize]; DescriptiveStatistics blockValues; for (int ii = 0; ii < blockedWidth; ii = ii + blockSize) { for (int jj = 0; jj < blockedHeight; jj = jj + blockSize) { blockValues = new DescriptiveStatistics(); for (int B_ii = ii; B_ii < ii + blockSize; B_ii++) { for (int B_jj = jj; B_jj < jj + blockSize; B_jj++) { blockValues.addValue(Math.abs(inputIm[B_ii][B_jj])); }//from w w w . j a v a2 s. c o m } blockedIm[ii / blockSize][jj / blockSize] = blockValues.getPopulationVariance(); } } return blockedIm; }
From source file:iac_soap.statsq.NormVerdService.java
@Override public NormVerdResponse calculateNormVerd(List<Double> data) throws MyFault { //Service Requirements if (data.isEmpty()) { throw new MyFault("No data is provided"); } else if (data.size() < 2) { throw new MyFault("A minimum of two data elements is required."); }/* ww w. j av a 2s .c o m*/ //Declaring Apache Commons DescriptiveStatistics DescriptiveStatistics stats = new DescriptiveStatistics(); //Filling DescriptiveStatistics class with the provided dataset for (int i = 0; i < data.size(); i++) { stats.addValue(data.get(i)); } //Let the DescriptiveStatistics class calculate the mean and standard deviation double mean = stats.getMean(); double std = stats.getStandardDeviation(); //Implementing the KolmogorovSmirnov test & calculating the kurtosis and skewness NormalDistribution x = new NormalDistribution(mean, std); double p_value = TestUtils.kolmogorovSmirnovTest(x, stats.getValues(), false); double kurtosis = stats.getKurtosis(); double skewness = stats.getSkewness(); boolean result = false; //Check if the dataset is a normal distribution: //KolmogorovSmirnov p_value should be >= 0.05 //Both kurtosis and skewness should be between -2.0 and 2.0 if (kurtosis < 2.0 && kurtosis > -2.0 && skewness < 2.0 && skewness > -2.0 && p_value >= 0.05) { result = true; } //Response message: NormVerdResponse nvr = new NormVerdResponse(result, p_value, kurtosis, skewness); return nvr; }
From source file:io.yields.math.framework.DomainTest.java
@Explore(name = "Test Variable Distribution", dataProvider = DataProviders.FixedMersenneTwisterDataProvider.class) @Exploration(name = "Test Function", context = FunctionExplorerContext.class, group = "domain") public void testVariableDistribution(Explorer<Double> explorer) { assertThat(explorer.all().count()).isEqualTo(explorer.valid().count()); assertThat(explorer.valid().count()).isEqualTo(explorer.valid().count()); assertThat(explorer.invalid().count()).isEqualTo(0); assertThat(explorer.propertyError().count()).isEqualTo(0); DescriptiveStatistics stats = new DescriptiveStatistics(); explorer.all().forEach(result -> stats.addValue(result.getFunctionOutcome().orElse(0d))); assertThat(stats.getMean()).isEqualTo(0, delta(0.1)); assertThat(stats.getMax()).isEqualTo(1, delta(0.1)); assertThat(stats.getMin()).isEqualTo(-1, delta(0.1)); }
From source file:io.yields.math.framework.DomainTest.java
@Explore(name = "Test Variable Distribution with multiple properties", dataProvider = DataProviders.FixedMersenneTwisterDataProvider.class) @Exploration(name = "Test Function", context = FunctionExplorerMultiplePropertiesContext.class, group = "domain") public void testVariableDistributionMultipleProperties(Explorer<Double> explorer) { assertThat(explorer.all().count()).isEqualTo(explorer.valid().count()); assertThat(explorer.valid().count()).isEqualTo(explorer.valid().count()); assertThat(explorer.invalid().count()).isEqualTo(0); assertThat(explorer.propertyError().count()).isEqualTo(0); DescriptiveStatistics stats = new DescriptiveStatistics(); explorer.all().forEach(result -> stats.addValue(result.getFunctionOutcome().orElse(0d))); assertThat(stats.getMean()).isEqualTo(0, delta(0.1)); assertThat(stats.getMax()).isEqualTo(1, delta(0.1)); assertThat(stats.getMin()).isEqualTo(-1, delta(0.1)); }
From source file:mase.stat.FitnessStat.java
/** * Prints out the statistics, but does not end with a println -- this lets * overriding methods print additional statistics on the same line *//*from ww w. j a v a 2 s .com*/ @Override public void postEvaluationStatistics(final EvolutionState state) { super.postEvaluationStatistics(state); int subpops = state.population.subpops.length; // number of supopulations DescriptiveStatistics[] fitness = new DescriptiveStatistics[subpops]; for (int i = 0; i < subpops; i++) { fitness[i] = new DescriptiveStatistics(); } int evals = state.evaluator.p_problem instanceof MaseProblem ? ((MaseProblem) state.evaluator.p_problem).getTotalEvaluations() : 0; // gather per-subpopulation statistics for (int x = 0; x < subpops; x++) { for (int y = 0; y < state.population.subpops[x].individuals.length; y++) { if (state.population.subpops[x].individuals[y].evaluated) {// he's got a valid fitness // update fitness double f = ((ExpandedFitness) state.population.subpops[x].individuals[y].fitness) .getFitnessScore(); bestSoFar[x] = Math.max(bestSoFar[x], f); absoluteBest = Math.max(absoluteBest, f); fitness[x].addValue(f); } } // print out fitness information if (doSubpops) { state.output.println(state.generation + " " + evals + " " + x + " " + fitness[x].getN() + " " + fitness[x].getMin() + " " + fitness[x].getMean() + " " + fitness[x].getMax() + " " + bestSoFar[x], statisticslog); } } // Now gather global statistics DescriptiveStatistics global = new DescriptiveStatistics(); for (DescriptiveStatistics ds : fitness) { for (double v : ds.getValues()) { global.addValue(v); } } state.output.println(state.generation + " " + evals + " NA " + global.getN() + " " + global.getMin() + " " + global.getMean() + " " + global.getMax() + " " + absoluteBest, statisticslog); }