dkpro/dkpro-statistics · PearsonCorrelation.java
java logo
public static double computeCorrelation(final double[] list1, final double[] list2)
    {
        // R = { N* (Sum(x*y) - Sum(x)*Sum(y)} / sqrt( { N* Sum( x**2 ) - Sum( x )**2} ) * sqrt ( {N
        // * Sum( y**2 ) - Sum( y )**2} )
        double sumXY = 0;
        double sumX = 0;
        double sumY = 0;
        double sumXsquares = 0;
        double sumYsquares = 0;
        final long N = list1.length; // we assume that both list are of equal length

        if (list1.length != list2.length) {
            log.fatal("Lists are not the same size (" + list1.length + " - " + list2.length + ").");
            System.exit(1);
        }

        for (int i = 0; i < N; i++) {
            final double x = list1[i];
            final double y = list2[i];
            sumXY += x * y;
            sumX += x;
            sumY += y;
            sumXsquares += x * x;
            sumYsquares += y * y;
        }

        final double nominator = (N * sumXY - sumX * sumY);

        final double root1 = N * sumXsquares - sumX * sumX;
        final double root2 = N * sumYsquares - sumY * sumY;
        final double denominator = Math.sqrt(root1) * Math.sqrt(root2);

        final double correlation = nominator / denominator;

        return correlation;
    }
Similar code snippets
1.
deeplearning4j/deeplearning4j · MathUtils.java
Match rating: 61.98% · See similar code snippets
java logo
public static double w_1(double[] x, double[] y, int n) {
        return (n * sumOfProducts(x, y) - sum(x) * sum(y)) / (n * sumOfSquares(x) - Math.pow(sum(x), 2));
    }
2.
biojava/biojava · Matrix.java
Match rating: 61.94% · See similar code snippets
java logo
public static double dot(double[] x, double[] y) {
		if (x.length != y.length) {
			throw new RuntimeException("Illegal vector dimensions.");
		}
		double sum = 0.0;
		for (int i = 0; i < x.length; i++) {
			sum += x[i] * y[i];
		}
		return sum;
	}
3.
NitorCreations/willow · MetricUtils.java
Match rating: 61.84% · See similar code snippets
java logo
public Double sumDouble(List<Double> list) {
    Double sum= 0D;
    for (Double i:list) {
      sum = sum + i;
    }
    return sum;
  }
4.
jMetal/jMetal · Benchmark.java
Match rating: 61.44% · See similar code snippets
java logo
static public double sphere(double[] x) {

    double sum = 0.0;

    for (int i = 0; i < x.length; i++) {
      sum += x[i] * x[i];
    }

    return (sum);
  }
5.
jMetal/jMetal · Benchmark.java
Match rating: 61.38% · See similar code snippets
java logo
static public double ackley(double[] x) {

    double sum1 = 0.0;
    double sum2 = 0.0;

    for (int i = 0; i < x.length; i++) {
      sum1 += (x[i] * x[i]);
      sum2 += (Math.cos(PIx2 * x[i]));
    }

    return (-20.0 * Math.exp(-0.2 * Math.sqrt(sum1 / ((double) x.length))) - Math
      .exp(sum2 / ((double) x.length)) + 20.0 + Math.E);
  }
6.
haifengl/smile · Math.java
Match rating: 60.98% · See similar code snippets
java logo
public static double[] colSds(double[][] data) {
        if (data.length < 2) {
            throw new IllegalArgumentException("Array length is less than 2.");
        }

        int p = data[0].length;
        double[] sum = new double[p];
        double[] sumsq = new double[p];
        for (double[] x : data) {
            for (int i = 0; i < p; i++) {
                sum[i] += x[i];
                sumsq[i] += x[i] * x[i];
            }
        }

        int n = data.length - 1;
        for (int i = 0; i < p; i++) {
            sumsq[i] = java.lang.Math.sqrt(sumsq[i] / n - (sum[i] / data.length) * (sum[i] / n));
        }

        return sumsq;
    }
7.
haifengl/smile · Math.java
Match rating: 60.32% · See similar code snippets
java logo
public static double var(int[] x) {
        if (x.length < 2) {
            throw new IllegalArgumentException("Array length is less than 2.");
        }

        double sum = 0.0;
        double sumsq = 0.0;
        for (int xi : x) {
            sum += xi;
            sumsq += xi * xi;
        }

        int n = x.length - 1;
        return sumsq / n - (sum / x.length) * (sum / n);
    }
8.
jMetal/jMetal · Benchmark.java
Match rating: 60.1% · See similar code snippets
java logo
static public double elliptic(double[] x) {

    double sum = 0.0;
    double a = 1e6;

    for (int i = 0; i < x.length; i++) {
      sum += Math.pow(a, (((double) i) / ((double) (x.length - 1)))) * x[i] * x[i];
    }

    return (sum);
  }
9.
nyla-solutions/nyla · Mathematics.java
Match rating: 59.93% · See similar code snippets
java logo
private static double sum(double[] a) {

        double sum = 0.0;
        for (int i = 0; i < a.length; i++) {
            sum += a[i];
        }
        return sum;
    }
10.
TheHortonMachine/hortonmachine · LeastSquaresInterpolator.java
Match rating: 59.83% · See similar code snippets
java logo
private void validateCoefficients() {
        if (coefsValid)
            return;

        if (n >= 2) {
            double xBar = (double) sumX / n;
            double yBar = (double) sumY / n;

            a1 = (double) ((n * sumXY - sumX * sumY) / (n * sumXX - sumX * sumX));
            a0 = (double) (yBar - a1 * xBar);
        } else {
            a0 = a1 = Double.NaN;
        }

        coefsValid = true;
    }