diff --git a/Notebooks/Chap07/7_2_Backpropagation.ipynb b/Notebooks/Chap07/7_2_Backpropagation.ipynb index 3e0c65b..8208ba0 100644 --- a/Notebooks/Chap07/7_2_Backpropagation.ipynb +++ b/Notebooks/Chap07/7_2_Backpropagation.ipynb @@ -4,7 +4,7 @@ "metadata": { "colab": { "provenance": [], - "authorship_tag": "ABX9TyOlKB4TrCJnt91TnHOrfRSJ", + "authorship_tag": "ABX9TyM2kkHLr00J4Jeypw41sTkQ", "include_colab_link": true }, "kernelspec": { @@ -311,10 +311,16 @@ " network_output_2, *_ = compute_network_output(net_input, all_weights, all_biases)\n", " dl_dbias[row] = (least_squares_loss(network_output_1, y) - least_squares_loss(network_output_2,y))/delta_fd\n", " all_dl_dbiases_fd[layer] = np.array(dl_dbias)\n", + " print(\"-----------------------------------------------\")\n", " print(\"Bias %d, derivatives from backprop:\"%(layer))\n", " print(all_dl_dbiases[layer])\n", " print(\"Bias %d, derivatives from finite differences\"%(layer))\n", " print(all_dl_dbiases_fd[layer])\n", + " if np.allclose(all_dl_dbiases_fd[layer],all_dl_dbiases[layer],rtol=1e-05, atol=1e-08, equal_nan=False):\n", + " print(\"Success! Derivatives match.\")\n", + " else:\n", + " print(\"Failure! Derivatives different.\")\n", + "\n", "\n", "\n", "# Test the derivatives of the weights matrices\n", @@ -330,10 +336,15 @@ " network_output_2, *_ = compute_network_output(net_input, all_weights, all_biases)\n", " dl_dweight[row][col] = (least_squares_loss(network_output_1, y) - least_squares_loss(network_output_2,y))/delta_fd\n", " all_dl_dweights_fd[layer] = np.array(dl_dweight)\n", + " print(\"-----------------------------------------------\")\n", " print(\"Weight %d, derivatives from backprop:\"%(layer))\n", " print(all_dl_dweights[layer])\n", " print(\"Weight %d, derivatives from finite differences\"%(layer))\n", - " print(all_dl_dweights_fd[layer])" + " print(all_dl_dweights_fd[layer])\n", + " if np.allclose(all_dl_dweights_fd[layer],all_dl_dweights[layer],rtol=1e-05, atol=1e-08, equal_nan=False):\n", + " print(\"Success! Derivatives match.\")\n", + " else:\n", + " print(\"Failure! Derivatives different.\")" ], "metadata": { "id": "PK-UtE3hreAK"