//Weight.cpp // #ifndef WEIGHT_C #define WEIGHT_C #include #include "Weight.h" using std::rand; //reader and writer functions template inline weightType Weight::readWeight () { return weight; } template inline void Weight::writeWeight (weightType value) { weight = value; } template inline weightType Weight::readWeightChange () { return lastWeightChange; } template void Weight::writeWeightChange (weightType value) { lastWeightChange = value; } template inline Node* Weight::readNodePointer () { return nodePointer; } template inline void Weight::writeNodePointer (Node *node) { nodePointer = node; } //weight randomization functions for various data types //integer types are initialized to 0 or 1 //floating point types are initialized in the -0.5 to 0.5 range template<> void Weight::randomizeWeight () { weight = bool(float (rand()) / float (RAND_MAX) + 0.5); } template<> void Weight::randomizeWeight () { weight = short(float (rand()) / float (RAND_MAX) + 0.5); } template<> void Weight::randomizeWeight () { weight = int(float (rand()) / float (RAND_MAX) + 0.5); } template<> void Weight::randomizeWeight () { weight = float (rand()) / float (RAND_MAX) - 0.5; } template<> void Weight::randomizeWeight () { weight = double (rand()) / double (RAND_MAX) - 0.5; } #endif