/////////////////////////////////////////////////////////////// // // // nnet2.cpp - simple neural net for experimentation // // - uses neuron class // // - 3 layers, input, hidden, and output // // - hidden, output layers have one neuron // // - input layer is simply an input buffer // // - hidden layer function is sigmoid // // - output layer function is linear // // // // version: 1.0 // // Language: Visual C++, ver 5.0 // // Platform: Micron Dual Pentium Pro 200 // // Windows NT 4.0, service pack 3 // // Application: ELE591/791 Example // // Author: Jim Fawcett // // CST 2-187, (315) 443-3948 // // fawcett@neptune.syr.edu // // // /////////////////////////////////////////////////////////////// // Build Process // /////////////////////////////////////////////////////////////// // Files Required: // // nnet2.cpp, bneuron.h, bneuron.cpp // // // // Build Command: // // cl -GX nnet.cpp bneuron.cpp // /////////////////////////////////////////////////////////////// // Maintenance History: // // ==================== // // ver 1.0 - 15 June 1998 // // - first release // // // /////////////////////////////////////////////////////////////// #include #include #include #include "bneuron.h" using namespace std; // //----< neural network model >--------------------------------- double nnet(double input, double desired, sneuron &nhid, lneuron &nout) { const double eta = .8; // network connections nhid.input(1) = input; nout.input(1) = nhid.output(); // steepest descent weight updates double outFactor = -0.5*eta*(nout.output()-desired); double DnoutWt0 = outFactor*nout.outder(); double DnoutWt1 = DnoutWt0*nout.input(1); double DnhidWt0 = DnoutWt0*nout.weight(1)*nhid.outder(); double DnhidWt1 = DnhidWt0*nhid.input(1); nout.weight(0) += DnoutWt0; nout.weight(1) += DnoutWt1; nhid.weight(0) += DnhidWt0; nhid.weight(1) += DnhidWt1; // use new weights to calculate network response nout.input(1) = nhid.output(); return (nout.output()); } //----< neural network administration >------------------------ void main(int argc, char *argv[]) { if(argc == 1) { cout << " Please enter name of an input data file\n"; return; } ifstream in(argv[1]); if(!in.good()) { cout << " can't open data file " << argv[1] << endl; return; } // // create input data array in memory int numIn; in >> numIn; double *input = new double[numIn]; if(!input) { cout << " can't create in-memory input array\n"; return; } // scale input array int i=0; do { in >> input[i++]; } while(in.good() && i < numIn); numIn = i-1; double max = 0; for(i=0; i