Created
April 19, 2015 15:08
-
-
Save nivdul/1ee82f923991fea93bc6 to your computer and use it in GitHub Desktop.
Average absolute difference
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @return Vector [ (1 / n ) * ∑ |b - mean_b|, for b in {x,y,z} ] | |
*/ | |
public static double[] computeAvgAbsDifference(JavaRDD<double[]> data, double[] mean) { | |
// then for each point x compute x - mean | |
// then apply an absolute value: |x - mean| | |
JavaRDD<Vector> abs = data.map(record -> new double[]{Math.abs(record[0] - mean[0]), | |
Math.abs(record[1] - mean[1]), | |
Math.abs(record[2] - mean[2])}) | |
.map(Vectors::dense); | |
// And to finish apply the mean: for each axis (1 / n ) * ∑ |b - mean| | |
return Statistics.colStats(abs.rdd()).mean().toArray(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment