summaryrefslogtreecommitdiff
path: root/neural_network.py
diff options
context:
space:
mode:
authorHombreLaser <sebastian-440@live.com>2023-10-09 22:07:46 -0600
committerHombreLaser <sebastian-440@live.com>2023-10-09 22:07:46 -0600
commit56a7431cf08bbdbd5c2e94bc0d95a702b1d8e398 (patch)
tree90e24cead9cd299501c6238f016d0a5b1b0fcd16 /neural_network.py
parent64b92ee787b3ef9c6da8804e3df2844c0169492f (diff)
Add feedforwarding method
Diffstat (limited to 'neural_network.py')
-rw-r--r--neural_network.py24
1 files changed, 18 insertions, 6 deletions
diff --git a/neural_network.py b/neural_network.py
index 827b066..3ca1c64 100644
--- a/neural_network.py
+++ b/neural_network.py
@@ -1,4 +1,5 @@
import numpy as np
+from scipy.special import expit
from utils import random_array
CYRILLIC_ALPHABET = ['I', 'А', 'Б', 'В', 'Г', 'Д', 'Е', 'Ë', 'Ж', 'З',
@@ -21,30 +22,41 @@ class NeuralNetwork:
Train the neural network. It loads the dataset contained in ./data,
converts each image into a numpy array and uses that data for training.
"""
- def train():
+ def train(self):
pass
"""
Guess the letter contained in the image file pointed by
input_image (a path).
"""
- def guess(input_image: str) -> str:
+ def guess(self, input_image: str) -> str:
pass
"""
Save the weights to a csv file.
"""
- def save():
+ def save(self):
pass
"""
Load the weights from a csv file.
"""
- def load(weights_file: str):
+ def load(self, weights_file: str):
pass
"""
Feedforwarding.
"""
- def _predict(input_layer: np.array):
- pass
+ def _predict(self, input_layer: np.array):
+ hidden_layer_inputs = np.dot(input_layer, self._hidden_weights)
+ hidden_layer_outputs = self._get_layer_output(hidden_layer_inputs)
+ output_layer_inputs = np.dot(self._output_weights, hidden_layer_outputs)
+
+ # The output layer outputs. (Final output of the neural network).
+ return self._get_layer_output(output_layer_inputs)
+
+ """
+ Apply the sigmoid function to a given layer
+ """
+ def _get_layer_output(self, layer: np.array):
+ return expit(layer)