官术网_书友最值得收藏!

Output layer

The number of input neurons is equal to the output of the hidden layer 1. Then the number of outputs is equal to the number of predicted labels. We set a smaller value yet again, considering a very few inputs and features.

Here we used the Softmax activation function, which gives us a probability distribution over classes (the outputs sum to 1.0), and the losses function as cross-entropy for binary classification (XNET) since we want to convert the output (probability) to a discrete class, that is, zero or one:

OutputLayer output_layer = new OutputLayer.Builder(LossFunction.XENT) // XENT for Binary Classification
.weightInit(WeightInit.XAVIER)
.activation(Activation.SOFTMAX)
.nIn(16).nOut(numOutputs)
.build();

XNET is used for binary classification with logistic regression. Check out more about this in LossFunctions.java class in DL4J.

Now we create a MultiLayerConfiguration by specifying NeuralNetConfiguration before conducting the training. With DL4J, we can add a layer by calling layer on the NeuralNetConfiguration.Builder(), specifying its place in the order of layers (the zero-indexed layer in the following code is the input layer):

MultiLayerConfiguration MLPconf = new NeuralNetConfiguration.Builder().seed(seed)
.optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
.weightInit(WeightInit.XAVIER)
.updater(new Adam(0.0001))
.list()
.layer(0, input_layer)
.layer(1, hidden_layer_1)
.layer(2, hidden_layer_2)
.layer(3, output_layer)
.pretrain(false).backprop(true).build();// no pre-traning required

Apart from these, we also specify how to set the network's weights. For example, as discussed, we use Xavier as the weight initialization and Stochastic Gradient Descent (SGD) optimization algorithm with Adam as the updater. Finally, we also specify that we do not need to do any pre-training (which is typically needed in DBN or stacked autoencoders). Nevertheless, since MLP is a feedforward network, we set backpropagation as true.

主站蜘蛛池模板: 商河县| 西城区| 涿鹿县| 南通市| 萨嘎县| 山阴县| 新巴尔虎左旗| 竹北市| 红桥区| 宁陕县| 仁布县| 许昌市| 屯昌县| 武汉市| 平邑县| 会昌县| 南阳市| 孙吴县| 阿勒泰市| 聂拉木县| 富民县| 淄博市| 马公市| 鹤岗市| 维西| 芜湖市| 务川| 永州市| 曲阜市| 阳原县| 易门县| 七台河市| 景洪市| 虹口区| 万载县| 望城县| 高州市| 嘉义县| 双柏县| 嘉义市| 沧源|