Skip to content

Commit 50f7929

Browse files
committed
fix(training): correct loop bounds and indexing in weights update
The change fixes incorrect loop bounds and indexing when updating weights from the hidden layer to output layer. The outer loop now iterates over network.inputCount instead of network.hiddenCount, and the inner loop iterates over network.hiddenCount instead of network.outputCount. This ensures that each input node properly updates its respective connections to the hidden nodes, correcting potential miscalculations in the weight adjustments during training.
1 parent 23dda53 commit 50f7929

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

Cpp/neural.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,10 @@ void Trainer::Train(const Vector& input, const Vector& y, double lr) {
129129
}
130130
}
131131

132-
for (size_t r = 0; r < network.hiddenCount; r++) {
133-
for (size_t c = 0; c < network.outputCount; c++) {
134-
network.weightsHidden[r * network.hiddenCount + c] -= lr * gradHidden[c] * input[r];
132+
for (size_t r = 0; r < network.inputCount; r++) {
133+
for (size_t c = 0; c < network.hiddenCount; c++) {
134+
network.weightsHidden[r * network.hiddenCount + c] -=
135+
lr * gradHidden[c] * input[r];
135136
}
136137
}
137138

0 commit comments

Comments
 (0)