Search in sources :

Example 1 with DAGNode

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

the class SigmoidTreeNetwork method getJson.

@Override
public JsonObject getJson(Map<CharSequence, byte[]> resources, DataSerializer dataSerializer) {
    assertConsistent();
    @Nullable final DAGNode head = getHead();
    final JsonObject json = super.getJson(resources, dataSerializer);
    json.addProperty("head", head.getId().toString());
    if (null != alpha) {
        json.addProperty("alpha", alpha.getId().toString());
    }
    if (null != alphaBias) {
        json.addProperty("alphaBias", alpha.getId().toString());
    }
    if (null != beta) {
        json.addProperty("beta", beta.getId().toString());
    }
    if (null != betaBias) {
        json.addProperty("betaBias", beta.getId().toString());
    }
    if (null != gate) {
        json.addProperty("gate", gate.getId().toString());
    }
    if (null != gateBias) {
        json.addProperty("gateBias", gate.getId().toString());
    }
    json.addProperty("mode", getMode().name());
    json.addProperty("skipChildStage", skipChildStage());
    json.addProperty("skipFuzzy", isSkipFuzzy());
    assert null != Layer.fromJson(json) : "Smoke apply deserialization";
    return json;
}
Also used : JsonObject(com.google.gson.JsonObject) DAGNode(com.simiacryptus.mindseye.network.DAGNode) Nullable(javax.annotation.Nullable)

Example 2 with DAGNode

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

the class SigmoidTreeNetwork method getHead.

@Nullable
@Override
public synchronized DAGNode getHead() {
    if (null == head) {
        synchronized (this) {
            if (null == head) {
                reset();
                final DAGNode input = getInput(0);
                switch(getMode()) {
                    case Linear:
                        head = add(alpha.setFrozen(false), add(alphaBias.setFrozen(false), input));
                        break;
                    case Fuzzy:
                        {
                            final DAGNode gateNode = add(gate.setFrozen(false), null != gateBias ? add(gateBias.setFrozen(false), input) : input);
                            head = add(new ProductInputsLayer(), add(alpha.setFrozen(false), add(alphaBias.setFrozen(false), input)), add(new LinearActivationLayer().setScale(2).freeze(), add(new SigmoidActivationLayer().setBalanced(false), gateNode)));
                            break;
                        }
                    case Bilinear:
                        {
                            final DAGNode gateNode = add(gate.setFrozen(false), null != gateBias ? add(gateBias.setFrozen(false), input) : input);
                            head = add(new SumInputsLayer(), add(new ProductInputsLayer(), add(alpha.setFrozen(false), add(alphaBias.setFrozen(false), input)), add(new SigmoidActivationLayer().setBalanced(false), gateNode)), add(new ProductInputsLayer(), add(beta.setFrozen(false), add(betaBias.setFrozen(false), input)), add(new SigmoidActivationLayer().setBalanced(false), add(new LinearActivationLayer().setScale(-1).freeze(), gateNode))));
                            break;
                        }
                    case Final:
                        final DAGNode gateNode = add(gate.setFrozen(false), null != gateBias ? add(gateBias.setFrozen(false), input) : input);
                        head = add(new SumInputsLayer(), add(new ProductInputsLayer(), add(alpha, input), add(new SigmoidActivationLayer().setBalanced(false), gateNode)), add(new ProductInputsLayer(), add(beta, input), add(new SigmoidActivationLayer().setBalanced(false), add(new LinearActivationLayer().setScale(-1).freeze(), gateNode))));
                        break;
                }
            }
        }
    }
    return head;
}
Also used : SumInputsLayer(com.simiacryptus.mindseye.layers.java.SumInputsLayer) DAGNode(com.simiacryptus.mindseye.network.DAGNode) SigmoidActivationLayer(com.simiacryptus.mindseye.layers.java.SigmoidActivationLayer) ProductInputsLayer(com.simiacryptus.mindseye.layers.java.ProductInputsLayer) LinearActivationLayer(com.simiacryptus.mindseye.layers.java.LinearActivationLayer) Nullable(javax.annotation.Nullable)

Example 3 with DAGNode

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

the class StochasticSamplingSubnetLayerTest method getLayer.

@Nonnull
@Override
public Layer getLayer(final int[][] inputSize, Random random) {
    PipelineNetwork subnetwork = new PipelineNetwork(1);
    subnetwork.wrap(new ProductLayer(), subnetwork.getInput(0), subnetwork.add(new StochasticBinaryNoiseLayer(0.5, 1.0, inputSize[0]), new DAGNode[] {}));
    StochasticSamplingSubnetLayer tileSubnetLayer = new StochasticSamplingSubnetLayer(subnetwork, 2);
    subnetwork.freeRef();
    return tileSubnetLayer;
}
Also used : ProductLayer(com.simiacryptus.mindseye.layers.cudnn.ProductLayer) PipelineNetwork(com.simiacryptus.mindseye.network.PipelineNetwork) DAGNode(com.simiacryptus.mindseye.network.DAGNode) Nonnull(javax.annotation.Nonnull)

