From b6fe3f75106d33c4c04dfd28c14c00a67f7fb771 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20GUEZO?= Date: Tue, 6 May 2025 20:05:02 +0200 Subject: [PATCH] feat: add ipynb file and write neuron function class --- nnetwork.ipynb | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 nnetwork.ipynb diff --git a/nnetwork.ipynb b/nnetwork.ipynb new file mode 100644 index 0000000..cf4e1f4 --- /dev/null +++ b/nnetwork.ipynb @@ -0,0 +1,60 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "9b3f1635", + "metadata": {}, + "source": [ + "# Neural Network\n", + "\n", + "## What is a neuron in a neural network?" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "126bc01c", + "metadata": {}, + "outputs": [], + "source": [ + "import math\n", + "import random\n", + "\n", + "def sigmoid(x: float) -> float:\n", + " return 1/(1 + math.exp(-x))\n", + "\n", + "class Neuron:\n", + " def __init__(self, isize: int) -> None:\n", + " self.isize = isize\n", + " self.weight = [random.uniform(0, 1) for _ in range(self.isize)]\n", + " self.bias = random.uniform(0, 1)\n", + "\n", + " def forward(self, inputs: list) -> float:\n", + " assert len(inputs) == self.isize, \"error: incorrect inputs number\"\n", + " total = sum(self.weight[i] * inputs[i] for i in range(self.isize)) + self.bias\n", + " return sigmoid(total)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": ".venv", + "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.13.3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}