From c02a94da731b0418aa5846735ad078297fcc1494 Mon Sep 17 00:00:00 2001 From: echo Date: Tue, 7 Jan 2025 12:56:54 +0100 Subject: [PATCH] Fixed gradient descent not properly working --- src/main/java/net/echo/brain4j/structure/Neuron.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/echo/brain4j/structure/Neuron.java b/src/main/java/net/echo/brain4j/structure/Neuron.java index e7c9fe2..1caadb3 100644 --- a/src/main/java/net/echo/brain4j/structure/Neuron.java +++ b/src/main/java/net/echo/brain4j/structure/Neuron.java @@ -8,8 +8,8 @@ public class Neuron { private final List synapses = new ArrayList<>(); - private final ThreadLocal localValue = new ThreadLocal<>(); - private final ThreadLocal delta = new ThreadLocal<>(); + private final ThreadLocal localValue = ThreadLocal.withInitial(() -> 0.0); + private final ThreadLocal delta = ThreadLocal.withInitial(() -> 0.0); private double totalDelta; @Expose private double bias; @@ -34,7 +34,7 @@ public double getDelta() { } public void setDelta(double delta) { - this.delta.set(delta); + this.delta.set(this.delta.get() + delta); this.totalDelta += delta; }