From 7c3c5dd0f8d7089bd50282e9dcd56e36798e18cf Mon Sep 17 00:00:00 2001 From: Georg Holzmann Date: Tue, 12 Jul 2005 14:40:21 +0000 Subject: initial commit of pix_recNN svn path=/trunk/externals/grh/; revision=3320 --- pix_recNN/Neuron.cpp | 169 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 169 insertions(+) create mode 100755 pix_recNN/Neuron.cpp (limited to 'pix_recNN/Neuron.cpp') diff --git a/pix_recNN/Neuron.cpp b/pix_recNN/Neuron.cpp new file mode 100755 index 0000000..c020c1c --- /dev/null +++ b/pix_recNN/Neuron.cpp @@ -0,0 +1,169 @@ +///////////////////////////////////////////////////////////////////////////// +// +// 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