mirror of
https://github.com/guezoloic/neural-network.git
synced 2026-01-25 09:34:23 +00:00
feat: add ipynb file and write neuron function class
This commit is contained in:
60
nnetwork.ipynb
Normal file
60
nnetwork.ipynb
Normal file
@@ -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
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user