neuralnet.py 文件源码

python
阅读 36 收藏 0 点赞 0 评论 0

项目:mlp-classifier 作者: meetvora 项目源码 文件源码
def batch_update(self, mini_batch, eta, n, regularization=L2):
        """ Update the network's weights and biases by applying gradient
        descent using backpropagation to a single mini batch. """
        nabla_b = [np.zeroes(b.shape) for b in self.biases]
        nabla_w = [np.zeros(w.shape) for w in self.weights]
        for x, y in mini_batch:
            delta_nabla_b, delta_nabla_w = self.back_propogation(x, y)
            nabla_b = [nb+dnb for nb, dnb in zip(nabla_b, delta_nabla_b)]
            nabla_w = [nw+dnw for nw, dnw in zip(nabla_w, delta_nabla_w)]
        self.biases = [b-(eta/len(mini_batch))*nb for b, nb in zip(self.biases, nabla_b)]
        if regularization == L2:
            self.weights = [(1-eta*(self.l2/n))*w-(eta/len(mini_batch))*nw for w, nw in zip(self.weights, nabla_w)]
        elif regularization == L1:
            self.weights = [w - eta*self.l1*np.sign(w)/n-(eta/len(mini_batch))*nw for w, nw in zip(self.weights, nabla_w)]
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号