Permalink
Browse files

Trying to solve the problem of getting stuck in the local minima by u…

…sing momemtum
  • Loading branch information...
1 parent bc11dfb commit eab5ee061dc09b2f31eae7ee44937e2e2071dc82 @vivin committed Nov 8, 2011
Showing with 12 additions and 0 deletions.
  1. +12 −0 src/main/java/net/vivin/neural/Backpropagator.java
@@ -1,6 +1,8 @@
package net.vivin.neural;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -28,6 +30,8 @@ public void train(double[][] inputs, double[][] expectedOutputs) {
List<Layer> layers = neuralNetwork.getLayers();
+ Map<Neuron, Double> neuronDeltaMap = new HashMap<Neuron, Double>();
+
double totalError;
do {
@@ -81,6 +85,14 @@ public void train(double[][] inputs, double[][] expectedOutputs) {
for (Synapse synapse : neuron.getInputs()) {
//System.out.println("delta = " + learningRate + " * " + neuronError + " * " + synapse.getSourceNeuron().getOutput());
double delta = learningRate * neuronError * synapse.getSourceNeuron().getOutput();
+
+ if(neuronDeltaMap.get(neuron) != null) {
+ double previous_delta = neuronDeltaMap.get(neuron);
+ delta += 0.75 * previous_delta;
+ }
+
+ neuronDeltaMap.put(neuron, delta); //read up more on this... figure out how to fix the algorithm to account for momentum
+
//System.out.println("Adjusting weight " + synapse.getWeight() + " by " + delta);
synapse.setWeight(synapse.getWeight() + delta);
}

0 comments on commit eab5ee0

Please sign in to comment.