#include #include #include #include #include "math_functions.h" #include "pitch.h" #include "node.h" #include "net.h" Node* inputs[NUMINPUTS]; Node* hidden[NUMHIDDEN]; Node* outputs[NUMOUTPUTS]; pitch* training[TRAINING_POINTS]; pitch* testing[TESTING_POINTS]; using namespace std; net::net(void) { } void net::trainNetwork() { double tmpAct, tmpDelta; double gain = 0.1; int success = 0; int currentPitch; int y,x,i,z; double hiddenDelta[NUMHIDDEN]; double outputDelta[NUMOUTPUTS]; double target[NUMOUTPUTS]; cout<<"Training Points"<xpos<<" "<ypos<< " "<recognition<activation = training[currentPitch]->xpos; inputs[1]->activation = training[currentPitch]->ypos; inputs[2]->activation = training[currentPitch]->recognition; // start the feed-forward steps: // calculate values of the hidden layer for (y=0; ybias; for ( z=0; zactivation * inputWeights[z][y]; hidden[y]->activation = calcSigmoid(tmpAct); } // calculate values of the Output layer for ( y=0; ybias; for ( z=0; zactivation * outputWeights[z][y]; outputs[y]->activation = calcSigmoid(tmpAct); } // end the feed-forward step // Given point class (S or T) set target values for outputLayer. if (training[currentPitch]->getType() == 'S') { target[0] = 1.0; target[1] = 0.0; } else { target[0] = 0.0; target[1] = 1.0; } // Perform the backpropogation steps for ( i=0; i < NUMOUTPUTS; i++) { outputDelta[i] = (target[i] - outputs[i]->activation) * outputs[i]->activation * (1.0 - outputs[i]->activation); } for ( y=0; yactivation * (1.0 - hidden[y]->activation); } // Update weights (between input and hidden layers). for ( y=0; yactivation; } // Update weights (between hidden and output layers). for ( y=0; yactivation; } // Update bias (hidden layer). for ( y=0; ybias += gain * hiddenDelta[y]; } // Update bias (output layer). for ( y=0; ybias += gain * outputDelta[y]; // end of the back-propogation steps } } cout<<"Exiting Training"<activation = testing[t]->xpos; inputs[1]->activation = testing[t]->ypos; inputs[2]->activation = testing[t]->recognition; // Calculate the net input to each hidden node for ( i = 1; i < NUMHIDDEN; i++) { net1 = hidden[i]->bias; for ( j = 0; j < NUMINPUTS; j++) net1 += (inputWeights[j][i] * inputs[j]->activation); hidden[i]->activation = calcSigmoid(net1); } //Calculate the net input to each output node for ( i = 0; i < NUMOUTPUTS; i++) { net1 = outputs[i]->bias; for ( j = 0; j < NUMHIDDEN; j++) net1 += (outputWeights[j][i] * hidden[j]->activation); outputs[i]->activation = calcSigmoid(net1); } if (outputs[0]->activation >= 1.0 - THRESHOLD) predicted = 'S'; else predicted = 'T'; actual = testing[t]->getType(); cout<xpos<<" "<ypos<< " "<recognition<<" "< 7.0 ) return .9999; else if (x < -7.0) return .0001; else { tempx = ((double) (1.0 / (1.0 + exp(-x)))); return tempx; } }