Accor.Net的DeepNeuralNetworkLearning如何运作?

时间:2016-06-27 21:11:21

标签: accord.net

我试图按照DeepNeuralNetworkLearning课程中的代码进行操作,并且无法遵循代码。

我怀疑它会对网络进行部分训练(例如,对于由5层组成的网络,从第3层到第5层)。使用backprop或Rprop训练该部分网络。

我不清楚如何正确使用它。我们应该开始从输入层到输出层的训练,反之亦然?

最后,如果此类中使用的技术在神经网络文献中有名称,有人知道吗?

1 个答案:

答案 0 :(得分:1)

我一直在研究同样的问题,但正如你所指出的,关于如何正确使用这个类的文档很少。我遇到过一些例子,但是他们都使用了一个具有讽刺意味的隐藏层,因为这个类是用于深度学习的。在任何情况下,下面的示例将帮助您了解如何将代码放在一起,然后您可以根据需要进行修改。

您可以通过设置属性teacher.Algorithm将算法更改为您想要的任何网络样式。即RPROP使用ParallelResilientBackpropagationLearning。

然后使用teacher.LayerIndex设置要训练的图层,通常设置为network.Machines.Count - 1

要训练网络,请使用teacher.RunEpoch训练整个批次并重复,直到返回错误足够低。

请在此处查看Accord .Net Framework类信息: - DeepNeuralNetworkLearning Class

DeepBeliefNetworkLearning Class

   ' Training data
        Dim inputs As Double()() = {New Double() {1, 1, 1, -1, -1, -1},
                                    New Double() {1, -1, 1, -1, -1, -1},
                                    New Double() {1, 1, 1, -1, -1, -1},
                                    New Double() {-1, -1, 1, 1, 1, -1},
                                    New Double() {-1, -1, 1, 1, -1, -1},
                                    New Double() {-1, -1, 1, 1, 1, -1}}
        Dim outputs As Double()() = {New Double() {1, -1},
                                     New Double() {1, -1},
                                     New Double() {1, -1},
                                     New Double() {-1, 1},
                                     New Double() {-1, 1},
                                     New Double() {-1, 1}}

        ' Generation of network
        Dim network = New DeepBeliefNetwork(inputs.Length,          ' The input layer dimension
                                            New Integer() {4, 2})   ' Dimension of the hidden layer And output layer

        ' Generation of learning algorithm of DNN
        Dim teacher = New DeepNeuralNetworkLearning(network)
        teacher.Algorithm = Function(ann, i) New ParallelResilientBackpropagationLearning(ann)
        teacher.LayerIndex = network.Machines.Count - 1

        ' Repeat learning 5000 times
        Dim layerData As Double()() = teacher.GetLayerInput(inputs)
        For i As Integer = 0 To 4999
            Dim dError As Double = teacher.RunEpoch(layerData, outputs)
            lblMean.Text = "Error: " + Format(dError, "0.000")
            Application.DoEvents()
        Next

        ' Update weights
        network.UpdateVisibleWeights()

        ' Compute the test data in the learning network is the probability that belong to each class
        Dim input As Double() = {1, -1, 1, -1, -1, -1}
        Dim output As Double() = network.Compute(input)

        '  Get the index of the highest probability class
        Dim imax As Double = output.Max()

        ' Result output
        ListBox1.Items.Clear()
        ListBox1.Items.Add("class: " + output.ToList().IndexOf(imax).ToString)
        For Each o As Double In output
            ListBox1.Items.Add(Format(o, "0.00000"))
        Next