//Node.h // //Node class (and subclass) declaration //designed for use in feedforward networks // // #ifndef NODE_H #define NODE_H #include "Weight.h" //generic node class template template class Node { public: Node (); ~Node (); //copy constructor Node (const Node &node); //assignment operator Node& operator= (const Node &node); //equality operator bool operator== (const Node &node); bool operator< (const Node &node); void initialize (int numberInputs, int numberOutputs); //initialize a node without a bias term: //numweights is the number of weights in the node; //these are initialized to random numbers in [-0.5, 0.5]; //most recent weight change is initialized to zero void initialize (int numweights); //initialize a node with a bias term void initializeWithBias (int numweights); //readers and writers //how many weights in the node? inline int readNumberWeights (); int initializeInputConnection (Node &node); int initializeOutputConnection (Node &node); int addInputConnection (Node &node); int addInputConnectionOnly (Node &node); int addOutputConnection (Node &node); int addOutputConnectionOnly (Node &node); int removeInputConnection (Node &node); int removeInputConnectionOnly (const Node &node); int removeOutputConnection (Node &node); int removeOutputConnectionOnly (const Node &node); userType readInputConnectionWeight (int connectionNumber); userType readInputConnectionWeight (const Node &node); void writeInputConnectionWeight(Node &node, userType value); userType readOutputConnectionWeight (int connectionNumber); userType readOutputConnectionWeight (const Node &node); void writeOutputConnectionWeight(Node &node, userType value); int readNumberInputConnections (); int readNumberOutputConnections (); userType activation (userType threshold); userType activationFunction (userType net, userType threshold); userType readActivation (); //calculate the output of the node //the default activation function is the logistic function //the "inputvector" must have a length equal to the number of weights in the node //double activation (double *inputvector); //default activation function //redefine this if you would like a different function //inline double activationFunction (double net); //update weights to minimize the error in the output of this node void adjustWeight (double *inputvector); //read the current error in the output of this node userType readError (); protected: Weight *inputWeight, *outputWeight; userType output, delta; static double alpha, eta; //momentum and weight adjustment parameter same for entire layer int numberWeights; int numberInputConnections; int numberOutputConnections; int nextInputConnection; int nextOutputConnection; }; //output node class - a subclass of the generic node class //inputs to this class should be the outputs of the hidden nodes template class OutputNode: public Node { public: //calculate the error in the output of this output layer node //"calculated value" is the activation of this node //"actual value" is actual value void calculateError (double actualValue); private: static double eta; }; //hidden node class - a subclass of the generic node class //inputs to this class should be the user-supplied input values template class HiddenNode: public Node { public: //calculate the error in the output of this node //"calculatedValue" is the activation of this node //"nodeAbove[]" is the array of nodes for which this node provides input //"numberNodesAbove" is the size of "nodesAbove[]" void calculateError (double calculatedValue, Node *nodeAbove, int numberNodesAbove); private: static double eta; }; template class FirstHiddenNode: public Node { }; #endif