use of com.simiacryptus.util.data.DoubleStatistics 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.data.DoubleStatistics in project MindsEye by SimiaCryptus.
the class ReferenceIO method test.
@Nullable
@Override
public ToleranceStatistics test(@Nonnull final NotebookOutput log, @Nonnull final Layer layer, @Nonnull final Tensor... inputPrototype) {
if (!referenceIO.isEmpty()) {
log.h1("Reference Input/Output Pairs");
log.p("Display pre-setBytes input/output example pairs:");
referenceIO.forEach((input, output) -> {
log.code(() -> {
@Nonnull final SimpleEval eval = SimpleEval.run(layer, input);
Tensor add = output.scale(-1).addAndFree(eval.getOutput());
@Nonnull final DoubleStatistics error = new DoubleStatistics().accept(add.getData());
add.freeRef();
String format = String.format("--------------------\nInput: \n[%s]\n--------------------\nOutput: \n%s\nError: %s\n--------------------\nDerivative: \n%s", Arrays.stream(input).map(t -> t.prettyPrint()).reduce((a, b) -> a + ",\n" + b).get(), eval.getOutput().prettyPrint(), error, Arrays.stream(eval.getDerivative()).map(t -> t.prettyPrint()).reduce((a, b) -> a + ",\n" + b).get());
eval.freeRef();
return format;
});
});
} else {
log.h1("Example Input/Output Pair");
log.p("Display input/output pairs from random executions:");
log.code(() -> {
@Nonnull final SimpleEval eval = SimpleEval.run(layer, inputPrototype);
String format = String.format("--------------------\nInput: \n[%s]\n--------------------\nOutput: \n%s\n--------------------\nDerivative: \n%s", Arrays.stream(inputPrototype).map(t -> t.prettyPrint()).reduce((a, b) -> a + ",\n" + b).orElse(""), eval.getOutput().prettyPrint(), Arrays.stream(eval.getDerivative()).map(t -> t.prettyPrint()).reduce((a, b) -> a + ",\n" + b).orElse(""));
eval.freeRef();
return format;
});
}
return null;
}
use of com.simiacryptus.util.data.DoubleStatistics in project MindsEye by SimiaCryptus.
the class PCAUtil method getCovariance.
/**
* Forked from Apache Commons Math
*
* @param stream the stream
* @return covariance covariance
*/
@Nonnull
public static RealMatrix getCovariance(@Nonnull final Supplier<Stream<double[]>> stream) {
final int dimension = stream.get().findAny().get().length;
final List<DoubleStatistics> statList = IntStream.range(0, dimension * dimension).mapToObj(i -> new DoubleStatistics()).collect(Collectors.toList());
stream.get().forEach(array -> {
for (int i = 0; i < dimension; i++) {
for (int j = 0; j <= i; j++) {
statList.get(i * dimension + j).accept(array[i] * array[j]);
}
}
RecycleBin.DOUBLES.recycle(array, array.length);
});
@Nonnull final RealMatrix covariance = new BlockRealMatrix(dimension, dimension);
for (int i = 0; i < dimension; i++) {
for (int j = 0; j <= i; j++) {
final double v = statList.get(i + dimension * j).getAverage();
covariance.setEntry(i, j, v);
covariance.setEntry(j, i, v);
}
}
return covariance;
}
Aggregations