Lecture 01

This commit is contained in:
judsonupchurch 2024-10-14 20:52:49 +00:00
parent f00854a167
commit 22ea946f16
3 changed files with 626 additions and 0 deletions

430
lecture01/handout.ipynb Normal file

File diff suppressed because one or more lines are too long

196
lecture01/lecture_01.ipynb Normal file
View File

@ -0,0 +1,196 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Neuron with 3 inputs"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Output: 2.3\n"
]
}
],
"source": [
"inputs = [1, 2, 3]\n",
"weights = [0.2, 0.8, -0.5]\n",
"bias = 2\n",
"\n",
"output = (inputs[0]*weights[0] + inputs[1]*weights[1] + inputs[2]*weights[2] + bias)\n",
"\n",
"print(f\"Output: {output}\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Neuron with 4 inputs"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Output: 4.8\n"
]
}
],
"source": [
"inputs = [1.0, 2.0, 3.0, 2.5]\n",
"weights = [0.2, 0.8, -0.5, 1.0]\n",
"bias = 2\n",
"\n",
"output = (inputs[0]*weights[0] + inputs[1]*weights[1] + inputs[2]*weights[2] + inputs[3]*weights[3] + bias)\n",
"\n",
"print(output)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Layer of 3 neurons with 4 inputs"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[4.8, 1.21, 2.385]\n"
]
}
],
"source": [
"num_neurons = 3\n",
"num_inputs = 4\n",
"inputs = [1.0, 2.0, 3.0, 2.5]\n",
"weights = [[0.2, 0.8, -0.5, 1.0],\n",
" [0.5, -0.91, 0.26, -0.5],\n",
" [-0.26, -0.27, 0.17, 0.87]]\n",
"biases = [2, 3, 0.5]\n",
"\n",
"outputs = []\n",
"for i in range(num_neurons):\n",
" output = 0\n",
" for j in range(num_inputs):\n",
" output += inputs[j]*weights[i][j]\n",
" output += biases[i]\n",
" outputs.append(output)\n",
"\n",
"print(outputs)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Layer of 3 neurons with 4 inputs"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[4.8, 1.21, 2.385]\n"
]
}
],
"source": [
"num_neurons = 3\n",
"num_inputs = 4\n",
"inputs = [1.0, 2.0, 3.0, 2.5]\n",
"weights = [[0.2, 0.8, -0.5, 1.0],\n",
" [0.5, -0.91, 0.26, -0.5],\n",
" [-0.26, -0.27, 0.17, 0.87]]\n",
"biases = [2, 3, 0.5]\n",
"\n",
"outputs = []\n",
"for neuron_weights, neuron_bias in zip(weights, biases):\n",
" neuron_output = 0\n",
" for input, weight in zip(inputs, neuron_weights):\n",
" neuron_output += input*weight\n",
" neuron_output += neuron_bias\n",
" outputs.append(neuron_output)\n",
"\n",
"print(outputs)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Single Neuron using Numpy"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"4.8\n"
]
}
],
"source": [
"import numpy as np\n",
"\n",
"inputs = [1.0, 2.0, 3.0, 2.5]\n",
"weights = [0.2, 0.8, -0.5, 1.0]\n",
"bias = 2\n",
"\n",
"output = np.dot(inputs, weights) + bias\n",
"print(output)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

View File