TVP

# 从零开始用 Python 构建神经网络

2 层神经网络的结构

class NeuralNetwork:

def __init__(self, x, y):

self.input      = x

self.y          = y

self.output     = np.zeros(y.shape)

class NeuralNetwork:

def __init__(self, x, y):

self.input      = x

self.y          = y

self.output     = np.zeros(self.y.shape)

def feedforward(self):

self.layer1 = sigmoid(np.dot(self.input, self.weights1))

self.output = sigmoid(np.dot(self.layer1, self.weights2))

class NeuralNetwork:

def __init__(self, x, y):

self.input      = x

self.y          = y

self.output     = np.zeros(self.y.shape)

def feedforward(self):

self.layer1 = sigmoid(np.dot(self.input, self.weights1))

self.output = sigmoid(np.dot(self.layer1, self.weights2))

def backprop(self):

# application of the chain rule to find derivative of the loss function with respect to weights2 and weights1

d_weights2 = np.dot(self.layer1.T, (2*(self.y - self.output) * sigmoid_derivative(self.output)))

d_weights1 = np.dot(self.input.T,  (np.dot(2*(self.y - self.output) * sigmoid_derivative(self.output), self.weights2.T) * sigmoid_derivative(self.layer1)))

# update the weights with the derivative (slope) of the loss function

self.weights1 += d_weights1

self.weights2 += d_weights2

• 发表于:
• 原文链接https://kuaibao.qq.com/s/20180702C0YEIR00?refer=cp_1026
• 腾讯「腾讯云开发者社区」是腾讯内容开放平台帐号（企鹅号）传播渠道之一，根据《腾讯内容开放平台服务协议》转载发布内容。
• 如有侵权，请联系 cloudcommunity@tencent.com 删除。

2018-10-25

2020-06-24

2018-01-26

2018-06-19

2018-01-27

2018-04-07

2018-10-24

2018-06-01

2020-11-18

2018-01-28

2018-01-26

2018-10-24

2018-01-27

2020-08-17

2018-03-29

2018-06-14

2018-07-06

2018-10-28

2019-07-26

2018-04-15