use of org.deeplearning4j.spark.impl.multilayer.scoring.ScoreFlatMapFunction in project deeplearning4j by deeplearning4j.
the class SparkDl4jMultiLayer method calculateScore.
/**
* Calculate the score for all examples in the provided {@code JavaRDD<DataSet>}, either by summing
* or averaging over the entire data set. To calculate a score for each example individually, use {@link #scoreExamples(JavaPairRDD, boolean)}
* or one of the similar methods
*
* @param data Data to score
* @param average Whether to sum the scores, or average them
* @param minibatchSize The number of examples to use in each minibatch when scoring. If more examples are in a partition than
* this, multiple scoring operations will be done (to avoid using too much memory by doing the whole partition
* in one go)
*/
public double calculateScore(JavaRDD<DataSet> data, boolean average, int minibatchSize) {
JavaRDD<Tuple2<Integer, Double>> rdd = data.mapPartitions(new ScoreFlatMapFunction(conf.toJson(), sc.broadcast(network.params(false)), minibatchSize));
//Reduce to a single tuple, with example count + sum of scores
Tuple2<Integer, Double> countAndSumScores = rdd.reduce(new IntDoubleReduceFunction());
if (average) {
return countAndSumScores._2() / countAndSumScores._1();
} else {
return countAndSumScores._2();
}
}
Aggregations