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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations