use of com.simiacryptus.util.data.PercentileStatistics in project MindsEye by SimiaCryptus.
the class MonitoringWrapperLayer method getMetrics.
@Nonnull
@Override
public Map<CharSequence, Object> getMetrics() {
@Nonnull final HashMap<CharSequence, Object> map = new HashMap<>();
map.put("class", getInner().getClass().getName());
map.put("totalBatches", totalBatches);
map.put("totalItems", totalItems);
map.put("outputStatistics", forwardSignal.getMetrics());
map.put("backpropStatistics", backwardSignal.getMetrics());
if (verbose) {
map.put("forwardPerformance", forwardPerformance.getMetrics());
map.put("backwardPerformance", backwardPerformance.getMetrics());
}
final double batchesPerItem = totalBatches * 1.0 / totalItems;
map.put("avgMsPerItem", 1000 * batchesPerItem * forwardPerformance.getMean());
map.put("medianMsPerItem", 1000 * batchesPerItem * forwardPerformance.getPercentile(0.5));
final double backpropMean = backwardPerformance.getMean();
final double backpropMedian = backwardPerformance.getPercentile(0.5);
map.put("avgMsPerItem_Backward", 1000 * batchesPerItem * backpropMean);
map.put("medianMsPerItem_Backward", 1000 * batchesPerItem * backpropMedian);
@Nullable final List<double[]> state = state();
@Nonnull final ScalarStatistics statistics = new PercentileStatistics();
for (@Nonnull final double[] s : state) {
for (final double v : s) {
statistics.add(v);
}
}
if (statistics.getCount() > 0) {
@Nonnull final HashMap<CharSequence, Object> weightStats = new HashMap<>();
weightStats.put("buffers", state.size());
weightStats.putAll(statistics.getMetrics());
map.put("weights", weightStats);
}
return map;
}
use of com.simiacryptus.util.data.PercentileStatistics in project MindsEye by SimiaCryptus.
the class TestUtil method extractPerformance.
/**
* Remove performance wrappers.
*
* @param log the log
* @param network the network
*/
public static void extractPerformance(@Nonnull final NotebookOutput log, @Nonnull final DAGNetwork network) {
log.p("Per-layer Performance Metrics:");
log.code(() -> {
@Nonnull final Map<CharSequence, MonitoringWrapperLayer> metrics = new HashMap<>();
network.visitNodes(node -> {
if (node.getLayer() instanceof MonitoringWrapperLayer) {
@Nullable final MonitoringWrapperLayer layer = node.getLayer();
Layer inner = layer.getInner();
String str = inner.toString();
str += " class=" + inner.getClass().getName();
// if(inner instanceof MultiPrecision<?>) {
// str += "; precision=" + ((MultiPrecision) inner).getPrecision().name();
// }
metrics.put(str, layer);
}
});
TestUtil.log.info("Performance: \n\t" + metrics.entrySet().stream().sorted(Comparator.comparing(x -> -x.getValue().getForwardPerformance().getMean())).map(e -> {
@Nonnull final PercentileStatistics performanceF = e.getValue().getForwardPerformance();
@Nonnull final PercentileStatistics performanceB = e.getValue().getBackwardPerformance();
return String.format("%.6fs +- %.6fs (%d) <- %s", performanceF.getMean(), performanceF.getStdDev(), performanceF.getCount(), e.getKey()) + (performanceB.getCount() == 0 ? "" : String.format("%n\tBack: %.6fs +- %.6fs (%s)", performanceB.getMean(), performanceB.getStdDev(), performanceB.getCount()));
}).reduce((a, b) -> a + "\n\t" + b).get());
});
removeInstrumentation(network);
}
Aggregations