/////////////////////////////////////////////////////////////// // layer.cpp - layer is a container of neurons // // 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 "neuron.h" #include "layer.h" using namespace std; //----< constructor >------------------------------------------ layer::layer(int numNeurons, neuron *pN) { int i; for(i=0; iclone()); } //----< destructor >------------------------------------------- layer::~layer() { int i; for(i=0; i<_neurons.size(); i++) delete _neurons[i]; } //----< evaluate an output value >----------------------------- double layer::output(int selectOutput) { if(selectOutput >= _neurons.size()) throw "index out of bounds in layer::output()"; return _neurons[selectOutput]->output(); } // //----< set an input value >----------------------------------- void layer::input(int selectInput, double value) { if(selectInput == 0) // don't change bias return; if(selectInput >= _neurons[0]->size()) throw "neuron input index out of bounds in layer::input()"; int i; for(i=0; i<_neurons.size(); i++) _neurons[i]->input(selectInput,value); } //----< set a weight >----------------------------------------- void layer::weight(int selectWeight, int selectNeuron, double value) { if(selectNeuron >= _neurons.size()) throw "neuron index out of bounds in layer::weight()"; _neurons[selectNeuron]->weight(selectWeight,value); } //----< show layer inputs >------------------------------------ void layer::showInputs(std::ostream &out, const char *msg) { _neurons[0]->showInputs(out,msg); } //----< show layer outputs >----------------------------------- void layer::showOutputs(std::ostream &out, const char *msg) { vector temp; int i; for(i=0; ioutput()); showCont(out,msg,temp); } //----< show layer weights >----------------------------------- void layer::showWeights(std::ostream &out, const char *msg) { out << msg; int i; for(i=0; ishowWeights(out,""); } } //----< test stub >-------------------------------------------- #ifdef TEST_LAYER #include using namespace std; void main() { cout << "\n Testing Layer Class " << "\n =====================\n"; try { cout << "\n building layer of 3 linear neurons with 4 inputs each " << "\n -------------------------------------------------------"; // construct layer linearNeuron ln(4); layer hiddenLayer(3,&ln); cout << "\n layer has " << hiddenLayer.numInputs() << " inputs - "; // set inputs int i; for(i=0; i