sigmoid神经网络梯度下降更新连接权重重要公式推导

$X_{hidden}=W_{input\_hidden} \cdot I$

$O_{hidden}=sigmoid(X_{hidden})$

$X_{output}=W_{hidden\_output} \cdot O_{hidden}$

$O_{output}=sigmoid(X_{output})$

$Error_{output}=Target-O_{output}$

$Error_{hidden}=W^{T} \cdot Error_{output}$

$$\frac{\partial E}{\partial W_{jk}}=\frac{\partial}{\partial W_{jk}} \sum_{n}(t_{n}-O_{n})^{2}$$

$$\frac{\partial E}{\partial W_{jk}}=\frac{\partial}{\partial W_{jk}}{\left(t_{k}-O_{k}\right)}^{2}$$

$$\frac{\partial E}{\partial W_{jk}}=\frac{\partial E}{\partial O_{k}}\cdot\frac{\partial O_{k}}{\partial W_{jk}}$$

$$\frac{\partial E}{\partial W_{jk}}=-2\left(t_{k}-O_{k}\right)\cdot\frac{\partial O_{k}}{\partial W_{jk}}$$

$$\frac{\partial E}{\partial W_{jk}}=-2\left(t_{k}-O_{k}\right)\cdot\frac{\partial }{\partial W_{jk}} sigmoid\left(\Sigma_{j}W_{jk}\cdot O_{j}\right)$$

$$\frac{\partial}{\partial X}sigmoid(X)=sigmoid(X)(1-sigmoid(X))$$

$$\frac{\partial E}{\partial W_{jk}}=-2(t_{k}-O_{k}) \cdot sigmoid(\sum_{j} W_{jk} \cdot O_{j})(1-sigmoid(\sum_{j} W_{jk} \cdot O_{j})) \cdot \frac{\partial}{\partial W_{jk}}(\sum_{j} W_{jk} \cdot O_{j})$$

 

$$\frac{\partial E}{\partial W_{jk}}=-2(t_{k}-O_{k}) \cdot sigmoid(\sum_{j} W_{jk} \cdot O_{j})(1-sigmoid(\sum_{j} W_{jk} \cdot O_{j})) \cdot O_{j}$$

 

$$new\ W_{jk}=old\ W_{jk}-\alpha\cdot\frac{\partial E}{\partial W_{jk}}$$

 

$\Delta W_{jk}=\alpha * E_{k} * sigmoid(O_{k}) *(1-sigmoid(O_{k})) \cdot O_{j}^{T} $

附:sigmoid神经网络核心代码

import numpy

class neuralNetwork :
    def __init__(self, inputnodes, hiddennodes, outputnodes,learningrate) :
        self.inodes = inputnodes
        self.hnodes = hiddennodes
        self.onodes = outputnodes
        self.wih = numpy.random.normal(0.0, pow(self.hnodes, 0.5),(self.hnodes, self.inodes))
        self.who = numpy.random.normal(0.0, pow(self.onodes, 0.5),(self.onodes, self.hnodes))
        self.lr = learningrate
        self.activation_function = lambda x:1/(1+numpy.exp(-x))
    
    def train(self, inputs_list, targets_list) :
        inputs = numpy.array(inputs_list, ndmin=2).T
        targets = numpy.array(targets_list, ndmin=2).T
        hidden_inputs = numpy.dot(self.wih, inputs)
        hidden_outputs = self.activation_function(hidden_inputs)
        final_inputs = numpy.dot(self.who, hidden_outputs)
        final_outputs = self.activation_function(final_inputs) 
        output_errors = targets-final_outputs
        hidden_errors = numpy.dot(self.who.T, output_errors)
        self.who += self.lr * numpy.dot((output_errors *  final_outputs * (1.0-final_outputs)),numpy.transpose(hidden_outputs))
        self.wih += self.lr * numpy.dot((hidden_errors *  hidden_outputs * (1.0-hidden_outputs)), numpy.transpose(inputs))

    def query(self, inputs_list) :
        inputs = numpy.array(inputs_list, ndmin=2).T
        hidden_inputs = numpy.dot(self.wih, inputs)
        hidden_outputs = self.activation_function(hidden_inputs)
        final_inputs = numpy.dot(self.who, hidden_outputs)
        final_outputs = self.activation_function(final_inputs)
        return final_outputs

 

你可能感兴趣的:(机器学习,神经网络)