Lecture 14

This commit is contained in:
judsonupchurch 2024-12-19 01:15:45 +00:00
parent 5de460e8d0
commit 12afb03d1f
2 changed files with 31 additions and 29 deletions

View File

@ -2,29 +2,29 @@
"cells": [ "cells": [
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 2,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"Iteration 0, Loss: 0.0\n", "Iteration 0, Loss: 466.56000000000006\n",
"Iteration 20, Loss: 0.0\n", "Iteration 20, Loss: 5.32959636083938\n",
"Iteration 40, Loss: 0.0\n", "Iteration 40, Loss: 0.41191523404899866\n",
"Iteration 60, Loss: 0.0\n", "Iteration 60, Loss: 0.031836212079467595\n",
"Iteration 80, Loss: 0.0\n", "Iteration 80, Loss: 0.002460565465389601\n",
"Iteration 100, Loss: 0.0\n", "Iteration 100, Loss: 0.000190172825660145\n",
"Iteration 120, Loss: 0.0\n", "Iteration 120, Loss: 1.4698126966451542e-05\n",
"Iteration 140, Loss: 0.0\n", "Iteration 140, Loss: 1.1359926717815175e-06\n",
"Iteration 160, Loss: 0.0\n", "Iteration 160, Loss: 8.779889800154524e-08\n",
"Iteration 180, Loss: 0.0\n", "Iteration 180, Loss: 6.7858241357822796e-09\n",
"Final weights:\n", "Final weights:\n",
" [[0. 0. 0. 0.]\n", " [[-0.00698895 -0.01397789 -0.02096684 -0.02795579]\n",
" [0. 0. 0. 0.]\n", " [ 0.25975286 0.11950572 -0.02074143 -0.16098857]\n",
" [0. 0. 0. 0.]]\n", " [ 0.53548461 0.27096922 0.00645383 -0.25806156]]\n",
"Final biases:\n", "Final biases:\n",
" [0. 0. 0.]\n" " [-0.00698895 -0.04024714 -0.06451539]\n"
] ]
} }
], ],

View File

@ -371,7 +371,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 8, "execution_count": 13,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -379,18 +379,18 @@
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"Iteration 0, Loss: 466.56000000000006\n", "Iteration 0, Loss: 466.56000000000006\n",
"Iteration 20, Loss: 5.329595763793193\n", "Iteration 20, Loss: 5.32959636083938\n",
"Iteration 40, Loss: 0.41191524253483786\n", "Iteration 40, Loss: 0.41191523404899866\n",
"Iteration 60, Loss: 0.03183621475376345\n", "Iteration 60, Loss: 0.031836212079467595\n",
"Iteration 80, Loss: 0.002460565405431671\n", "Iteration 80, Loss: 0.002460565465389601\n",
"Iteration 100, Loss: 0.0001901729121621426\n", "Iteration 100, Loss: 0.000190172825660145\n",
"Iteration 120, Loss: 1.4698120139337557e-05\n", "Iteration 120, Loss: 1.4698126966451542e-05\n",
"Iteration 140, Loss: 1.1359948840900371e-06\n", "Iteration 140, Loss: 1.1359926717815175e-06\n",
"Iteration 160, Loss: 8.779778427447647e-08\n", "Iteration 160, Loss: 8.779889800154524e-08\n",
"Iteration 180, Loss: 6.785903626216421e-09\n", "Iteration 180, Loss: 6.7858241357822796e-09\n",
"Final weights:\n", "Final weights:\n",
" [[-0.00698895 -0.0139779 -0.02096685 -0.0279558 ]\n", " [[-0.00698895 -0.01397789 -0.02096684 -0.02795579]\n",
" [ 0.25975286 0.11950571 -0.02074143 -0.16098857]\n", " [ 0.25975286 0.11950572 -0.02074143 -0.16098857]\n",
" [ 0.53548461 0.27096922 0.00645383 -0.25806156]]\n", " [ 0.53548461 0.27096922 0.00645383 -0.25806156]]\n",
"Final biases:\n", "Final biases:\n",
" [-0.00698895 -0.04024714 -0.06451539]\n" " [-0.00698895 -0.04024714 -0.06451539]\n"
@ -446,11 +446,13 @@
" dL_dneuron_output = dL_dfinal_output * dfinal_output_drelu_output * drelu_output_dneuron_output\n", " dL_dneuron_output = dL_dfinal_output * dfinal_output_drelu_output * drelu_output_dneuron_output\n",
"\n", "\n",
" # Get the gradient of the Loss with respect to the weights and biases\n", " # Get the gradient of the Loss with respect to the weights and biases\n",
" dL_dW = np.outer(dL_dneuron_output, inputs)\n", " # dL_dW = np.outer(dL_dneuron_output, inputs)\n",
" dL_dW = inputs.reshape(-1, 1) @ dL_dneuron_output.reshape(1, -1)\n",
" dL_db = dL_dneuron_output\n", " dL_db = dL_dneuron_output\n",
"\n", "\n",
" # Update the weights and biases\n", " # Update the weights and biases\n",
" weights -= learning_rate * dL_dW\n", " # Remove the .T if using dL_dW = np.outer(dL_dneuron_output, inputs)\n",
" weights -= learning_rate * dL_dW.T\n",
" biases -= learning_rate * dL_db\n", " biases -= learning_rate * dL_db\n",
"\n", "\n",
" # Print the loss every 20 iterations\n", " # Print the loss every 20 iterations\n",