summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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)