///////////////////////////////////////////////////////////////////////////// // // class Neuron // // source file // // Copyright (c) 2005 Georg Holzmann // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. // ///////////////////////////////////////////////////////////////////////////// #include "Neuron.h" namespace TheBrain { //-------------------------------------------------- /* Constructor */ Neuron::Neuron(int inputs, int dummy) : learn_rate_(0), range_(1), IW_(NULL), b1_(0) { inputs_ = (inputs<1) ? 1 : inputs; } //-------------------------------------------------- /* Destructor */ Neuron::~Neuron() { if(IW_) delete[] IW_; } //-------------------------------------------------- /* creates a new IW-matrix (size: inputs_) and * b1-vector * ATTENTION: if they exist they'll be deleted */ void Neuron::create() throw(NNExcept) { // delete if they exist if(IW_) delete[] IW_; IW_ = new float[inputs_]; if(!IW_) throw NNExcept("No memory for Neurons!"); } //-------------------------------------------------- /* inits the weight matrix and the bias vector of * the network with random values between [min|max] */ void Neuron::initRand(const int &min, const int &max) throw(NNExcept) { if(!IW_) throw NNExcept("You must first create the Net!"); // make randomvalue between 0 and 1 // then map it to the bounds b1_ = ((float)rand()/(float)RAND_MAX)*(max-min) + min; for(int i=0; i