//FeedforwardNode.cpp // //Function definitions for the FeedForward node class. // #ifndef FEEDFN_C #define FEEDFN_C #include #include "FeedforwardNode.h" FeedforwardNode::FeedforwardNode () {} //copy constructor FeedforwardNode::FeedforwardNode (const FeedforwardNode &fnode) { error = fnode.error; } //--------assignment operator---------- FeedforwardNode& FeedforwardNode::operator= (const FeedforwardNode &fnode) { if (this != &fnode) { Node::operator= (fnode); //we don't care about the value of the error -- //it becomes meaningless as we change the network } return *this; } //---------activation functions---------- double FeedforwardNode::activation (double threshold = 0) { double net = 0; for (int counter = 0; counter < numberInputConnections; ++counter) { net += inputWeight[counter].readWeight () * (inputWeight[counter].readNodePointer())->readActivation(); } output = activationFunction(net, threshold); return output; } double FeedforwardNode::firstHiddenLayerActivation (double *inputVector, double threshold = 0) { double net = 0; for (int counter = 0; counter < numberInputConnections; ++counter) { net += inputWeight[counter].readWeight() * *(inputVector+counter); } output = activationFunction(net, threshold); return output; } inline double FeedforwardNode::activationFunction (double net, double threshold = 0) { if (net > 10) return 1; else {if (net < -10) return 0; else return 1/(1+exp(-net+threshold)); } } //---------readers-------------- inline double FeedforwardNode::readError () {return error;} #endif