00001 #ifndef _ABSTRACTNEURON_H 00002 #define _ABSTRACTNEURON_H 00003 00004 #include "Neuron.h" 00005 #include "defines.h" 00006 00007 namespace annie 00008 { 00009 00017 class AbstractNeuron : public Neuron 00018 { 00019 protected: 00021 bool _hasBias; 00022 00024 real _bias; 00025 00027 real _deltaBias; 00028 00030 virtual void _recacheOutput() const =0; 00031 00033 virtual void _recacheError() const =0; 00034 00035 static const real INIT_WEIGHT_MAX; //< initial weights will be uniformly sampled from [-INIT_WEIGHT_MAX, INIT_WEIGHT_MAX] 00036 public: 00037 00038 static real getRandomWeight(); 00044 AbstractNeuron(int label, bool hasBias = true); 00045 00050 virtual void setBias(real bias); 00051 00053 virtual bool hasBias() const; 00054 00056 virtual real getBias() const; 00057 00059 virtual void removeBias(); 00060 00068 virtual void setDesiredOutput(real desired)=0; 00069 00074 virtual void connect(Neuron *from); 00075 void connect(Neuron &from) { connect(&from); } 00076 void connect(Neuron &from, real w) { connect(&from, w); } 00077 00079 void connectFrom(Neuron *from) { connect(from); } 00080 00087 virtual void connect(Neuron *from, real weight); 00088 00094 virtual void calculateNewWeights(real learningRate, real momentum); 00095 00100 virtual void update(); 00101 00103 virtual const char *getClassName() const; 00104 00109 virtual real getWeight(Neuron *from) const; 00110 00111 void randomizeWeights(); 00112 00114 virtual operator std::string() const; 00115 }; 00116 00117 }; //namespace annie 00118 #endif // define _ABSTRACTNEURON_H 00119