use of com.simiacryptus.util.lang.Tuple2 in project MindsEye by SimiaCryptus.
the class PerformanceTester method test.
/**
* Test.
*
* @param component the component
* @param inputPrototype the input prototype
*/
public void test(@Nonnull final Layer component, @Nonnull final Tensor[] inputPrototype) {
log.info(String.format("%s batch length, %s trials", batches, samples));
log.info("Input Dimensions:");
Arrays.stream(inputPrototype).map(t -> "\t" + Arrays.toString(t.getDimensions())).forEach(System.out::println);
log.info("Performance:");
List<Tuple2<Double, Double>> performance = IntStream.range(0, samples).mapToObj(i -> {
return testPerformance(component, inputPrototype);
}).collect(Collectors.toList());
if (isTestEvaluation()) {
@Nonnull final DoubleStatistics statistics = new DoubleStatistics().accept(performance.stream().mapToDouble(x -> x._1).toArray());
log.info(String.format("\tEvaluation performance: %.6fs +- %.6fs [%.6fs - %.6fs]", statistics.getAverage(), statistics.getStandardDeviation(), statistics.getMin(), statistics.getMax()));
}
if (isTestLearning()) {
@Nonnull final DoubleStatistics statistics = new DoubleStatistics().accept(performance.stream().mapToDouble(x -> x._2).toArray());
if (null != statistics) {
log.info(String.format("\tLearning performance: %.6fs +- %.6fs [%.6fs - %.6fs]", statistics.getAverage(), statistics.getStandardDeviation(), statistics.getMin(), statistics.getMax()));
}
}
}
use of com.simiacryptus.util.lang.Tuple2 in project MindsEye by SimiaCryptus.
the class MaxPoolingLayer method calcRegions.
private static List<Tuple2<Integer, int[]>> calcRegions(@Nonnull final MaxPoolingLayer.CalcRegionsParameter p) {
@Nonnull final Tensor input = new Tensor(p.inputDims);
final int[] newDims = IntStream.range(0, p.inputDims.length).map(i -> {
// assert 0 == p.inputDims[i] % p.kernelDims[i];
return (int) Math.ceil(p.inputDims[i] * 1.0 / p.kernelDims[i]);
}).toArray();
@Nonnull final Tensor output = new Tensor(newDims);
List<Tuple2<Integer, int[]>> tuple2s = output.coordStream(true).map(o -> {
Tensor tensor = new Tensor(p.kernelDims);
final int[] inCoords = tensor.coordStream(true).mapToInt(kernelCoord -> {
@Nonnull final int[] result = new int[o.getCoords().length];
for (int index = 0; index < o.getCoords().length; index++) {
final int outputCoordinate = o.getCoords()[index];
final int kernelSize = p.kernelDims[index];
final int baseCoordinate = Math.min(outputCoordinate * kernelSize, p.inputDims[index] - kernelSize);
final int kernelCoordinate = kernelCoord.getCoords()[index];
result[index] = baseCoordinate + kernelCoordinate;
}
return input.index(result);
}).toArray();
tensor.freeRef();
return new Tuple2<>(o.getIndex(), inCoords);
}).collect(Collectors.toList());
input.freeRef();
output.freeRef();
return tuple2s;
}
Aggregations