@@ -22,7 +22,7 @@ public class Network {
2222 HiddenNeuron [] hidden ;
2323 OutputNeuron output ;
2424
25- public static final float LEARNING_CONSTANT = 0.5f ;
25+ public static final double LEARNING_CONSTANT = 0.5 ;
2626
2727 // Only One output now to start!!! (i can do better, really. . .)
2828 // Constructor makes the entire network based on number of inputs & number of neurons in hidden layer
@@ -70,7 +70,7 @@ public Network(int inputs, int hiddentotal) {
7070 }
7171
7272
73- public float feedForward (float [] inputVals ) {
73+ public double feedForward (double [] inputVals ) {
7474
7575 // Feed the input with an array of inputs
7676 for (int i = 0 ; i < inputVals .length ; i ++) {
@@ -89,13 +89,13 @@ public float feedForward(float[] inputVals) {
8989 return output .getOutput ();
9090 }
9191
92- public float train (float [] inputs , float answer ) {
93- float result = feedForward (inputs );
92+ public double train (double [] inputs , double answer ) {
93+ double result = feedForward (inputs );
9494
9595
9696 // This is where the error correction all starts
9797 // Derivative of sigmoid output function * diff between known and guess
98- float deltaOutput = result *(1 -result ) * (answer -result );
98+ double deltaOutput = result *(1 -result ) * (answer -result );
9999
100100
101101 // BACKPROPOGATION
@@ -105,15 +105,15 @@ 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 loutput = neuron .getOutput ();
109- float deltaWeight = loutput *deltaOutput ;
108+ double loutput = neuron .getOutput ();
109+ double deltaWeight = loutput *deltaOutput ;
110110 c .adjustWeight (LEARNING_CONSTANT *deltaWeight );
111111 }
112112
113113 // ADJUST HIDDEN WEIGHTS
114114 for (HiddenNeuron hidden1 : hidden ) {
115115 connections = hidden1 .getConnections ();
116- float sum = 0 ;
116+ double 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 );
@@ -128,11 +128,11 @@ public float train(float[] inputs, float answer) {
128128 Connection c = (Connection ) connections .get (j );
129129 // Is this a connection from previous layer (input) to hidden layer?
130130 if (c .getTo () == hidden1 ) {
131- float loutput = hidden1 .getOutput ();
132- float deltaHidden = loutput * (1 - loutput ); // Derivative of sigmoid(x)
131+ double loutput = hidden1 .getOutput ();
132+ double 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 ();
135- float deltaWeight = neuron .getOutput ()*deltaHidden ;
135+ double deltaWeight = neuron .getOutput ()*deltaHidden ;
136136 c .adjustWeight (LEARNING_CONSTANT *deltaWeight );
137137 }
138138 }
0 commit comments