in modules/ml-ext/ml/src/main/java/org/apache/ignite/ml/selection/scoring/evaluator/Evaluator.java [556:608]
private static <K, V> Map<Class, MetricStatsAggregator> computeStats(IgniteModel<Vector, Double> mdl,
Dataset<EmptyContext, FeatureMatrixWithLabelsOnHeapData> dataset, IgniteCache<K, V> cache,
Preprocessor<K, V> preprocessor,
Map<Class, EvaluationContext> ctxs, Metric... metrics) {
if (isOnlyLocalEstimation(mdl) && cache != null) {
Map<Class, MetricStatsAggregator> aggrs = initAggregators(ctxs, metrics);
try (QueryCursor<Cache.Entry<K, V>> qry = cache.query(new ScanQuery<>())) {
qry.iterator().forEachRemaining(kv -> {
LabeledVector vector = preprocessor.apply(kv.getKey(), kv.getValue());
for (Class key : aggrs.keySet()) {
MetricStatsAggregator aggr = aggrs.get(key);
aggr.aggregate(mdl, vector);
}
});
}
return aggrs;
}
else {
return dataset.compute(data -> {
Map<Class, MetricStatsAggregator> aggrs = initAggregators(ctxs, metrics);
for (int i = 0; i < data.getLabels().length; i++) {
LabeledVector<Double> vector = VectorUtils.of(data.getFeatures()[i]).labeled(data.getLabels()[i]);
for (Class key : aggrs.keySet()) {
MetricStatsAggregator aggr = aggrs.get(key);
aggr.aggregate(mdl, vector);
}
}
return aggrs;
}, (left, right) -> {
if (left == null && right == null)
return new HashMap<>();
if (left == null)
return right;
if (right == null)
return left;
HashMap<Class, MetricStatsAggregator> res = new HashMap<>();
for (Class key : left.keySet()) {
MetricStatsAggregator agg1 = left.get(key);
MetricStatsAggregator agg2 = right.get(key);
A.ensure(agg1 != null && agg2 != null, "agg1 != null && agg2 != null");
res.put(key, agg1.mergeWith(agg2));
}
return res;
});
}
}