00001 #ifndef __NEURON_H 00002 #define __NEURON_H 00003 00004 #include <set> 00005 #include <map> 00006 #include <string> 00007 00008 #include <an/Random.h> 00009 00010 #include "../../utils/Graph.h" 00011 #include "../../utils/SpikeDelayLine.h" 00012 00019 namespace Teem 00020 { 00021 class Synapse; 00022 00058 class Neuron 00059 { 00060 public: 00062 typedef std::set<Synapse*> SynapseSet; 00063 00064 SynapseSet incoming; 00065 SynapseSet outgoing; 00066 TagSet tags; 00067 00068 public: 00070 Neuron(); 00072 virtual ~Neuron(); 00073 00075 virtual void finalize() { } 00076 00079 virtual bool getSpike() const {return lastSpike;} 00082 virtual double getCurrent() const {return lastCurrent;} 00083 00085 virtual void setParams(const std::map<std::string, double> params); 00087 virtual void setParams(const std::string ¶m, double value); 00088 00089 00091 virtual void update(double dt = 1.0) = 0; 00093 virtual void commit() = 0; 00094 00095 protected: 00097 bool lastSpike; 00099 double lastCurrent; 00100 00101 }; 00102 00105 class InputNeuron : public Neuron 00106 { 00107 public: 00108 virtual ~InputNeuron() { } 00109 00110 virtual void update(double dt = 1.0) { } 00111 virtual void commit() { } 00112 00113 virtual void setParams(const std::string ¶m, double value); 00114 00116 virtual void setInputValue(double value) = 0; 00117 }; 00118 00121 class CurrentInputNeuron : public InputNeuron 00122 { 00123 public: 00124 virtual ~CurrentInputNeuron() { } 00125 00126 virtual void setInputValue(double value) { lastCurrent = value; } 00127 }; 00128 00131 class SimpleSpikeInputNeuron : public InputNeuron 00132 { 00133 public: 00134 virtual ~SimpleSpikeInputNeuron() { } 00135 00136 virtual void setInputValue(double value) { lastSpike = value != 0.0; } 00137 00140 void setSpike(bool spike) { lastSpike = spike; } 00141 }; 00142 00146 class FiringRateInputNeuron : public InputNeuron 00147 { 00148 public: 00149 virtual ~FiringRateInputNeuron() { } 00150 00151 virtual void setInputValue(double value) { probability = value; } 00152 virtual void commit() { lastSpike = An::boolRand(probability); } 00153 00154 protected: 00155 double probability; 00156 }; 00157 00169 class FiringRateOutputNeuron : public Neuron 00170 { 00171 public: 00173 FiringRateOutputNeuron() : totalSpike(0), queueSize(20) { } 00175 virtual ~FiringRateOutputNeuron() { } 00176 00177 virtual void setParams(const std::string ¶m, double value); 00178 virtual void update(double dt = 1.0); 00179 virtual void commit(); 00180 00181 protected: 00182 std::queue<unsigned> spikes; 00183 unsigned totalSpike; 00184 unsigned queueSize; 00185 00186 // FIXME: this is hacky, since it is dependend on step-size. It is 00187 // working for the dt = 1.0 case but doesnt scale well to different 00188 // time-step size values. 00189 }; 00190 00194 class Synapse 00195 { 00196 public: 00197 double weight; 00198 TagSet tags; 00199 00200 public: 00202 Synapse(); 00204 virtual ~Synapse(); 00205 00207 virtual void init(Neuron* pre, Neuron* post, const double weight = 0); 00209 virtual void finalize() { } 00210 00212 virtual void setParams(const std::map<std::string, double> params); 00214 virtual void setParams(const std::string ¶m, double value); 00215 00217 virtual bool getSpike() const {return preNeuron ? preNeuron->getSpike() : false;} 00219 virtual double getCurrent() const {return preNeuron ? preNeuron->getCurrent() : 0.0;} 00220 00222 virtual void update(double dt = 1.0) {} 00223 00225 const Neuron *getPreNeuron() const { return preNeuron; } 00226 00228 const Neuron *getPostNeuron() const { return postNeuron; } 00229 00230 protected: 00231 Neuron* preNeuron; 00232 Neuron* postNeuron; 00233 }; 00234 } 00235 00236 00237 #endif