Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created structure for Jupyter Notebooks #179

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions Notebooks/Jupyter/Python 3/P.1 Intro and Neuron Code.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 6,
"id": "b5ced594",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2.3\n"
]
}
],
"source": [
"## Input layer that contains 3 neurons https://nnfs.io/bkr/\n",
"inputs = [1, 2, 3]\n",
"\n",
"## Each neuron has a connection to the 1 neuron we are modelling. Therefore 3 weights.\n",
"weights = [0.2, 0.8, -0.5]\n",
"\n",
"## However, the neuron we are modelling is the only thing that has a bias and thus only 1 bias. \n",
"bias = 2\n",
"\n",
"## Input * weight for each + bias\n",
"output = inputs[0]*weights[0] + inputs[1]*weights[1] + inputs[2]*weights[2] + bias\n",
"\n",
"print(output)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.5"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
72 changes: 72 additions & 0 deletions Notebooks/Jupyter/Python 3/P.2 Coding a Layer.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 12,
"id": "e0daf014",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[4.8, 1.21, 2.385]\n"
]
}
],
"source": [
"## Inputs are from a layer, 4 incoming neurons going to 3 neurons - https://nnfs.io/mxo/\n",
"inputs = [1, 2, 3, 2.5]\n",
"\n",
"## Each input neurons has its own weight for each of the neurons\n",
"weights1 = [0.2, 0.8, -0.5, 1.0]\n",
"weights2 = [0.5, -0.91, 0.26, -0.5]\n",
"weights3 = [-0.26, -0.27, 0.17, 0.87]\n",
"\n",
"## Each neurons has its own bias\n",
"bias1 = 2\n",
"bias2 = 3\n",
"bias3 = 0.5\n",
"\n",
"output = [\n",
" inputs[0]*weights1[0] + \n",
" inputs[1]*weights1[1] + \n",
" inputs[2]*weights1[2] + \n",
" inputs[3]*weights1[3] + bias1,\n",
" \n",
" inputs[0]*weights2[0] + \n",
" inputs[1]*weights2[1] + \n",
" inputs[2]*weights2[2] + \n",
" inputs[3]*weights2[3] + bias2,\n",
" \n",
" inputs[0]*weights3[0] + \n",
" inputs[1]*weights3[1] + \n",
" inputs[2]*weights3[2] + \n",
" inputs[3]*weights3[3] + bias3]\n",
"\n",
"print(output)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.5"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
139 changes: 139 additions & 0 deletions Notebooks/Jupyter/Python 3/P.3 The Dot Product.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 4,
"id": "e0daf014",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[4.8, 1.21, 2.385]\n"
]
}
],
"source": [
"## Part 1\n",
"## Inputs are from a layer, 4 incoming neurons going to 3 neurons - https://nnfs.io/mxo/\n",
"inputs = [1, 2, 3, 2.5]\n",
"\n",
"## Each input neurons has its own weight for each of the neurons\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",
"\n",
"## Each neurons has its own bias\n",
"biases = [2, 3, 0.5]\n",
"\n",
"\n",
"layer_outputs = [] # Output of current layer\n",
"for neuron_weights, neuron_bias in zip(weights, biases):\n",
" neuron_output = 0 # Output of given neuron\n",
" for n_input, weight in zip(inputs, neuron_weights):\n",
" neuron_output += n_input*weight\n",
" neuron_output += neuron_bias\n",
" layer_outputs.append(neuron_output)\n",
"\n",
"print(layer_outputs)\n"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "0ff952ab",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"4.8\n"
]
}
],
"source": [
"## Part 2 - https://nnfs.io/blq/\n",
"import numpy as np\n",
"\n",
"## Inputs are from a layer, 4 incoming neurons going to 1 neuron - https://nnfs.io/mxo/\n",
"inputs = [1, 2, 3, 2.5]\n",
"\n",
"## Each input neuron has its own weight for each neuron\n",
"weights = [0.2, 0.8, -0.5, 1.0]\n",
"\n",
"## Each neuron has its own bias\n",
"bias = 2\n",
"\n",
"## Dot product - https://nnfs.io/xpo/\n",
"output = np.dot(weights, inputs) + bias\n",
"\n",
"print(output)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "df49c4eb",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[4.8 1.21 2.385]\n"
]
}
],
"source": [
"## Part 3 - https://nnfs.io/cyx/\n",
"import numpy as np\n",
"\n",
"## Inputs are from a layer, 4 incoming neurons going to 3 neurons - https://nnfs.io/mxo/\n",
"inputs = [1, 2, 3, 2.5]\n",
"\n",
"## Each input neurons has its own weight for each of the neurons\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",
"\n",
"## Each neurons has its own bias\n",
"biases = [2, 3, 0.5]\n",
"\n",
"output = np.dot(weights, inputs) + biases\n",
"\n",
"print(output)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ac3482e5",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.5"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
126 changes: 126 additions & 0 deletions Notebooks/Jupyter/Python 3/P.4 Batches, Layers, and Objects.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 3,
"id": "df49c4eb",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[ 0.5031 -1.04185 -2.03875]\n",
" [ 0.2434 -2.7332 -5.7633 ]\n",
" [-0.99314 1.41254 -0.35655]]\n"
]
}
],
"source": [
"## Part 4 - Batch data: https://nnfs.io/vyu/\n",
"import numpy as np\n",
"\n",
"## Inputs are from a layer, 4 incoming neurons going to 3 neurons - https://nnfs.io/lqw/\n",
"inputs = [[1, 2, 3, 2.5], \n",
" [2, 5, -1, 2], \n",
" [-1.5, 2.7, 3.3, -0.8]]\n",
"\n",
"## Each input neurons has its own weight for each of the neurons\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",
"\n",
"## Each neurons has its own bias\n",
"biases = [2, 3, 0.5]\n",
"\n",
"weights2 = [[0.1, -0.14, 0.5],\n",
" [-0.5, 0.12, -0.33],\n",
" [-0.44, 0.73, -0.13]]\n",
"\n",
"biases2 = [-1, 2, -0.5]\n",
"\n",
"## https://nnfs.io/gjw/\n",
"layer1_outputs = np.dot(inputs, np.array(weights).T) + biases\n",
"layer2_outputs = np.dot(layer1_outputs, np.array(weights2).T) + biases2\n",
"\n",
"print(layer2_outputs)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "ac3482e5",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[ 0.10758131 1.03983522 0.24462411 0.31821498 0.18851053]\n",
" [-0.08349796 0.70846411 0.00293357 0.44701525 0.36360538]\n",
" [-0.50763245 0.55688422 0.07987797 -0.34889573 0.04553042]]\n",
"[[ 0.148296 -0.08397602]\n",
" [ 0.14100315 -0.01340469]\n",
" [ 0.20124979 -0.07290616]]\n"
]
}
],
"source": [
"## Object\n",
"import numpy as np\n",
"\n",
"np.random.seed(0)\n",
"\n",
"X = [[1, 2, 3, 2.5], \n",
" [2, 5, -1, 2], \n",
" [-1.5, 2.7, 3.3, -0.8]]\n",
"\n",
"class Layer_Dense:\n",
" def __init__(self, n_inputs, n_neurons):\n",
" self.weights = 0.10 * np.random.randn(n_inputs, n_neurons)\n",
" self.biases = np.zeros((1, n_neurons))\n",
" \n",
" def forward(self, inputs):\n",
" self.output = np.dot(inputs, self.weights) + self.biases\n",
" \n",
"layer1 = Layer_Dense(4, 5)\n",
"layer2 = Layer_Dense(5, 2)\n",
"\n",
"layer1.forward(X)\n",
"layer2.forward(layer1.output)\n",
"\n",
"print(layer1.output)\n",
"print(layer2.output)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9dde84db",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.5"
}
},
"nbformat": 4,
"nbformat_minor": 5
}