List of usage examples for org.apache.commons.math3.stat.inference MannWhitneyUTest mannWhitneyU
public double mannWhitneyU(final double[] x, final double[] y) throws NullArgumentException, NoDataException
From source file:mase.spec.MannTest.java
public static void main(String[] args) { /*double[] b = new double[]{1,2,3,4,5}; double[] a = new double[]{6,7,8,9,10};*/ /*double[] a = new double[]{1,2,3,4,5}; double[] b = new double[]{6,7,8,9,10};*/ double[] a = new double[] { 1, 3, 5, 7, 9 }; double[] b = new double[] { 0, 2, 4, 6, 8, 10 }; MannWhitneyUTest test = new MannWhitneyUTest(); double u1 = test.mannWhitneyU(a, b); double u2 = test.mannWhitneyU(b, a); System.out.println(u1 + " " + u2 + " Max: " + a.length * b.length); }
From source file:exec.validate_evaluation.greedy_and_endgoal.GreedyAndEndGoalEval.java
public static void main(String[] args) { double[] a = new double[] { 1, 2, 3, 2, 2, 2, 2 }; double[] b = new double[] { 2, 3.1, 4, 3, 3, 3, 3, 3 }; MannWhitneyUTest test = new MannWhitneyUTest(); double pVal = test.mannWhitneyUTest(a, b); double pVal2 = test.mannWhitneyU(a, b); System.out.println("pval = " + pVal + ";\nwert2: " + pVal2); }
From source file:mase.spec.SafeHybridExchanger.java
private double fitnessDifference(MetaPopulation reference, MetaPopulation other, EvolutionState state) { // search foreign of reference in other Foreign f = null;/*from w ww .java 2s.c o m*/ for (Foreign fOther : other.foreigns) { if (fOther.origin == reference) { f = fOther; break; } } if (f == null || f.inds == null) { return Double.POSITIVE_INFINITY; } // pick individuals from the reference population, using the same method used to pick the foreign individuals Individual[] refInds = pickIndividuals(reference.inds, f.inds.length, foreignMode, state); if (differenceMode == DifferenceMode.mean) { double refFit = 0; for (Individual i : refInds) { refFit += i.fitness.fitness(); } double foreignFit = 0; for (Individual i : f.inds) { foreignFit += i.fitness.fitness(); } return refFit == 0 ? Double.POSITIVE_INFINITY : Math.abs(refFit - foreignFit) / Math.abs(refFit); } else if (differenceMode == DifferenceMode.max) { double refFit = Double.NEGATIVE_INFINITY; for (Individual i : refInds) { refFit = Math.max(refFit, i.fitness.fitness()); } double foreignFit = Double.NEGATIVE_INFINITY; for (Individual i : f.inds) { foreignFit = Math.max(foreignFit, i.fitness.fitness()); } return refFit == 0 ? Double.POSITIVE_INFINITY : Math.abs(refFit - foreignFit) / Math.abs(refFit); } else if (differenceMode == DifferenceMode.utest) { double[] refFits = new double[refInds.length]; double[] forFits = new double[f.inds.length]; for (int i = 0; i < refFits.length; i++) { refFits[i] = refInds[i].fitness.fitness(); } for (int i = 0; i < forFits.length; i++) { forFits[i] = f.inds[i].fitness.fitness(); } MannWhitneyUTest test = new MannWhitneyUTest(); return test.mannWhitneyU(refFits, forFits) / (refFits.length * forFits.length); } else { return Double.NaN; } }
From source file:megan.commands.ComputeMannWhitneyUCommand.java
public void apply(NexusStreamParser np) throws Exception { np.matchIgnoreCase(getSyntax());//w w w .ja v a 2 s .com final Document doc = getDir().getDocument(); int numberSelectedNodes = ((ViewerBase) getViewer()).getNumberSelectedNodes(); MannWhitneyUTest mannWhitneyUTest = new MannWhitneyUTest(); double[] x = new double[numberSelectedNodes]; double[] y = new double[numberSelectedNodes]; ViewerBase viewer = (ViewerBase) getViewer(); int count = 0; for (Node v : viewer.getSelectedNodes()) { if (v.getOutDegree() > 0) { x[count] = ((NodeData) v.getData()).getAssigned(0); y[count] = ((NodeData) v.getData()).getAssigned(1); } else { x[count] = ((NodeData) v.getData()).getSummarized(0); y[count] = ((NodeData) v.getData()).getSummarized(1); } } double p = mannWhitneyUTest.mannWhitneyUTest(x, y); final String message = "Mann Whitney U Test for " + doc.getNumberOfSamples() + " samples based on " + numberSelectedNodes + " selected nodes:\n" + "U value=" + mannWhitneyUTest.mannWhitneyU(x, y) + "\n" + "p-value=" + (float) p + "\n"; //System.err.println(message); NotificationsInSwing.showInformation(getViewer().getFrame(), message); }
From source file:org.apache.solr.client.solrj.io.eval.MannWhitneyUEvaluator.java
@Override public Object doWork(Object... values) throws IOException { List<double[]> mannWhitneyUInput = Arrays.stream(values) .map(value -> ((List<Number>) value).stream().mapToDouble(Number::doubleValue).toArray()) .collect(Collectors.toList()); if (mannWhitneyUInput.size() == 2) { MannWhitneyUTest mannwhitneyutest = new MannWhitneyUTest(); double u = mannwhitneyutest.mannWhitneyU(mannWhitneyUInput.get(0), mannWhitneyUInput.get(1)); double p = mannwhitneyutest.mannWhitneyUTest(mannWhitneyUInput.get(0), mannWhitneyUInput.get(1)); Map<String, Number> m = new HashMap<>(); m.put("u-statistic", u); m.put("p-value", p); return new Tuple(m); } else {// w w w .j a v a 2 s.c o m throw new IOException(String.format(Locale.ROOT, "%s(...) only works with a list of 2 arrays but a list of %d array(s) was provided.", constructingFactory.getFunctionName(getClass()), mannWhitneyUInput.size())); } }
From source file:org.caleydo.view.enroute.correlation.wilcoxon.WilcoxonManualResultPage.java
@Override public void pageChanged(PageChangedEvent event) { if (event.getSelectedPage() == this) { WilcoxonRankSumTestWizard wizard = (WilcoxonRankSumTestWizard) getWizard(); DataCellInfo targetInfo = wizard.getTargetInfo(); // java.util.List<WilcoxonResult> resultList = WilcoxonUtil.applyWilcoxonToAllElements( // wizard.getSourceClassifier(), wizard.getSourceInfo(), targetInfo.columnPerspective); ////w ww . j a v a 2 s .c om // for (WilcoxonResult r : resultList) { // System.out.println(r.p); // } // System.out.println("NumElements: " + resultList.size()); // WilcoxonUtil.calcWilcoxonRankSumTest(sourceInfo, classifier, targetInfo) SimpleIDClassifier derivedClassifier = wizard.getDerivedIDClassifier(); MannWhitneyUTest test = new MannWhitneyUTest(NaNStrategy.REMOVED, TiesStrategy.AVERAGE); double[] values1 = WilcoxonUtil.getSampleValuesArray(targetInfo, derivedClassifier.getClass1IDs()); double[] values2 = WilcoxonUtil.getSampleValuesArray(targetInfo, derivedClassifier.getClass2IDs()); double u = test.mannWhitneyU(values1, values2); double p = test.mannWhitneyUTest(values1, values2); resultsWidget.update(wizard.getSourceInfo(), targetInfo, new WilcoxonResult(p, u, wizard.getSourceClassifier(), derivedClassifier)); // resultsWidget.updateClassSummary(0, values1, derivedClassifier.getDataClasses().get(0)); // resultsWidget.updateClassSummary(1, values2, derivedClassifier.getDataClasses().get(1)); // // resultsWidget.updateStatistics(u, p); } }
From source file:org.moeaframework.util.statistics.MannWhitneyUTestTest.java
/** * Commons Math 3.0 introduced their own MannWhitneyUTest class. The * Commons Math implementation only supports the normal approximation for * the U statistic, and will be inaccurate with small sample sizes. *//*from w w w. j av a 2s . com*/ @Test public void testCommonsMath() { double[] d1 = new double[100]; double[] d2 = new double[100]; for (int i = 0; i < 100; i++) { d1[i] = PRNG.nextGaussian(10.0, 5.0); d2[i] = PRNG.nextGaussian(11.0, 6.0); } MannWhitneyUTest test1 = new MannWhitneyUTest(); test1.addAll(d1, 0); test1.addAll(d2, 1); test1.test(0.05); double u1 = test1.lastU; org.apache.commons.math3.stat.inference.MannWhitneyUTest test2 = new org.apache.commons.math3.stat.inference.MannWhitneyUTest(); double u2 = test2.mannWhitneyU(d1, d2); Assert.assertEquals(100 * 100 - u2, u1, Settings.EPS); }