ComputationGraphConfiguration.GraphBuilder assemble(int numInputs, int numHiddenNodes, int numLayers, String baseLayer, int startingIndex) { assert numHiddenNodes > 0 : "model capacity is too small. At least some hidden nodes must be created."; WeightInit WEIGHT_INIT = WeightInit.XAVIER; float reduction = 1f; int minimum = (int) (numHiddenNodes * Math.pow(reduction, numLayers)); assert minimum > 2 : "Too much reduction, not enough outputs: "; int numIn = numInputs; int numOut = (int) (numHiddenNodes * modelCapacity); String previousLayerName; String lastDenseLayerName = "no layers"; for (int i = startingIndex; i < startingIndex + numLayers; i++) { // System.out.printf("layer %d numIn=%d numOut=%d%n", i, numIn, numOut); lastDenseLayerName = "dense" + i; previousLayerName = i == startingIndex ? baseLayer : "dense" + (i - 1); numOut = (int) (numHiddenNodes * Math.pow(reductionRate, i) * modelCapacity); build.addLayer(lastDenseLayerName, new DenseLayer.Builder().nIn(numIn).nOut(numOut) .weightInit(WEIGHT_INIT) .activation("relu").learningRateDecayPolicy(learningRatePolicy).epsilon(LAYER_EPSILON) .build(), previousLayerName); numIn = numOut; } this.numOutputs = numOut; this.lastLayerName = lastDenseLayerName; return build; }
.layer(0, new DenseLayer.Builder().nIn(numInputs).nOut(numHiddenNodes) .weightInit(WEIGHT_INIT) .activation("relu").learningRateDecayPolicy(learningRatePolicy) .build()) .layer(1, new DenseLayer.Builder().nIn(numHiddenNodes).nOut((int) (numHiddenNodes * reduction)) .weightInit(WEIGHT_INIT) .activation("relu").learningRateDecayPolicy(learningRatePolicy) .build()) .layer(2, new DenseLayer.Builder().nIn((int) (numHiddenNodes * reduction)).nOut((int) (numHiddenNodes * Math.pow(reduction, 2))) .weightInit(WEIGHT_INIT).learningRateDecayPolicy(learningRatePolicy) .activation("relu") .build()) .layer(3, new DenseLayer.Builder().nIn((int) (numHiddenNodes * Math.pow(reduction, 2))).nOut((int) (numHiddenNodes * Math.pow(reduction, 3))) .weightInit(WEIGHT_INIT).learningRateDecayPolicy(learningRatePolicy) .activation("relu") .build()) .layer(4, new DenseLayer.Builder().nIn((int) (numHiddenNodes * Math.pow(reduction, 3))).nOut((int) (numHiddenNodes * Math.pow(reduction, 4))) .weightInit(WEIGHT_INIT).learningRateDecayPolicy(learningRatePolicy) .activation("relu") .build())
.layer(0, new DenseLayer.Builder().nIn(numInputs).nOut(numHiddenNodes) .weightInit(WEIGHT_INIT) .activation("relu").learningRateDecayPolicy(learningRatePolicy) .build()) .layer(1, new DenseLayer.Builder().nIn(numHiddenNodes).nOut((int) (numHiddenNodes * reduction)) .weightInit(WEIGHT_INIT) .activation("relu").learningRateDecayPolicy(learningRatePolicy) .build()) .layer(2, new DenseLayer.Builder().nIn((int) (numHiddenNodes * reduction)).nOut((int) (numHiddenNodes * Math.pow(reduction, 2))) .weightInit(WEIGHT_INIT).learningRateDecayPolicy(learningRatePolicy) .activation("relu") .build()) .layer(3, new DenseLayer.Builder().nIn((int) (numHiddenNodes * Math.pow(reduction, 2))).nOut((int) (numHiddenNodes * Math.pow(reduction, 3))) .weightInit(WEIGHT_INIT).learningRateDecayPolicy(learningRatePolicy) .activation("relu") .build()) .layer(4, new DenseLayer.Builder().nIn((int) (numHiddenNodes * Math.pow(reduction, 3))).nOut((int) (numHiddenNodes * Math.pow(reduction, 4))) .weightInit(WEIGHT_INIT).learningRateDecayPolicy(learningRatePolicy) .activation("relu") .build())
.addLayer("dense1", new DenseLayer.Builder().nIn(numInputs).nOut(nOut0) .weightInit(WEIGHT_INIT) .activation("relu").learningRateDecayPolicy(learningRatePolicy) .build(), "input") .addLayer("dense2", new DenseLayer.Builder().nIn(nOut0).nOut(nOut1) .weightInit(WEIGHT_INIT) .activation("relu").learningRateDecayPolicy(learningRatePolicy) .build(), "dense1") .addLayer("dense3", new DenseLayer.Builder().nIn(nOut1).nOut(nOut2) .weightInit(WEIGHT_INIT).learningRateDecayPolicy(learningRatePolicy) .activation("relu") .build(), "dense2") .addLayer("dense4", new DenseLayer.Builder().nIn(nOut2).nOut(nOut3) .weightInit(WEIGHT_INIT).learningRateDecayPolicy(learningRatePolicy) .activation("relu") .build(), "dense3") .addLayer("dense5", new DenseLayer.Builder().nIn(nOut3).nOut(nOut4) .weightInit(WEIGHT_INIT).learningRateDecayPolicy(learningRatePolicy) .activation("relu") .build(), "dense4")
.addLayer("dense1", new DenseLayer.Builder().nIn(numInputs).nOut(nOut0) .weightInit(WEIGHT_INIT) .activation("relu").learningRateDecayPolicy(learningRatePolicy) .build(), "input") .addLayer("dense2", new DenseLayer.Builder().nIn(nOut0).nOut(nOut1) .weightInit(WEIGHT_INIT) .activation("relu").learningRateDecayPolicy(learningRatePolicy) .build(), "dense1") .addLayer("dense3", new DenseLayer.Builder().nIn(nOut1).nOut(nOut2) .weightInit(WEIGHT_INIT).learningRateDecayPolicy(learningRatePolicy) .activation("relu") .build(), "dense2") .addLayer("dense4", new DenseLayer.Builder().nIn(nOut2).nOut(nOut3) .weightInit(WEIGHT_INIT).learningRateDecayPolicy(learningRatePolicy) .activation("relu") .build(), "dense3") .addLayer("dense5", new DenseLayer.Builder().nIn(nOut3).nOut(nOut4) .weightInit(WEIGHT_INIT).learningRateDecayPolicy(learningRatePolicy) .activation("relu") .build(), "dense4")
.addLayer("dense1", new DenseLayer.Builder().nIn(numInputs).nOut(numHiddenNodes) .weightInit(WEIGHT_INIT) .activation("relu").learningRateDecayPolicy(learningRatePolicy) .build(), "input") .addLayer("dense2", new DenseLayer.Builder().nIn(numHiddenNodes).nOut((int) (numHiddenNodes * reduction)) .weightInit(WEIGHT_INIT) .activation("relu").learningRateDecayPolicy(learningRatePolicy) .build(), "dense1") .addLayer("dense3", new DenseLayer.Builder().nIn((int) (numHiddenNodes * reduction)).nOut((int) (numHiddenNodes * Math.pow(reduction, 2))) .weightInit(WEIGHT_INIT).learningRateDecayPolicy(learningRatePolicy) .activation("relu") .build(), "dense2") .addLayer("dense4", new DenseLayer.Builder().nIn((int) (numHiddenNodes * Math.pow(reduction, 2))).nOut((int) (numHiddenNodes * Math.pow(reduction, 3))) .weightInit(WEIGHT_INIT).learningRateDecayPolicy(learningRatePolicy) .activation("relu") .build(), "dense3") .addLayer("dense5", new DenseLayer.Builder().nIn((int) (numHiddenNodes * Math.pow(reduction, 3))).nOut((int) (numHiddenNodes * Math.pow(reduction, 4))) .weightInit(WEIGHT_INIT).learningRateDecayPolicy(learningRatePolicy) .activation("relu") .build(), "dense4")
.layer(0, new DenseLayer.Builder().nIn(numInputs).nOut(numHiddenNodes) .weightInit(WEIGHT_INIT) .activation("relu").learningRateDecayPolicy(learningRatePolicy) .build()) .layer(1,new BatchNormalization.Builder().nOut( (numHiddenNodes)) .layer(2, new DenseLayer.Builder().nIn(numHiddenNodes).nOut((int) (numHiddenNodes * reduction)) .weightInit(WEIGHT_INIT) .activation("relu").learningRateDecayPolicy(learningRatePolicy) .build()) .layer(3,new BatchNormalization.Builder().nOut((int) (numHiddenNodes * reduction)) .build()) .layer(4, new DenseLayer.Builder().nIn((int) (numHiddenNodes * reduction)).nOut((int) (numHiddenNodes * Math.pow(reduction, 2))) .weightInit(WEIGHT_INIT).learningRateDecayPolicy(learningRatePolicy) .activation("relu") .build()) .layer(5, new DenseLayer.Builder().nIn((int) (numHiddenNodes * Math.pow(reduction, 2))).nOut((int) (numHiddenNodes * Math.pow(reduction, 3))) .weightInit(WEIGHT_INIT).learningRateDecayPolicy(learningRatePolicy) .activation("relu") .build()) .weightInit(WEIGHT_INIT).learningRateDecayPolicy(learningRatePolicy) .activation("relu") .build())
.layer(0, new DenseLayer.Builder().nIn(numInputs).nOut(numHiddenNodes) .weightInit(WEIGHT_INIT) .activation("relu").learningRateDecayPolicy(learningRatePolicy) .build()) .layer(1, new DenseLayer.Builder().nIn(numHiddenNodes).nOut((int) (numHiddenNodes)) .weightInit(WEIGHT_INIT) .activation("relu").learningRateDecayPolicy(learningRatePolicy) .build()) .layer(2, new DenseLayer.Builder().nIn((int) (numHiddenNodes)).nOut((int) (numHiddenNodes)) .weightInit(WEIGHT_INIT).learningRateDecayPolicy(learningRatePolicy) .activation("relu") .build()) .layer(3, new DenseLayer.Builder().nIn((int) (numHiddenNodes)).nOut((int) (numHiddenNodes)) .weightInit(WEIGHT_INIT).learningRateDecayPolicy(learningRatePolicy) .activation("relu") .build()) .layer(4, new DenseLayer.Builder().nIn((int) (numHiddenNodes)).nOut((int) (numHiddenNodes)) .weightInit(WEIGHT_INIT).learningRateDecayPolicy(learningRatePolicy) .activation("relu") .build())
.weightInit(WEIGHT_INIT) .activation("relu") .learningRateDecayPolicy(learningRatePolicy) .nIn(numReductionLayerInputNodes) .nOut(numReductionLayerOutputNodes)
.layer(0, new DenseLayer.Builder().nIn(numInputs).nOut(numHiddenNodes) .weightInit(WEIGHT_INIT) .activation("relu").learningRateDecayPolicy(learningRatePolicy) .build()) .layer(1, new DenseLayer.Builder().nIn(numHiddenNodes).nOut((int) (numHiddenNodes)) .weightInit(WEIGHT_INIT) .activation("relu").learningRateDecayPolicy(learningRatePolicy) .build()) .layer(2, new DenseLayer.Builder().nIn((int) (numHiddenNodes)).nOut((int) (numHiddenNodes * Math.pow(reduction, 2))) .weightInit(WEIGHT_INIT).learningRateDecayPolicy(learningRatePolicy) .activation("relu") .build())
.layer(0, new DenseLayer.Builder().nIn(numInputs).nOut(numHiddenNodes) .weightInit(WEIGHT_INIT) .activation("relu").learningRateDecayPolicy(learningRatePolicy) .build()) .layer(1, new DenseLayer.Builder().nIn(numHiddenNodes).nOut(numHiddenNodes) .weightInit(WEIGHT_INIT) .activation("relu").learningRateDecayPolicy(learningRatePolicy) .build()) .layer(2, new DenseLayer.Builder().nIn(numHiddenNodes).nOut(numHiddenNodes) .weightInit(WEIGHT_INIT).learningRateDecayPolicy(learningRatePolicy) .activation("relu") .build()) .layer(3, new DenseLayer.Builder().nIn(numHiddenNodes).nOut(numHiddenNodes) .weightInit(WEIGHT_INIT).learningRateDecayPolicy(learningRatePolicy) .activation("relu") .build()) .layer(4, new DenseLayer.Builder().nIn(numHiddenNodes).nOut(numHiddenNodes) .weightInit(WEIGHT_INIT).learningRateDecayPolicy(learningRatePolicy) .activation("relu") .build())
public MultiLayerConfiguration createNetwork() { MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder() .seed(seed) .iterations(1) .optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT) .learningRate(learningRate).regularization(regularization).l2(regularizationRate) .updater(Updater.ADAGRAD) .list() .layer(0, new DenseLayer.Builder().nIn(numInputs).nOut(numHiddenNodes) .weightInit(WEIGHT_INIT) .activation("relu").learningRateDecayPolicy(learningRatePolicy) .build()) .layer(1, new DenseLayer.Builder().nIn(numHiddenNodes).nOut(numHiddenNodes) .weightInit(WEIGHT_INIT) .activation("relu").learningRateDecayPolicy(learningRatePolicy) .build()) .layer(2, new DenseLayer.Builder().nIn(numHiddenNodes).nOut(numHiddenNodes) .weightInit(WEIGHT_INIT) .activation("relu").learningRateDecayPolicy(learningRatePolicy) .build()) .layer(3, new OutputLayer.Builder(LossFunctions.LossFunction.MSE) .weightInit(WEIGHT_INIT) .activation("sigmoid").learningRateDecayPolicy(learningRatePolicy) .nIn(numHiddenNodes).nOut(numOutputs).build()) .pretrain(false).backprop(true).build(); return conf; } }
public MultiLayerConfiguration createNetwork() { MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder() .seed(seed) .iterations(1) .optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT) .learningRate(learningRate).regularization(regularization).l2(regularizationRate) .updater(Updater.ADAGRAD) .list() .layer(0, new DenseLayer.Builder().nIn(numInputs).nOut(numHiddenNodes) .weightInit(WEIGHT_INIT) .activation("relu").learningRateDecayPolicy(learningRatePolicy) .build()) .layer(1, new DenseLayer.Builder().nIn(numHiddenNodes).nOut(numHiddenNodes) .weightInit(WEIGHT_INIT) .activation("relu").learningRateDecayPolicy(learningRatePolicy) .build()) .layer(2, new OutputLayer.Builder(lossFunction) .weightInit(WEIGHT_INIT) .activation("softmax").learningRateDecayPolicy(learningRatePolicy) .nIn(numHiddenNodes).nOut(numOutputs).build()) .pretrain(false).backprop(true).build(); return conf; } }