<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -2,36 +2,45 @@
 % http://www.trapexit.org/Erlang_and_Neural_Networks
 
 -module(ann).
--export([perceptron/3, connect/2]).
+-export([perceptron/4, connect/2]).
 
 
-perceptron(Weights, Inputs, Sensitivities) -&gt;
+perceptron(Weights, Inputs, Sensitivities, Stale_inputs) -&gt;
   Sigmoid = fun(X) -&gt; 1/(1+math:exp(-X)) end,
   Sigmoid_deriv = fun(X) -&gt; math:exp(-X)/(1+math:exp(-2*X)) end,
 
   receive
     {stimulate, Input} -&gt;
       % add input to inputs
+      New_stale_inputs = delete_input(Stale_inputs, Input),
       New_inputs = replace_input(Inputs, Input),
       
-      {In_PID, In_Val} = Input,
+      {In_PID, In_Val, Expected_Val} = Input,
       ann_grapher ! {stimulate, In_PID, self(), In_Val},
-      % calculate perceptron output
-      Output = feed_forward(Sigmoid, Weights, 
-                        convert_to_values(New_inputs)),
-
-      % stimulate connected perceptrons
-      case Sensitivities of
-        [] -&gt; 
-          ann_grapher ! {output, self(), Output},
-          io:format(&quot;Output (~w): ~w~n&quot;, [self(), Output]),
-          self() ! {learn, {self(), 1}};
-        S -&gt; lists:foreach(fun(Output_PID) -&gt;
-              Output_PID ! {stimulate, {self(), Output}}
-            end,
-            convert_to_keys(S))
-      end,
-      perceptron(Weights, New_inputs, Sensitivities);
+
+      case New_stale_inputs of
+        % calculate perceptron output
+        [] -&gt; Output = feed_forward(Sigmoid, Weights, 
+                          convert_to_input_values(New_inputs)),
+  
+        % stimulate connected perceptrons
+        case Sensitivities of
+          [] -&gt; 
+            ann_grapher ! {output, self(), Output},
+            io:format(&quot;Output (~w): ~w~n&quot;, [self(), Output]),
+            case Expected_Val of
+              null -&gt; ok;
+              E -&gt; self() ! {learn, {self(), E}}
+            end;
+          S -&gt; lists:foreach(fun(Output_PID) -&gt;
+                Output_PID ! {stimulate, {self(), Output, Expected_Val}}
+              end,
+              convert_to_keys(S))
+        end,
+        perceptron(Weights, New_inputs, Sensitivities, New_inputs);
+
+        New_stale -&gt; perceptron(Weights, New_inputs, Sensitivities, New_stale)
+      end;
 
     {learn, Backprop} -&gt;
     
@@ -41,16 +50,16 @@ perceptron(Weights, Inputs, Sensitivities) -&gt;
       Learning_rate = 0.5,
       New_sensitivities = add_sensitivity(Sensitivities, Backprop),
       Output = feed_forward(Sigmoid, Weights, 
-                  convert_to_values(Inputs)),
+                  convert_to_input_values(Inputs)),
       Deriv = feed_forward(Sigmoid_deriv, Weights, 
-                  convert_to_values(Inputs)),
+                  convert_to_input_values(Inputs)),
       Sensitivity = calculate_sensitivities(Backprop, Inputs,
                   New_sensitivities, Output, Deriv),
 
       Weight_adjustments = lists:map(fun(Input) -&gt;
                               Learning_rate * Sensitivity * Input
                             end,
-                            convert_to_values(Inputs)),
+                            convert_to_input_values(Inputs)),
       New_weights = vector_map(fun(W, D) -&gt; W+D end, Weights,
                       Weight_adjustments),
 
@@ -58,25 +67,26 @@ perceptron(Weights, Inputs, Sensitivities) -&gt;
           Input_PID ! {learn, {self(), Sensitivity * Weight}}
         end,
         New_weights,
-        convert_to_keys(Inputs)),
+        convert_to_input_keys(Inputs)),
 
-      perceptron(New_weights, Inputs, New_sensitivities);
+      perceptron(New_weights, Inputs, New_sensitivities, Stale_inputs);
 
     {connect_to_output, Receiver_PID} -&gt;
       Combined_sensitivities = 
-        [{Receiver_PID, 0} | Sensitivities],
-      perceptron(Weights, Inputs, Combined_sensitivities);
+        [{Receiver_PID, 0.5} | Sensitivities],
+      perceptron(Weights, Inputs, Combined_sensitivities, Stale_inputs);
 
     {connect_to_input, Sender_PID} -&gt;
-      Combined_input = [{Sender_PID, 0.5} | Inputs],
-      perceptron([0.5 | Weights], Combined_input, Sensitivities);
+      Combined_input = [{Sender_PID, 0.5, null} | Inputs],
+      New_stale_input = [{Sender_PID, 0.5, null} | Stale_inputs],
+      perceptron([0.5 | Weights], Combined_input, Sensitivities, New_stale_input);
 
