List of usage examples for org.apache.commons.math3.stat.descriptive DescriptiveStatistics getValues
public double[] getValues()
From source file:async.nio2.Main.java
private static DescriptiveStatistics combine(DescriptiveStatistics stats1, DescriptiveStatistics stats2) { Arrays.stream(stats2.getValues()).forEach(d -> stats1.addValue(d)); stats2.clear();// w w w . j a v a2 s.c o m return stats1; }
From source file:net.adamjak.thomas.graph.application.commons.StatisticsUtils.java
public static DescriptiveStatistics statisticsWithoutExtremes(DescriptiveStatistics inputStatistics, GrubbsLevel grubbsLevel) throws IllegalArgumentException { if (inputStatistics == null || grubbsLevel == null) throw new IllegalArgumentException("Params inputStatistics and grubbsLevel can not be null."); int countInput = inputStatistics.getValues().length; Double avgInput = inputStatistics.getMean(); Double stdInput = inputStatistics.getStandardDeviation(); Double s = stdInput * Math.sqrt((countInput - 1.0) / countInput); Double criticalValue = grubbsLevel.getCriticalValue(countInput); DescriptiveStatistics outputStatistic = new DescriptiveStatistics(); for (double inpVal : inputStatistics.getValues()) { double test = Math.abs(inpVal - avgInput) / s; if (test <= criticalValue) { outputStatistic.addValue(inpVal); }//from ww w. j a v a2 s . c o m } return outputStatistic; }
From source file:net.adamjak.thomas.graph.application.commons.StatisticsUtils.java
public static double getConfidenceInterval(DescriptiveStatistics inputStatistics, NormCritical uAlpha) throws IllegalArgumentException { if (inputStatistics == null || uAlpha == null) throw new IllegalArgumentException("Params inputStatistics or uAlpha can not be null!"); return (inputStatistics.getStandardDeviation() * uAlpha.getCriticalValue()) / Math.sqrt(inputStatistics.getValues().length); }
From source file:com.linkedin.pinot.perf.ForwardIndexReaderBenchmark.java
public static void singleValuedReadBenchMarkV1(File file, int numDocs, int columnSizeInBits) throws Exception { boolean signed = false; boolean isMmap = false; PinotDataBuffer heapBuffer = PinotDataBuffer.fromFile(file, ReadMode.heap, FileChannel.MapMode.READ_ONLY, "benchmark"); BaseSingleColumnSingleValueReader reader = new com.linkedin.pinot.core.io.reader.impl.v1.FixedBitSingleValueReader( heapBuffer, numDocs, columnSizeInBits, signed); // sequential read long start, end; DescriptiveStatistics stats = new DescriptiveStatistics(); for (int run = 0; run < MAX_RUNS; run++) { start = System.currentTimeMillis(); for (int i = 0; i < numDocs; i++) { int value = reader.getInt(i); }//from ww w . ja v a 2 s .c o m end = System.currentTimeMillis(); stats.addValue(end - start); } System.out.println(" v1 sequential read stats for " + file.getName()); System.out.println(stats.toString().replaceAll("\n", ", ") + " raw:" + Arrays.toString(stats.getValues())); reader.close(); heapBuffer.close(); }
From source file:com.linkedin.pinot.perf.ForwardIndexReaderBenchmark.java
public static void multiValuedReadBenchMarkV2(File file, int numDocs, int totalNumValues, int maxEntriesPerDoc, int columnSizeInBits) throws Exception { boolean signed = false; boolean isMmap = false; boolean readOneEachTime = true; PinotDataBuffer heapBuffer = PinotDataBuffer.fromFile(file, ReadMode.heap, FileChannel.MapMode.READ_ONLY, "benchmarking"); com.linkedin.pinot.core.io.reader.impl.v2.FixedBitMultiValueReader reader = new com.linkedin.pinot.core.io.reader.impl.v2.FixedBitMultiValueReader( heapBuffer, numDocs, totalNumValues, columnSizeInBits, signed); int[] intArray = new int[maxEntriesPerDoc]; long start, end; // read one entry at a time if (readOneEachTime) { DescriptiveStatistics stats = new DescriptiveStatistics(); for (int run = 0; run < MAX_RUNS; run++) { start = System.currentTimeMillis(); for (int i = 0; i < numDocs; i++) { int length = reader.getIntArray(i, intArray); }//w w w . j a v a2 s.c om end = System.currentTimeMillis(); stats.addValue((end - start)); } System.out.println("v2 multi value sequential read one stats for " + file.getName()); System.out.println( stats.toString().replaceAll("\n", ", ") + " raw:" + Arrays.toString(stats.getValues())); } reader.close(); heapBuffer.close(); }
From source file:com.fpuna.preproceso.PreprocesoTS.java
private static TrainingSetFeature calculoFeaturesMagnitud(List<Registro> muestras, String activity) { TrainingSetFeature Feature = new TrainingSetFeature(); DescriptiveStatistics stats_m = new DescriptiveStatistics(); double[] fft_m; double[] AR_4; muestras = Util.calcMagnitud(muestras); for (int i = 0; i < muestras.size(); i++) { stats_m.addValue(muestras.get(i).getM_1()); }/* w w w .jav a 2 s. com*/ //********* FFT ********* //fft_m = Util.transform(stats_m.getValues()); fft_m = FFTMixedRadix.fftPowerSpectrum(stats_m.getValues()); //******************* Calculos Magnitud *******************// //mean(s) - Arithmetic mean System.out.print(stats_m.getMean() + ","); Feature.setMeanX((float) stats_m.getMean()); //std(s) - Standard deviation System.out.print(stats_m.getStandardDeviation() + ","); Feature.setStdX((float) stats_m.getStandardDeviation()); //mad(s) - Median absolute deviation // //max(s) - Largest values in array System.out.print(stats_m.getMax() + ","); Feature.setMaxX((float) stats_m.getMax()); //min(s) - Smallest value in array System.out.print(stats_m.getMin() + ","); Feature.setMinX((float) stats_m.getMin()); //skewness(s) - Frequency signal Skewness System.out.print(stats_m.getSkewness() + ","); Feature.setSkewnessX((float) stats_m.getSkewness()); //kurtosis(s) - Frequency signal Kurtosis System.out.print(stats_m.getKurtosis() + ","); Feature.setKurtosisX((float) stats_m.getKurtosis()); //energy(s) - Average sum of the squares System.out.print(stats_m.getSumsq() / stats_m.getN() + ","); Feature.setEnergyX((float) (stats_m.getSumsq() / stats_m.getN())); //entropy(s) - Signal Entropy System.out.print(Util.calculateShannonEntropy(fft_m) + ","); Feature.setEntropyX(Util.calculateShannonEntropy(fft_m).floatValue()); //iqr (s) Interquartile range System.out.print(stats_m.getPercentile(75) - stats_m.getPercentile(25) + ","); Feature.setIqrX((float) (stats_m.getPercentile(75) - stats_m.getPercentile(25))); try { //autoregression (s) -4th order Burg Autoregression coefficients AR_4 = AutoRegression.calculateARCoefficients(stats_m.getValues(), 4, true); System.out.print(AR_4[0] + ","); System.out.print(AR_4[1] + ","); System.out.print(AR_4[2] + ","); System.out.print(AR_4[3] + ","); Feature.setArX1((float) AR_4[0]); Feature.setArX2((float) AR_4[1]); Feature.setArX3((float) AR_4[2]); Feature.setArX4((float) AR_4[3]); } catch (Exception ex) { Logger.getLogger(PreprocesoTS.class.getName()).log(Level.SEVERE, null, ex); } //meanFreq(s) - Frequency signal weighted average System.out.print(Util.meanFreq(fft_m, stats_m.getValues()) + ","); Feature.setMeanFreqx((float) Util.meanFreq(fft_m, stats_m.getValues())); //******************* Actividad *******************/ System.out.print(activity); System.out.print("\n"); Feature.setEtiqueta(activity); return Feature; }
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 w w w . j a v a 2 s . c o m @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); }
From source file:com.linkedin.pinot.perf.ForwardIndexReaderBenchmark.java
public static void multiValuedReadBenchMarkV1(File file, int numDocs, int totalNumValues, int maxEntriesPerDoc, int columnSizeInBits) throws Exception { System.out.println("******************************************************************"); System.out.println("Analyzing " + file.getName() + " numDocs:" + numDocs + ", totalNumValues:" + totalNumValues + ", maxEntriesPerDoc:" + maxEntriesPerDoc + ", numBits:" + columnSizeInBits); long start, end; boolean readFile = true; boolean randomRead = true; boolean contextualRead = true; boolean signed = false; boolean isMmap = false; PinotDataBuffer heapBuffer = PinotDataBuffer.fromFile(file, ReadMode.mmap, FileChannel.MapMode.READ_ONLY, "benchmarking"); BaseSingleColumnMultiValueReader reader = new com.linkedin.pinot.core.io.reader.impl.v1.FixedBitMultiValueReader( heapBuffer, numDocs, totalNumValues, columnSizeInBits, signed); int[] intArray = new int[maxEntriesPerDoc]; File outfile = new File("/tmp/" + file.getName() + ".raw"); FileWriter fw = new FileWriter(outfile); for (int i = 0; i < numDocs; i++) { int length = reader.getIntArray(i, intArray); StringBuilder sb = new StringBuilder(); String delim = ""; for (int j = 0; j < length; j++) { sb.append(delim);/*w w w .j a v a 2 s . com*/ sb.append(intArray[j]); delim = ","; } fw.write(sb.toString()); fw.write("\n"); } fw.close(); // sequential read if (readFile) { DescriptiveStatistics stats = new DescriptiveStatistics(); RandomAccessFile raf = new RandomAccessFile(file, "rw"); ByteBuffer buffer = ByteBuffer.allocateDirect((int) file.length()); raf.getChannel().read(buffer); for (int run = 0; run < MAX_RUNS; run++) { long length = file.length(); start = System.currentTimeMillis(); for (int i = 0; i < length; i++) { byte b = buffer.get(i); } end = System.currentTimeMillis(); stats.addValue((end - start)); } System.out.println("v1 multi value read bytes stats for " + file.getName()); System.out.println( stats.toString().replaceAll("\n", ", ") + " raw:" + Arrays.toString(stats.getValues())); raf.close(); } if (randomRead) { DescriptiveStatistics stats = new DescriptiveStatistics(); for (int run = 0; run < MAX_RUNS; run++) { start = System.currentTimeMillis(); for (int i = 0; i < numDocs; i++) { int length = reader.getIntArray(i, intArray); } end = System.currentTimeMillis(); stats.addValue((end - start)); } System.out.println("v1 multi value sequential read one stats for " + file.getName()); System.out.println( stats.toString().replaceAll("\n", ", ") + " raw:" + Arrays.toString(stats.getValues())); } if (contextualRead) { DescriptiveStatistics stats = new DescriptiveStatistics(); for (int run = 0; run < MAX_RUNS; run++) { MultiValueReaderContext context = (MultiValueReaderContext) reader.createContext(); start = System.currentTimeMillis(); for (int i = 0; i < numDocs; i++) { int length = reader.getIntArray(i, intArray, context); } end = System.currentTimeMillis(); // System.out.println("RUN:" + run + "Time:" + (end-start)); stats.addValue((end - start)); } System.out.println("v1 multi value sequential read one with context stats for " + file.getName()); System.out.println( stats.toString().replaceAll("\n", ", ") + " raw:" + Arrays.toString(stats.getValues())); } reader.close(); heapBuffer.close(); System.out.println("******************************************************************"); }
From source file:com.insightml.data.features.stats.FeatureStatistics.java
private int getDistinct(final String feature) { final DescriptiveStatistics stat = stats.get(feature); if (stat == null) { return 0; }/*from ww w . j av a 2 s . c om*/ final Set<Double> values = Sets.create((int) stat.getN()); for (final double val : stat.getValues()) { values.add(val); } return values.size(); }
From source file:com.fpuna.preproceso.PreprocesoTS.java
private static void calculoFeatures(Registro[] muestras, String activity) { DescriptiveStatistics stats_x = new DescriptiveStatistics(); DescriptiveStatistics stats_y = new DescriptiveStatistics(); DescriptiveStatistics stats_z = new DescriptiveStatistics(); //DescriptiveStatistics stats_m1 = new DescriptiveStatistics(); //DescriptiveStatistics stats_m2 = new DescriptiveStatistics(); double[] fft_x; double[] fft_y; double[] fft_z; double[] AR_4; for (int i = 0; i < muestras.length; i++) { stats_x.addValue(muestras[i].getValor_x()); stats_y.addValue(muestras[i].getValor_y()); stats_z.addValue(muestras[i].getValor_z()); }/* w w w .ja va 2s . c o m*/ //********* FFT ********* fft_x = Util.transform(stats_x.getValues()); fft_y = Util.transform(stats_y.getValues()); fft_z = Util.transform(stats_z.getValues()); //******************* Eje X *******************// //mean(s) - Arithmetic mean System.out.print(stats_x.getMean() + ","); //std(s) - Standard deviation System.out.print(stats_x.getStandardDeviation() + ","); //mad(s) - Median absolute deviation // //max(s) - Largest values in array System.out.print(stats_x.getMax() + ","); //min(s) - Smallest value in array System.out.print(stats_x.getMin() + ","); //skewness(s) - Frequency signal Skewness System.out.print(stats_x.getSkewness() + ","); //kurtosis(s) - Frequency signal Kurtosis System.out.print(stats_x.getKurtosis() + ","); //energy(s) - Average sum of the squares System.out.print(stats_x.getSumsq() / stats_x.getN() + ","); //entropy(s) - Signal Entropy System.out.print(Util.calculateShannonEntropy(fft_x) + ","); //iqr (s) Interquartile range System.out.print(stats_x.getPercentile(75) - stats_x.getPercentile(25) + ","); try { //autoregression (s) -4th order Burg Autoregression coefficients AR_4 = AutoRegression.calculateARCoefficients(stats_x.getValues(), 4, true); System.out.print(AR_4[0] + ","); System.out.print(AR_4[1] + ","); System.out.print(AR_4[2] + ","); System.out.print(AR_4[3] + ","); } catch (Exception ex) { Logger.getLogger(PreprocesoTS.class.getName()).log(Level.SEVERE, null, ex); } //meanFreq(s) - Frequency signal weighted average System.out.print(Util.meanFreq(fft_x, stats_x.getValues()) + ","); //******************* Eje Y *******************// //mean(s) - Arithmetic mean System.out.print(stats_y.getMean() + ","); //std(s) - Standard deviation System.out.print(stats_y.getStandardDeviation() + ","); //mad(s) - Median absolute deviation // //max(s) - Largest values in array System.out.print(stats_y.getMax() + ","); //min(s) - Smallest value in array System.out.print(stats_y.getMin() + ","); //skewness(s) - Frequency signal Skewness System.out.print(stats_y.getSkewness() + ","); //kurtosis(s) - Frequency signal Kurtosis System.out.print(stats_y.getKurtosis() + ","); //energy(s) - Average sum of the squares System.out.print(stats_y.getSumsq() / stats_y.getN() + ","); //entropy(s) - Signal Entropy System.out.print(Util.calculateShannonEntropy(fft_y) + ","); //iqr (s) Interquartile range System.out.print(stats_y.getPercentile(75) - stats_y.getPercentile(25) + ","); try { //autoregression (s) -4th order Burg Autoregression coefficients AR_4 = AutoRegression.calculateARCoefficients(stats_y.getValues(), 4, true); System.out.print(AR_4[0] + ","); System.out.print(AR_4[1] + ","); System.out.print(AR_4[2] + ","); System.out.print(AR_4[3] + ","); } catch (Exception ex) { Logger.getLogger(PreprocesoTS.class.getName()).log(Level.SEVERE, null, ex); } //meanFreq(s) - Frequency signal weighted average System.out.print(Util.meanFreq(fft_y, stats_y.getValues()) + ","); //******************* Eje Z *******************// //mean(s) - Arithmetic mean System.out.print(stats_z.getMean() + ","); //std(s) - Standard deviation System.out.print(stats_z.getStandardDeviation() + ","); //mad(s) - Median absolute deviation // //max(s) - Largest values in array System.out.print(stats_z.getMax() + ","); //min(s) - Smallest value in array System.out.print(stats_z.getMin() + ","); //skewness(s) - Frequency signal Skewness System.out.print(stats_z.getSkewness() + ","); //kurtosis(s) - Frequency signal Kurtosis System.out.print(stats_z.getKurtosis() + ","); //energy(s) - Average sum of the squares System.out.print(stats_z.getSumsq() / stats_z.getN() + ","); //entropy(s) - Signal Entropy System.out.print(Util.calculateShannonEntropy(fft_z) + ","); //iqr (s) Interquartile range System.out.print(stats_z.getPercentile(75) - stats_z.getPercentile(25) + ","); try { //autoregression (s) -4th order Burg Autoregression coefficients AR_4 = AutoRegression.calculateARCoefficients(stats_z.getValues(), 4, true); System.out.print(AR_4[0] + ","); System.out.print(AR_4[1] + ","); System.out.print(AR_4[2] + ","); System.out.print(AR_4[3] + ","); } catch (Exception ex) { Logger.getLogger(PreprocesoTS.class.getName()).log(Level.SEVERE, null, ex); } //meanFreq(s) - Frequency signal weighted average System.out.print(Util.meanFreq(fft_z, stats_z.getValues()) + ","); //******************* Feature combinados *******************/ //sma(s1; s2; s3) - Signal magnitude area System.out.print(Util.sma(stats_x.getValues(), stats_y.getValues(), stats_z.getValues()) + ","); //correlation(s1; s2) - Pearson Correlation coefficient System.out.print(new PearsonsCorrelation().correlation(stats_x.getValues(), stats_y.getValues()) + ","); System.out.print(new PearsonsCorrelation().correlation(stats_x.getValues(), stats_z.getValues()) + ","); System.out.print(new PearsonsCorrelation().correlation(stats_y.getValues(), stats_z.getValues()) + ","); //******************* Actividad *******************/ System.out.print(activity); System.out.print("\n"); }