List of usage examples for org.apache.commons.math3.stat.descriptive DescriptiveStatistics DescriptiveStatistics
public DescriptiveStatistics()
From source file:mase.deprecated.FastMathTest.java
public static void main(String[] args) { double MIN = -10; double MAX = 10; int N = 10000; DescriptiveStatistics diff = new DescriptiveStatistics(); DescriptiveStatistics diffJava = new DescriptiveStatistics(); long tFast = 0, tNormal = 0, tBounded = 0, tJava = 0; for (int i = 0; i < N; i++) { double x = Math.random() * (MAX - MIN) + MIN; long t = System.nanoTime(); double v1 = (1.0 / (1.0 + FastMath.expQuick(-1 * x))); tFast += System.nanoTime() - t; t = System.nanoTime();/* w w w .j a v a 2 s .co m*/ double v2 = (1.0 / (1.0 + FastMath.exp(-1 * x))); tNormal += System.nanoTime() - t; t = System.nanoTime(); double v3 = (1.0 / (1.0 + BoundMath.exp(-1 * x))); tBounded += System.nanoTime() - t; t = System.nanoTime(); double v4 = (1.0 / (1.0 + Math.exp(-1 * x))); tJava += System.nanoTime() - t; diff.addValue(Math.abs(v1 - v2)); diffJava.addValue(Math.abs(v3 - v1)); } System.out.println("MAX: " + diff.getMax()); System.out.println("MEAN: " + diff.getMean()); System.out.println("MAX JAVA: " + diffJava.getMax()); System.out.println("MEAN JAVA: " + diffJava.getMean()); System.out.println("Fast: " + tFast); System.out.println("Normal: " + tNormal); System.out.println("Bounded: " + tBounded); System.out.println("Java: " + tJava); }
From source file:com.fpuna.preproceso.TestApacheMathLibDemo.java
/** * @param args//from w ww.jav a 2 s . c om */ public static void main(String[] args) { RandomGenerator randomGenerator = new JDKRandomGenerator(); System.out.println(randomGenerator.nextInt()); System.out.println(randomGenerator.nextDouble()); /** * Descriptive Statistics like MEAN,GP,SD,MAX * */ DescriptiveStatistics stats = new DescriptiveStatistics(); stats.addValue(1); stats.addValue(2); stats.addValue(3); stats.addValue(4); stats.addValue(5); stats.addValue(6); stats.addValue(7); System.out.print("Mean : " + stats.getMean() + "\n"); System.out.print("Standard deviation : " + stats.getStandardDeviation() + "\n"); System.out.print("Max : " + stats.getMax() + "\n"); /** * Complex number format a+bi * */ Complex c1 = new Complex(1, 2); Complex c2 = new Complex(2, 3); System.out.print("Absolute of c1 " + c1.abs() + "\n"); System.out.print("Addition : " + (c1.add(c2)) + "\n"); }
From source file:mase.deprecated.SelectionBenchmark.java
public static void main(String[] args) { int L = 100, N = 10000; double[] truncationP = new double[] { 0.25, 0.50, 0.75 }; int[] tournamentP = new int[] { 2, 5, 7, 10 }; DescriptiveStatistics[] truncationStat = new DescriptiveStatistics[truncationP.length]; for (int i = 0; i < truncationStat.length; i++) { truncationStat[i] = new DescriptiveStatistics(); }/*from w w w . j a v a 2 s .c o m*/ DescriptiveStatistics[] tournamentStat = new DescriptiveStatistics[tournamentP.length]; DescriptiveStatistics[] tournamentStat2 = new DescriptiveStatistics[tournamentP.length]; for (int i = 0; i < tournamentStat.length; i++) { tournamentStat[i] = new DescriptiveStatistics(); tournamentStat2[i] = new DescriptiveStatistics(); } DescriptiveStatistics rouletteStat = new DescriptiveStatistics(); DescriptiveStatistics rouletteStat2 = new DescriptiveStatistics(); DescriptiveStatistics baseStat = new DescriptiveStatistics(); for (int i = 0; i < N; i++) { // generate test vector double[] test = new double[L]; for (int j = 0; j < L; j++) { test[j] = Math.random(); } // truncation for (int p = 0; p < truncationP.length; p++) { double[] v = Arrays.copyOf(test, test.length); Arrays.sort(v); int nElites = (int) Math.ceil(truncationP[p] * test.length); double cutoff = v[test.length - nElites]; double[] weights = new double[test.length]; for (int k = 0; k < test.length; k++) { weights[k] = test[k] >= cutoff ? test[k] * (1 / truncationP[p]) : 0; } truncationStat[p].addValue(sum(weights)); } // tournament for (int p = 0; p < tournamentP.length; p++) { double[] weights = new double[test.length]; HashSet<Integer> added = new HashSet<Integer>(); for (int k = 0; k < test.length; k++) { int idx = makeTournament(test, tournamentP[p]); weights[idx] += test[idx]; added.add(idx); } tournamentStat2[p].addValue(added.size()); tournamentStat[p].addValue(sum(weights)); } // roulette double[] weights = new double[test.length]; HashSet<Integer> added = new HashSet<Integer>(); for (int k = 0; k < test.length; k++) { int idx = roulette(test); weights[idx] += test[idx]; added.add(idx); } rouletteStat.addValue(sum(weights)); rouletteStat2.addValue(added.size()); // base baseStat.addValue(sum(test)); } for (int p = 0; p < truncationP.length; p++) { System.out.println("Truncation\t" + truncationP[p] + "\t" + truncationStat[p].getMean() + "\t" + truncationStat[p].getStandardDeviation() + "\t" + ((int) Math.ceil(L * truncationP[p])) + "\t 0"); } for (int p = 0; p < tournamentP.length; p++) { System.out.println("Tournament\t" + tournamentP[p] + "\t" + tournamentStat[p].getMean() + "\t" + tournamentStat[p].getStandardDeviation() + "\t" + tournamentStat2[p].getMean() + "\t" + tournamentStat2[p].getStandardDeviation()); } System.out.println("Roulette\t\t" + rouletteStat.getMean() + "\t" + rouletteStat.getStandardDeviation() + "\t" + rouletteStat2.getMean() + "\t" + rouletteStat2.getStandardDeviation()); System.out.println( "Base \t\t" + baseStat.getMean() + "\t" + baseStat.getStandardDeviation() + "\t " + L + "\t0"); }
From source file:es.upm.oeg.tools.rdfshapes.libdemo.CommonsMathDemo.java
public static void main(String[] args) { DescriptiveStatistics stats = new DescriptiveStatistics(); int inputArray[] = { 3, 4, 5, 6, 2, 3, 4, 3, 3, 4, 3, 6, 3, 2, 3, 1, 2, 1, 1, 1, 3 }; // Add the data from the array for (int i = 0; i < inputArray.length; i++) { stats.addValue(inputArray[i]);//from w ww . j av a 2s .c o m } double mean = stats.getMean(); double std = stats.getStandardDeviation(); double median = stats.getPercentile(50); System.out.println("mean" + stats.getMean()); System.out.println("standard deviation" + stats.getStandardDeviation()); System.out.println("skewness" + stats.getSkewness()); }
From source file:de.tudarmstadt.ukp.experiments.argumentation.convincingness.sampling.Step5bGoldLabelStatistics.java
@SuppressWarnings("unchecked") public static void main(String[] args) throws Exception { String inputDir = args[0];/*from w ww . j a va2s . c o m*/ Collection<File> files = IOHelper.listXmlFiles(new File(inputDir)); int totalPairsWithReasonSameAsGold = 0; DescriptiveStatistics ds = new DescriptiveStatistics(); DescriptiveStatistics statsPerTopic = new DescriptiveStatistics(); Map<String, Integer> goldDataDistribution = new HashMap<>(); int totalGoldReasonTokens = 0; for (File file : files) { List<AnnotatedArgumentPair> argumentPairs = (List<AnnotatedArgumentPair>) XStreamTools.getXStream() .fromXML(file); int pairsPerTopicCounter = 0; for (AnnotatedArgumentPair annotatedArgumentPair : argumentPairs) { String goldLabel = annotatedArgumentPair.getGoldLabel(); int sameInOnePair = 0; if (goldLabel != null) { if (!goldDataDistribution.containsKey(goldLabel)) { goldDataDistribution.put(goldLabel, 0); } goldDataDistribution.put(goldLabel, goldDataDistribution.get(goldLabel) + 1); // get gold reason statistics for (AnnotatedArgumentPair.MTurkAssignment assignment : annotatedArgumentPair.mTurkAssignments) { String label = assignment.getValue(); if (goldLabel.equals(label)) { sameInOnePair++; totalGoldReasonTokens += assignment.getReason().split("\\W+").length; } } pairsPerTopicCounter++; } ds.addValue(sameInOnePair); totalPairsWithReasonSameAsGold += sameInOnePair; } statsPerTopic.addValue(pairsPerTopicCounter); } System.out.println("Total reasons matching gold " + totalPairsWithReasonSameAsGold); System.out.println(ds); int totalPairs = 0; for (Integer pairs : goldDataDistribution.values()) { totalPairs += pairs; } System.out.println(goldDataDistribution); System.out.println(goldDataDistribution.values()); System.out.println("Total pairs: " + totalPairs); System.out.println("Stats per topic: " + statsPerTopic); System.out.println("Total gold reason tokens: " + totalGoldReasonTokens); }
From source file:AverageCost.java
public static void main(String[] args) throws FileNotFoundException, IOException { //Directory of the n files String directory_path = "/home/gauss/rgrunitzki/Dropbox/Profissional/UFRGS/Doutorado/Artigo TRI15/SF Experiments/IQ-Learning/"; BufferedReader reader = null; //Line to analyse String line = ""; String csvDivisor = ";"; int totalLines = 1002; int totalRows = 532; String filesToRead[] = new File(directory_path).list(); Arrays.sort(filesToRead);//from ww w. j a v a2 s . c o m System.out.println(filesToRead.length); List<List<DescriptiveStatistics>> summary = new ArrayList<>(); for (int i = 0; i <= totalLines; i++) { summary.add(new ArrayList<DescriptiveStatistics>()); for (int j = 0; j <= totalRows; j++) { summary.get(i).add(new DescriptiveStatistics()); } } //reads all files for (String file : filesToRead) { reader = new BufferedReader(new FileReader(directory_path + file)); int lineCounter = 0; //reads all file's line while ((line = reader.readLine()) != null) { if (lineCounter > 0) { String[] rows = line.trim().split(csvDivisor); //reads all line's row for (int r = 0; r < rows.length; r++) { summary.get(lineCounter).get(r).addValue(Double.parseDouble(rows[r])); } } lineCounter++; } //System.out.println(file.split("/")[file.split("/").length - 1] + csvDivisor + arithmeticMean(avgCost) + csvDivisor + standardDeviation(avgCost)); } //generate mean and standard deviation; for (List<DescriptiveStatistics> summaryLines : summary) { System.out.println(); for (DescriptiveStatistics summaryLineRow : summaryLines) { System.out.print(summaryLineRow.getMean() + ";" + summaryLineRow.getStandardDeviation() + ";"); } } }
From source file:fr.inria.eventcloud.benchmarks.QuadrupleStatsEvaluator.java
public static void main(String[] args) throws FileNotFoundException { final DescriptiveStatistics g = new DescriptiveStatistics(); final DescriptiveStatistics s = new DescriptiveStatistics(); final DescriptiveStatistics p = new DescriptiveStatistics(); final DescriptiveStatistics o = new DescriptiveStatistics(); RDFDataMgr.parse(new StreamRDF() { @Override/* w ww. ja va 2s . c o m*/ public void triple(Triple triple) { } @Override public void start() { } @Override public void quad(Quad quad) { g.addValue(SemanticCoordinate.applyDopingFunction(quad.getGraph()) // quad.getGraph().toString() .length()); s.addValue(SemanticCoordinate.applyDopingFunction(quad.getSubject()) // quad.getSubject().toString() .length()); p.addValue(SemanticCoordinate.applyDopingFunction(quad.getPredicate()) // quad.getPredicate().toString() .length()); o.addValue(SemanticCoordinate.applyDopingFunction(quad.getObject()) // quad.getObject().toString() .length()); } @Override public void prefix(String prefix, String iri) { } @Override public void finish() { } @Override public void base(String base) { } }, new FileInputStream(args[0]), Lang.TRIG); double percentage = 0.99; System.out.println("g --> " + g.getPercentile(percentage)); System.out.println("s --> " + s.getPercentile(percentage)); System.out.println("p --> " + p.getPercentile(percentage)); System.out.println("o --> " + o.getPercentile(percentage)); }
From source file:com.sop4j.SimpleStatistics.java
public static void main(String[] args) { final MersenneTwister rng = new MersenneTwister(); // used for RNG... READ THE DOCS!!! final int[] values = new int[NUM_VALUES]; final DescriptiveStatistics descriptiveStats = new DescriptiveStatistics(); // stores values final SummaryStatistics summaryStats = new SummaryStatistics(); // doesn't store values final Frequency frequency = new Frequency(); // add numbers into our stats for (int i = 0; i < NUM_VALUES; ++i) { values[i] = rng.nextInt(MAX_VALUE); descriptiveStats.addValue(values[i]); summaryStats.addValue(values[i]); frequency.addValue(values[i]);// w ww .j a v a2 s . c o m } // print out some standard stats System.out.println("MIN: " + summaryStats.getMin()); System.out.println("AVG: " + String.format("%.3f", summaryStats.getMean())); System.out.println("MAX: " + summaryStats.getMax()); // get some more complex stats only offered by DescriptiveStatistics System.out.println("90%: " + descriptiveStats.getPercentile(90)); System.out.println("MEDIAN: " + descriptiveStats.getPercentile(50)); System.out.println("SKEWNESS: " + String.format("%.4f", descriptiveStats.getSkewness())); System.out.println("KURTOSIS: " + String.format("%.4f", descriptiveStats.getKurtosis())); // quick and dirty stats (need a little help from Guava to convert from int[] to double[]) System.out.println("MIN: " + StatUtils.min(Doubles.toArray(Ints.asList(values)))); System.out.println("AVG: " + String.format("%.4f", StatUtils.mean(Doubles.toArray(Ints.asList(values))))); System.out.println("MAX: " + StatUtils.max(Doubles.toArray(Ints.asList(values)))); // some stats based upon frequencies System.out.println("NUM OF 7s: " + frequency.getCount(7)); System.out.println("CUMULATIVE FREQUENCY OF 7: " + frequency.getCumFreq(7)); System.out.println("PERCENTAGE OF 7s: " + frequency.getPct(7)); }
From source file:cc.redberry.core.performance.ProductBijectionPerformanceTest.java
public static void main(String[] args) { int badCounter = 0; // CC.resetTensorNames(-3912578993076521674L); RandomTensor rp = new RandomTensor(4, 10, new int[] { 4, 0, 0, 0 }, new int[] { 10, 0, 0, 0 }, false); rp.reset(-3806751651286565680L);//from w w w. j a va 2 s.c o m System.out.println("Random Seed = " + rp.getSeed()); System.out.println("NM Seed = " + CC.getNameManager().getSeed()); DescriptiveStatistics timeStats = new DescriptiveStatistics(); DescriptiveStatistics trysStats = new DescriptiveStatistics(); int count = 0; while (++count < 500) { // CC.resetTensorNames(); Tensor t = rp.nextProduct(15); if (!(t instanceof Product)) continue; Product from = (Product) t; long start = System.nanoTime(); ProductsBijectionsPort port = new ProductsBijectionsPort(from.getContent(), from.getContent()); int[] bijection; boolean good = false; int trys = 0; OUTER: while (trys++ < 5000 && (bijection = port.take()) != null) { for (int i = 0; i < bijection.length; ++i) if (bijection[i] != i) continue OUTER; good = true; break; } double millis = 1E-6 * (System.nanoTime() - start); timeStats.addValue(millis); trysStats.addValue(trys); if (!good) throw new RuntimeException(); } System.out.println(timeStats); System.out.println(trysStats); }
From source file:de.tudarmstadt.ukp.experiments.argumentation.convincingness.sampling.Step7aLearningDataProducer.java
@SuppressWarnings("unchecked") public static void main(String[] args) throws IOException { String inputDir = args[0];/*from ww w . j a va 2s . c om*/ File outputDir = new File(args[1]); if (!outputDir.exists()) { outputDir.mkdirs(); } Collection<File> files = IOHelper.listXmlFiles(new File(inputDir)); // for generating ConvArgStrict use this String prefix = "no-eq_DescendingScoreArgumentPairListSorter"; // for oversampling using graph transitivity properties use this // String prefix = "generated_no-eq_AscendingScoreArgumentPairListSorter"; Iterator<File> iterator = files.iterator(); while (iterator.hasNext()) { File file = iterator.next(); if (!file.getName().startsWith(prefix)) { iterator.remove(); } } int totalGoldPairsCounter = 0; Map<String, Integer> goldDataDistribution = new HashMap<>(); DescriptiveStatistics statsPerTopic = new DescriptiveStatistics(); int totalPairsWithReasonSameAsGold = 0; DescriptiveStatistics ds = new DescriptiveStatistics(); for (File file : files) { List<AnnotatedArgumentPair> argumentPairs = (List<AnnotatedArgumentPair>) XStreamTools.getXStream() .fromXML(file); int pairsPerTopicCounter = 0; String name = file.getName().replaceAll(prefix, "").replaceAll("\\.xml", ""); PrintWriter pw = new PrintWriter(new File(outputDir, name + ".csv"), "utf-8"); pw.println("#id\tlabel\ta1\ta2"); for (AnnotatedArgumentPair argumentPair : argumentPairs) { String goldLabel = argumentPair.getGoldLabel(); if (!goldDataDistribution.containsKey(goldLabel)) { goldDataDistribution.put(goldLabel, 0); } goldDataDistribution.put(goldLabel, goldDataDistribution.get(goldLabel) + 1); pw.printf(Locale.ENGLISH, "%s\t%s\t%s\t%s%n", argumentPair.getId(), goldLabel, multipleParagraphsToSingleLine(argumentPair.getArg1().getText()), multipleParagraphsToSingleLine(argumentPair.getArg2().getText())); pairsPerTopicCounter++; int sameInOnePair = 0; // get gold reason statistics for (AnnotatedArgumentPair.MTurkAssignment assignment : argumentPair.mTurkAssignments) { String label = assignment.getValue(); if (goldLabel.equals(label)) { sameInOnePair++; } } ds.addValue(sameInOnePair); totalPairsWithReasonSameAsGold += sameInOnePair; } totalGoldPairsCounter += pairsPerTopicCounter; statsPerTopic.addValue(pairsPerTopicCounter); pw.close(); } System.out.println("Total reasons matching gold " + totalPairsWithReasonSameAsGold); System.out.println(ds); System.out.println("Total gold pairs: " + totalGoldPairsCounter); System.out.println(statsPerTopic); int totalPairs = 0; for (Integer pairs : goldDataDistribution.values()) { totalPairs += pairs; } System.out.println("Total pairs: " + totalPairs); System.out.println(goldDataDistribution); }