// Util.cpp // David R. Morrison #include "util.hpp" // Activation functions. // f squashes to the range [0,1] // g squashes to the range [-2, 2] // h squashes to the range [-1, 1] double f(double x) { return 1 / (1 + exp(-x)); } double g(double x) { return 4 / (1 + exp(-x)) - 2; } double h(double x) { return 2 / (1 + exp(-x)) - 1; } double fPrime(double x) { return (1 - f(x)) * f(x); } double gPrime(double x) { return 1 - h(x) * h(x); } double hPrime(double x) { return 0.5 * (1 - h(x) * h(x)); } // Initialize the random number generator void initRand() { srand48(time(NULL)); } // Create a vector of random weights between -.1 and .1 vector getRandomWeights(int size) { vector weights(size); for (int i = 0; i < size; ++i) weights[i] = drand48() > 0.5 ? drand48() / 10 : -drand48() / 10; return weights; }