iSpike
2.1
Spike conversion library for robotics
|
00001 #include <iSpike/NeuronSim/IzhikevichNeuronSim.hpp> 00002 #include <iSpike/ISpikeException.hpp> 00003 #include <iSpike/Log/Log.hpp> 00004 00005 #include <algorithm> 00006 00007 using namespace ispike; 00008 00009 00011 IzhikevichNeuronSim::IzhikevichNeuronSim() : 00012 numNeurons(0), 00013 aParam(0.1), 00014 bParam(0.2), 00015 cParam(-65.0), 00016 dParam(2.0) 00017 { 00018 ; 00019 } 00020 00021 00023 IzhikevichNeuronSim::IzhikevichNeuronSim(size_t numNeurons, 00024 double a, double b, double c, double d) : 00025 numNeurons(numNeurons), 00026 aParam(a), 00027 bParam(b), 00028 cParam(c), 00029 dParam(d), 00030 vArray(numNeurons, c), 00031 uArray(numNeurons, b*c), 00032 iArray(numNeurons, 0.0), 00033 firedArray(numNeurons, false) 00034 { 00035 ; 00036 } 00037 00038 00039 00040 /*--------------------------------------------------------------------*/ 00041 /*--------- PUBLIC METHODS -------*/ 00042 /*--------------------------------------------------------------------*/ 00043 00045 void IzhikevichNeuronSim::initialize(size_t numNeurons){ 00046 00047 LOG(LOG_DEBUG)<<"Initializing neuron simulator with "<<numNeurons<<" neurons."; 00048 this->numNeurons = numNeurons; 00049 00050 vArray.clear(); 00051 uArray.clear(); 00052 iArray.clear(); 00053 firedArray.clear(); 00054 00055 vArray.resize(numNeurons, cParam); 00056 uArray.resize(numNeurons, bParam * cParam); 00057 iArray.resize(numNeurons, 0.0); 00058 firedArray.resize(numNeurons, false); 00059 } 00060 00061 00063 void IzhikevichNeuronSim::setInputCurrent(unsigned index, double current){ 00064 if(index >= numNeurons) { 00065 throw ISpikeException("IzhikevichNeuronSim: Index is out of range."); 00066 } 00067 iArray[index] = current; 00068 } 00069 00070 00072 void IzhikevichNeuronSim::step(){ 00073 00074 //Clear spikes and fired array 00075 spikeVector.clear(); 00076 std::fill(firedArray.begin(), firedArray.end(), false); 00077 00078 //Calculate state of neurons 00079 for(unsigned n = 0; n < numNeurons; ++n) { 00080 for(unsigned t=0; t<4; ++t) { 00081 if(!firedArray[n]) { 00082 vArray[n] += 0.25 * ((0.04* vArray[n] + 5.0) * vArray[n] + 140.0 - uArray[n] + iArray[n]); 00083 uArray[n] += 0.25 * (aParam * (bParam * vArray[n] - uArray[n])); 00084 firedArray[n] = vArray[n] >= 30.0; 00085 } 00086 } 00087 iArray[n] = 0.0; 00088 00089 //Neuron has fired -add spike to buffer 00090 if(firedArray[n]) { 00091 vArray[n] = cParam; 00092 uArray[n] += dParam; 00093 spikeVector.push_back(n); 00094 } 00095 } 00096 } 00097