mirror of
https://github.com/guezoloic/neural-network.git
synced 2026-01-25 00:34:22 +00:00
refactor(network.py): annotacte activation functions
This commit is contained in:
@@ -1,13 +1,12 @@
|
||||
import math
|
||||
import random
|
||||
|
||||
# transform all numbers between 0 and 1
|
||||
def sigmoid(x):
|
||||
def sigmoid(x: float) -> float:
|
||||
return 1 / (1 + math.exp(-x))
|
||||
|
||||
# sigmoid's derivation
|
||||
def sigmoid_deriv(x):
|
||||
y = sigmoid(x)
|
||||
|
||||
def sigmoid_deriv(x: float) -> float:
|
||||
y: float = sigmoid(x)
|
||||
return y * (1 - y)
|
||||
|
||||
# neuron class
|
||||
|
||||
@@ -224,7 +224,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"execution_count": null,
|
||||
"id": "f6de25ea",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
@@ -284,7 +284,7 @@
|
||||
" # update bias: bias -= learning_rate * dC/dy * dy/dz * dz/db\n",
|
||||
" self.bias -= learning_rate * dcost_dy * dy_dz * dz_db\n",
|
||||
"\n",
|
||||
" # return gradient vector len(input) dimension\n",
|
||||
" # return gradient vector len(weight) dimension\n",
|
||||
" return [dcost_dy * dy_dz * w for w in self.weight]"
|
||||
]
|
||||
},
|
||||
@@ -353,7 +353,7 @@
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.13.4"
|
||||
"version": "3.13.5"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
||||
Reference in New Issue
Block a user