Search in sources :

Example 1 with PipelineNetwork

use of com.simiacryptus.mindseye.network.PipelineNetwork in project MindsEye by SimiaCryptus.

the class BinarySumLayer method getCompatibilityLayer.

/**
 * Gets compatibility layer.
 *
 * @return the compatibility layer
 */
@Nonnull
public Layer getCompatibilityLayer() {
    @Nonnull PipelineNetwork network = new PipelineNetwork(2);
    network.wrap(new SumInputsLayer(), network.wrap(new LinearActivationLayer().setScale(this.leftFactor).freeze(), network.getInput(0)), network.wrap(new LinearActivationLayer().setScale(this.rightFactor).freeze(), network.getInput(1)));
    return network;
}
Also used : Nonnull(javax.annotation.Nonnull) SumInputsLayer(com.simiacryptus.mindseye.layers.java.SumInputsLayer) PipelineNetwork(com.simiacryptus.mindseye.network.PipelineNetwork) LinearActivationLayer(com.simiacryptus.mindseye.layers.java.LinearActivationLayer) Nonnull(javax.annotation.Nonnull)

Example 2 with PipelineNetwork

use of com.simiacryptus.mindseye.network.PipelineNetwork in project MindsEye by SimiaCryptus.

the class ExplodedConvolutionGrid method getNetwork.

/**
 * Gets network.
 *
 * @return the network
 */
@Nonnull
public PipelineNetwork getNetwork() {
    assertAlive();
    @Nonnull PipelineNetwork network = new PipelineNetwork(1);
    add(network.getInput(0));
    return network;
}
Also used : Nonnull(javax.annotation.Nonnull) PipelineNetwork(com.simiacryptus.mindseye.network.PipelineNetwork) Nonnull(javax.annotation.Nonnull)

Example 3 with PipelineNetwork

use of com.simiacryptus.mindseye.network.PipelineNetwork in project MindsEye by SimiaCryptus.

the class MnistTestBase method buildModel.

/**
 * Build model dag network.
 *
 * @param log the log
 * @return the dag network
 */
public DAGNetwork buildModel(@Nonnull final NotebookOutput log) {
    log.h1("Model");
    log.p("This is a very simple model that performs basic logistic regression. " + "It is expected to be trainable to about 91% accuracy on MNIST.");
    return log.code(() -> {
        @Nonnull final PipelineNetwork network = new PipelineNetwork();
        network.add(new BiasLayer(28, 28, 1));
        network.add(new FullyConnectedLayer(new int[] { 28, 28, 1 }, new int[] { 10 }).set(() -> 0.001 * (Math.random() - 0.45)));
        network.add(new SoftmaxActivationLayer());
        return network;
    });
}
Also used : SoftmaxActivationLayer(com.simiacryptus.mindseye.layers.java.SoftmaxActivationLayer) FullyConnectedLayer(com.simiacryptus.mindseye.layers.java.FullyConnectedLayer) Nonnull(javax.annotation.Nonnull) PipelineNetwork(com.simiacryptus.mindseye.network.PipelineNetwork) BiasLayer(com.simiacryptus.mindseye.layers.java.BiasLayer)

Example 4 with PipelineNetwork

use of com.simiacryptus.mindseye.network.PipelineNetwork in project MindsEye by SimiaCryptus.

the class EncodingUtil method buildTrainingModel.

/**
 * Build training model dag network.
 *
 * @param innerModel       the heapCopy model
 * @param reproducedColumn the reproduced column
 * @param learnedColumn    the learned column
 * @return the dag network
 */
@Nonnull
public static DAGNetwork buildTrainingModel(final Layer innerModel, final int reproducedColumn, final int learnedColumn) {
    @Nonnull final PipelineNetwork network = new PipelineNetwork(Math.max(learnedColumn, reproducedColumn) + 1);
    // network.add(new NthPowerActivationLayer().setPower(0.5), );
    network.wrap(new MeanSqLossLayer(), network.add("image", innerModel, network.getInput(learnedColumn)), network.getInput(reproducedColumn));
    // addLogging(network);
    return network;
}
Also used : Nonnull(javax.annotation.Nonnull) PipelineNetwork(com.simiacryptus.mindseye.network.PipelineNetwork) MeanSqLossLayer(com.simiacryptus.mindseye.layers.java.MeanSqLossLayer) Nonnull(javax.annotation.Nonnull)

