Skip to content

Commit 9c7382e

Browse files
committed
modified formatting
1 parent c8567ae commit 9c7382e

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

neural_network/recurrent_neural_network.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def sigmoid_function(value: float, deriv: bool = False) -> float:
2727

2828
# Initial constants
2929
INITIAL_VALUE = 0.02 # learning rate
30-
SEQUENCE_LENGTH = 5 # time steps in the sequence
30+
SEQUENCE_LENGTH = 5 # time steps in the sequence
3131

3232

3333
def forward_propagation_rnn(expected: int, number_propagations: int) -> float:
@@ -44,38 +44,38 @@ def forward_propagation_rnn(expected: int, number_propagations: int) -> float:
4444
random.seed(0)
4545

4646
# Random weight initialization
47-
W_xh = (random.random() * 2 - 1) # Input to hidden
48-
W_hh = (random.random() * 2 - 1) # Hidden to hidden (recurrent)
49-
W_hy = (random.random() * 2 - 1) # Hidden to output
47+
w_xh = random.random() * 2 - 1 # Input to hidden
48+
w_hh = random.random() * 2 - 1 # Hidden to hidden (recurrent)
49+
w_hy = random.random() * 2 - 1 # Hidden to output
5050

5151
# Training loop
5252
for _ in range(number_propagations):
5353
h_prev = 0.0 # hidden state starts at zero
5454
total_error = 0.0
5555

5656
# Forward pass through time
57-
for t in range(SEQUENCE_LENGTH):
57+
for _t in range(SEQUENCE_LENGTH):
5858
# Fake input sequence: small constant or could be pattern-based
5959
x_t = INITIAL_VALUE
6060

6161
# Hidden state update
62-
h_t = sigmoid_function(W_xh * x_t + W_hh * h_prev)
62+
h_t = sigmoid_function(w_xh * x_t + w_hh * h_prev)
6363

6464
# Output
65-
y_t = sigmoid_function(W_hy * h_t)
65+
y_t = sigmoid_function(w_hy * h_t)
6666

6767
# Error (target distributed over time steps)
6868
error_t = (expected / 100) - y_t
6969
total_error += abs(error_t)
7070

7171
# Backpropagation Through Time (simplified)
7272
d_y = error_t * sigmoid_function(y_t, True)
73-
d_h = d_y * W_hy * sigmoid_function(h_t, True)
73+
d_h = d_y * w_hy * sigmoid_function(h_t, True)
7474

7575
# Weight updates
76-
W_hy += INITIAL_VALUE * d_y * h_t
77-
W_xh += INITIAL_VALUE * d_h * x_t
78-
W_hh += INITIAL_VALUE * d_h * h_prev
76+
w_hy += INITIAL_VALUE * d_y * h_t
77+
w_xh += INITIAL_VALUE * d_h * x_t
78+
w_hh += INITIAL_VALUE * d_h * h_prev
7979

8080
# Move to next time step
8181
h_prev = h_t

0 commit comments

Comments
 (0)