-    {pass, Input_value} -&gt;
+    {pass, Input_value, Expected_Output} -&gt;
       lists:foreach(fun(Output_PID) -&gt;
-          Output_PID ! {stimulate, {self(), Input_value}}
+          Output_PID ! {stimulate, {self(), Input_value, Expected_Output}}
         end,
         convert_to_keys(Sensitivities)),
-      perceptron(Weights, Inputs, Sensitivities)
+      perceptron(Weights, Inputs, Sensitivities, Stale_inputs)
 
   end.
 
@@ -85,7 +95,7 @@ feed_forward(Func, Weights, Inputs) -&gt;
 
 add_sensitivity([], _Backprop) -&gt; [];
 add_sensitivity(Sensitivities, Backprop) -&gt; 
-  replace_input(Sensitivities, Backprop).
+  replace_sensitivity_input(Sensitivities, Backprop).
 
 calculate_sensitivities(_Backprop, [], 
   _Sensitivities, _Output, _Deriv) -&gt;
@@ -102,10 +112,25 @@ connect(Sender, Receiver) -&gt;
   Sender ! {connect_to_output, Receiver},
   Receiver ! {connect_to_input, Sender}.
 
-replace_input(Inputs, Input) -&gt;
+replace_sensitivity_input(Inputs, Input) -&gt;
   {Input_PID, _} = Input,
   lists:keyreplace(Input_PID, 1, Inputs, Input).
 
+replace_input(Inputs, Input) -&gt;
+  {Input_PID, _, _} = Input,
+  lists:keyreplace(Input_PID, 1, Inputs, Input).
+
+delete_input(Inputs, Input) -&gt;
+  {Input_PID, _, _} = Input,
+  lists:keydelete(Input_PID, 1, Inputs).
+
+
+convert_to_input_values(Input_list) -&gt;
+  lists:map(fun({_, Val, _}) -&gt; Val end, Input_list).
+
+convert_to_input_keys(Input_list) -&gt;
+  lists:map(fun({Key, _, _}) -&gt; Key end, Input_list).
+
 convert_to_values(Tuple_list) -&gt;
   lists:map(fun({_, Val}) -&gt; Val end, Tuple_list).
 </diff>
      <filename>ann.erl</filename>
    </modified>
    <modified>
      <diff>@@ -3,13 +3,13 @@
 
 setup() -&gt;
   ann_graph:start(),
-  N1_pid = spawn(ann, perceptron, [[],[],[]]),
-  N2_pid = spawn(ann, perceptron, [[],[],[]]),
-  N3_pid = spawn(ann, perceptron, [[],[],[]]),
-  N4_pid = spawn(ann, perceptron, [[],[],[]]),
-  N5_pid = spawn(ann, perceptron, [[],[],[]]),
-  N6_pid = spawn(ann, perceptron, [[],[],[]]),
-  N7_pid = spawn(ann, perceptron, [[],[],[]]),
+  N1_pid = spawn(ann, perceptron, [[],[],[],[]]),
+  N2_pid = spawn(ann, perceptron, [[],[],[],[]]),
+  N3_pid = spawn(ann, perceptron, [[],[],[],[]]),
+  N4_pid = spawn(ann, perceptron, [[],[],[],[]]),
+  N5_pid = spawn(ann, perceptron, [[],[],[],[]]),
+  N6_pid = spawn(ann, perceptron, [[],[],[],[]]),
+  N7_pid = spawn(ann, perceptron, [[],[],[],[]]),
 
   ann:connect(N1_pid, N2_pid),
   ann:connect(N1_pid, N3_pid),
@@ -26,7 +26,7 @@ setup() -&gt;
   ann:connect(N5_pid, N7_pid),
   ann:connect(N6_pid, N7_pid),
 
-  N1_pid ! {pass, 0.5}.
+  N1_pid ! {pass, 0.5, 0.7}.
 
 run() -&gt; 
   ann_graph:start(),</diff>
      <filename>ann_test.erl</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>226bebc11ee6dfbd5df8ff43b9d7ca516fd3919e</id>
    </parent>
  </parents>
  <author>
    <name>Ben Hughes</name>
    <email>ben@pixelmachine.org</email>
  </author>
  <url>http://github.com/schleyfox/erlang_ann/commit/98c108cdd47d9636799f0ee1a1a284c1e6d190bb</url>
  <id>98c108cdd47d9636799f0ee1a1a284c1e6d190bb</id>
  <committed-date>2008-08-22T09:36:43-07:00</committed-date>
  <authored-date>2008-08-22T09:36:43-07:00</authored-date>
  <message>Inputs can now be associated with the final expected value
perceptrons now only fire when all inputs are new/fresh
(this should help with overcorrection in training)</message>
  <tree>8866e26c4b17963de23e36108ba1fbf307029181</tree>
  <committer>
    <name>Ben Hughes</name>
    <email>ben@pixelmachine.org</email>
  </committer>
</commit>
