/////////////////////////////////////////////////////////////// // 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 "neuron.h" #include "layer.h" //----< 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]; } //----< layer size = number of neurons it contains >----------- int layer::size() { return _neurons.size(); } //----< 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); } //----< test stub >-------------------------------------------- #ifdef TEST_LAYER #include using namespace std; void main() { try { linearNeuron ln(4); layer outLayer(3,&ln); int i; for(i=0; i<4; i++) outLayer.input(i,i); int j; for(j=0; j<3; j++) for(i=0; i<4; i++) outLayer.weight(i,j,j); cout << "\n Layer Outputs are: "; for(j=0; j<3; j++) cout << " " << outLayer.output(j); } catch(char *msg) { cout << "\n " << msg; } cout << "\n\n"; } #endif