for k in range(epochs):#k在第几次的循环中 i = np.random.randint(X.shape[0]) a = [X[i]] for l in range(len(self.weights)): #going forward network, for each layer a.append(self.activation(np.dot(a[l], self.weights[l]))) #Computer the node value for each layer (O_i) using activation function error = y[i] - a[-1] #Computer the error at the top layer deltas = [error * self.activation_deriv(a[-1])] #For output layer, Err calculation (delta is updated error) #Staring backprobagation for l in range(len(a) - 2, 0, -1): # we need to begin at the second to last layer #Compute the updated error (i,e, deltas) for each node going from top layer to input layer deltas.append(deltas[-1].dot(self.weights[l].T)*self.activation_deriv(a[l])) deltas.reverse() for i in range(len(self.weights)): layer = np.atleast_2d(a[i]) delta = np.atleast_2d(deltas[i]) self.weights[i] += learning_rate * layer.T.dot(delta) 代码含义
时间: 2023-02-12 07:23:16 浏览: 125
系统更新-在keras中利用np.random.shuffle()打乱数据集实例
在Python中,"for k in range(epochs):" 意味着进行一个循环,循环变量 k 的值将在范围 [0, epochs) 中变化,每次循环都会执行其后面的语句。在这里,epochs 是一个变量或常量,表示循环的次数。
阅读全文