Add debugging print statements

This commit is contained in:
Murtadha 2024-09-27 11:02:06 -04:00
parent 708a8e7222
commit 0fb1f69b1f

View file

@ -2,7 +2,7 @@
"cells": [ "cells": [
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1, "execution_count": 21,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -37,7 +37,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": 23,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -61,6 +61,25 @@
"X_train, X_val = X_train.T, X_val.T" "X_train, X_val = X_train.T, X_val.T"
] ]
}, },
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(\"Data shapes:\")\n",
"print(f\"X_train shape: {X_train.shape}\")\n",
"print(f\"Y_train shape: {Y_train.shape}\")\n",
"print(f\"X_test shape: {X_test.shape}\")\n",
"print(f\"Y_test shape: {Y_test.shape}\")\n",
"\n",
"print(\"\\nData statistics:\")\n",
"print(f\"X_train mean: {xp.mean(X_train)}, std: {xp.std(X_train)}\")\n",
"print(f\"X_test mean: {xp.mean(X_test)}, std: {xp.std(X_test)}\")\n",
"print(f\"Unique Y_train values: {xp.unique(Y_train)}\")\n",
"print(f\"Unique Y_test values: {xp.unique(Y_test)}\")"
]
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
@ -77,7 +96,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 5, "execution_count": 26,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -88,7 +107,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 6, "execution_count": 27,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -105,7 +124,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 7, "execution_count": 28,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -113,8 +132,8 @@
" return xp.maximum(Z, 0)\n", " return xp.maximum(Z, 0)\n",
"\n", "\n",
"def softmax(Z):\n", "def softmax(Z):\n",
" A = xp.exp(Z) / sum(xp.exp(Z))\n", " exp_Z = xp.exp(Z - xp.max(Z, axis=0, keepdims=True))\n",
" return A\n", " return exp_Z / xp.sum(exp_Z, axis=0, keepdims=True)\n",
"\n", "\n",
"def forward_prop(X, params):\n", "def forward_prop(X, params):\n",
" caches = []\n", " caches = []\n",
@ -190,7 +209,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 8, "execution_count": 29,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -213,6 +232,10 @@
" val_accuracy = get_accuracy(val_predictions, Y_val)\n", " val_accuracy = get_accuracy(val_predictions, Y_val)\n",
" \n", " \n",
" print(f\"Iteration {i}: Train Accuracy: {train_accuracy:.4f}, Validation Accuracy: {val_accuracy:.4f}\")\n", " print(f\"Iteration {i}: Train Accuracy: {train_accuracy:.4f}, Validation Accuracy: {val_accuracy:.4f}\")\n",
" print(f\"Sample predictions: {train_predictions[:10]}\")\n",
" print(f\"Sample true labels: {Y_train[:10]}\")\n",
" \n",
" print(f\"Iteration {i}: Train Accuracy: {train_accuracy:.4f}, Validation Accuracy: {val_accuracy:.4f}\")\n",
" acc_store.append((train_accuracy, val_accuracy))\n", " acc_store.append((train_accuracy, val_accuracy))\n",
" \n", " \n",
" if val_accuracy > best_val_accuracy:\n", " if val_accuracy > best_val_accuracy:\n",
@ -229,7 +252,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 9, "execution_count": 30,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -248,7 +271,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 17, "execution_count": 31,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -284,15 +307,24 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 11, "execution_count": 32,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"hidden_layers = [1, 2, 3, 4]\n", "hidden_layers = [1, 2]\n",
"neurons_per_layer = [64, 128, 256]\n", "neurons_per_layer = [64, 128, 256, 512]\n",
"layer_configs = list(product(*[neurons_per_layer] * max(hidden_layers)))" "layer_configs = list(product(*[neurons_per_layer] * max(hidden_layers)))"
] ]
}, },
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(layer_configs)"
]
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
@ -315,6 +347,17 @@
"print(f\"Best validation accuracy: {best_accuracy:.4f}\")" "print(f\"Best validation accuracy: {best_accuracy:.4f}\")"
] ]
}, },
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(\"\\nModel Architecture:\")\n",
"for i in range(1, len(best_params)//2 + 1):\n",
" print(f\"Layer {i}: {best_params[f'W{i}'].shape}\")"
]
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,