Created
April 19, 2015 15:10
-
-
Save nivdul/666310c767cb6ef97503 to your computer and use it in GitHub Desktop.
Average Resultant acceleration
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 Double resultant = 1/n * ∑ √(x² + y² + z²) | |
*/ | |
public static double computeResultantAcc(JavaRDD<double[]> data) { | |
// first let's compute the square of each value and the sum | |
// compute then the root square: √(x² + y² + z²) | |
// to finish apply a mean function: 1/n * sum [√(x² + y² + z²)] | |
JavaRDD<Vector> squared = data.map(record -> Math.pow(record[0], 2) | |
+ Math.pow(record[1], 2) | |
+ Math.pow(record[2], 2)) | |
.map(Math::sqrt) | |
.map(sum -> Vectors.dense(new double[]{sum})); | |
return Statistics.colStats(squared.rdd()).mean().toArray()[0]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment