/////////////////////////////////////////////////////////////// // network.cpp - implements a network of layers // // ver 1.0 // // // // Language: Visual C++, ver 6.0 // // Platform: Dell XPS B1000r, Windows 2000 // // Application: Prototype for Pr#1, ELE 591/791 // // Author: Jim Fawcett, CST 2-187, Syracuse Univ // // (315) 443-3948, jfawcett@twcny.rr.com // /////////////////////////////////////////////////////////////// #include #include #include "network.h" using namespace std; //----< constructor >------------------------------------------ network::network() { } //----< destructor >------------------------------------------- network::~network() { // do this only if layers are created on heap // - not done this way in this prototype at this time // int i; // for(i=0; i----------------------------------- void network::input(int selectInput, double value) { // bounds checking performed by layer _layers[0]->input(selectInput, value); } //----< evaluate an output value >----------------------------- // // Note that this function flows data through the network // inefficiently. Outputs of preceding layer are recomputed // each time an input is needed. Can you improve this? // double network::output(int selectOutput) { const char *errMsg = "mismatch between number of layer outputs and next layer inputs"; // bounds checking performed by layer int i,j; for(i=1; inumOutputs() != _layers[i]->numInputs()) throw errMsg; for(j=0; j<_layers[i-1]->numOutputs(); j++) { _layers[i]->input(j,_layers[i-1]->output(j)); } } return (_layers[size()-1]->output(selectOutput)); } // //----< set a weight >----------------------------------------- void network::setWeights(int layer) { // modify weights using back propagation } //----< show weights for each layer in network >--------------- void network::showWeights(std::ostream &out, const char *msg) { cout << "\n " << msg; int i; for(i=0; ishowWeights(out,temp.str().c_str()); } } //----< show outputs for each layer in network >--------------- void network::showLayerOutputs(std::ostream &out, const char *msg) { out << "\n " << msg; vector temp; int i,j; for(i=0; inumOutputs(); j++) { temp.push_back(_layers[i]->output(j)); if(iinput(j,_layers[i]->output(j)); } showCont(out,"",temp); temp.clear(); } } //----< show network outputs >--------------------------------- void network::showOutputs(std::ostream &out, const char *msg) { _layers[size()-1]->showOutputs(out,msg); } //----< test stub >-------------------------------------------- #ifdef TEST_NETWORK #include using namespace std; void main() { try { cout << "\n building layer of 3 linear neurons with 2 inputs each " << "\n -------------------------------------------------------"; // construct layer linearNeuron lnHid(2); layer hiddenLayer(3,&lnHid); cout << "\n layer has " << hiddenLayer.numInputs() << " inputs - "; // set inputs int i; for(i=0; i