use of com.simiacryptus.util.data.ScalarStatistics in project MindsEye by SimiaCryptus.
the class SingleDerivativeTester method test.
/**
* Test tolerance statistics.
*
* @param output
* @param component the component
* @param inputPrototype the input prototype
* @return the tolerance statistics
*/
@Override
public ToleranceStatistics test(@Nonnull final NotebookOutput output, @Nonnull final Layer component, @Nonnull final Tensor... inputPrototype) {
output.h1("Differential Validation");
ToleranceStatistics _statistics = new ToleranceStatistics();
final Tensor outputPrototype = SimpleEval.run(component, inputPrototype).getOutputAndFree();
try {
if (verbose) {
output.code(() -> {
log.info(String.format("Inputs: %s", Arrays.stream(inputPrototype).map(t -> t.prettyPrint()).reduce((a, b) -> a + ",\n" + b).orElse("")));
log.info(String.format("Inputs Statistics: %s", Arrays.stream(inputPrototype).map(x -> new ScalarStatistics().add(x.getData()).toString()).reduce((a, b) -> a + ",\n" + b).orElse("")));
log.info(String.format("Output: %s", null == outputPrototype ? null : outputPrototype.prettyPrint()));
log.info(String.format("Outputs Statistics: %s", new ScalarStatistics().add(outputPrototype.getData())));
});
}
if (isTestFeedback()) {
output.h2("Feedback Validation");
output.p("We validate the agreement between the implemented derivative _of the inputs_ apply finite difference estimations:");
final ToleranceStatistics statistics = _statistics;
_statistics = output.code(() -> {
return testFeedback(statistics, component, inputPrototype, outputPrototype);
});
}
if (isTestLearning()) {
output.h2("Learning Validation");
output.p("We validate the agreement between the implemented derivative _of the internal weights_ apply finite difference estimations:");
final ToleranceStatistics statistics = _statistics;
_statistics = output.code(() -> {
return testLearning(statistics, component, inputPrototype, outputPrototype);
});
}
} finally {
outputPrototype.freeRef();
}
output.h2("Total Accuracy");
output.p("The overall agreement accuracy between the implemented derivative and the finite difference estimations:");
final ToleranceStatistics statistics = _statistics;
output.code(() -> {
// log.info(String.format("Component: %s\nInputs: %s\noutput=%s", component, Arrays.toString(inputPrototype), outputPrototype));
log.info(String.format("Finite-Difference Derivative Accuracy:"));
log.info(String.format("absoluteTol: %s", statistics.absoluteTol));
log.info(String.format("relativeTol: %s", statistics.relativeTol));
});
output.h2("Frozen and Alive Status");
output.code(() -> {
testFrozen(component, inputPrototype);
testUnFrozen(component, inputPrototype);
});
return _statistics;
}
use of com.simiacryptus.util.data.ScalarStatistics in project MindsEye by SimiaCryptus.
the class EncodingUtil method printModel.
/**
* Print model.
*
* @param log the log
* @param network the network
* @param modelNo the model no
*/
public static void printModel(@Nonnull final NotebookOutput log, @Nonnull final Layer network, final int modelNo) {
log.out("Learned Model Statistics: ");
log.code(() -> {
@Nonnull final ScalarStatistics scalarStatistics = new ScalarStatistics();
network.state().stream().flatMapToDouble(x -> Arrays.stream(x)).forEach(v -> scalarStatistics.add(v));
return scalarStatistics.getMetrics();
});
@Nonnull final String modelName = "model" + modelNo + ".json";
log.p("Saved model as " + log.file(network.getJson().toString(), modelName, modelName));
}
Aggregations