Harium/keel · Distance.java
java logo
private static double Covariance(double[] x, double[] y, double meanX, double meanY) {
        double result = 0;
        for (int i = 0; i < x.length; i++) {
            result += (x[i] - meanX) * (y[i] - meanY);
        }

        return result / (double) (x.length);
    }
Similar code snippets
1.
thorstenwagner/TraJ · RadiusGyrationTensor2D.java
Match rating: 68.31% · See similar code snippets
java logo
public static Array2DRowRealMatrix getRadiusOfGyrationTensor(Trajectory t){
		double meanx =0;
		double meany =0;
		for(int i = 0; i < t.size(); i++){
			meanx+= t.get(i).x;
			meany+= t.get(i).y;
		}
		meanx = meanx/t.size();
		meany = meany/t.size();
		
		double e11 = 0;
		double e12 = 0;
		double e21 = 0;
		double e22 = 0;
		
		for(int i = 0; i < t.size(); i++){
			e11 += Math.pow(t.get(i).x-meanx,2);
			e12 += (t.get(i).x-meanx)*(t.get(i).y-meany);
			e22 += Math.pow(t.get(i).y-meany,2);
		}
		e11 = e11 / t.size();
		e12 = e12 / t.size();
		e21 = e12;
		e22 = e22 / t.size();
		int rows = 2;
		int columns = 2;
		Array2DRowRealMatrix gyr = new Array2DRowRealMatrix(rows, columns); 
		
		gyr.addToEntry(0, 0, e11);
		gyr.addToEntry(0, 1, e12);
		gyr.addToEntry(1, 0, e21);
		gyr.addToEntry(1, 1, e22);
		
		return gyr;
	}
2.
fuzzylite/jfuzzylite · Op.java
Match rating: 63.87% · See similar code snippets
java logo
public static double variance(double[] x, double mean) {
        if (x.length == 0) {
            return Double.NaN;
        }
        if (x.length == 1) {
            return 0.0;
        }
        double result = 0.0;
        for (double i : x) {
            result += (i - mean) * (i - mean);
        }
        result /= -1 + x.length;
        return result;
    }
3.
haifengl/smile · Math.java
Match rating: 63.5% · See similar code snippets
java logo
public static double[] rowMeans(double[][] data) {
        double[] x = new double[data.length];

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

        return x;
    }
public static void doubleCenterSymmetric(double[][] m) {
    final int size = m.length;
    // Storage for mean values - initially all 0.
    double[] means = new double[size];
    for(int x = 0; x < m.length; x++) {
      final double[] rowx = m[x];
      // We already added "x" values in previous iterations.
      // Fake-add 0: mean + (0 - mean) / (x + 1)
      double rmean = means[x] - means[x] / (x + 1);
      for(int y = x + 1; y < rowx.length; y++) {
        final double nv = rowx[y];
        final double dx = nv - rmean, dy = nv - means[y];
        // For x < y, this is the yth entry.
        rmean += dx / (y + 1);
        // For y > x, this is the xth entry
        means[y] += dy / (x + 1);
      }
      means[x] = rmean;
    }
    // Compute total mean by averaging column means.
    double mean = means[0];
    for(int x = 1; x < size; x++) {
      double dm = means[x] - mean;
      mean += dm / (x + 1);
    }
    // Row and column center; also make symmetric.
    for(int x = 0; x < size; x++) {
      m[x][x] = -2. * means[x] + mean;
      for(int y = x + 1; y < size; y++) {
        final double nv = m[x][y] - means[x] - means[y] + mean;
        m[x][y] = nv;
        m[y][x] = nv;
      }
    }
  }
5.
deeplearning4j/deeplearning4j · MathUtils.java
Match rating: 63.34% · See similar code snippets
java logo
public static double[] weightsFor(List<Double> vector) {
        /* split coordinate system */
        List<double[]> coords = coordSplit(vector);
        /* x vals */
        double[] x = coords.get(0);
        /* y vals */
        double[] y = coords.get(1);


        double meanX = sum(x) / x.length;
        double meanY = sum(y) / y.length;

        double sumOfMeanDifferences = sumOfMeanDifferences(x, y);
        double xDifferenceOfMean = sumOfMeanDifferencesOnePoint(x);

        double w_1 = sumOfMeanDifferences / xDifferenceOfMean;

        double w_0 = meanY - (w_1) * meanX;

        //double w_1=(n*sumOfProducts(x,y) - sum(x) * sum(y))/(n*sumOfSquares(x) - Math.pow(sum(x),2));

        //	double w_0=(sum(y) - (w_1 * sum(x)))/n;

        double[] ret = new double[vector.size()];
        ret[0] = w_0;
        ret[1] = w_1;

        return ret;
    }
