///////////////////////////////////////////////////////////////////////////// // // class RecurrentNeuron // // 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 "RecurrentNeuron.h" namespace TheBrain { //-------------------------------------------------- /* Constructor */ RecurrentNeuron::RecurrentNeuron(int inputs, int memory) : Neuron(inputs), LW_(NULL), mem_data_(NULL) { memory_ = (memory<0) ? 1 : memory+1; } //-------------------------------------------------- /* Destructor */ RecurrentNeuron::~RecurrentNeuron() { if(LW_) delete[] LW_; if(mem_data_) delete[] mem_data_; } //-------------------------------------------------- /* creates a new IW-matrix (size: inputs_) and * b1-vector * ATTENTION: if they exist they'll be deleted */ void RecurrentNeuron::create() throw(NNExcept) { // delete if they exist if(IW_) delete[] IW_; if(LW_) delete[] LW_; if(mem_data_) delete[] mem_data_; IW_ = new float[inputs_]; LW_ = new float[memory_]; mem_data_ = new float[memory_]; if(!IW_ || !LW_ || !mem_data_) throw NNExcept("No memory for Neurons!"); index_=0; } //-------------------------------------------------- /* inits the weight matrix and the bias vector of * the network with random values between [min|max] */ void RecurrentNeuron::initRand(const int &min, const int &max) throw(NNExcept) { if(!IW_ || !LW_) 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