List of usage examples for org.apache.commons.math3.stat.correlation PearsonsCorrelation PearsonsCorrelation
public PearsonsCorrelation()
From source file:PCC.java
/** * @param args the command line arguments * @throws java.io.IOException//from ww w . j a va 2s. c o m */ public static void main(String[] args) throws IOException { // TODO code application logic here PearsonsCorrelation corel = new PearsonsCorrelation(); PCC method = new PCC(); ArrayList<String> name = new ArrayList<>(); Multimap<String, String> genes = ArrayListMultimap.create(); BufferedWriter bw = new BufferedWriter(new FileWriter(args[1])); BufferedReader br = new BufferedReader(new FileReader(args[0])); String str; while ((str = br.readLine()) != null) { String[] a = str.split("\t"); name.add(a[0]); for (int i = 1; i < a.length; i++) { genes.put(a[0], a[i]); } } for (String key : genes.keySet()) { double[] first = new double[genes.get(key).size()]; int element1 = 0; for (String value : genes.get(key)) { double d = Double.parseDouble(value); first[element1] = d; element1++; } for (String key1 : genes.keySet()) { if (!key.equals(key1)) { double[] second = new double[genes.get(key1).size()]; int element2 = 0; for (String value : genes.get(key1)) { double d = Double.parseDouble(value); second[element2] = d; element2++; } double corrlation = corel.correlation(first, second); if (corrlation > 0.5) { bw.write(key + "\t" + key1 + "\t" + corrlation + "\t" + method.pvalue(corrlation, second.length) + "\n"); } } } } br.close(); bw.close(); }
From source file:com.medlog.webservice.util.MathUtl.java
public static void main(String[] args) { BigDecimal d;//from w ww . j ava 2 s . c om d = new BigDecimal(0); double[] xs = { 30, 80, 90, 70, 70, 80, 50, 50, 50, 100, 10, 40, 80, 100 }; double ys[] = { 52.9676423, 28.14739166, 45.22978518, 60.54520645, 58.43671379, 15.94587142, 58.869, 57.8465, 58.686, 40.38026666, 55.8178, 60.3812, 88.1389, 61.1895 }; double r = new PearsonsCorrelation().correlation(xs, ys); double rb = new SpearmansCorrelation().correlation(xs, ys); System.out.println("com.medlog.webservice.util.MathUtl.main()" + r * r); System.out.println("com.medlog.webservice.util.MathUtl.main()" + rb * rb); }
From source file:edu.umd.umiacs.clip.tools.math.CorrelationUtils.java
public static void main(String[] args) { double[] x = { 0.9, 0.6, 0.4, 0.3, 0.2, 0.1 }; double[] y = { 0.5, 0.6, 0.4, 0.3, 0.2, 0.1 }; System.out.println(new PearsonsCorrelation().correlation(x, y)); System.out.println(new KendallsCorrelation().correlation(x, y)); System.out.println(tauAP(x, y)); System.out.println(tauGAP(x, y)); System.out.println(pr(x, y)); }
From source file:edu.indiana.soic.ts.streaming.dataflow.utils.DistanceFunction.java
public static double calculateDistance(VectorPoint vp1, VectorPoint vp2) { //FIXME This should be replaced by the actual distance calculation PearsonsCorrelation pearsonsCorrelation = new PearsonsCorrelation(); return pearsonsCorrelation.correlation(vp1.getNumbers(), vp2.getNumbers()); }
From source file:elaborate.tag_analysis.feature.PearsonCorrelationDistanceCalculatorImpl.java
@Override public double getDistance(double[] feature1, double[] feature2) { PearsonsCorrelation p = new PearsonsCorrelation(); double cor = p.correlation(feature1, feature2); return 1.0 / (cor + 2);//prevent negative value }
From source file:com.davidbracewell.ml.regression.Regression.java
/** * Pearson's correlation coefficient.//from w ww. j a v a 2s .co m * * @param model the model * @param data the data * @return the double */ public static double correlationCoefficient(RegressionModel model, List<Instance> data) { PearsonsCorrelation correlation = new PearsonsCorrelation(); List<Double> gold = Lists.newArrayList(); List<Double> pred = Lists.newArrayList(); for (Instance instance : data) { if (instance.hasTargetValue()) { gold.add(instance.getTargetValue()); pred.add(model.estimate(instance)); } } return correlation.correlation(Doubles.toArray(gold), Doubles.toArray(pred)); }
From source file:jgap.SpearmansFitnessFunction.java
/** * Determine the fitness of the given Chromosome instance. The higher the * return value, the more fit the instance. This method should always * return the same fitness value for two equivalent Chromosome instances. * * @param a_subject the Chromosome instance to evaluate * @return positive double reflecting the fitness rating of the given * Chromosome/*from w w w. ja v a 2 s . c om*/ * @author Neil Rotstan, Klaus Meffert, John Serri * @since 2.0 (until 1.1: return type int) */ @Override public double evaluate(IChromosome a_subject) { double[] newAhpResult = runAHP(a_subject); // double correlation = new SpearmansCorrelation().correlation(this.original, newAhpResult); double correlation = new PearsonsCorrelation().correlation(this.original, newAhpResult); // System.out.println(correlation); return correlation < 0.0d ? (correlation * -1) : correlation; }
From source file:com.facebook.presto.operator.aggregation.TestFloatCorrelationAggregation.java
@Override public Object getExpectedValue(int start, int length) { if (length <= 1) { return null; }/*from w w w . j a v a 2 s . c om*/ PearsonsCorrelation corr = new PearsonsCorrelation(); return (float) corr.correlation(constructDoublePrimitiveArray(start + 2, length), constructDoublePrimitiveArray(start, length)); }
From source file:com.facebook.presto.operator.aggregation.TestCorrelationAggregation.java
@Override public Object getExpectedValue(int start, int length) { if (length <= 1) { return null; }//from w w w . ja va 2 s.co m PearsonsCorrelation corr = new PearsonsCorrelation(); return corr.correlation(constructDoublePrimitiveArray(start + 2, length), constructDoublePrimitiveArray(start, length)); }
From source file:com.insightml.math.statistics.Correlation.java
public Correlation(final double[] x, final double[] y) { arrays = new double[2][x.length]; for (int i = 0; i < x.length; ++i) { arrays[0][i] = x[i];/*w ww .j av a 2 s . c om*/ arrays[1][i] = y[i]; } final DoubleLinkedList x2 = new DoubleLinkedList(); final DoubleLinkedList y2 = new DoubleLinkedList(); for (int i = 0; i < x.length; ++i) { if (!Double.isNaN(x[i])) { x2.add(x[i]); y2.add(y[i]); } } final double[] x2arr = x2.toArray(); final double[] y2arr = y2.toArray(); covariance = new Covariance().covariance(x2arr, y2arr); pearson = new PearsonsCorrelation().correlation(x2arr, y2arr); spearman = new SpearmansCorrelation().correlation(x2arr, y2arr); mean = (Math.abs(pearson) + Math.abs(spearman)) / 2; }