use of com.simiacryptus.mindseye.lang.Layer in project MindsEye by SimiaCryptus.
the class MomentumStrategy method orient.
@Nonnull
@Override
public SimpleLineSearchCursor orient(final Trainable subject, @Nonnull final PointSample measurement, final TrainingMonitor monitor) {
final LineSearchCursor orient = inner.orient(subject, measurement, monitor);
final DeltaSet<Layer> direction = ((SimpleLineSearchCursor) orient).direction;
@Nonnull final DeltaSet<Layer> newDelta = new DeltaSet<Layer>();
direction.getMap().forEach((layer, delta) -> {
final DoubleBuffer<Layer> prevBuffer = prevDelta.get(layer, delta.target);
newDelta.get(layer, delta.target).addInPlace(ArrayUtil.add(ArrayUtil.multiply(prevBuffer.getDelta(), carryOver), delta.getDelta()));
});
prevDelta = newDelta;
return new SimpleLineSearchCursor(subject, measurement, newDelta);
}
use of com.simiacryptus.mindseye.lang.Layer in project MindsEye by SimiaCryptus.
the class ImgCropLayerTest method getPerformanceTester.
@Nullable
@Override
public ComponentTest<ToleranceStatistics> getPerformanceTester() {
@Nonnull ComponentTest<ToleranceStatistics> inner = new PerformanceTester().setSamples(100).setBatches(10);
return new ComponentTestBase<ToleranceStatistics>() {
@Override
public ToleranceStatistics test(@Nonnull NotebookOutput log, Layer component, Tensor... inputPrototype) {
@Nullable PrintStream apiLog = null;
try {
apiLog = new PrintStream(log.file("cuda_perf.log"));
CudaSystem.addLog(apiLog);
return inner.test(log, component, inputPrototype);
} finally {
log.p(log.file((String) null, "cuda_perf.log", "GPU Log"));
if (null != apiLog) {
apiLog.close();
CudaSystem.apiLog.remove(apiLog);
}
}
}
@Override
protected void _free() {
inner.freeRef();
super._free();
}
};
}
use of com.simiacryptus.mindseye.lang.Layer in project MindsEye by SimiaCryptus.
the class RecursiveSubspace method orient.
@Nonnull
@Override
public SimpleLineSearchCursor orient(@Nonnull Trainable subject, @Nonnull PointSample measurement, @Nonnull TrainingMonitor monitor) {
@Nonnull PointSample origin = measurement.copyFull().backup();
@Nullable Layer macroLayer = buildSubspace(subject, measurement, monitor);
train(monitor, macroLayer);
Result eval = macroLayer.eval((Result) null);
macroLayer.freeRef();
eval.getData().freeRef();
eval.freeRef();
@Nonnull StateSet<Layer> backupCopy = origin.weights.backupCopy();
@Nonnull DeltaSet<Layer> delta = backupCopy.subtract(origin.weights);
backupCopy.freeRef();
origin.restore();
@Nonnull SimpleLineSearchCursor simpleLineSearchCursor = new SimpleLineSearchCursor(subject, origin, delta);
delta.freeRef();
origin.freeRef();
return simpleLineSearchCursor.setDirectionType(CURSOR_LABEL);
}
use of com.simiacryptus.mindseye.lang.Layer in project MindsEye by SimiaCryptus.
the class ActivationLayerTestBase method run.
@Override
public void run(final NotebookOutput log) {
super.run(log);
log.h3("Function Plots");
final Layer layer = getLayer(new int[][] { { 1 } }, new Random());
final List<double[]> plotData = scan().mapToObj(x -> {
@Nonnull Tensor tensor = new Tensor(x);
@Nonnull final SimpleEval eval = SimpleEval.run(layer, tensor);
tensor.freeRef();
@Nonnull double[] doubles = { x, eval.getOutput().get(0), eval.getDerivative()[0].get(0) };
eval.freeRef();
return doubles;
}).collect(Collectors.toList());
log.code(() -> {
return ActivationLayerTestBase.plot("Value Plot", plotData, x -> new double[] { x[0], x[1] });
});
log.code(() -> {
return ActivationLayerTestBase.plot("Derivative Plot", plotData, x -> new double[] { x[0], x[2] });
});
}
use of com.simiacryptus.mindseye.lang.Layer in project MindsEye by SimiaCryptus.
the class EncodingUtil method renderLayer.
/**
* Render layer.
*
* @param log the log
* @param dataPipeline the data pipeline
* @param row the row
* @param col the col
* @param tensor the tensor
*/
public static void renderLayer(@Nonnull final NotebookOutput log, @Nonnull final List<Layer> dataPipeline, @Nonnull final LinkedHashMap<CharSequence, Object> row, final int col, @Nonnull final Tensor tensor) {
row.put("Data_" + col, TestUtil.render(log, tensor, 0 < col));
if (dataPipeline.size() >= col - 1 && 1 < col) {
@Nonnull final PipelineNetwork decoder = new PipelineNetwork();
for (int i = col - 2; i >= 0; i--) {
decoder.add(dataPipeline.get(i));
}
@Nullable final Tensor decoded = decoder.eval(tensor).getData().get(0);
row.put("Decode_" + col, TestUtil.render(log, decoded, false));
final List<Tensor> rawComponents = IntStream.range(0, tensor.getDimensions()[2]).mapToObj(band -> EncodingUtil.findUnitComponent(decoder, band, tensor)).collect(Collectors.toList());
@Nullable final Tensor baseline = EncodingUtil.findBaseline(decoder, tensor);
final List<Tensor> signedComponents = IntStream.range(0, tensor.getDimensions()[2]).mapToObj(band -> rawComponents.get(band).minus(baseline)).collect(Collectors.toList());
row.put("SVG_" + col, log.file(EncodingUtil.decompositionSvg(log, baseline, signedComponents), "svg" + EncodingUtil.svgNumber++ + ".svg", "SVG Composite Image"));
row.put("GIF_" + col, EncodingUtil.animatedGif(log, baseline, signedComponents));
@Nonnull final CharSequence render = signedComponents.stream().map(signedContribution -> TestUtil.render(log, signedContribution, true)).reduce((a, b) -> a + "" + b).get();
row.put("Band_Decode_" + col, render);
}
}
Aggregations