Skip to content

Instantly share code, notes, and snippets.

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