use of guru.nidi.graphviz.engine.Graphviz in project MindsEye by SimiaCryptus.
the class StandardLayerTests method run.
/**
* Test.
*
* @param log the log
*/
public void run(@Nonnull final NotebookOutput log) {
long seed = (long) (Math.random() * Long.MAX_VALUE);
int[][] smallDims = getSmallDims(new Random(seed));
final Layer smallLayer = getLayer(smallDims, new Random(seed));
int[][] largeDims = getLargeDims(new Random(seed));
final Layer largeLayer = getLayer(largeDims, new Random(seed));
try {
if (smallLayer instanceof DAGNetwork) {
try {
log.h1("Network Diagram");
log.p("This is a network apply the following layout:");
log.code(() -> {
return Graphviz.fromGraph(TestUtil.toGraph((DAGNetwork) smallLayer)).height(400).width(600).render(Format.PNG).toImage();
});
} catch (Throwable e) {
logger.info("Error plotting graph", e);
}
} else if (smallLayer instanceof Explodable) {
try {
Layer explode = ((Explodable) smallLayer).explode();
if (explode instanceof DAGNetwork) {
log.h1("Exploded Network Diagram");
log.p("This is a network apply the following layout:");
@Nonnull DAGNetwork network = (DAGNetwork) explode;
log.code(() -> {
@Nonnull Graphviz graphviz = Graphviz.fromGraph(TestUtil.toGraph(network)).height(400).width(600);
@Nonnull File file = new File(log.getResourceDir(), log.getName() + "_network.svg");
graphviz.render(Format.SVG_STANDALONE).toFile(file);
log.link(file, "Saved to File");
return graphviz.render(Format.SVG).toString();
});
}
} catch (Throwable e) {
logger.info("Error plotting graph", e);
}
}
@Nonnull ArrayList<TestError> exceptions = standardTests(log, seed);
if (!exceptions.isEmpty()) {
if (smallLayer instanceof DAGNetwork) {
for (@Nonnull Invocation invocation : getInvocations(smallLayer, smallDims)) {
log.h1("Small SubTests: " + invocation.getLayer().getClass().getSimpleName());
log.p(Arrays.deepToString(invocation.getDims()));
tests(log, getLittleTests(), invocation, exceptions);
invocation.freeRef();
}
}
if (largeLayer instanceof DAGNetwork) {
testEquivalency = false;
for (@Nonnull Invocation invocation : getInvocations(largeLayer, largeDims)) {
log.h1("Large SubTests: " + invocation.getLayer().getClass().getSimpleName());
log.p(Arrays.deepToString(invocation.getDims()));
tests(log, getBigTests(), invocation, exceptions);
invocation.freeRef();
}
}
}
log.code(() -> {
throwException(exceptions);
});
} finally {
smallLayer.freeRef();
largeLayer.freeRef();
}
getFinalTests().stream().filter(x -> null != x).forEach(test -> {
final Layer perfLayer;
perfLayer = getLayer(largeDims, new Random(seed));
perfLayer.assertAlive();
@Nonnull Layer copy;
copy = perfLayer.copy();
Tensor[] randomize = randomize(largeDims);
try {
test.test(log, copy, randomize);
} finally {
test.freeRef();
for (@Nonnull Tensor tensor : randomize) {
tensor.freeRef();
}
perfLayer.freeRef();
copy.freeRef();
}
});
}
Aggregations