You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"# Start feeding forward and backpropagate *epochs* times.\n",
140
+
"for epoch in range(epochs):\n",
141
+
" # Feed forward\n",
142
+
" z_h = np.dot(X, w01) #Calculate the input of the hidden layer zh using matrix multiplication.\n",
143
+
" #print(z_h)\n",
144
+
" a_h = sigmoid(z_h) #Calculate the output of the hidden layer ah using sigmoid activation function.\n",
145
+
" #print(a_h)\n",
146
+
"\n",
147
+
" z_o = np.dot(a_h, w12) #Calculate the input of the output layer zo using matrix multiplication.\n",
148
+
" #print(z_o)\n",
149
+
" a_o = sigmoid(z_o) #Calculate the output of the output layer ao using sigmoid activation function.\n",
150
+
" #print(a_o)\n",
151
+
"\n",
152
+
" # Calculate the error\n",
153
+
" a_o_error = ((1 / 2) * (np.power((a_o - y), 2))) # Calculate the error of the output neuron ao using squared error function.\n",
154
+
" #print(a_o_error)\n",
155
+
"\n",
156
+
" # Backpropagation\n",
157
+
" ## Output layer\n",
158
+
" delta_a_o_error = a_o - y #Calculate the derivate of the error of the output layer.\n",
159
+
" #print(delta_a_o_error)\n",
160
+
" delta_z_o = sigmoid(a_o,derive=True) #Calculate the derivate of the sigmoid function of the output layer.\n",
161
+
" #print(delta_z_o)\n",
162
+
" delta_w12 = a_h #Calculate the derivate of the input of the output layer zo with respect to the weights w.\n",
163
+
" #print(a_h)\n",
164
+
" delta_output_layer = np.dot(delta_w12.T,(delta_a_o_error * delta_z_o)) # Calculate the update matrix for the output layer using matrix multiplication and hadamard product.\n",
165
+
" #print(delta_output_layer)\n",
166
+
"\n",
167
+
" ## Hidden layer\n",
168
+
" delta_a_h = np.dot(delta_a_o_error * delta_z_o, w12.T) #Calculate the derivate of the Error function E with respect to the output of the hidden layer ah.\n",
169
+
" #print(delta_a_h)\n",
170
+
" delta_z_h = sigmoid(a_h,derive=True) #Calculate the derivate of the sigmoid of the hidden layer.\n",
171
+
" #print(delta_z_h)\n",
172
+
" delta_w01 = X #Calculate the derivate of the input of the hidden layer zh with respect to the weight matrix w01.\n",
173
+
" #print(X)\n",
174
+
" delta_hidden_layer = np.dot(delta_w01.T, delta_a_h * delta_z_h) #Calculate the update matrix for the hidden layer using matrix multiplication and hadamard product.\n",
0 commit comments