@@ -51,19 +51,19 @@ public Network(int inputs, int hiddentotal) {
5151 output = new OutputNeuron ();
5252
5353 // Connect input layer to hidden layer
54- for (int i = 0 ; i < input . length ; i ++ ) {
54+ for (InputNeuron input1 : input ) {
5555 for (int j = 0 ; j < hidden .length -1 ; j ++) {
5656 // Create the connection object and put it in both neurons
57- Connection c = new Connection (input [ i ], hidden [j ]);
58- input [ i ] .addConnection (c );
57+ Connection c = new Connection (input1 , hidden [j ]);
58+ input1 .addConnection (c );
5959 hidden [j ].addConnection (c );
6060 }
6161 }
6262
6363 // Connect the hidden layer to the output neuron
64- for (int i = 0 ; i < hidden . length ; i ++ ) {
65- Connection c = new Connection (hidden [ i ], output );
66- hidden [ i ] .addConnection (c );
64+ for (HiddenNeuron hidden1 : hidden ) {
65+ Connection c = new Connection (hidden1 , output );
66+ hidden1 .addConnection (c );
6767 output .addConnection (c );
6868 }
6969
@@ -105,20 +105,20 @@ public float train(float[] inputs, float answer) {
105105 for (int i = 0 ; i < connections .size (); i ++) {
106106 Connection c = (Connection ) connections .get (i );
107107 Neuron neuron = c .getFrom ();
108- float output = neuron .getOutput ();
109- float deltaWeight = output *deltaOutput ;
108+ float loutput = neuron .getOutput ();
109+ float deltaWeight = loutput *deltaOutput ;
110110 c .adjustWeight (LEARNING_CONSTANT *deltaWeight );
111111 }
112112
113113 // ADJUST HIDDEN WEIGHTS
114- for (int i = 0 ; i < hidden . length ; i ++ ) {
115- connections = hidden [ i ] .getConnections ();
114+ for (HiddenNeuron hidden1 : hidden ) {
115+ connections = hidden1 .getConnections ();
116116 float sum = 0 ;
117117 // Sum output delta * hidden layer connections (just one output)
118118 for (int j = 0 ; j < connections .size (); j ++) {
119119 Connection c = (Connection ) connections .get (j );
120120 // Is this a connection from hidden layer to next layer (output)?
121- if (c .getFrom () == hidden [ i ] ) {
121+ if (c .getFrom () == hidden1 ) {
122122 sum += c .getWeight ()*deltaOutput ;
123123 }
124124 }
@@ -127,9 +127,9 @@ public float train(float[] inputs, float answer) {
127127 for (int j = 0 ; j < connections .size (); j ++) {
128128 Connection c = (Connection ) connections .get (j );
129129 // Is this a connection from previous layer (input) to hidden layer?
130- if (c .getTo () == hidden [ i ] ) {
131- float output = hidden [ i ] .getOutput ();
132- float deltaHidden = output * (1 - output ); // Derivative of sigmoid(x)
130+ if (c .getTo () == hidden1 ) {
131+ float loutput = hidden1 .getOutput ();
132+ float deltaHidden = loutput * (1 - loutput ); // Derivative of sigmoid(x)
133133 deltaHidden *= sum ; // Would sum for all outputs if more than one output
134134 Neuron neuron = c .getFrom ();
135135 float deltaWeight = neuron .getOutput ()*deltaHidden ;
0 commit comments