|
48 | 48 | " return 1/(1+np.exp(-z))\n",
|
49 | 49 | "\n",
|
50 | 50 | "def cost(activations, expectations):\n",
|
51 |
| - " #return np.sum(expectations*np.log(activations), 1)\n", |
52 | 51 | " return np.sum(-expectations*np.log(activations))"
|
53 | 52 | ]
|
54 | 53 | },
|
|
321 | 320 | "for i in xrange(num_epochs):\n",
|
322 | 321 | " # feed forward\n",
|
323 | 322 | " z2 = np.dot(input, w2) + b2\n",
|
324 |
| - " #z2 = np.dot(input, w2)\n", |
325 | 323 | " a2 = sigmoid(z2) # 7x5\n",
|
326 | 324 | "\n",
|
327 | 325 | " z3 = np.dot(a2, w3) + b3\n",
|
|
340 | 338 | "\n",
|
341 | 339 | " # 7x2\n",
|
342 | 340 | " delta_l3 = a3 - output\n",
|
343 |
| - " #deriv_w3 = np.dot(delta_l3, w3.T)*a2\n", |
344 | 341 | " deriv_w3 = np.dot(a2.T, delta_l3)\n",
|
345 | 342 | " deriv_b3 = delta_l3\n",
|
346 | 343 | " w3 -= eta*deriv_w3\n",
|
347 | 344 | " b3 -= eta*np.mean(deriv_b3, 0)\n",
|
348 | 345 | " \n",
|
349 | 346 | " delta_l2 = np.dot(delta_l3, w3.T)*(a2*(1-a2)) # 7x5\n",
|
350 |
| - " #print \"d2\", delta_l2\n", |
351 |
| - " #print \"w2\", w2\n", |
352 |
| - " # d: 7x5\n", |
353 |
| - " # w: 4x5\n", |
354 | 347 | " deriv_w2 = np.dot(input.T, delta_l2)\n",
|
355 | 348 | " deriv_b2 = delta_l2\n",
|
356 |
| - " #print deriv_w2\n", |
357 |
| - " #print deriv_b2\n", |
358 | 349 | " w2 -= eta*deriv_w2\n",
|
359 | 350 | " b2 -= eta*np.mean(deriv_b2, 0)"
|
360 | 351 | ]
|
|
0 commit comments