List of usage examples for org.apache.commons.math3.stat.correlation KendallsCorrelation correlation
public double correlation(final double[] xArray, final double[] yArray) throws DimensionMismatchException
From source file:elaborate.tag_analysis.feature.KendallsCorrelationDistanceCalculatorImpl.java
@Override public double getDistance(double[] feature1, double[] feature2) { KendallsCorrelation p = new KendallsCorrelation(); double cor = p.correlation(feature1, feature2); return 1.0 / (cor + 2);//prevent negative value }
From source file:Evaluator.StatCalculator.java
public double kendalTauCalc(HashMap<String, Double> kderunQidMap, HashMap<String, Double> aprunQidMap) { double xArray[], yArray[]; int count = 0; xArray = new double[kderunQidMap.size()]; yArray = new double[kderunQidMap.size()]; Iterator it = kderunQidMap.keySet().iterator(); while (it.hasNext()) { String run = (String) it.next(); xArray[count] = kderunQidMap.get(run); yArray[count++] = aprunQidMap.get(run); }// w w w . ja v a2 s. co m KendallsCorrelation kc = new KendallsCorrelation(); return kc.correlation(xArray, yArray); }
From source file:eu.eexcess.diversityasurement.CorrelationTest.java
@Test public void kendallsTao_givenAKartesianQuadrandIandIIISymmetraleParallelLine() { CorrelationValues c = newCorrelationValue3(); KendallsCorrelation kCorrelation = new KendallsCorrelation(); System.out.println("kendall's tao correlation t(x, y)=" + kCorrelation.correlation(c.x, c.y)); assertEquals(c.kendallTaoB, kCorrelation.correlation(c.x, c.y), c.epsilon); }
From source file:eu.eexcess.diversityasurement.CorrelationTest.java
@Test public void kendallsTao_givenAKartesianQuadrandIIandIVSymmetralePrallelLine() { CorrelationValues c = newCorrelationValue2(); KendallsCorrelation kCorrelation = new KendallsCorrelation(); System.out.println("kendall's tao correlation t(x, y)=" + kCorrelation.correlation(c.x, c.y)); assertEquals(c.kendallTaoB, kCorrelation.correlation(c.x, c.y), c.epsilon); }
From source file:eu.eexcess.diversityasurement.CorrelationTest.java
@Test public void kendallsTao_givenDefaultValues_expectCorrectResult() { CorrelationValues c = newCorrelationValue1(); KendallsCorrelation kCorrelation = new KendallsCorrelation(); System.out.println("kendall's tao correlation t(x, y)=" + kCorrelation.correlation(c.x, c.y)); assertEquals(c.kendallTaoB, kCorrelation.correlation(c.x, c.y), c.epsilon); }
From source file:org.apache.solr.client.solrj.io.eval.CorrelationEvaluator.java
@Override public Object doWork(Object... values) throws IOException { if (values.length == 2) { Object first = values[0]; Object second = values[1]; if (null == first) { throw new IOException( String.format(Locale.ROOT, "Invalid expression %s - null found for the first value", toExpression(constructingFactory))); }/*from w w w. j av a 2s. c o m*/ if (null == second) { throw new IOException( String.format(Locale.ROOT, "Invalid expression %s - null found for the second value", toExpression(constructingFactory))); } if (!(first instanceof List<?>)) { throw new IOException(String.format(Locale.ROOT, "Invalid expression %s - found type %s for the first value, expecting a list of numbers", toExpression(constructingFactory), first.getClass().getSimpleName())); } if (!(second instanceof List<?>)) { throw new IOException(String.format(Locale.ROOT, "Invalid expression %s - found type %s for the second value, expecting a list of numbers", toExpression(constructingFactory), first.getClass().getSimpleName())); } if (type.equals(CorrelationType.pearsons)) { PearsonsCorrelation pearsonsCorrelation = new PearsonsCorrelation(); return pearsonsCorrelation.correlation( ((List) first).stream().mapToDouble(value -> ((BigDecimal) value).doubleValue()).toArray(), ((List) second).stream().mapToDouble(value -> ((BigDecimal) value).doubleValue()) .toArray()); } else if (type.equals(CorrelationType.kendalls)) { KendallsCorrelation kendallsCorrelation = new KendallsCorrelation(); return kendallsCorrelation.correlation( ((List) first).stream().mapToDouble(value -> ((BigDecimal) value).doubleValue()).toArray(), ((List) second).stream().mapToDouble(value -> ((BigDecimal) value).doubleValue()) .toArray()); } else if (type.equals(CorrelationType.spearmans)) { SpearmansCorrelation spearmansCorrelation = new SpearmansCorrelation(); return spearmansCorrelation.correlation( ((List) first).stream().mapToDouble(value -> ((BigDecimal) value).doubleValue()).toArray(), ((List) second).stream().mapToDouble(value -> ((BigDecimal) value).doubleValue()) .toArray()); } else { return null; } } else if (values.length == 1) { if (values[0] instanceof Matrix) { Matrix matrix = (Matrix) values[0]; double[][] data = matrix.getData(); if (type.equals(CorrelationType.pearsons)) { PearsonsCorrelation pearsonsCorrelation = new PearsonsCorrelation(data); RealMatrix corrMatrix = pearsonsCorrelation.getCorrelationMatrix(); double[][] corrMatrixData = corrMatrix.getData(); Matrix realMatrix = new Matrix(corrMatrixData); realMatrix.addToContext("corr", pearsonsCorrelation); return realMatrix; } else if (type.equals(CorrelationType.kendalls)) { KendallsCorrelation kendallsCorrelation = new KendallsCorrelation(data); RealMatrix corrMatrix = kendallsCorrelation.getCorrelationMatrix(); double[][] corrMatrixData = corrMatrix.getData(); Matrix realMatrix = new Matrix(corrMatrixData); realMatrix.addToContext("corr", kendallsCorrelation); return realMatrix; } else if (type.equals(CorrelationType.spearmans)) { SpearmansCorrelation spearmansCorrelation = new SpearmansCorrelation( new Array2DRowRealMatrix(data)); RealMatrix corrMatrix = spearmansCorrelation.getCorrelationMatrix(); double[][] corrMatrixData = corrMatrix.getData(); Matrix realMatrix = new Matrix(corrMatrixData); realMatrix.addToContext("corr", spearmansCorrelation.getRankCorrelation()); return realMatrix; } else { return null; } } else { throw new IOException( "corr function operates on either two numeric arrays or a single matrix as parameters."); } } else { throw new IOException( "corr function operates on either two numeric arrays or a single matrix as parameters."); } }
From source file:org.apache.solr.client.solrj.io.eval.KendallsCorrelationEvaluator.java
@Override public Object doWork(Object first, Object second) throws IOException { if (null == first) { throw new IOException(String.format(Locale.ROOT, "Invalid expression %s - null found for the first value", toExpression(constructingFactory))); }//from w ww . ja v a 2 s. co m if (null == second) { throw new IOException(String.format(Locale.ROOT, "Invalid expression %s - null found for the second value", toExpression(constructingFactory))); } if (!(first instanceof List<?>)) { throw new IOException(String.format(Locale.ROOT, "Invalid expression %s - found type %s for the first value, expecting a list of numbers", toExpression(constructingFactory), first.getClass().getSimpleName())); } if (!(second instanceof List<?>)) { throw new IOException(String.format(Locale.ROOT, "Invalid expression %s - found type %s for the second value, expecting a list of numbers", toExpression(constructingFactory), first.getClass().getSimpleName())); } KendallsCorrelation kendallsCorrelation = new KendallsCorrelation(); return kendallsCorrelation.correlation( ((List) first).stream().mapToDouble(value -> ((BigDecimal) value).doubleValue()).toArray(), ((List) second).stream().mapToDouble(value -> ((BigDecimal) value).doubleValue()).toArray()); }
From source file:org.meteoinfo.math.stats.StatsUtil.java
/** * Calculates Kendall's tau, a correlation measure for ordinal data. * * @param x X data//from w ww . j a v a 2s. com * @param y Y data * @return Kendall's tau correlation. */ public static double kendalltau(Array x, Array y) { double[] xd = (double[]) ArrayUtil.copyToNDJavaArray(x); double[] yd = (double[]) ArrayUtil.copyToNDJavaArray(y); KendallsCorrelation kc = new KendallsCorrelation(); double r = kc.correlation(xd, yd); return r; }