Example 5 with PipelineNetwork

use of com.simiacryptus.mindseye.network.PipelineNetwork 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);
    }
}
Also used : PipelineNetwork(com.simiacryptus.mindseye.network.PipelineNetwork) IntStream(java.util.stream.IntStream) Coordinate(com.simiacryptus.mindseye.lang.Coordinate) Arrays(java.util.Arrays) DoubleStatistics(com.simiacryptus.util.data.DoubleStatistics) GifSequenceWriter(com.simiacryptus.util.io.GifSequenceWriter) TableOutput(com.simiacryptus.util.TableOutput) LoggerFactory(org.slf4j.LoggerFactory) Tensor(com.simiacryptus.mindseye.lang.Tensor) Caltech101(com.simiacryptus.mindseye.test.data.Caltech101) Function(java.util.function.Function) LinkedHashMap(java.util.LinkedHashMap) ImgBandScaleLayer(com.simiacryptus.mindseye.layers.java.ImgBandScaleLayer) TrainingMonitor(com.simiacryptus.mindseye.opt.TrainingMonitor) ImageIO(javax.imageio.ImageIO) Layer(com.simiacryptus.mindseye.lang.Layer) StepRecord(com.simiacryptus.mindseye.test.StepRecord) NotebookOutput(com.simiacryptus.util.io.NotebookOutput) PCAUtil(com.simiacryptus.mindseye.test.PCAUtil) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) PrintStream(java.io.PrintStream) MeanSqLossLayer(com.simiacryptus.mindseye.layers.java.MeanSqLossLayer) Logger(org.slf4j.Logger) SysOutInterceptor(com.simiacryptus.util.test.SysOutInterceptor) BufferedImage(java.awt.image.BufferedImage) ImgBandSelectLayer(com.simiacryptus.mindseye.layers.java.ImgBandSelectLayer) IOException(java.io.IOException) TestUtil(com.simiacryptus.mindseye.test.TestUtil) FastRandom(com.simiacryptus.util.FastRandom) Collectors(java.util.stream.Collectors) File(java.io.File) DoubleStream(java.util.stream.DoubleStream) ConvolutionLayer(com.simiacryptus.mindseye.layers.cudnn.ConvolutionLayer) List(java.util.List) Stream(java.util.stream.Stream) ScalarStatistics(com.simiacryptus.util.data.ScalarStatistics) ToDoubleFunction(java.util.function.ToDoubleFunction) ImgReshapeLayer(com.simiacryptus.mindseye.layers.java.ImgReshapeLayer) ImgBandBiasLayer(com.simiacryptus.mindseye.layers.java.ImgBandBiasLayer) DAGNetwork(com.simiacryptus.mindseye.network.DAGNetwork) Step(com.simiacryptus.mindseye.opt.Step) Comparator(java.util.Comparator) Tensor(com.simiacryptus.mindseye.lang.Tensor) Nonnull(javax.annotation.Nonnull) PipelineNetwork(com.simiacryptus.mindseye.network.PipelineNetwork) Nullable(javax.annotation.Nullable)

Aggregations

PipelineNetwork (com.simiacryptus.mindseye.network.PipelineNetwork)33 Nonnull (javax.annotation.Nonnull)29 Tensor (com.simiacryptus.mindseye.lang.Tensor)16 DAGNode (com.simiacryptus.mindseye.network.DAGNode)13 Nullable (javax.annotation.Nullable)12 ArrayList (java.util.ArrayList)11 StepRecord (com.simiacryptus.mindseye.test.StepRecord)10 Layer (com.simiacryptus.mindseye.lang.Layer)9 Arrays (java.util.Arrays)9 List (java.util.List)9 ArrayTrainable (com.simiacryptus.mindseye.eval.ArrayTrainable)8 DAGNetwork (com.simiacryptus.mindseye.network.DAGNetwork)8 IntStream (java.util.stream.IntStream)8 MeanSqLossLayer (com.simiacryptus.mindseye.layers.java.MeanSqLossLayer)7 TestUtil (com.simiacryptus.mindseye.test.TestUtil)7 NotebookOutput (com.simiacryptus.util.io.NotebookOutput)7 Map (java.util.Map)7 Trainable (com.simiacryptus.mindseye.eval.Trainable)6 IterativeTrainer (com.simiacryptus.mindseye.opt.IterativeTrainer)6 BufferedImage (java.awt.image.BufferedImage)6