Created using Colaboratory
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
"metadata": {
|
"metadata": {
|
||||||
"colab": {
|
"colab": {
|
||||||
"provenance": [],
|
"provenance": [],
|
||||||
"authorship_tag": "ABX9TyOlKB4TrCJnt91TnHOrfRSJ",
|
"authorship_tag": "ABX9TyM2kkHLr00J4Jeypw41sTkQ",
|
||||||
"include_colab_link": true
|
"include_colab_link": true
|
||||||
},
|
},
|
||||||
"kernelspec": {
|
"kernelspec": {
|
||||||
@@ -311,10 +311,16 @@
|
|||||||
" network_output_2, *_ = compute_network_output(net_input, all_weights, all_biases)\n",
|
" 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",
|
" 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",
|
" all_dl_dbiases_fd[layer] = np.array(dl_dbias)\n",
|
||||||
|
" print(\"-----------------------------------------------\")\n",
|
||||||
" print(\"Bias %d, derivatives from backprop:\"%(layer))\n",
|
" print(\"Bias %d, derivatives from backprop:\"%(layer))\n",
|
||||||
" print(all_dl_dbiases[layer])\n",
|
" print(all_dl_dbiases[layer])\n",
|
||||||
" print(\"Bias %d, derivatives from finite differences\"%(layer))\n",
|
" print(\"Bias %d, derivatives from finite differences\"%(layer))\n",
|
||||||
" print(all_dl_dbiases_fd[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",
|
||||||
"\n",
|
"\n",
|
||||||
"# Test the derivatives of the weights matrices\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",
|
" 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",
|
" 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",
|
" all_dl_dweights_fd[layer] = np.array(dl_dweight)\n",
|
||||||
|
" print(\"-----------------------------------------------\")\n",
|
||||||
" print(\"Weight %d, derivatives from backprop:\"%(layer))\n",
|
" print(\"Weight %d, derivatives from backprop:\"%(layer))\n",
|
||||||
" print(all_dl_dweights[layer])\n",
|
" print(all_dl_dweights[layer])\n",
|
||||||
" print(\"Weight %d, derivatives from finite differences\"%(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": {
|
"metadata": {
|
||||||
"id": "PK-UtE3hreAK"
|
"id": "PK-UtE3hreAK"
|
||||||
|
|||||||
Reference in New Issue
Block a user