Skip to content

Instantly share code, notes, and snippets.

@nivdul
Created April 19, 2015 15:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nivdul/666310c767cb6ef97503 to your computer and use it in GitHub Desktop.
Save nivdul/666310c767cb6ef97503 to your computer and use it in GitHub Desktop.
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