public static double sumSquaredError(double[] a) { double mean = mean(a); double result = 0.0; for (double anA : a) { double diff = anA - mean; result += (diff * diff); } return result; }
/** * For testing only. * @param args Ignored */ public static void main(String[] args) { Random random = new Random(); int length = 100; double[] A = new double[length]; double[] B = new double[length]; double aAvg = 70.0; double bAvg = 70.5; for (int i = 0; i < length; i++) { A[i] = aAvg + random.nextGaussian(); B[i] = bAvg + random.nextGaussian(); } System.out.println("A has length " + A.length + " and mean " + mean(A)); System.out.println("B has length " + B.length + " and mean " + mean(B)); for (int t = 0; t < 10; t++) { System.out.println("p-value: " + sigLevelByApproxRand(A, B)); } }
/** * Returns the mean of a vector of doubles. Any values which are NaN or * infinite are ignored. If the vector is empty, 0.0 is returned. */ public static double safeMean(double[] v) { double[] u = filterNaNAndInfinite(v); if (numRows(u) == 0) return 0.0; return mean(u); }
/** * Standardize values in this array, i.e., subtract the mean and divide by the standard deviation. * If standard deviation is 0.0, throws a RuntimeException. */ public static void standardize(double[] a) { double m = mean(a); if (Double.isNaN(m)) { throw new RuntimeException("Can't standardize array whose mean is NaN"); } double s = stdev(a); if (s == 0.0 || Double.isNaN(s)) { throw new RuntimeException("Can't standardize array whose standard deviation is 0.0 or NaN"); } addInPlace(a, -m); // subtract mean multiplyInPlace(a, 1.0/s); // divide by standard deviation }
public static double sumSquaredError(double[] a) { double mean = mean(a); double result = 0.0; for (double anA : a) { double diff = anA - mean; result += (diff * diff); } return result; }
public static double sumSquaredError(double[] a) { double mean = mean(a); double result = 0.0; for (double anA : a) { double diff = anA - mean; result += (diff * diff); } return result; }
public static double sumSquaredError(double[] a) { double mean = mean(a); double result = 0.0; for (double anA : a) { double diff = anA - mean; result += (diff * diff); } return result; }
public static double sumSquaredError(double[] a) { double mean = mean(a); double result = 0.0; for (double anA : a) { double diff = anA - mean; result += (diff * diff); } return result; }
public static double[][] covariance(double[][] data) { double[] means = new double[data.length]; for (int i = 0; i < means.length; i++) { means[i] = mean(data[i]); } double[][] covariance = new double[means.length][means.length]; for (int i = 0; i < data[0].length; i++) { for (int j = 0; j < means.length; j++) { for (int k = 0; k < means.length; k++) { covariance[j][k] += (means[j]-data[j][i])*(means[k]-data[k][i]); } } } for (int i = 0; i < covariance.length; i++) { for (int j = 0; j < covariance[i].length; j++) { covariance[i][j] = Math.sqrt(covariance[i][j])/(data[0].length); } } return covariance; }
public static double[][] covariance(double[][] data) { double[] means = new double[data.length]; for (int i = 0; i < means.length; i++) { means[i] = mean(data[i]); } double[][] covariance = new double[means.length][means.length]; for (int i = 0; i < data[0].length; i++) { for (int j = 0; j < means.length; j++) { for (int k = 0; k < means.length; k++) { covariance[j][k] += (means[j]-data[j][i])*(means[k]-data[k][i]); } } } for (int i = 0; i < covariance.length; i++) { for (int j = 0; j < covariance[i].length; j++) { covariance[i][j] = Math.sqrt(covariance[i][j])/(data[0].length); } } return covariance; }
/** * For testing only. * @param args Ignored */ public static void main(String[] args) { Random random = new Random(); int length = 100; double[] A = new double[length]; double[] B = new double[length]; double aAvg = 70.0; double bAvg = 70.5; for (int i = 0; i < length; i++) { A[i] = aAvg + random.nextGaussian(); B[i] = bAvg + random.nextGaussian(); } System.out.println("A has length " + A.length + " and mean " + mean(A)); System.out.println("B has length " + B.length + " and mean " + mean(B)); for (int t = 0; t < 10; t++) { System.out.println("p-value: " + sigLevelByApproxRand(A, B)); } }
/** * For testing only. * @param args Ignored */ public static void main(String[] args) { Random random = new Random(); int length = 100; double[] A = new double[length]; double[] B = new double[length]; double aAvg = 70.0; double bAvg = 70.5; for (int i = 0; i < length; i++) { A[i] = aAvg + random.nextGaussian(); B[i] = bAvg + random.nextGaussian(); } System.out.println("A has length " + A.length + " and mean " + mean(A)); System.out.println("B has length " + B.length + " and mean " + mean(B)); for (int t = 0; t < 10; t++) { System.out.println("p-value: " + sigLevelByApproxRand(A, B)); } }
/** * Standardize values in this array, i.e., subtract the mean and divide by the standard deviation. * If standard deviation is 0.0, throws a RuntimeException. */ public static void standardize(double[] a) { double m = mean(a); if (Double.isNaN(m)) { throw new RuntimeException("Can't standardize array whose mean is NaN"); } double s = stdev(a); if (s == 0.0 || Double.isNaN(s)) { throw new RuntimeException("Can't standardize array whose standard deviation is 0.0 or NaN"); } addInPlace(a, -m); // subtract mean multiplyInPlace(a, 1.0/s); // divide by standard deviation }
/** * Returns the mean of a vector of doubles. Any values which are NaN or * infinite are ignored. If the vector is empty, 0.0 is returned. */ public static double safeMean(double[] v) { double[] u = filterNaNAndInfinite(v); if (numRows(u) == 0) return 0.0; return mean(u); }
/** * Returns the mean of a vector of doubles. Any values which are NaN or * infinite are ignored. If the vector is empty, 0.0 is returned. */ public static double safeMean(double[] v) { double[] u = filterNaNAndInfinite(v); if (numRows(u) == 0) return 0.0; return mean(u); }
/** * Standardize values in this array, i.e., subtract the mean and divide by the standard deviation. * If standard deviation is 0.0, throws an RuntimeException. */ public static void standardize(double[] a) { double m = mean(a); if (Double.isNaN(m)) throw new RuntimeException("Can't standardize array whose mean is NaN"); double s = stdev(a); if(s == 0.0 || Double.isNaN(s)) throw new RuntimeException("Can't standardize array whose standard deviation is 0.0 or NaN"); addInPlace(a, -m); // subtract mean multiplyInPlace(a, 1.0/s); // divide by standard deviation }
/** * Standardize values in this array, i.e., subtract the mean and divide by the standard deviation. * If standard deviation is 0.0, throws a RuntimeException. */ public static void standardize(double[] a) { double m = mean(a); if (Double.isNaN(m)) { throw new RuntimeException("Can't standardize array whose mean is NaN"); } double s = stdev(a); if (s == 0.0 || Double.isNaN(s)) { throw new RuntimeException("Can't standardize array whose standard deviation is 0.0 or NaN"); } addInPlace(a, -m); // subtract mean multiplyInPlace(a, 1.0/s); // divide by standard deviation }
/** * Standardize values in this array, i.e., subtract the mean and divide by the standard deviation. * If standard deviation is 0.0, throws a RuntimeException. */ public static void standardize(double[] a) { double m = mean(a); if (Double.isNaN(m)) { throw new RuntimeException("Can't standardize array whose mean is NaN"); } double s = stdev(a); if (s == 0.0 || Double.isNaN(s)) { throw new RuntimeException("Can't standardize array whose standard deviation is 0.0 or NaN"); } addInPlace(a, -m); // subtract mean multiplyInPlace(a, 1.0/s); // divide by standard deviation }
/** * Returns the mean of a vector of doubles. Any values which are NaN or * infinite are ignored. If the vector is empty, 0.0 is returned. */ public static double safeMean(double[] v) { double[] u = filterNaNAndInfinite(v); if (numRows(u) == 0) return 0.0; return mean(u); }
/** * Returns the mean of a vector of doubles. Any values which are NaN or * infinite are ignored. If the vector is empty, 0.0 is returned. */ public static double safeMean(double[] v) { double[] u = filterNaNAndInfinite(v); if (numRows(u) == 0) return 0.0; return mean(u); }