//Original source code by Dr Phil Brierley //www.philbrierley.com //Translated to C++ - dspink Sep 2005 //This code may be freely used and modified at will //C++ Compiled using Bloodshed Dev-C++ free compiler http://www.bloodshed.net/ //C Compiled using Pelles C free windows compiler http://smorgasbordet.com/ ////////////////////////////////////////////////////////////////////////////
// the outputs of the hidden neurons double hiddenVal[numHidden];
// the weights double weightsIH[numInputs][numHidden]; double weightsHO[numHidden];
// the data int trainInputs[numPatterns][numInputs]; int trainOutput[numPatterns];
//============================================================== //************** function definitions ************************** //==============================================================
//*********************************** // calculates the network output void calcNet(void) { //calculate the outputs of the hidden neurons //the hidden neurons are tanh int i = 0; for(i = 0;i<numHidden;i++) { hiddenVal[i] = 0.0;
//************************************ // read in the data void initData(void) { printf("initialising data\n");
// the data here is the XOR data // it has been rescaled to the range // [-1][1] // an extra input valued 1 is also added // to act as the bias // the output must lie in the range -1 to 1
//============================================================== //********** THIS IS THE MAIN PROGRAM ************************** //==============================================================
int main(void) { // seed random number function srand ( time(NULL) );
// initiate the weights initWeights();
// load in the data initData();
// train the network for(int j = 0;j <= numEpochs;j++) { for(int i = 0;i<numPatterns;i++) { //select a pattern at random patNum = rand()%numPatterns;
//calculate the current network output //and error for this pattern calcNet();