/////////////////////////////////////////////////////////////// // neuron.h - define family of neurons /* complete prologue */ #include #include "neuron.h" using namespace std; //----< generic function to display container contents >------- template void showCont(const char *msg, const T &cont) { cout << "\n " << msg; T::const_iterator it; for(it=cont.begin(); it!=cont.end(); it++) cout << " " << *it; } //----< show inputs >------------------------------------------ void neuron::showInputs() { showCont("neuron inputs: ", _inputs); } //----< show weights >----------------------------------------- void neuron::showWeights() { showCont("neuron weights: ", _weights); } //----< set input value >-------------------------------------- void neuron::input(int selectInput, double value) { if(selectInput < 0 || _inputs.size() <= selectInput) throw "index out of bounds in neuron::input()"; _inputs[selectInput] = value; } //----< set weight value >------------------------------------- void neuron::weight(int selectWeight, double value) { if(selectWeight < 0 || _weights.size() <= selectWeight) throw "index out of bounds in neuron::weight()"; _weights[selectWeight] = value; } //----< constructor >------------------------------------------ linearNeuron::linearNeuron(int numInputs) { int i; for(i=0; i-------------------------------- double linearNeuron::output() { double s = 0; int i; for(i=0; i<_inputs.size(); i++) s += _inputs[i]*_weights[i]; return s; } //----< computer neuron function slope >----------------------- double linearNeuron::slope() { return 1; } //----< make a new neuron >------------------------------------ neuron* linearNeuron::clone() { return new linearNeuron(_inputs.size()); } #ifdef TEST_NEURON void main() { linearNeuron ln(3); ln.input(1,2); ln.input(2,3); ln.showInputs(); ln.weight(1,2); ln.weight(2,3); ln.showWeights(); cout << "\n linear neuorn output is: " << ln.output() << endl; cout << "\n\n"; } #endif