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