From 12afb03d1f982074b68e0454a551f3fbac05e72d Mon Sep 17 00:00:00 2001 From: judsonupchurch Date: Thu, 19 Dec 2024 01:15:45 +0000 Subject: [PATCH] Lecture 14 --- lecture13_15/handout_13.ipynb | 30 +++++++++++++++--------------- lecture13_15/notes_13.ipynb | 30 ++++++++++++++++-------------- 2 files changed, 31 insertions(+), 29 deletions(-) diff --git a/lecture13_15/handout_13.ipynb b/lecture13_15/handout_13.ipynb index 1ac3ee2..699a258 100644 --- a/lecture13_15/handout_13.ipynb +++ b/lecture13_15/handout_13.ipynb @@ -2,29 +2,29 @@ "cells": [ { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Iteration 0, Loss: 0.0\n", - "Iteration 20, Loss: 0.0\n", - "Iteration 40, Loss: 0.0\n", - "Iteration 60, Loss: 0.0\n", - "Iteration 80, Loss: 0.0\n", - "Iteration 100, Loss: 0.0\n", - "Iteration 120, Loss: 0.0\n", - "Iteration 140, Loss: 0.0\n", - "Iteration 160, Loss: 0.0\n", - "Iteration 180, Loss: 0.0\n", + "Iteration 0, Loss: 466.56000000000006\n", + "Iteration 20, Loss: 5.32959636083938\n", + "Iteration 40, Loss: 0.41191523404899866\n", + "Iteration 60, Loss: 0.031836212079467595\n", + "Iteration 80, Loss: 0.002460565465389601\n", + "Iteration 100, Loss: 0.000190172825660145\n", + "Iteration 120, Loss: 1.4698126966451542e-05\n", + "Iteration 140, Loss: 1.1359926717815175e-06\n", + "Iteration 160, Loss: 8.779889800154524e-08\n", + "Iteration 180, Loss: 6.7858241357822796e-09\n", "Final weights:\n", - " [[0. 0. 0. 0.]\n", - " [0. 0. 0. 0.]\n", - " [0. 0. 0. 0.]]\n", + " [[-0.00698895 -0.01397789 -0.02096684 -0.02795579]\n", + " [ 0.25975286 0.11950572 -0.02074143 -0.16098857]\n", + " [ 0.53548461 0.27096922 0.00645383 -0.25806156]]\n", "Final biases:\n", - " [0. 0. 0.]\n" + " [-0.00698895 -0.04024714 -0.06451539]\n" ] } ], diff --git a/lecture13_15/notes_13.ipynb b/lecture13_15/notes_13.ipynb index 7dc7486..b16ed07 100644 --- a/lecture13_15/notes_13.ipynb +++ b/lecture13_15/notes_13.ipynb @@ -371,7 +371,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 13, "metadata": {}, "outputs": [ { @@ -379,18 +379,18 @@ "output_type": "stream", "text": [ "Iteration 0, Loss: 466.56000000000006\n", - "Iteration 20, Loss: 5.329595763793193\n", - "Iteration 40, Loss: 0.41191524253483786\n", - "Iteration 60, Loss: 0.03183621475376345\n", - "Iteration 80, Loss: 0.002460565405431671\n", - "Iteration 100, Loss: 0.0001901729121621426\n", - "Iteration 120, Loss: 1.4698120139337557e-05\n", - "Iteration 140, Loss: 1.1359948840900371e-06\n", - "Iteration 160, Loss: 8.779778427447647e-08\n", - "Iteration 180, Loss: 6.785903626216421e-09\n", + "Iteration 20, Loss: 5.32959636083938\n", + "Iteration 40, Loss: 0.41191523404899866\n", + "Iteration 60, Loss: 0.031836212079467595\n", + "Iteration 80, Loss: 0.002460565465389601\n", + "Iteration 100, Loss: 0.000190172825660145\n", + "Iteration 120, Loss: 1.4698126966451542e-05\n", + "Iteration 140, Loss: 1.1359926717815175e-06\n", + "Iteration 160, Loss: 8.779889800154524e-08\n", + "Iteration 180, Loss: 6.7858241357822796e-09\n", "Final weights:\n", - " [[-0.00698895 -0.0139779 -0.02096685 -0.0279558 ]\n", - " [ 0.25975286 0.11950571 -0.02074143 -0.16098857]\n", + " [[-0.00698895 -0.01397789 -0.02096684 -0.02795579]\n", + " [ 0.25975286 0.11950572 -0.02074143 -0.16098857]\n", " [ 0.53548461 0.27096922 0.00645383 -0.25806156]]\n", "Final biases:\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", "\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", "\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", "\n", " # Print the loss every 20 iterations\n",