6.
TheHortonMachine/hortonmachine · Stats.java
Match rating: 62.69% · See similar code snippets
java logo
private static double[] calcLinReg(double[] xData, double[] yData) {
        double sumX = 0;
        double sumY = 0;
        double prod = 0;
        int nstat = xData.length;
        double[] regCoef = new double[3]; //(intercept, gradient, r2)

        double meanYValue = mean(yData);
        double meanXValue = mean(xData);

        //calculating regression coefficients
        for (int i = 0; i < nstat; i++) {
            sumX += (xData[i] - meanXValue) * (xData[i] - meanXValue);
            sumY += (yData[i] - meanYValue) * (yData[i] - meanYValue);
            prod += (xData[i] - meanXValue) * (yData[i] - meanYValue);
        }
        if (sumX > 0 && sumY > 0) {
            regCoef[1] = prod / sumX;  //gradient
            regCoef[0] = meanYValue - regCoef[1] * meanXValue; //intercept
            regCoef[2] = Math.pow((prod / Math.sqrt(sumX * sumY)), 2); //r2
        }
        return regCoef;
    }
7.
lessthanoptimal/BoofCV · LowLevelMultiViewOps.java
Match rating: 60.83% · See similar code snippets
java logo
public static void computeNormalization(List<AssociatedPair> points, NormalizationPoint2D N1, NormalizationPoint2D N2)
	{
		double meanX1 = 0; double meanY1 = 0;
		double meanX2 = 0; double meanY2 = 0;

		for( AssociatedPair p : points ) {
			meanX1 += p.p1.x; meanY1 += p.p1.y;
			meanX2 += p.p2.x; meanY2 += p.p2.y;
		}

		meanX1 /= points.size(); meanY1 /= points.size();
		meanX2 /= points.size(); meanY2 /= points.size();

		double stdX1 = 0; double stdY1 = 0;
		double stdX2 = 0; double stdY2 = 0;

		for( AssociatedPair p : points ) {
			double dx = p.p1.x - meanX1;
			double dy = p.p1.y - meanY1;
			stdX1 += dx*dx;
			stdY1 += dy*dy;

			dx = p.p2.x - meanX2;
			dy = p.p2.y - meanY2;
			stdX2 += dx*dx;
			stdY2 += dy*dy;
		}

		N1.meanX = meanX1; N1.meanY = meanY1;
		N2.meanX = meanX2; N2.meanY = meanY2;

		N1.stdX = Math.sqrt(stdX1/points.size()); N1.stdY = Math.sqrt(stdY1/points.size());
		N2.stdX = Math.sqrt(stdX2/points.size()); N2.stdY = Math.sqrt(stdY2/points.size());
	}
8.
Match rating: 59.78% · See similar code snippets
java logo
private double euclideanDistance(double[] x, double[] y) {
		double result = 0.0;
		// d(x, y) = sqrt( \sum_{i=1 to d} ( (x_i - y_i)^2 ) )
		for (int i = 0; i < x.length; i++) {
			result += (x[i] - y[i]) * (x[i] - y[i]);
		}
		return Math.sqrt(result);
	}
9.
prestodb/presto · AggregationUtils.java
Match rating: 59.71% · See similar code snippets
java logo
private static void updateCovarianceState(CovarianceState state, CovarianceState otherState)
    {
        long na = state.getCount();
        long nb = otherState.getCount();
        long n = na + nb;
        state.setCount(n);
        double meanX = state.getMeanX();
        double meanY = state.getMeanY();
        double deltaX = otherState.getMeanX() - meanX;
        double deltaY = otherState.getMeanY() - meanY;
        state.setC2(state.getC2() + otherState.getC2() + deltaX * deltaY * na * nb / (double) n);
        state.setMeanX(meanX + deltaX * nb / (double) n);
        state.setMeanY(meanY + deltaY * nb / (double) n);
    }
10.
HanSolo/tilesfx · Statistics.java
Match rating: 58.32% · See similar code snippets
java logo
public static final double getVariance(final List<Double> DATA) {
        double mean = getMean(DATA);
        double temp = 0;
        for (double a : DATA) { temp += ((a - mean) * (a - mean)); }
        return temp / DATA.size();
    }