Skip to content

Commit

Permalink
Switch hidden gradient calculation to use reduce
Browse files Browse the repository at this point in the history
isometriks committed Sep 5, 2024
1 parent 3265935 commit 7f7fdf1
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/trainer/backpropagation.ts
Original file line number Diff line number Diff line change
@@ -72,12 +72,11 @@ export default class Backpropagation {

#calculateHiddenGradient(neuron: ConnectableNeuronInterface)
{
let a = 0;

for (const [prevNeuron, synapse] of neuron.reverseSynapseNeurons) {
a += prevNeuron.sigma * synapse.weight
}

return neuron.derivative() * a
return neuron.derivative() * neuron.reverseSynapseNeurons.reduce(
(accumulator, [prevNeuron, synapse]) => {
return accumulator + prevNeuron.sigma * synapse.weight
},
0
)
}
}

0 comments on commit 7f7fdf1

Please sign in to comment.