Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Average absolute difference
/**
* @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
You can’t perform that action at this time.