Example 4 with DAGNode

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

the class DeepDream method fitnessNetwork.

/**
 * Fitness function pipeline network.
 *
 * @param setup the setup
 * @return the pipeline network
 */
@Nonnull
public PipelineNetwork fitnessNetwork(NeuralSetup setup) {
    PipelineNetwork pipelineNetwork = getInstance().getNetwork();
    Map<T, DAGNode> nodes = new HashMap<>();
    Map<T, UUID> ids = getInstance().getNodes();
    ids.forEach((l, id) -> nodes.put(l, pipelineNetwork.getChildNode(id)));
    PipelineNetwork network = processStats(setup, nodes, pipelineNetwork);
    // network = withClamp(network);
    ArtistryUtil.setPrecision(network, setup.style.precision);
    return network;
}
Also used : HashMap(java.util.HashMap) PipelineNetwork(com.simiacryptus.mindseye.network.PipelineNetwork) DAGNode(com.simiacryptus.mindseye.network.DAGNode) UUID(java.util.UUID) Nonnull(javax.annotation.Nonnull)

Example 5 with DAGNode

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

the class DeepDream method getContentComponents.

/**
 * Gets content components.
 *
 * @param setup   the setup
 * @param nodeMap the node map
 * @return the content components
 */
@Nonnull
public ArrayList<Tuple2<Double, DAGNode>> getContentComponents(NeuralSetup<T> setup, final Map<T, DAGNode> nodeMap) {
    ArrayList<Tuple2<Double, DAGNode>> contentComponents = new ArrayList<>();
    for (final T layerType : getLayerTypes()) {
        final DAGNode node = nodeMap.get(layerType);
        if (setup.style.coefficients.containsKey(layerType)) {
            final double coeff_content = setup.style.coefficients.get(layerType).rms;
            DAGNetwork network = node.getNetwork();
            contentComponents.add(new Tuple2<>(coeff_content, network.wrap(new MeanSqLossLayer(), node, network.wrap(new ValueLayer(setup.contentTarget.content.get(layerType))))));
            final double coeff_gain = setup.style.coefficients.get(layerType).gain;
            contentComponents.add(new Tuple2<>(-coeff_gain, network.wrap(new AvgReducerLayer(), network.wrap(new SquareActivationLayer(), node))));
        }
    }
    return contentComponents;
}
Also used : Tuple2(com.simiacryptus.util.lang.Tuple2) AvgReducerLayer(com.simiacryptus.mindseye.layers.cudnn.AvgReducerLayer) ArrayList(java.util.ArrayList) ValueLayer(com.simiacryptus.mindseye.layers.cudnn.ValueLayer) SquareActivationLayer(com.simiacryptus.mindseye.layers.cudnn.SquareActivationLayer) DAGNetwork(com.simiacryptus.mindseye.network.DAGNetwork) DAGNode(com.simiacryptus.mindseye.network.DAGNode) MeanSqLossLayer(com.simiacryptus.mindseye.layers.cudnn.MeanSqLossLayer) Nonnull(javax.annotation.Nonnull)

Aggregations

DAGNode (com.simiacryptus.mindseye.network.DAGNode)17 Nonnull (javax.annotation.Nonnull)14 PipelineNetwork (com.simiacryptus.mindseye.network.PipelineNetwork)11 ArrayList (java.util.ArrayList)9 Nullable (javax.annotation.Nullable)8 Tensor (com.simiacryptus.mindseye.lang.Tensor)6 DAGNetwork (com.simiacryptus.mindseye.network.DAGNetwork)6 JsonObject (com.google.gson.JsonObject)5 Layer (com.simiacryptus.mindseye.lang.Layer)5 Arrays (java.util.Arrays)5 List (java.util.List)5 IntStream (java.util.stream.IntStream)5 Result (com.simiacryptus.mindseye.lang.Result)4 Map (java.util.Map)4 DataSerializer (com.simiacryptus.mindseye.lang.DataSerializer)3 MeanSqLossLayer (com.simiacryptus.mindseye.layers.cudnn.MeanSqLossLayer)3 ValueLayer (com.simiacryptus.mindseye.layers.cudnn.ValueLayer)3 ArrayTrainable (com.simiacryptus.mindseye.eval.ArrayTrainable)2 LayerBase (com.simiacryptus.mindseye.lang.LayerBase)2 TensorList (com.simiacryptus.mindseye.lang.TensorList)2