Skip to content

Commit 481ce13

Browse files
committed
modified: neural_network/artificial_neural_network.py
1 parent 1d219b3 commit 481ce13

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

neural_network/artificial_neural_network.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ class SimpleANN:
55
Simple Artificial Neural Network (ANN)
66
77
- Feedforward Neural Network with 1 hidden layer and Sigmoid activation.
8-
- Uses Gradient Descent for backpropagation and Mean Squared Error (MSE)
9-
as the loss function.
8+
- Uses Gradient Descent for backpropagation and Mean Squared Error (MSE) as the loss function.
109
- Example demonstrates solving the XOR problem.
1110
"""
1211

@@ -19,14 +18,17 @@ def __init__(self, input_size: int, hidden_size: int, output_size: int, learning
1918
hidden_size (int): Number of neurons in the hidden layer.
2019
output_size (int): Number of neurons in the output layer.
2120
learning_rate (float): Learning rate for gradient descent.
21+
22+
Example:
23+
>>> ann = SimpleANN(2, 2, 1)
24+
>>> isinstance(ann, SimpleANN)
25+
True
2226
"""
2327
rng = np.random.default_rng()
2428
self.weights_input_hidden = rng.standard_normal((input_size, hidden_size))
2529
self.weights_hidden_output = rng.standard_normal((hidden_size, output_size))
26-
2730
self.bias_hidden = np.zeros((1, hidden_size))
2831
self.bias_output = np.zeros((1, output_size))
29-
3032
self.learning_rate = learning_rate
3133

3234
def sigmoid(self, value: np.ndarray) -> np.ndarray:
@@ -40,7 +42,6 @@ def sigmoid(self, value: np.ndarray) -> np.ndarray:
4042
ndarray: Activated output using sigmoid function.
4143
4244
Example:
43-
>>> from __main__ import SimpleANN
4445
>>> ann = SimpleANN(2, 2, 1)
4546
>>> ann.sigmoid(np.array([0]))
4647
array([0.5])
@@ -58,7 +59,6 @@ def sigmoid_derivative(self, sigmoid_output: np.ndarray) -> np.ndarray:
5859
ndarray: Derivative of the sigmoid function.
5960
6061
Example:
61-
>>> from __main__ import SimpleANN
6262
>>> ann = SimpleANN(2, 2, 1)
6363
>>> output = ann.sigmoid(np.array([0.5]))
6464
>>> ann.sigmoid_derivative(output)
@@ -77,7 +77,6 @@ def feedforward(self, inputs: np.ndarray) -> np.ndarray:
7777
ndarray: Output from the network after feedforward pass.
7878
7979
Example:
80-
>>> from __main__ import SimpleANN
8180
>>> ann = SimpleANN(2, 2, 1)
8281
>>> inputs = np.array([[0, 0], [1, 1]])
8382
>>> ann.feedforward(inputs).shape
@@ -99,7 +98,6 @@ def backpropagation(self, inputs: np.ndarray, targets: np.ndarray, outputs: np.n
9998
outputs (ndarray): Output predicted by the network.
10099
101100
Example:
102-
>>> from __main__ import SimpleANN
103101
>>> ann = SimpleANN(2, 2, 1)
104102
>>> inputs = np.array([[0, 0], [1, 1]])
105103
>>> outputs = ann.feedforward(inputs)
@@ -127,7 +125,6 @@ def train(self, inputs: np.ndarray, targets: np.ndarray, epochs: int = 10000) ->
127125
epochs (int): Number of training iterations.
128126
129127
Example:
130-
>>> from __main__ import SimpleANN
131128
>>> ann = SimpleANN(2, 2, 1)
132129
>>> inputs = np.array([[0, 0], [1, 1]])
133130
>>> targets = np.array([[0], [1]])
@@ -151,7 +148,6 @@ def predict(self, inputs: np.ndarray) -> np.ndarray:
151148
ndarray: Predicted output from the network.
152149
153150
Example:
154-
>>> from __main__ import SimpleANN
155151
>>> ann = SimpleANN(2, 2, 1)
156152
>>> inputs = np.array([[0, 0], [1, 1]])
157153
>>> ann.predict(inputs).shape

0 commit comments

Comments
 (0)