layer.cpp 115 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765
  1. #include "sys.hpp" // for libcwd
  2. #include "debug.hpp" // for libcwd
  3. #include <gsl/gsl_rng.h>
  4. #include <gsl/gsl_randist.h>
  5. // #include <QThread>
  6. #include "layer.hpp"
  7. #include "simloop.hpp"
  8. #include "libcsim.hpp"
  9. #include "spiketrain.hpp"
  10. #include <limits> // for detecting denormals
  11. #include "rng_paraqueue_pool.hpp"
  12. ////////////////////////////////
  13. layer::layer(int n)
  14. :SimElement(seLayer), N(n), NoiseSigma(0),
  15. NormPos(false), PoissonLambda(12.5), NoiseAmplitude(0),
  16. BalancedInhibition(0), TooManySpikes(false), mSpikeTrain(0)
  17. {
  18. Name="Layer";
  19. int i;
  20. SetRandomSpikeFrequency(1.0); //Hz
  21. Binary = true;
  22. SpikeFileName = "ospikes";
  23. if (Binary) FileType=".bin";
  24. else FileType=".dat";
  25. RandomInputStrength=20.;
  26. Dmax=DMAX;
  27. if (MacroTimeStep <=Dmax)
  28. {
  29. Dout(dc::layer | dc::warning, "MacroTimeStep too low: " << MacroTimeStep);
  30. }
  31. Dout(dc::layer, "LayerConstructor " << "N=" << N << "TimeStep = " << dt << "ms");
  32. v = new float [N];
  33. u = new float [N];
  34. Input = new float [N];
  35. for (i=0;i<N;++i) Input[i] =0;
  36. N_firings_max=int(400*N/dt); // upper limit on the number of fired neurons per sec
  37. NewArray2d(firings, N_firings_max,2); //mybe change the dimensions?? what is more efficient? (faster?)
  38. // at least it would require less memory (only two pointers would have to be stored
  39. // indeces and timings of spikes
  40. // firings[N_firings_max][2]; // indeces and timings of spikes
  41. N_firings=1; // spike timings
  42. firings[0][0]=-Dmax; // put a dummy spike at -D for simulation efficiency
  43. firings[0][1]=0; // index of the dummy spike
  44. mPositions.resize(N);
  45. Pos = &(mPositions[0]);
  46. NormPos=true;
  47. Nx=Ny=0;
  48. }
  49. layer::~layer()
  50. {
  51. Dout(dc::layer, "Deleting Layer");
  52. delete[] v;
  53. delete[] u;
  54. DeleteArray2d(firings, N_firings_max);
  55. delete[] Input;
  56. if (mSpikeTrain) {
  57. delete mSpikeTrain;
  58. }
  59. }
  60. long layer::calcMemoryConsumption()
  61. {
  62. long MemSum=0;
  63. MemSum += 3*N*sizeof(float); // float *v, *u; float *Input;
  64. MemSum += N_firings_max*sizeof(int*); //NewArray2d(firings, N_firings_max,2);
  65. MemSum += N_firings_max*2*sizeof(int); //NewArray2d(firings, N_firings_max,2);
  66. MemSum += N*sizeof(vector2d); //Pos = new vector2d [N];
  67. return MemSum;
  68. }
  69. int layer::WriteSimInfo(fstream &fw)
  70. {
  71. fw << "<" << seTypeString << " id=\"" << IdNumber << "\" Type=\"" << seType << "\" Name=\"" << Name << "\"> \n";
  72. fw << "<LayerDimensions N=\"" << N << "\" Nx=\"" << Nx << "\" Ny=\"" << Ny << "\"/> \n";
  73. // fw << "<N value=\"" << N << "\"/> \n";
  74. // fw << "<Nx value=\"" << Nx << "\"/> \n";
  75. // fw << "<Ny value=\"" << Ny << "\"/> \n";
  76. fw << "<NormPos value=\"" << NormPos << "\"/> \n";
  77. fw << "<Dmax value=\"" << Dmax << "\"/> \n";
  78. fw << "<Resetable value=\"" << resetable << "\"/> \n";
  79. fw << "</" << seTypeString << "> \n";
  80. }
  81. int layer::WriteSimInfo(fstream &fw, const string &ChildInfo)
  82. {
  83. stringstream sstr;
  84. sstr << "<LayerDimensions N=\"" << N << "\" Nx=\"" << Nx << "\" Ny=\"" << Ny << "\"/> \n";
  85. sstr << "<NormPos value=\"" << NormPos << "\"/> \n";
  86. sstr << "<Dmax value=\"" << Dmax << "\"/> \n";
  87. sstr << "<Resetable value=\"" << resetable << "\"/> \n";
  88. sstr << ChildInfo;
  89. SimElement::WriteSimInfo(fw, sstr.str());
  90. }
  91. const vector<vector2d>& layer::getPositions()
  92. {
  93. return mPositions;
  94. }
  95. int layer::SetupPositions()
  96. {
  97. int i;
  98. // calculate neuron positions
  99. // default: quadratic (allmost)
  100. Ny = int(sqrt(float(N)));
  101. Nx = int(ceil(float(N)/float(Ny)));
  102. for (i=0;i<N;++i) Pos[i].set(i%Nx, int(i/Nx));
  103. NormPos=false;
  104. }
  105. int layer::SetupPositions(int _nx, int _ny, bool Normalize)
  106. {
  107. int i;
  108. Nx=_nx;
  109. Ny=_ny;
  110. if ((Nx*Ny) != N) {
  111. Dout(dc::layer | dc::warning, "WARNING: Nx*Ny =" << Nx*Ny
  112. << "!= N=" << N << " Nx=" << Nx << " Ny=" << Ny << " _ny=" << _ny);
  113. }
  114. if (Normalize) {
  115. for (i=0; i<N; ++i) {
  116. Pos[i].set(float(i%Nx)/Nx, float(int(i/Nx))/Ny);
  117. }
  118. } else {
  119. for (i=0; i<N; ++i) {
  120. Pos[i].set(i%Nx, int(i/Nx));
  121. }
  122. }
  123. NormPos = Normalize;
  124. }
  125. int layer::SetupPositionsShift(int _nx, int _ny, float xshift, float yshift, bool Normalize)
  126. {
  127. int i;
  128. Nx=_nx;
  129. Ny=_ny;
  130. if ((Nx*Ny) != N) Dout(dc::layer | dc::warning, "Nx*Ny =" << Nx*Ny << "!= N=" << N);
  131. if (Normalize) {
  132. for (i=0;i<N;++i) Pos[i].set((float(i%Nx)/Nx)+xshift, (float(int(i/Nx))/Ny)+yshift);
  133. } else {
  134. for (i=0;i<N;++i) Pos[i].set(i%Nx+xshift, int(i/Nx)+yshift);
  135. }
  136. NormPos = Normalize;
  137. }
  138. int layer::SetupPositionsLinDiscrete(int NeuronsPerPatch)
  139. {
  140. int i;
  141. int NPatches = N/NeuronsPerPatch;
  142. for (i=0;i<N;++i) {
  143. Pos[i].set(float(i*NPatches/N)/NPatches,0);
  144. }
  145. NormPos=true;
  146. Ny = int(sqrt(float(N)));
  147. Nx = int(ceil(float(N)/float(Ny)));
  148. }
  149. void layer::hallo()
  150. {
  151. Dout(dc::layer, "Hallo");
  152. }
  153. float layer::GetDt()
  154. {
  155. return dt;
  156. }
  157. int layer::proceede(int t)
  158. {
  159. int i,j,k;
  160. for (int i=1;i<=nris;++i) Input[getrandom(N)]= RandomInputStrength; // random thalamic input
  161. if (getrandom(1000)< RestProb) Input[getrandom(N)]= RandomInputStrength; // random thalamic input
  162. }
  163. // prepare next sec
  164. int layer::prepare(int sec)
  165. {
  166. SimElement::prepare(sec);
  167. int i,j,k;
  168. FILE *fs;
  169. // Dout(dc::layer, Name << " firing rate=" << float(N_firings-1)/(dt*N) << "");fflush(stdout);
  170. Dout(dc::layer, Name << " firing rate=" << 1000*float(N_firings-1)/((MacroTimeStep+Dmax)*dt*N) << " Hz");
  171. // save firings
  172. stringstream sstr;
  173. sstr << sec;
  174. std::string tmpstring = DataDirectory+SpikeFileName+SimTag+FileType;
  175. const char* CurFileName = tmpstring.c_str();
  176. // save spike trains
  177. if (sec ==0) // open new file
  178. {
  179. fs = fopen(CurFileName,"w");
  180. if (fs) {
  181. if (Binary) {
  182. for (i=1;i<N_firings;i++)
  183. if (firings[i][0] >=0)
  184. fwrite(firings[i], 2*sizeof(firings[0][0]), 1, fs);
  185. } else {
  186. for (i=1;i<N_firings;i++)
  187. if (firings[i][0] >=0)
  188. fprintf(fs, "%d %d\n", firings[i][0], firings[i][1]);
  189. }
  190. fclose(fs);
  191. } else {
  192. Dout(dc::layer | dc::fatal, "failed opening file " << CurFileName << " for writing");
  193. }
  194. }
  195. else
  196. { // append spikes to existing file
  197. fs = fopen(CurFileName,"a");
  198. if (fs) {
  199. if (Binary) {
  200. int **temp_firings;
  201. int *buffer = new int [2*N_firings];
  202. int count=0;
  203. for (i=1;i<N_firings;++i) {
  204. if (firings[i][0] >= 0) {
  205. buffer[2*count] = firings[i][0] + sec*MacroTimeStep;
  206. buffer[2*count+1] = firings[i][1];
  207. ++count;
  208. }
  209. }
  210. fwrite(buffer, 2*count*sizeof(*buffer), 1, fs);
  211. delete[] buffer;
  212. } else {
  213. for (i=1;i<N_firings;i++)
  214. if (firings[i][0] >=0)
  215. fprintf(fs, "%d %d\n", dt*firings[i][0]+sec*MacroTimeStep, firings[i][1]);
  216. }
  217. fclose(fs);
  218. } else {
  219. Dout(dc::layer | dc::fatal, "failed opening file " << CurFileName << " for writing");
  220. }
  221. }
  222. k=N_firings-1;
  223. while (MacroTimeStep-firings[k][0]<Dmax) k--;
  224. for (i=1;i<N_firings-k;i++)
  225. {
  226. firings[i][0]=firings[k+i][0]-MacroTimeStep;
  227. firings[i][1]=firings[k+i][1];
  228. }
  229. N_firings = N_firings-k;
  230. }
  231. int layer::reset(int TotalTime)
  232. {
  233. int t = TotalTime % MacroTimeStep;
  234. SimElement::reset(t);
  235. Dout(dc::layer, Name << " RESET LAYER ");
  236. cerr << Name << " ERROR in layer::reset: usually the layer class has to overwrite this method\n";
  237. fflush(stdout);
  238. // delete all spikes which are still in the delay line
  239. // firings with firing times higher than t-MaximumDelay
  240. int MaximumDelay = MainSimLoop->GetMaximumDelay();
  241. int i,j,k;
  242. k=N_firings-1;
  243. while (t-firings[k][0]<MaximumDelay) k--;
  244. N_firings = k+1;
  245. for (int i=0;i<N;++i) {
  246. u[i]=0;
  247. v[i]=0;
  248. Input[i]=0;
  249. }
  250. }
  251. void layer::SetName(const char* _name)
  252. {
  253. SimElement::SetName(_name);
  254. SpikeFileName = Name + "spikes.dat";
  255. MemPotFileName = Name + "MemPot.dat";
  256. }
  257. void layer::SetSpikeFileName(char* FileName)
  258. {
  259. SpikeFileName = FileName;
  260. cout << "SpikeFile: " << SpikeFileName;
  261. }
  262. void layer::SetRandomInputStrength(float ris)
  263. {
  264. RandomInputStrength = ris;
  265. Dout(dc::layer, "set RandomInputStrength to " << RandomInputStrength << "");
  266. }
  267. void layer::SetRandomSpikeFrequency(float _rsf)
  268. {
  269. RandomSpikeFrequency = _rsf;
  270. NumRandomInputSpikes = dt*N*RandomSpikeFrequency/1000;
  271. nris = (int) floor(NumRandomInputSpikes);
  272. RestProb = int(1000*(NumRandomInputSpikes - nris));
  273. Dout(dc::layer, " NumRandomInputSpikes= " << NumRandomInputSpikes << " RestProb= " << RestProb << " nris= " << nris << "");
  274. }
  275. void layer::SetNoiseSigma(float _sigma)
  276. {
  277. NoiseSigma=_sigma;
  278. }
  279. void layer::SetBalancedInhibition(float value)
  280. {
  281. BalancedInhibition = value;
  282. }
  283. void layer::SetNoiseAmplitude(float value)
  284. {
  285. NoiseAmplitude = value;
  286. }
  287. float* layer::GetInputPointer(csimInputChannel InputNumber)
  288. {
  289. return Input;
  290. }
  291. float* layer::GetPspPointer(csimInputChannel channel)
  292. {
  293. return Input;
  294. }
  295. int layer::SaveSimInfo()
  296. {
  297. int i;
  298. string FileName=Name+string(".info");
  299. cout << "Save SimInfo in File: " << FileName;
  300. FILE *fw;
  301. fw = fopen((DataDirectory+FileName).c_str(),"w");
  302. fprintf(fw, "<LayerDimensions Nx=\"%d\" Ny=\"%d\" />\n", Nx, Ny);
  303. for (i=0;i<N;++i)
  304. {
  305. fprintf(fw, "%d", i);
  306. Pos[i].fprintfcs(fw);
  307. }
  308. // fwrite(&ns, sizeof(ns), 1, fw);
  309. // fwrite(&nt, sizeof(nt), 1, fw);
  310. // fwrite(&M, sizeof(M), 1, fw);
  311. // fwrite(&Dmax, sizeof(Dmax), 1, fw);
  312. // fwrite(&maxN_pre, sizeof(maxN_pre), 1, fw);
  313. // // NewArray2d(delays_length,N,Dmax); // distribution of delays
  314. // // NewArray3d(delays,N,Dmax,M); // arrangement of delays
  315. // for (i=0;i<ns;++i) fwrite(post[i], M*sizeof(post[0][0]), 1, fw);
  316. // for (i=0;i<ns;++i) fwrite(s[i], M*sizeof(s[0][0]), 1, fw);
  317. // for (i=0;i<ns;++i) fwrite(delays_length[i], Dmax*sizeof(delays_length[0][0]),1,fw);
  318. // for (i=0;i<ns;++i) for (j=0;j<Dmax;++j) fwrite(delays[i][j], M*sizeof(delays[0][0][0]),1,fw);
  319. fclose(fw);
  320. Dout(dc::layer, " saved SimInfo ");
  321. }
  322. int layer::StartBinRec(int nobserve, int StartNumber)
  323. {
  324. int NumObserve = nobserve;
  325. float** Buffer = new float* [NumObserve];
  326. for (int i=0;i<NumObserve; ++i) Buffer[i] = &(v[i]);
  327. string FileName(MemPotFileName);
  328. BinRec = new BinRecorder(MacroTimeStep, NumObserve, NumObserve, Buffer, dt, (DataDirectory+FileName).c_str());
  329. }
  330. void layer::ThrowTooManySpikes(int time)
  331. {
  332. cout << Name << "Two many spikes at t=" << time << " (ignoring all)";
  333. N_firings=1; // not zero to keep the dummy spike as first element in the array
  334. TooManySpikes=true;
  335. }
  336. int layer::TuneNoiseAmplitude(float DesiredFrequency)
  337. {
  338. int time=0;
  339. NoiseAmplitude = 0.01;
  340. int SettlingTime = int(100./dt); // ms/dt
  341. int MeasureTime = int(500./dt); // ms/dt
  342. float Tollerance = 0.01;
  343. float ChangeFactor=1;
  344. const int MaxTuneTrials=100;
  345. int TuneTrials=0;
  346. bool Stop=false;
  347. int MStep=0;
  348. enum ChangeDirVal {up, down};
  349. ChangeDirVal ChDir=up;
  350. ChangeDirVal LastChDir=up;
  351. while (! Stop) {
  352. for (int i=0;i<SettlingTime;++i) {
  353. proceede(time++);
  354. if (( time % MacroTimeStep) == 0) {
  355. prepare(MStep++);
  356. }
  357. }
  358. int LastNSpikesStart=N_firings;
  359. int SpikeCounter=0;
  360. TooManySpikes=false;
  361. for (int i=0;i<MeasureTime;++i) {
  362. proceede(time++);
  363. if (( time % MacroTimeStep) == 0) {
  364. SpikeCounter += N_firings-LastNSpikesStart;
  365. prepare(MStep++);
  366. LastNSpikesStart=N_firings;
  367. }
  368. }
  369. SpikeCounter += N_firings-LastNSpikesStart;
  370. float SpikeFrequency = 1000*float(SpikeCounter)/(dt*MeasureTime*N);
  371. cout << "SC=" << SpikeCounter << " NoiseAmp=" << NoiseAmplitude
  372. << " CurSpikeFrequency=" << SpikeFrequency << "Hz\n";
  373. if (abs(SpikeFrequency-DesiredFrequency) < Tollerance*DesiredFrequency) {
  374. Stop = true;
  375. Dout(dc::layer, "successfully finished noise tuning");
  376. } else {
  377. if ((SpikeFrequency>DesiredFrequency) || TooManySpikes) {
  378. ChDir=down;
  379. if (LastChDir == up) {
  380. ChangeFactor *= 0.5;
  381. }
  382. NoiseAmplitude /= (1+ChangeFactor);
  383. } else {
  384. ChDir=up;
  385. if (LastChDir == down) {
  386. ChangeFactor *= 0.5;
  387. }
  388. NoiseAmplitude *= (1+ChangeFactor);
  389. }
  390. LastChDir = ChDir;
  391. if (TuneTrials++ > MaxTuneTrials) {
  392. Stop=true;
  393. Dout(dc::layer, "ERROR: unsuccessfully finished noise tuning");
  394. }
  395. }
  396. }
  397. prepare(0);
  398. N_firings=1;
  399. }
  400. int layer::TuneBalancedInhibition(float DesiredFrequency)
  401. {
  402. int time=0;
  403. BalancedInhibition = 0.1;
  404. int SettlingTime = int(100./dt); // ms/dt
  405. int MeasureTime = int(500./dt); // ms/dt
  406. float Tollerance = 0.01;
  407. float ChangeFactor=1;
  408. const int MaxTuneTrials=100;
  409. int TuneTrials=0;
  410. bool Stop=false;
  411. int MStep=0;
  412. enum ChangeDirVal {up, down};
  413. ChangeDirVal ChDir=up;
  414. ChangeDirVal LastChDir=up;
  415. while (! Stop) {
  416. for (int i=0;i<SettlingTime;++i) {
  417. proceede(time++);
  418. if (( time % MacroTimeStep) == 0) {
  419. prepare(MStep++);
  420. }
  421. }
  422. int LastNSpikesStart=N_firings;
  423. int SpikeCounter=0;
  424. TooManySpikes=false;
  425. for (int i=0;i<MeasureTime;++i) {
  426. proceede(time++);
  427. if (( time % MacroTimeStep) == 0) {
  428. SpikeCounter += N_firings-LastNSpikesStart;
  429. prepare(MStep++);
  430. LastNSpikesStart=N_firings;
  431. }
  432. }
  433. SpikeCounter += N_firings-LastNSpikesStart;
  434. float SpikeFrequency = 1000*float(SpikeCounter)/(dt*MeasureTime*N);
  435. cout << "SC=" << SpikeCounter << " BalancedInhibition=" << BalancedInhibition
  436. << " CurSpikeFrequency=" << SpikeFrequency << "Hz\n";
  437. if (abs(SpikeFrequency-DesiredFrequency) < Tollerance*DesiredFrequency) {
  438. Stop = true;
  439. Dout(dc::layer, "successfully finished BalancedInhibition tuning");
  440. } else {
  441. if ((SpikeFrequency<DesiredFrequency) || TooManySpikes) {
  442. ChDir=down;
  443. if (LastChDir == up) {
  444. ChangeFactor *= 0.5;
  445. }
  446. BalancedInhibition /= (1+ChangeFactor);
  447. } else {
  448. ChDir=up;
  449. if (LastChDir == down) {
  450. ChangeFactor *= 0.5;
  451. }
  452. BalancedInhibition *= (1+ChangeFactor);
  453. }
  454. LastChDir = ChDir;
  455. if (TuneTrials++ > MaxTuneTrials) {
  456. Stop=true;
  457. Dout(dc::layer, "ERROR: unsuccessfully finished BalancedInhibition tuning");
  458. }
  459. }
  460. }
  461. prepare(0);
  462. N_firings=1;
  463. }
  464. SpikeTrain* layer::GetSpikeTrain()
  465. {
  466. Dout(dc::layer, "layer::GetSpikeTrain()");
  467. if (!mSpikeTrain) {
  468. Dout(dc::layer, "created new SpikeTrain object");
  469. return mSpikeTrain=new SpikeTrain(firings, &N_firings, &N, dt);
  470. } else {
  471. Dout(dc::layer, "returned old SpikeTrain object");
  472. return mSpikeTrain;
  473. }
  474. }
  475. /////////////////////////////
  476. // Konstruktor der Basisklasse muss in der Initialisierungsliste aufgerufen werden
  477. liflayer::liflayer(
  478. int n, float tau,
  479. float thresh, float k0, float k1,
  480. float k2, float kffi, float kfbi,
  481. float taus, float _InputSat, float _NoiseSigma)
  482. : layer(n), TauM(tau),
  483. Threshold(thresh), K0(k0), K1(k1), K2(k2),
  484. Kffi(kffi), Kfbi(kfbi), TauS(taus), InputSaturation(_InputSat)
  485. {
  486. NoiseSigma=_NoiseSigma;
  487. int i;
  488. cout << "Leaky Integrate- and Fire Neuron: K1="
  489. << K1 << " K2=" << K2 << " Kffi=" << Kffi << " Kfbi= " << Kfbi << "\n";
  490. RandomInputStrength=5;
  491. TauMfac = dt/TauM;
  492. TauSfac = exp(-dt/TauS);
  493. LastSpike = new int[N];
  494. for (i=0;i<N;++i) {
  495. LastSpike[i]=-2;
  496. v[i]=0;
  497. u[i]=0;
  498. }
  499. Input1 = new float[N];
  500. for (i=0;i<N;++i) Input1[i]=0;
  501. InhibitionDelay = int(1./dt); // 1 milli second
  502. Dout(dc::layer, "InhibitionDelay=" << InhibitionDelay << " TimeSteps ");
  503. mquer = new float [MacroTimeStep + InhibitionDelay + 1];
  504. squer = new float [MacroTimeStep + InhibitionDelay + 1];
  505. for (i=0; i<(MacroTimeStep+InhibitionDelay+1); ++i) {
  506. mquer[i]=0;
  507. squer[i]=0;
  508. }
  509. RunAvgFac = exp(-dt/2.0);
  510. Dout(dc::layer, "RunAvgFac=" << RunAvgFac << "");
  511. RefractoryPeriod = int(2/dt);
  512. }
  513. liflayer::~liflayer()
  514. {
  515. delete[] LastSpike;
  516. delete[] Input1;
  517. delete[] mquer;
  518. delete[] squer;
  519. }
  520. int liflayer::proceede(int TotalTime)
  521. {
  522. int t = TotalTime % MacroTimeStep;
  523. int i,j,k;
  524. float CurInput;
  525. // Izhikevich-like noise generation (poissonian noise with strong pulses)
  526. // for (int i=1;i<=nris;++i) Input[getrandom(N)]= RandomInputStrength; // random thalamic input
  527. // if (getrandom(1000)< RestProb) Input[getrandom(N)]= RandomInputStrength; // random thalamic input
  528. last_N_firings = N_firings;
  529. Iinh = K0+Kffi*squer[t]+Kfbi*mquer[t];
  530. for (i=0;i<N;i++)
  531. {
  532. CurInput = K1*Input[i] + K2*Input1[i] + gsl_ran_gaussian(gslr, NoiseSigma);
  533. u[i] += InputSaturation*CurInput/(CurInput+Iinh);
  534. if ((i==0) && (rec !=0)) rec->record(dt*TotalTime, squer[t], mquer[t]); // record potentials for DEBUGing
  535. squer[t+InhibitionDelay] += dt*Input[i];
  536. v[i] +=TauMfac*(-v[i] + u[i]);
  537. if ((v[i] > Threshold) && (t-LastSpike[i] > 2/dt)) // did it fire?
  538. {
  539. v[i] -= Threshold; // voltage reset
  540. LastSpike[i] = t;
  541. firings[N_firings ][0]=t;
  542. firings[N_firings++][1]=i;
  543. mquer[t+InhibitionDelay] += 1;
  544. // Dout(dc::layer, "Mquer increased to " << mquer[t+InhibitionDelay] << "");
  545. if (N_firings == N_firings_max) {
  546. ThrowTooManySpikes(t);
  547. }
  548. }
  549. u[i] *= TauSfac;
  550. }
  551. mquer[t+InhibitionDelay+1] = mquer[t+InhibitionDelay]*RunAvgFac;
  552. squer[t+InhibitionDelay+1] = squer[t+InhibitionDelay]*RunAvgFac;
  553. // Dout(dc::layer, "Squer= " << squer[t] << " Mquer= " << mquer[t] << "");
  554. for (i=0;i<N;i++)
  555. {
  556. Input[i] = 0.0; // reset the input
  557. Input1[i] = 0.0;
  558. }
  559. }
  560. int liflayer::prepare(int sec)
  561. {
  562. int i,j;
  563. // prepare for the next MacroTimeStep
  564. layer::prepare(sec);
  565. for (i=0;i<N;++i) LastSpike[i] -= MacroTimeStep;
  566. for (i=0;i<InhibitionDelay+1;i++)
  567. {
  568. mquer[i] = mquer[MacroTimeStep+i];
  569. squer[i] = squer[MacroTimeStep+i];
  570. }
  571. for (i=InhibitionDelay+1;i<MacroTimeStep+InhibitionDelay+1;++i)
  572. {
  573. mquer[i]=0;
  574. squer[i]=0;
  575. }
  576. }
  577. float* liflayer::GetInputPointer(csimInputChannel InputNumber)
  578. {
  579. switch (InputNumber) {
  580. case csimInputChannel_AMPA:
  581. Dout(dc::layer, "EG/DG Input");
  582. return Input;
  583. break;
  584. case csimInputChannel_GABAa:
  585. Dout(dc::layer, "recurrent input");
  586. return Input1;
  587. break;
  588. default:
  589. return Input;
  590. break;
  591. }
  592. return 0;
  593. }
  594. int liflayer::SetKfbi(float _kfbi)
  595. {
  596. Kfbi=_kfbi;
  597. }
  598. int liflayer::InitInhibitionPot(float _mquer, float _squer)
  599. {
  600. int i;
  601. for (i=0;i<InhibitionDelay+1;i++)
  602. {
  603. mquer[i] = _mquer;
  604. squer[i] = _squer;
  605. }
  606. }
  607. //////////////////////////////////
  608. thetaliflayer::thetaliflayer(
  609. int n, float tau,
  610. float thresh, float k0, float k1,
  611. float k2, float kffi, float kfbi,
  612. float taus, float _InputSat, float _NoiseSigma, int _ThetaPeriod)
  613. : liflayer(n, tau, thresh, k0, k1, k2, kffi, kfbi,taus, _InputSat, _NoiseSigma), ThetaPeriod (_ThetaPeriod)
  614. {
  615. ThetaPhase = int(ThetaPeriod/dt);
  616. ThetaOn=true;
  617. }
  618. thetaliflayer::~thetaliflayer()
  619. {
  620. }
  621. int thetaliflayer::proceede(int TotalTime)
  622. {
  623. int t = TotalTime % MacroTimeStep;
  624. int i,j,k;
  625. float CurInput;
  626. // Izhikevich-like noise generation (poissonian noise with strong pulses)
  627. // for (int i=1;i<=nris;++i) Input[getrandom(N)]= RandomInputStrength; // random thalamic input
  628. // if (getrandom(1000)< RestProb) Input[getrandom(N)]= RandomInputStrength; // random thalamic input
  629. last_N_firings = N_firings;
  630. Iinh = K0+Kffi*squer[t]+Kfbi*mquer[t];
  631. float ThetaK2;
  632. if (ThetaOn)
  633. {
  634. if (ThetaPhase++ >= (ThetaPeriod/dt)) ThetaPhase=0;
  635. ThetaK2 = K2*(dt*ThetaPhase/ThetaPeriod);
  636. } else ThetaK2 = K2;
  637. // cout << ThetaK2/K2 << " ";
  638. for (i=0;i<N;i++)
  639. {
  640. CurInput = K1*Input[i] + ThetaK2*Input1[i] + gsl_ran_gaussian(gslr, NoiseSigma);
  641. u[i] += InputSaturation*CurInput/(CurInput+Iinh);
  642. if ((i==0) && (rec !=0)) rec->record(dt*TotalTime, squer[t], mquer[t]); // record potentials for DEBUGing
  643. squer[t+InhibitionDelay] += dt*Input[i];
  644. v[i] +=TauMfac*(-v[i] + u[i]);
  645. if ((v[i] > Threshold) && (t-LastSpike[i] > 2/dt)) // did it fire?
  646. {
  647. v[i] -= Threshold; // voltage reset
  648. LastSpike[i] = t;
  649. firings[N_firings ][0]=t;
  650. firings[N_firings++][1]=i;
  651. mquer[t+InhibitionDelay] += 1;
  652. // Dout(dc::layer, "Mquer increased to " << mquer[t+InhibitionDelay] << "");
  653. if (N_firings == N_firings_max) {
  654. ThrowTooManySpikes(t);
  655. }
  656. }
  657. mquer[t+InhibitionDelay+1] = mquer[t+InhibitionDelay]*RunAvgFac;
  658. squer[t+InhibitionDelay+1] = squer[t+InhibitionDelay]*RunAvgFac;
  659. // Dout(dc::layer, "Squer= " << squer[t] << " Mquer= " << mquer[t] << "");
  660. u[i] *= TauSfac;
  661. }
  662. for (i=0;i<N;i++)
  663. {
  664. Input[i] = 0.0; // reset the input
  665. Input1[i] = 0.0;
  666. }
  667. }
  668. int thetaliflayer::prepare(int sec)
  669. {
  670. int i,j;
  671. // prepare for the next MacroTimeStep
  672. layer::prepare(sec);
  673. for (i=0;i<N;++i) LastSpike[i] -= MacroTimeStep;
  674. for (i=0;i<InhibitionDelay+1;i++)
  675. {
  676. mquer[i] = mquer[MacroTimeStep+i];
  677. squer[i] = squer[MacroTimeStep+i];
  678. }
  679. for (i=InhibitionDelay+1;i<MacroTimeStep+InhibitionDelay+1;++i)
  680. {
  681. mquer[i]=0;
  682. squer[i]=0;
  683. }
  684. }
  685. void thetaliflayer::SetThetaOn(bool status)
  686. {
  687. ThetaOn = status;
  688. }
  689. ////////////////////////
  690. int IzhParas::print()
  691. {
  692. Dout(dc::layer, "IzhParas: a=" << A << " b=" << B << " c=" << C << " d=" << D << " e=" << E << " f=" << F << "");
  693. }
  694. /////////////////////////////
  695. izhlayer::izhlayer (int n, float a, float b, float c, float d, float e, float f, float _InputSat, float _InhInputSat): layer(n), A(a), B(b), C(c), D(d), E(e), F(f), InputSaturation(_InputSat), InhInputSaturation(_InhInputSat)
  696. {
  697. Dout(dc::layer, "Constructor: Quadratic Integrate- and Fire Neuron ");
  698. Init();
  699. }
  700. izhlayer::izhlayer (int n, IzhParas _paras, float _InputSat, float _InhInputSat): layer(n), A(_paras.A), B(_paras.B), C(_paras.C), D(_paras.D), E(_paras.E), F(_paras.F), InputSaturation(_InputSat), InhInputSaturation(_InhInputSat)
  701. {
  702. SetNoiseSigma(_paras.sigma);
  703. Dout(dc::layer, "Constructor: Quadratic Integrate- and Fire Neuron ");
  704. _paras.print();
  705. Init();
  706. }
  707. int izhlayer::Init()
  708. {
  709. int i;
  710. InitEquilibriumPotentials();
  711. TauS = 2.0;
  712. TauSfac = exp(-dt/TauS);
  713. TauInh = 10.0;
  714. TauInhFac = exp(-dt/TauInh);
  715. ExSynPot = new float [N];
  716. for (i=0;i<N;++i) ExSynPot[i]=0;
  717. InhSynPot = new float [N];
  718. for (i=0;i<N;++i) InhSynPot[i]=0;
  719. Dout(dc::layer, "dt = " << dt << "");
  720. }
  721. int izhlayer::SetTauInh(float _TauInh)
  722. {
  723. TauInh = _TauInh;
  724. TauInhFac = exp(-dt/TauInh);
  725. }
  726. int izhlayer::SetTauEx(float _TauEx)
  727. {
  728. TauS = _TauEx;
  729. TauSfac = exp(-dt/TauS);
  730. }
  731. izhlayer::izhlayer (IzhType type, int n, float _InputSat, float _InhInputSat): layer(n), A(0.02), B(0.2), C(-65), D(2), E(140), F(5), InputSaturation(_InputSat), InhInputSaturation(_InhInputSat)
  732. {
  733. switch (type) {
  734. case Integrator: {
  735. Dout(dc::layer, "Initialize Izhikevich-Neuron Layer as Integrator");
  736. A=0.02;
  737. B=-0.1;
  738. C=-55;
  739. D=6;
  740. E=108;
  741. F=4.1;
  742. } break;
  743. case FastSpiking: {
  744. Dout(dc::layer, "Initialize Izhikevich-Neuron Layer as FastSpiking");
  745. A=0.02;
  746. B=0.25;
  747. C=-65;
  748. D=1;
  749. E=140;
  750. F=5;
  751. } break;
  752. default:
  753. Dout(dc::layer, "No correct Izhikevich-Neuron-Type");
  754. break;
  755. }
  756. Init();
  757. }
  758. izhlayer::~izhlayer()
  759. {
  760. delete[] ExSynPot;
  761. delete[] InhSynPot;
  762. }
  763. int izhlayer::InitEquilibriumPotentials()
  764. {
  765. int i;
  766. float p = (F-B)/0.04;
  767. float q = E/0.04;
  768. float FixPoint = -60;
  769. float FP2 = -40;
  770. cout << "p=" << p << " q=" << q;
  771. if (q<=(p*p/4.0))
  772. {
  773. FixPoint = -p/2.0 - sqrt(p*p/4 - q);
  774. FP2 = -p/2.0 + sqrt(p*p/4 - q);
  775. Dout(dc::layer, " Equilibrium point is v=" << FixPoint << "mV");
  776. } else Dout(dc::layer, "NO Equilibrium point!! v=" << FixPoint << "mV");
  777. float FPu = B*FixPoint;
  778. float StartJitterV = 0.5; //(FP2 - FixPoint)/40;
  779. // float StartJitterV = 0.0; //(FP2 - FixPoint)/40;
  780. EquilibriumPot=FixPoint;
  781. for (i=0;i<N;i++) v[i]= FixPoint + StartJitterV*(float(getrandom(1000))/1000 - 0.5); // initial values for v // calculate equilibrium point!!
  782. for (i=0;i<N;i++) u[i]=FPu ; // initial values for u
  783. }
  784. float* izhlayer::GetInputPointer(csimInputChannel InputNumber)
  785. {
  786. switch (InputNumber) {
  787. case csimInputChannel_AMPA: {
  788. Dout(dc::layer, "Excitatory Input");
  789. return Input;
  790. } break;
  791. case csimInputChannel_GABAa: {
  792. Dout(dc::layer, "Inhibitory Input");
  793. return InhSynPot;
  794. } break;
  795. default:
  796. return Input;
  797. }
  798. return 0;
  799. }
  800. int izhlayer::WriteSimInfo(fstream &fw)
  801. {
  802. fw << "<" << seTypeString << " id=\"" << IdNumber << "\" Type=\"" << seType << "\" Name=\"" << Name << "\"> \n";
  803. fw << "<LayerType value=\"" << "Izhikevich" << "\"/> \n";
  804. fw << "<LayerDimensions N=\"" << N << "\" Nx=\"" << Nx << "\" Ny=\"" << Ny << "\"/> \n";
  805. fw << "<NormPos value=\"" << NormPos << "\"/> \n";
  806. fw << "<Dmax value=\"" << Dmax << "\"/> \n";
  807. fw << "<InputSaturation ex=\"" << InputSaturation << " \" inh=\"" << InhInputSaturation << "\"/> \n";
  808. fw << "<Parameter A=\"" << A << "\" B=\"" << B << "\" C=\"" << C << "\" D=\"" << D << "\" E=\"" << E << "\" F=\"" << F << "\"" << "/>\n";
  809. fw << "<EquilibriumPot value=\"" << EquilibriumPot << "\"/> \n";
  810. fw << "</" << seTypeString << "> \n";
  811. }
  812. int izhlayer::WriteSimInfo(fstream &fw, const string &ChildInfo)
  813. {
  814. stringstream sstr;
  815. // sstr << "<LayerType value=\"" << "Izhikevich" << "\"/> \n";
  816. sstr << "<InputSaturation ex=\"" << InputSaturation << " \" inh=\"" << InhInputSaturation << "\"/> \n";
  817. sstr << "<Parameter A=\"" << A << "\" B=\"" << B << "\" C=\"" << C << "\" D=\"" << D << "\" E=\"" << E << "\" F=\"" << F << "\"" << "/>\n";
  818. sstr << "<EquilibriumPot value=\"" << EquilibriumPot << "\"/> \n";
  819. sstr << ChildInfo;
  820. layer::WriteSimInfo(fw, sstr.str());
  821. }
  822. int izhlayer::proceede(int TotalTime)
  823. {
  824. int t = TotalTime % MacroTimeStep;
  825. int i,j,k;
  826. for (int i=1;i<=nris;++i) Input[getrandom(N)]= RandomInputStrength; // random thalamic input
  827. if (getrandom(1000)< RestProb) Input[getrandom(N)]= RandomInputStrength; // random thalamic input
  828. last_N_firings = N_firings;
  829. for (i=0;i<N;i++)
  830. {
  831. ExSynPot[i] += InputSaturation*Input[i]/(Input[i] + 1 + InhSynPot[i]);
  832. if ((i==0) && (rec != 0)) rec->record(dt*TotalTime, v[i], Input[i]);
  833. v[i] += dt*((0.04 *v[i] + F) * v[i] + E - u[i] + ExSynPot[i]);
  834. // v[i] +=dt*0.5*((0.04*v[i]+F)*v[i]+E-u[i]+Input[i]); // for numerical stability // time step is 0.5 ms
  835. u[i] += dt * A * (B * v[i] - u[i]);
  836. if (v[i]>=30) // did it fire?
  837. {
  838. // Dout(dc::layer, N_firings << "spike"); fflush(stdout);
  839. v[i] = C; // voltage reset
  840. u[i]+= D; // recovery variable reset
  841. firings[N_firings ][0]=t;
  842. firings[N_firings++][1]=i;
  843. if (N_firings == N_firings_max) {
  844. ThrowTooManySpikes(t);
  845. }
  846. }
  847. }
  848. for (i=0;i<N;i++)
  849. {
  850. Input[i] = 0; // reset input
  851. ExSynPot[i] *= TauSfac; // decay the input potential
  852. InhSynPot[i] *= TauInhFac; // decay inhibitory input potential
  853. }
  854. }
  855. int izhlayer::StartBinRec(int nobserve, int NNumber)
  856. {
  857. int NumObserve = 3*nobserve;
  858. float** Buffer = new float* [NumObserve];
  859. for (int i=0;i<nobserve; ++i) Buffer[i] = &(v[i+NNumber]);
  860. for (int i=0;i<nobserve; ++i) Buffer[i+nobserve] = &(ExSynPot[i+NNumber]);
  861. // for (int i=0;i<nobserve; ++i) Buffer[i+2*nobserve] = &(Input[i+NNumber]);
  862. for (int i=0;i<nobserve; ++i) Buffer[i+2*nobserve] = &(InhSynPot[i+NNumber]);
  863. string FileName(MemPotFileName);
  864. BinRec = new BinRecorder(MacroTimeStep, NumObserve, nobserve, Buffer, dt, (DataDirectory+FileName).c_str());
  865. }
  866. ////////////////////////////////////////
  867. izh2layer::izh2layer (int n, float a, float b, float c, float d, float e, float f, float _InputSat): izhlayer(n,a,b,c,d,e,f,_InputSat)
  868. {
  869. }
  870. izh2layer::izh2layer (int n, IzhParas _paras, float _InputSat): izhlayer(n,_paras, _InputSat)
  871. {
  872. SetNoiseSigma(_paras.sigma);
  873. }
  874. izh2layer::~izh2layer()
  875. {
  876. }
  877. int izh2layer::proceede(int TotalTime)
  878. {
  879. int t = TotalTime % MacroTimeStep;
  880. int i,j,k;
  881. // for (int i=1;i<=nris;++i) Input[getrandom(N)]= RandomInputStrength; // random thalamic input
  882. // if (getrandom(1000)< RestProb) Input[getrandom(N)]= RandomInputStrength; // random thalamic input
  883. last_N_firings = N_firings;
  884. int RecNum=52;
  885. float tmp=0;
  886. // if (rec != 0) rec->record(dt*TotalTime, u[RecNum], Input[RecNum]);
  887. if (BinRec) BinRec->record();
  888. for (i=0;i<N;i++)
  889. {
  890. // Input[i] += abs(gsl_ran_gaussian(gslr, NoiseSigma));
  891. // Input[i] += gsl_ran_gaussian(gslr, NoiseSigma);
  892. ExSynPot[i] += gsl_ran_gaussian(gslr, NoiseSigma) + InputSaturation*Input[i]/(Input[i] + 1 + InhSynPot[i]);
  893. v[i] +=dt*((0.04*v[i]+F)*v[i]+E-u[i]+ExSynPot[i]-InhSynPot[i]);
  894. // v[i] +=dt*((0.04*v[i]+F)*v[i]+E-u[i]+ExSynPot[i]-InhSynPot[i] + gsl_ran_gaussian(gslr, NoiseSigma) + );
  895. u[i] +=dt*A*(B*v[i]-u[i]);
  896. if (v[i]>=30) // did it fire?
  897. {
  898. // Dout(dc::layer, N_firings << "spike"); fflush(stdout);
  899. v[i] = C; // voltage reset
  900. u[i]+= D; // recovery variable reset
  901. firings[N_firings ][0]=t;
  902. firings[N_firings++][1]=i;
  903. if (N_firings == N_firings_max) {
  904. ThrowTooManySpikes(t);
  905. }
  906. }
  907. }
  908. for (i=0;i<N;i++)
  909. {
  910. Input[i] = 0; // reset input
  911. ExSynPot[i] *= TauSfac; // decay the input potential
  912. InhSynPot[i] *= TauInhFac; // decay inhibitory input potential
  913. }
  914. }
  915. ////////////////////////////////////////
  916. izh3layer::izh3layer(int n, float a, float b, float c, float d, float e, float f, float _InputSat, float IRPotDiff, float _InhInputSat): izhlayer(n,a,b,c,d,e,f,_InputSat, _InhInputSat)
  917. {
  918. InhReversePot = EquilibriumPot-IRPotDiff; // default: Ruhepot - 10 mV
  919. InhInput = new float [N];
  920. for (int i=0;i<N;++i) InhInput[i] =0;
  921. }
  922. izh3layer::izh3layer (int n, IzhParas _paras, float _InputSat, float IRPotDiff, float _InhInputSat): izhlayer(n,_paras, _InputSat,_InhInputSat)
  923. {
  924. SetNoiseSigma(_paras.sigma);
  925. InhReversePot = EquilibriumPot-IRPotDiff; // default: Ruhepot - 10 mV
  926. InhInput = new float [N];
  927. for (int i=0;i<N;++i) InhInput[i] =0;
  928. }
  929. izh3layer::~izh3layer()
  930. {
  931. delete[] InhInput;
  932. }
  933. float* izh3layer::GetInputPointer(csimInputChannel InputNumber)
  934. {
  935. switch (InputNumber) {
  936. case csimInputChannel_AMPA: {
  937. Dout(dc::layer, "Excitatory Input");
  938. return Input;
  939. } break;
  940. case csimInputChannel_GABAa: {
  941. Dout(dc::layer, "Inhibitory Input");
  942. return InhInput;
  943. } break;
  944. default:
  945. return Input;
  946. }
  947. return 0;
  948. }
  949. int izh3layer::proceede(int TotalTime)
  950. {
  951. // Dout(dc::layer, "izh3layer::proceede");fflush(stdout);
  952. int t = TotalTime % MacroTimeStep;
  953. int i,j,k;
  954. // for (int i=1;i<=nris;++i) Input[getrandom(N)]= RandomInputStrength; // random thalamic input
  955. // if (getrandom(1000)< RestProb) Input[getrandom(N)]= RandomInputStrength; // random thalamic input
  956. last_N_firings = N_firings;
  957. int RecNum=52;
  958. float tmp=0;
  959. // if (rec != 0) rec->record(dt*TotalTime, u[RecNum], Input[RecNum]);
  960. if (BinRec) BinRec->record();
  961. for (i=0;i<N;i++)
  962. {
  963. Input[i] += abs(gsl_ran_gaussian(gslr, NoiseSigma));
  964. // Input[i] += gsl_ran_gaussian(gslr, NoiseSigma);
  965. ExSynPot[i] += InputSaturation*Input[i]/(Input[i] + 1);
  966. InhSynPot[i] += InhInputSaturation*InhInput[i]/(InhInput[i] + 1);
  967. v[i] +=dt*((0.04*v[i]+F)*v[i]+E-u[i]+ExSynPot[i]-InhSynPot[i]*(v[i]-InhReversePot));
  968. // v[i] +=dt*((0.04*v[i]+F)*v[i]+E-u[i]+ExSynPot[i]-InhSynPot[i] + gsl_ran_gaussian(gslr, NoiseSigma) + );
  969. u[i] +=dt*A*(B*v[i]-u[i]);
  970. if (v[i]>=30) // did it fire?
  971. {
  972. // Dout(dc::layer, N_firings << "spike"); fflush(stdout);
  973. v[i] = C; // voltage reset
  974. u[i]+= D; // recovery variable reset
  975. firings[N_firings ][0]=t;
  976. firings[N_firings++][1]=i;
  977. if (N_firings == N_firings_max) {
  978. ThrowTooManySpikes(t);
  979. }
  980. }
  981. }
  982. for (i=0;i<N;i++)
  983. {
  984. Input[i] = 0; // reset input
  985. InhInput[i] = 0; // reset input
  986. ExSynPot[i] *= TauSfac; // decay the input potential
  987. InhSynPot[i] *= TauInhFac; // decay inhibitory input potential
  988. }
  989. // Dout(dc::layer, "izh3layer::proceede___feddisch");fflush(stdout);
  990. }
  991. //////////////////////////////////////////
  992. izh4layer::izh4layer (int n, IzhParas _paras, float _InputSat, float IRPotDiff, float _TauLink): izh3layer(n,_paras, _InputSat, IRPotDiff), TauLink(_TauLink)
  993. {
  994. LinkSynPot = new float[N];
  995. for (int i=0;i<N;++i) LinkSynPot[i]=0;
  996. TauLinkFac = exp(-dt/TauLink);
  997. }
  998. float* izh4layer::GetInputPointer(csimInputChannel InputNumber)
  999. {
  1000. switch (InputNumber) {
  1001. case csimInputChannel_AMPA: {
  1002. Dout(dc::layer, "Excitatory Input");
  1003. return Input;
  1004. } break;
  1005. case csimInputChannel_GABAa: {
  1006. Dout(dc::layer, "Inhibitory Input");
  1007. return InhSynPot;
  1008. } break;
  1009. case csimInputChannel_NMDA_AMPA: {
  1010. Dout(dc::layer, "Linking Input");
  1011. return LinkSynPot;
  1012. } break;
  1013. default:
  1014. return Input;
  1015. }
  1016. return 0;
  1017. }
  1018. izh4layer::~izh4layer()
  1019. {
  1020. delete[] LinkSynPot;
  1021. }
  1022. int izh4layer::proceede(int TotalTime)
  1023. {
  1024. // Dout(dc::layer, "izh4layer::proceede");fflush(stdout);
  1025. int t = TotalTime % MacroTimeStep;
  1026. int i,j,k;
  1027. last_N_firings = N_firings;
  1028. if (BinRec) BinRec->record();
  1029. for (i=0;i<N;i++)
  1030. {
  1031. Input[i] += abs(gsl_ran_gaussian(gslr, NoiseSigma));
  1032. Input[i] *= 1+LinkSynPot[i];
  1033. ExSynPot[i] += InputSaturation*Input[i]/(Input[i] + 1);
  1034. v[i] +=dt*((0.04*v[i]+F)*v[i]+E-u[i]+ExSynPot[i]-InhSynPot[i]*(v[i]-InhReversePot));
  1035. u[i] +=dt*A*(B*v[i]-u[i]);
  1036. if (v[i]>=30) // did it fire?
  1037. {
  1038. // Dout(dc::layer, N_firings << "spike"); fflush(stdout);
  1039. v[i] = C; // voltage reset
  1040. u[i]+= D; // recovery variable reset
  1041. firings[N_firings ][0]=t;
  1042. firings[N_firings++][1]=i;
  1043. if (N_firings == N_firings_max) {
  1044. ThrowTooManySpikes(t);
  1045. }
  1046. }
  1047. }
  1048. for (i=0;i<N;i++)
  1049. {
  1050. Input[i] = 0; // reset input
  1051. ExSynPot[i] *= TauSfac; // decay the input potential
  1052. InhSynPot[i] *= TauInhFac; // decay inhibitory input potential
  1053. LinkSynPot[i] *= TauLinkFac;
  1054. }
  1055. // Dout(dc::layer, "izh4layer::proceede___feddisch");fflush(stdout);
  1056. }
  1057. //////////////////////////////////////////
  1058. ////////////////////////////////////////
  1059. izh5layer::izh5layer(int n, float a, float b, float c, float d, float e, float f, float _InputSat, float IRPotDiff, float _InhInputSat): izhlayer(n,a,b,c,d,e,f,_InputSat, _InhInputSat)
  1060. {
  1061. InhReversePot = EquilibriumPot-IRPotDiff; // default: Ruhepot - 10 mV
  1062. }
  1063. izh5layer::izh5layer (int n, IzhParas _paras, float _InputSat, float IRPotDiff, float _InhInputSat): izhlayer(n,_paras, _InputSat,_InhInputSat)
  1064. {
  1065. SetNoiseSigma(_paras.sigma);
  1066. InhReversePot = EquilibriumPot-IRPotDiff; // default: Ruhepot - 10 mV
  1067. }
  1068. izh5layer::~izh5layer()
  1069. {
  1070. }
  1071. float* izh5layer::GetInputPointer(csimInputChannel InputNumber)
  1072. {
  1073. switch (InputNumber) {
  1074. case csimInputChannel_AMPA: {
  1075. Dout(dc::layer, "Excitatory Input");
  1076. return ExSynPot;
  1077. } break;
  1078. case csimInputChannel_GABAa: {
  1079. Dout(dc::layer, "Inhibitory Input");
  1080. return InhSynPot;
  1081. } break;
  1082. default:
  1083. return ExSynPot;
  1084. }
  1085. return 0;
  1086. }
  1087. int izh5layer::proceede(int TotalTime)
  1088. {
  1089. // Dout(dc::layer, "izh5layer::proceede");fflush(stdout);
  1090. int t = TotalTime % MacroTimeStep;
  1091. int i,j,k;
  1092. // for (int i=1;i<=nris;++i) Input[getrandom(N)]= RandomInputStrength; // random thalamic input
  1093. // if (getrandom(1000)< RestProb) Input[getrandom(N)]= RandomInputStrength; // random thalamic input
  1094. last_N_firings = N_firings;
  1095. int RecNum=52;
  1096. float tmp=0;
  1097. // if (rec != 0) rec->record(dt*TotalTime, u[RecNum], Input[RecNum]);
  1098. if (BinRec) BinRec->record();
  1099. for (i=0;i<N;i++)
  1100. {
  1101. ExSynPot[i] += abs(gsl_ran_gaussian(gslr, NoiseSigma));
  1102. // InhSynPot[i] += abs(gsl_ran_gaussian(gslr, NoiseSigma));
  1103. v[i] +=dt*((0.04*v[i]+F)*v[i]+E-u[i]
  1104. + InputSaturation*ExSynPot[i]/(ExSynPot[i]+1)
  1105. - (v[i]-InhReversePot)*InhInputSaturation*InhSynPot[i]/(InhSynPot[i]+1));
  1106. u[i] += dt*A*(B*v[i]-u[i]);
  1107. if (v[i]>=30) // did it fire?
  1108. {
  1109. // Dout(dc::layer, N_firings << "spike"); fflush(stdout);
  1110. v[i] = C; // voltage reset
  1111. u[i]+= D; // recovery variable reset
  1112. firings[N_firings ][0]=t;
  1113. firings[N_firings++][1]=i;
  1114. if (N_firings == N_firings_max) {
  1115. ThrowTooManySpikes(t);
  1116. }
  1117. }
  1118. }
  1119. for (i=0;i<N;i++)
  1120. {
  1121. ExSynPot[i] *= TauSfac; // decay the input potential
  1122. InhSynPot[i] *= TauInhFac; // decay inhibitory input potential
  1123. }
  1124. // Dout(dc::layer, "izh5layer::proceede___feddisch");fflush(stdout);
  1125. }
  1126. //////////////////////////////////////////
  1127. izh6layer::izh6layer (int n, IzhParas _paras, float _InputSat, float IRPotDiff, float _InhInputSat, float _NmdaSaturation): izhlayer(n,_paras, _InputSat,_InhInputSat), NmdaSaturation(_NmdaSaturation)
  1128. {
  1129. SetNoiseSigma(_paras.sigma);
  1130. InhReversePot = EquilibriumPot-IRPotDiff; // default: Ruhepot - 10 mV
  1131. NmdaSynPot = new float [N];
  1132. for (int i=0;i<N;++i) NmdaSynPot[i]=0;
  1133. SetTauNmda(100);
  1134. SetNmdaAmpaRatio(0.1);
  1135. }
  1136. izh6layer::~izh6layer()
  1137. {
  1138. delete[] NmdaSynPot;
  1139. }
  1140. float* izh6layer::GetInputPointer(csimInputChannel InputNumber)
  1141. {
  1142. switch (InputNumber) {
  1143. case csimInputChannel_AMPA: {
  1144. Dout(dc::layer, "Excitatory Input");
  1145. return ExSynPot;
  1146. } break;
  1147. case csimInputChannel_GABAa: {
  1148. Dout(dc::layer, "Inhibitory Input");
  1149. return InhSynPot;
  1150. } break;
  1151. case csimInputChannel_NMDA_AMPA: {
  1152. Dout(dc::layer, "Mixed: Excitatory and NMDA-Input");
  1153. return Input;
  1154. } break;
  1155. default:
  1156. return ExSynPot;
  1157. }
  1158. return 0;
  1159. }
  1160. int izh6layer::proceede(int TotalTime)
  1161. {
  1162. // Dout(dc::layer, "izh6layer::proceede");fflush(stdout);
  1163. int t = TotalTime % MacroTimeStep;
  1164. int i,j,k;
  1165. // for (int i=1;i<=nris;++i) Input[getrandom(N)]= RandomInputStrength; // random thalamic input
  1166. // if (getrandom(1000)< RestProb) Input[getrandom(N)]= RandomInputStrength; // random thalamic input
  1167. last_N_firings = N_firings;
  1168. int RecNum=52;
  1169. float tmp=0;
  1170. // if (rec != 0) rec->record(dt*TotalTime, u[RecNum], Input[RecNum]);
  1171. if (BinRec) BinRec->record();
  1172. for (i=0;i<N;i++)
  1173. {
  1174. ExSynPot[i] += Input[i];
  1175. NmdaSynPot[i] += NmdaAmpaRatio*Input[i];
  1176. ExSynPot[i] += abs(gsl_ran_gaussian(gslr, NoiseSigma));
  1177. // InhSynPot[i] += abs(gsl_ran_gaussian(gslr, NoiseSigma));
  1178. v[i] +=dt*((0.04*v[i]+F)*v[i]+E-u[i]
  1179. + InputSaturation*ExSynPot[i]/(ExSynPot[i]+1)
  1180. + NmdaSaturation*INmda(v[i])*NmdaSynPot[i]/(NmdaSynPot[i]+1)
  1181. - (v[i]-InhReversePot)*InhInputSaturation*InhSynPot[i]/(InhSynPot[i]+1));
  1182. u[i] += dt*A*(B*v[i]-u[i]);
  1183. if (v[i]>=30) // did it fire?
  1184. {
  1185. // Dout(dc::layer, N_firings << "spike"); fflush(stdout);
  1186. v[i] = C; // voltage reset
  1187. u[i]+= D; // recovery variable reset
  1188. firings[N_firings ][0]=t;
  1189. firings[N_firings++][1]=i;
  1190. if (N_firings == N_firings_max) {
  1191. ThrowTooManySpikes(t);
  1192. }
  1193. }
  1194. }
  1195. for (i=0;i<N;i++)
  1196. {
  1197. Input[i] = 0; // reset input
  1198. ExSynPot[i] *= TauSfac; // decay the input potential
  1199. NmdaSynPot[i] *= TauNmdaFac; // decay the input potential
  1200. InhSynPot[i] *= TauInhFac; // decay inhibitory input potential
  1201. }
  1202. // Dout(dc::layer, "izh6layer::proceede___feddisch");fflush(stdout);
  1203. }
  1204. void izh6layer::SetNmdaAmpaRatio(float ratio)
  1205. {
  1206. NmdaAmpaRatio = ratio;
  1207. }
  1208. void izh6layer::SetTauNmda(float value)
  1209. {
  1210. TauNmda=value;
  1211. TauNmdaFac = exp(-dt/TauNmda);
  1212. }
  1213. int izh6layer::WriteSimInfo(fstream &fw)
  1214. {
  1215. fw << "<" << seTypeString << " id=\"" << IdNumber << "\" Type=\"" << seType << "\" Name=\"" << Name << "\"> \n";
  1216. fw << "<LayerType value=\"" << "Izhikevich6" << "\"/> \n";
  1217. fw << "<LayerDimensions N=\"" << N << "\" Nx=\"" << Nx << "\" Ny=\"" << Ny << "\"/> \n";
  1218. fw << "<NormPos value=\"" << NormPos << "\"/> \n";
  1219. fw << "<Dmax value=\"" << Dmax << "\"/> \n";
  1220. fw << "<InputSaturation ex=\"" << InputSaturation << " \" inh=\"" << InhInputSaturation << " \" nmda=\"" << NmdaSaturation << "\"/> \n";
  1221. fw << "<EquilibriumPot value=\"" << EquilibriumPot << "\"/> \n";
  1222. fw << "</" << seTypeString << "> \n";
  1223. }
  1224. int izh6layer::StartBinRec(int nobserve, int NNumber)
  1225. {
  1226. int NumObserve = 4*nobserve;
  1227. float** Buffer = new float* [NumObserve];
  1228. for (int i=0;i<nobserve; ++i) Buffer[i] = &(v[i+NNumber]);
  1229. for (int i=0;i<nobserve; ++i) Buffer[i+nobserve] = &(ExSynPot[i+NNumber]);
  1230. for (int i=0;i<nobserve; ++i) Buffer[i+2*nobserve] = &(NmdaSynPot[i+NNumber]);
  1231. // for (int i=0;i<nobserve; ++i) Buffer[i+2*nobserve] = &(Input[i]);
  1232. for (int i=0;i<nobserve; ++i) Buffer[i+3*nobserve] = &(InhSynPot[i+NNumber]);
  1233. string FileName(MemPotFileName);
  1234. BinRec = new BinRecorder(MacroTimeStep, NumObserve, nobserve, Buffer, dt, (DataDirectory+FileName).c_str());
  1235. }
  1236. //////////////////////////////////////////
  1237. izh7layer::izh7layer (int n, IzhParas _paras, float _InputSat, float IRPotDiff, float _InhInputSat, float _NmdaSaturation)
  1238. :izhlayer(n,_paras, _InputSat,_InhInputSat), NmdaSaturation(_NmdaSaturation),
  1239. TauAmpaRise(0.5), TauAmpaFall(2.4),
  1240. TauGabaRise(1.0), TauGabaFall(7.0),
  1241. TauNmdaRise(5.5), TauNmdaFall(100)
  1242. {
  1243. SetNoiseSigma(_paras.sigma); // 0.00233 -> 3Hz f�r IzhIntegrator
  1244. InhReversePot = EquilibriumPot-IRPotDiff; // default: Ruhepot - 10 mV
  1245. Dout(dc::layer, "izh7layer::izh7layer");
  1246. // use arrays from izhlayer
  1247. AmpaFallPot = ExSynPot;
  1248. GabaFallPot = InhSynPot;
  1249. NmdaRisePot = new float [N];
  1250. NmdaFallPot = new float [N];
  1251. AmpaRisePot = new float [N];
  1252. GabaRisePot = new float [N];
  1253. InhInput = new float [N];
  1254. NmdaAmpaInput = new float [N];
  1255. // initialize arrays with zero
  1256. for (int i=0;i<N;++i) {
  1257. NmdaRisePot[i]=0;
  1258. NmdaFallPot[i]=0;
  1259. AmpaRisePot[i]=0;
  1260. GabaRisePot[i]=0;
  1261. InhInput[i]=0;
  1262. NmdaAmpaInput[i]=0;
  1263. }
  1264. SetTauNmda(TauNmdaRise, TauNmdaFall);
  1265. SetTauGaba(TauGabaRise, TauGabaFall);
  1266. SetTauAmpa(TauAmpaRise, TauAmpaFall);
  1267. SetNmdaAmpaRatio(0.1);
  1268. }
  1269. izh7layer::~izh7layer()
  1270. {
  1271. delete[] NmdaRisePot;
  1272. delete[] NmdaFallPot;
  1273. delete[] AmpaRisePot;
  1274. delete[] GabaRisePot;
  1275. delete[] InhInput;
  1276. delete[] NmdaAmpaInput;
  1277. }
  1278. float* izh7layer::GetInputPointer(csimInputChannel InputNumber)
  1279. {
  1280. switch (InputNumber) {
  1281. case csimInputChannel_AMPA: {
  1282. Dout(dc::layer, "Excitatory Input");
  1283. return Input;
  1284. } break;
  1285. case csimInputChannel_GABAa: {
  1286. Dout(dc::layer, "Inhibitory Input");
  1287. return InhInput;
  1288. } break;
  1289. case csimInputChannel_NMDA_AMPA: {
  1290. Dout(dc::layer, "Mixed: Excitatory and NMDA-Input");
  1291. return NmdaAmpaInput;
  1292. } break;
  1293. default:
  1294. return Input;
  1295. }
  1296. return 0;
  1297. }
  1298. int izh7layer::proceede(int TotalTime)
  1299. {
  1300. // Dout(dc::layer, "izh7layer::proceede");fflush(stdout);
  1301. int t = TotalTime % MacroTimeStep;
  1302. int i,j,k;
  1303. // for (int i=1;i<=nris;++i) Input[getrandom(N)]= RandomInputStrength; // random thalamic input
  1304. // if (getrandom(1000)< RestProb) Input[getrandom(N)]= RandomInputStrength; // random thalamic input
  1305. last_N_firings = N_firings;
  1306. int RecNum=52;
  1307. float tmp=0;
  1308. // if (rec != 0) rec->record(dt*TotalTime, u[RecNum], Input[RecNum]);
  1309. if (BinRec) BinRec->record();
  1310. for (i=0;i<N;i++)
  1311. {
  1312. Input[i] += abs(gsl_ran_gaussian(gslr, NoiseSigma));
  1313. // Input[i] += NoiseSigma*gsl_ran_poisson(gslr, PoissonLambda);
  1314. Input[i] += NmdaAmpaInput[i];
  1315. Input[i] *= AmpaCorr;
  1316. InhInput[i] *= GabaCorr;
  1317. NmdaAmpaInput[i] *= NmdaCorr;
  1318. AmpaRisePot[i] += Input[i];
  1319. AmpaFallPot[i] += Input[i];
  1320. NmdaRisePot[i] += NmdaAmpaRatio*NmdaAmpaInput[i];
  1321. NmdaFallPot[i] += NmdaAmpaRatio*NmdaAmpaInput[i];
  1322. GabaRisePot[i] += InhInput[i];
  1323. GabaFallPot[i] += InhInput[i];
  1324. // InhSynPot[i] += abs(gsl_ran_gaussian(gslr, NoiseSigma));
  1325. float Ampa = AmpaFallPot[i] - AmpaRisePot[i];
  1326. float Nmda = NmdaFallPot[i] - NmdaRisePot[i];
  1327. float Gaba = GabaFallPot[i] - GabaRisePot[i];
  1328. v[i] +=dt*((0.04*v[i]+F)*v[i]+E-u[i]
  1329. + InputSaturation*Ampa/(Ampa+1)
  1330. + NmdaSaturation*INmda(v[i])*Nmda/(Nmda+1)
  1331. - (v[i]-InhReversePot)*InhInputSaturation*Gaba/(Gaba+1));
  1332. u[i] += dt*A*(B*v[i]-u[i]);
  1333. if (v[i]>=30) // did it fire?
  1334. {
  1335. // Dout(dc::layer, N_firings << "spike"); fflush(stdout);
  1336. v[i] = C; // voltage reset
  1337. u[i]+= D; // recovery variable reset
  1338. firings[N_firings ][0]=t;
  1339. firings[N_firings++][1]=i;
  1340. if (N_firings == N_firings_max) {
  1341. ThrowTooManySpikes(t);
  1342. }
  1343. }
  1344. }
  1345. for (i=0;i<N;i++)
  1346. {
  1347. Input[i] = 0; // reset input
  1348. InhInput[i]=0;
  1349. NmdaAmpaInput[i]=0;
  1350. // decay synaptic potentials
  1351. NmdaRisePot[i] *= TauNmdaRiseFac;
  1352. NmdaFallPot[i] *= TauNmdaFallFac;
  1353. AmpaRisePot[i] *= TauAmpaRiseFac;
  1354. AmpaFallPot[i] *= TauAmpaFallFac;
  1355. GabaRisePot[i] *= TauGabaRiseFac;
  1356. GabaFallPot[i] *= TauGabaFallFac;
  1357. }
  1358. // Dout(dc::layer, "izh7layer::proceede___feddisch");fflush(stdout);
  1359. }
  1360. void izh7layer::SetNmdaAmpaRatio(float ratio)
  1361. {
  1362. NmdaAmpaRatio = ratio;
  1363. }
  1364. void izh7layer::SetTauNmda(float rise, float fall)
  1365. {
  1366. TauNmdaRise = rise;
  1367. TauNmdaFall = fall;
  1368. TauNmdaRiseFac = exp(-dt/TauNmdaRise);
  1369. TauNmdaFallFac = exp(-dt/TauNmdaFall);
  1370. NmdaCorr = DoubleExpCorrectionFactor(TauNmdaRise, TauNmdaFall);
  1371. }
  1372. void izh7layer::SetTauAmpa(float rise, float fall)
  1373. {
  1374. TauAmpaRise = rise;
  1375. TauAmpaFall = fall;
  1376. TauAmpaRiseFac = exp(-dt/TauAmpaRise);
  1377. TauAmpaFallFac = exp(-dt/TauAmpaFall);
  1378. AmpaCorr = DoubleExpCorrectionFactor(TauAmpaRise, TauAmpaFall);
  1379. }
  1380. void izh7layer::SetTauGaba(float rise, float fall)
  1381. {
  1382. TauGabaRise = rise;
  1383. TauGabaFall = fall;
  1384. TauGabaRiseFac = exp(-dt/TauGabaRise);
  1385. TauGabaFallFac = exp(-dt/TauGabaFall);
  1386. GabaCorr = DoubleExpCorrectionFactor(TauGabaRise, TauGabaFall);
  1387. }
  1388. int izh7layer::WriteSimInfo(fstream &fw)
  1389. {
  1390. stringstream sstr;
  1391. sstr << "<LayerType value=\"" << "Izhikevich7" << "\"/> \n";
  1392. sstr << "<InputSaturation ex=\"" << InputSaturation << " \" inh=\"" << InhInputSaturation << " \" nmda=\"" << NmdaSaturation << "\"/> \n";
  1393. sstr << "<EquilibriumPot value=\"" << EquilibriumPot << "\"/> \n";
  1394. layer::WriteSimInfo(fw, sstr.str());
  1395. }
  1396. int izh7layer::StartBinRec(int nobserve, int NNumber)
  1397. {
  1398. int NumObserve = 7*nobserve;
  1399. float** Buffer = new float* [NumObserve];
  1400. for (int i=0;i<nobserve; ++i) Buffer[i] = &(v[i+NNumber]);
  1401. for (int i=0;i<nobserve; ++i) Buffer[i+nobserve] = &(AmpaRisePot[i+NNumber]);
  1402. for (int i=0;i<nobserve; ++i) Buffer[i+2*nobserve] = &(AmpaFallPot[i+NNumber]);
  1403. for (int i=0;i<nobserve; ++i) Buffer[i+3*nobserve] = &(GabaRisePot[i+NNumber]);
  1404. for (int i=0;i<nobserve; ++i) Buffer[i+4*nobserve] = &(GabaFallPot[i+NNumber]);
  1405. for (int i=0;i<nobserve; ++i) Buffer[i+5*nobserve] = &(NmdaRisePot[i+NNumber]);
  1406. for (int i=0;i<nobserve; ++i) Buffer[i+6*nobserve] = &(NmdaFallPot[i+NNumber]);
  1407. string FileName(MemPotFileName);
  1408. BinRec = new BinRecorder(MacroTimeStep, NumObserve, nobserve, Buffer, dt, (DataDirectory+FileName).c_str());
  1409. }
  1410. /////////////////////////////////////////
  1411. izh8layer::izh8layer (int n, IzhParas _paras, float IRPotDiff)
  1412. :izhlayer(n,_paras),
  1413. TauAmpaRise(0.5), TauAmpaFall(2.4),
  1414. TauGabaRise(1.0), TauGabaFall(7.0),
  1415. TauNmdaRise(5.5), TauNmdaFall(100)
  1416. {
  1417. SetNoiseSigma(_paras.sigma); // 0.00233 -> 3Hz f�r IzhIntegrator
  1418. InhReversePot = EquilibriumPot-IRPotDiff; // default: Ruhepot - 10 mV
  1419. Dout(dc::layer, "izh8layer::izh8layer");
  1420. // use arrays from izhlayer
  1421. AmpaPot = ExSynPot;
  1422. GabaFallPot = InhSynPot;
  1423. NmdaRisePot = new float [N];
  1424. NmdaFallPot = new float [N];
  1425. AmpaRisePot = new float [N];
  1426. AmpaFallPot = new float [N];
  1427. GabaRisePot = new float [N];
  1428. InhInput = new float [N];
  1429. NmdaAmpaInput = new float [N];
  1430. // initialize arrays with zero
  1431. for (int i=0;i<N;++i) {
  1432. NmdaRisePot[i]=0;
  1433. NmdaFallPot[i]=0;
  1434. AmpaRisePot[i]=0;
  1435. AmpaFallPot[i]=0;
  1436. GabaRisePot[i]=0;
  1437. InhInput[i]=0;
  1438. NmdaAmpaInput[i]=0;
  1439. }
  1440. SetTauNmda(TauNmdaRise, TauNmdaFall);
  1441. SetTauGaba(TauGabaRise, TauGabaFall);
  1442. SetTauAmpa(TauAmpaRise, TauAmpaFall);
  1443. SetNmdaAmpaRatio(0.1);
  1444. }
  1445. izh8layer::~izh8layer()
  1446. {
  1447. delete[] NmdaRisePot;
  1448. delete[] NmdaFallPot;
  1449. delete[] AmpaRisePot;
  1450. delete[] AmpaFallPot;
  1451. delete[] GabaRisePot;
  1452. delete[] InhInput;
  1453. delete[] NmdaAmpaInput;
  1454. }
  1455. float* izh8layer::GetInputPointer(csimInputChannel InputNumber)
  1456. {
  1457. switch (InputNumber) {
  1458. case csimInputChannel_AMPA: {
  1459. Dout(dc::layer, "Excitatory Input");
  1460. return Input;
  1461. } break;
  1462. case csimInputChannel_GABAa: {
  1463. Dout(dc::layer, "Inhibitory Input");
  1464. return InhInput;
  1465. } break;
  1466. case csimInputChannel_NMDA_AMPA: {
  1467. Dout(dc::layer, "Mixed: Excitatory and NMDA-Input");
  1468. return NmdaAmpaInput;
  1469. } break;
  1470. default:
  1471. return Input;
  1472. }
  1473. return 0;
  1474. }
  1475. float* izh8layer::GetPspPointer(csimInputChannel InputNumber)
  1476. {
  1477. switch (InputNumber) {
  1478. case csimInputChannel_AMPA: {
  1479. Dout(dc::layer, "Excitatory Input");
  1480. return AmpaPot;
  1481. } break;
  1482. default:
  1483. return AmpaPot;
  1484. }
  1485. return 0;
  1486. }
  1487. int izh8layer::proceede(int TotalTime)
  1488. {
  1489. // Dout(dc::layer, "izh8layer::proceede");fflush(stdout);
  1490. int t = TotalTime % MacroTimeStep;
  1491. int i,j,k;
  1492. last_N_firings = N_firings;
  1493. if (BinRec) BinRec->record();
  1494. for (i=0;i<N;i++)
  1495. {
  1496. // Input[i] += abs(gsl_ran_gaussian(gslr, NoiseSigma));
  1497. Input[i] += NoiseAmplitude*gsl_ran_poisson(gslr, PoissonLambda);
  1498. Input[i] += NmdaAmpaInput[i];
  1499. Input[i] *= AmpaCorr;
  1500. InhInput[i] *= GabaCorr;
  1501. NmdaAmpaInput[i] *= NmdaCorr;
  1502. AmpaRisePot[i] += Input[i];
  1503. AmpaFallPot[i] += Input[i];
  1504. NmdaRisePot[i] += NmdaAmpaRatio*NmdaAmpaInput[i];
  1505. NmdaFallPot[i] += NmdaAmpaRatio*NmdaAmpaInput[i];
  1506. GabaRisePot[i] += InhInput[i];
  1507. GabaFallPot[i] += InhInput[i];
  1508. // InhSynPot[i] += abs(gsl_ran_gaussian(gslr, NoiseSigma));
  1509. AmpaPot[i] = AmpaFallPot[i] - AmpaRisePot[i];
  1510. float Nmda = NmdaFallPot[i] - NmdaRisePot[i];
  1511. float Gaba = GabaFallPot[i] - GabaRisePot[i];
  1512. v[i] +=dt*((0.04*v[i]+F)*v[i]+E-u[i]
  1513. + AmpaPot[i]
  1514. + INmda(v[i])*Nmda
  1515. - (v[i]-InhReversePot)*(Gaba+BalancedInhibition));
  1516. u[i] += dt*A*(B*v[i]-u[i]);
  1517. if (v[i]>=30) // did it fire?
  1518. {
  1519. // Dout(dc::layer, N_firings << "spike"); fflush(stdout);
  1520. v[i] = C; // voltage reset
  1521. u[i]+= D; // recovery variable reset
  1522. firings[N_firings ][0]=t;
  1523. firings[N_firings++][1]=i;
  1524. if (N_firings == N_firings_max) {
  1525. ThrowTooManySpikes(t);
  1526. }
  1527. }
  1528. }
  1529. for (i=0;i<N;i++)
  1530. {
  1531. Input[i] = 0; // reset input
  1532. InhInput[i]=0;
  1533. NmdaAmpaInput[i]=0;
  1534. // decay synaptic potentials
  1535. NmdaRisePot[i] *= TauNmdaRiseFac;
  1536. NmdaFallPot[i] *= TauNmdaFallFac;
  1537. AmpaRisePot[i] *= TauAmpaRiseFac;
  1538. AmpaFallPot[i] *= TauAmpaFallFac;
  1539. GabaRisePot[i] *= TauGabaRiseFac;
  1540. GabaFallPot[i] *= TauGabaFallFac;
  1541. }
  1542. // Dout(dc::layer, "izh8layer::proceede___feddisch");fflush(stdout);
  1543. }
  1544. void izh8layer::SetNmdaAmpaRatio(float ratio)
  1545. {
  1546. NmdaAmpaRatio = ratio;
  1547. }
  1548. void izh8layer::SetTauNmda(float rise, float fall)
  1549. {
  1550. TauNmdaRise = rise;
  1551. TauNmdaFall = fall;
  1552. TauNmdaRiseFac = exp(-dt/TauNmdaRise);
  1553. TauNmdaFallFac = exp(-dt/TauNmdaFall);
  1554. NmdaCorr = DoubleExpCorrectionFactor(TauNmdaRise, TauNmdaFall);
  1555. }
  1556. void izh8layer::SetTauAmpa(float rise, float fall)
  1557. {
  1558. TauAmpaRise = rise;
  1559. TauAmpaFall = fall;
  1560. TauAmpaRiseFac = exp(-dt/TauAmpaRise);
  1561. TauAmpaFallFac = exp(-dt/TauAmpaFall);
  1562. AmpaCorr = DoubleExpCorrectionFactor(TauAmpaRise, TauAmpaFall);
  1563. }
  1564. void izh8layer::SetTauGaba(float rise, float fall)
  1565. {
  1566. TauGabaRise = rise;
  1567. TauGabaFall = fall;
  1568. TauGabaRiseFac = exp(-dt/TauGabaRise);
  1569. TauGabaFallFac = exp(-dt/TauGabaFall);
  1570. GabaCorr = DoubleExpCorrectionFactor(TauGabaRise, TauGabaFall);
  1571. }
  1572. int izh8layer::WriteSimInfo(fstream &fw)
  1573. {
  1574. stringstream sstr;
  1575. sstr << "<LayerType value=\"" << "Izhikevich8" << "\"/> \n";
  1576. sstr << "<NoiseAmplitude value=\"" << NoiseAmplitude << "\"/> \n";
  1577. sstr << "<BalancedInhibition value=\"" << BalancedInhibition << "\"/> \n";
  1578. sstr << "<TauAmpa "
  1579. << "Rise=\"" << TauAmpaRise << "\" "
  1580. << "Fall=\"" << TauAmpaFall << "\" "
  1581. << "/> \n";
  1582. sstr << "<TauGaba "
  1583. << "Rise=\"" << TauGabaRise << "\" "
  1584. << "Fall=\"" << TauGabaFall << "\" "
  1585. << "/> \n";
  1586. sstr << "<TauNmda "
  1587. << "Rise=\"" << TauNmdaRise << "\" "
  1588. << "Fall=\"" << TauNmdaFall << "\" "
  1589. << "/> \n";
  1590. izhlayer::WriteSimInfo(fw, sstr.str());
  1591. }
  1592. int izh8layer::StartBinRec(int nobserve, int NNumber)
  1593. {
  1594. int NumObserve = 7*nobserve;
  1595. float** Buffer = new float* [NumObserve];
  1596. for (int i=0;i<nobserve; ++i) Buffer[i] = &(v[i+NNumber]);
  1597. for (int i=0;i<nobserve; ++i) Buffer[i+nobserve] = &(AmpaRisePot[i+NNumber]);
  1598. for (int i=0;i<nobserve; ++i) Buffer[i+2*nobserve] = &(AmpaFallPot[i+NNumber]);
  1599. for (int i=0;i<nobserve; ++i) Buffer[i+3*nobserve] = &(GabaRisePot[i+NNumber]);
  1600. for (int i=0;i<nobserve; ++i) Buffer[i+4*nobserve] = &(GabaFallPot[i+NNumber]);
  1601. for (int i=0;i<nobserve; ++i) Buffer[i+5*nobserve] = &(NmdaRisePot[i+NNumber]);
  1602. for (int i=0;i<nobserve; ++i) Buffer[i+6*nobserve] = &(NmdaFallPot[i+NNumber]);
  1603. string FileName(MemPotFileName);
  1604. BinRec = new BinRecorder(MacroTimeStep, NumObserve, nobserve, Buffer, dt, (DataDirectory+FileName).c_str());
  1605. }
  1606. /////////////////////////////////////////
  1607. izh9layer::izh9layer(int n, IzhParas _paras, float GabaARPotDiff, float GabaBRPotDiff)
  1608. :izhlayer(n,_paras),
  1609. TauAmpaRise(0.5), TauAmpaFall(2.4),
  1610. TauGabaARise(1.0), TauGabaAFall(7.0),
  1611. TauGabaBRise(13.5), TauGabaBFall(140),
  1612. TauNmdaRise(5.5), TauNmdaFall(100),
  1613. GabaABRatio(0.1)
  1614. {
  1615. SetNoiseSigma(_paras.sigma);
  1616. InhReversePot = EquilibriumPot-GabaARPotDiff; // GabaA
  1617. GabaBReversePot = EquilibriumPot-GabaBRPotDiff; // GabaB
  1618. Dout(dc::layer, "izh9layer::izh9layer");
  1619. // use arrays from izhlayer
  1620. AmpaPot = ExSynPot;
  1621. GabaAFallPot = InhSynPot;
  1622. NmdaRisePot = new float [N];
  1623. NmdaFallPot = new float [N];
  1624. GabaBRisePot = new float [N];
  1625. GabaBFallPot = new float [N];
  1626. AmpaRisePot = new float [N];
  1627. AmpaFallPot = new float [N];
  1628. GabaARisePot = new float [N];
  1629. InhInput = new float [N];
  1630. NmdaAmpaInput = new float [N];
  1631. // initialize arrays with zero
  1632. for (int i=0;i<N;++i) {
  1633. NmdaRisePot[i]=0;
  1634. NmdaFallPot[i]=0;
  1635. GabaBRisePot[i]=0;
  1636. GabaBFallPot[i]=0;
  1637. AmpaRisePot[i]=0;
  1638. AmpaFallPot[i]=0;
  1639. GabaARisePot[i]=0;
  1640. InhInput[i]=0;
  1641. NmdaAmpaInput[i]=0;
  1642. }
  1643. SetTauNmda(TauNmdaRise, TauNmdaFall);
  1644. SetTauGabaA(TauGabaARise, TauGabaAFall);
  1645. SetTauGabaB(TauGabaBRise, TauGabaBFall);
  1646. SetTauAmpa(TauAmpaRise, TauAmpaFall);
  1647. SetNmdaAmpaRatio(0.1);
  1648. }
  1649. izh9layer::~izh9layer()
  1650. {
  1651. delete[] NmdaRisePot;
  1652. delete[] NmdaFallPot;
  1653. delete[] AmpaRisePot;
  1654. delete[] AmpaFallPot;
  1655. delete[] GabaBRisePot;
  1656. delete[] GabaBFallPot;
  1657. delete[] GabaARisePot;
  1658. delete[] InhInput;
  1659. delete[] NmdaAmpaInput;
  1660. }
  1661. float* izh9layer::GetInputPointer(csimInputChannel InputNumber)
  1662. {
  1663. switch (InputNumber) {
  1664. case csimInputChannel_AMPA: {
  1665. Dout(dc::layer, "Excitatory Input");
  1666. return Input;
  1667. } break;
  1668. case csimInputChannel_GABAa: {
  1669. Dout(dc::layer, "Inhibitory Input");
  1670. return InhInput;
  1671. } break;
  1672. case csimInputChannel_NMDA_AMPA: {
  1673. Dout(dc::layer, "Mixed: Excitatory and NMDA-Input");
  1674. return NmdaAmpaInput;
  1675. } break;
  1676. default:
  1677. return Input;
  1678. }
  1679. return 0;
  1680. }
  1681. float* izh9layer::GetPspPointer(csimInputChannel InputNumber)
  1682. {
  1683. switch (InputNumber) {
  1684. case csimInputChannel_AMPA: {
  1685. Dout(dc::layer, "Excitatory Input");
  1686. return AmpaPot;
  1687. } break;
  1688. default:
  1689. return AmpaPot;
  1690. }
  1691. return 0;
  1692. }
  1693. int izh9layer::proceede(int TotalTime)
  1694. {
  1695. // Dout(dc::layer, "izh9layer::proceede");fflush(stdout);
  1696. int t = TotalTime % MacroTimeStep;
  1697. int i,j,k;
  1698. last_N_firings = N_firings;
  1699. if (BinRec) BinRec->record();
  1700. for (i=0;i<N;i++)
  1701. {
  1702. // Input[i] += abs(gsl_ran_gaussian(gslr, NoiseSigma));
  1703. Input[i] += NoiseAmplitude*gsl_ran_poisson(gslr, PoissonLambda);
  1704. Input[i] += NmdaAmpaInput[i];
  1705. Input[i] *= AmpaCorr; // to normalize the amplitude of the ampa epsp
  1706. InhInput[i] *= GabaACorr;
  1707. NmdaAmpaInput[i] *= NmdaCorr;
  1708. AmpaRisePot[i] += Input[i];
  1709. AmpaFallPot[i] += Input[i];
  1710. NmdaRisePot[i] += NmdaAmpaRatio*NmdaAmpaInput[i];
  1711. NmdaFallPot[i] += NmdaAmpaRatio*NmdaAmpaInput[i];
  1712. GabaARisePot[i] += InhInput[i];
  1713. GabaAFallPot[i] += InhInput[i];
  1714. GabaBRisePot[i] +=GabaABRatio*InhInput[i];
  1715. GabaBFallPot[i] += GabaABRatio*InhInput[i];
  1716. // InhSynPot[i] += abs(gsl_ran_gaussian(gslr, NoiseSigma));
  1717. AmpaPot[i] = AmpaFallPot[i] - AmpaRisePot[i];
  1718. float Nmda = NmdaFallPot[i] - NmdaRisePot[i];
  1719. float GabaA = GabaAFallPot[i] - GabaARisePot[i];
  1720. float GabaB = GabaBFallPot[i] - GabaBRisePot[i];
  1721. v[i] +=dt*((0.04*v[i]+F)*v[i]+E-u[i]
  1722. + AmpaPot[i]
  1723. + INmda(v[i])*Nmda
  1724. - (v[i]-InhReversePot)*(GabaA+BalancedInhibition))
  1725. - (v[i]-GabaBReversePot)*GabaB;
  1726. u[i] += dt*A*(B*v[i]-u[i]);
  1727. if (v[i]>=30) // did it fire?
  1728. {
  1729. // Dout(dc::layer, N_firings << "spike"); fflush(stdout);
  1730. v[i] = C; // voltage reset
  1731. u[i]+= D; // recovery variable reset
  1732. firings[N_firings ][0]=t;
  1733. firings[N_firings++][1]=i;
  1734. if (N_firings == N_firings_max) {
  1735. ThrowTooManySpikes(t);
  1736. }
  1737. }
  1738. }
  1739. for (i=0;i<N;i++)
  1740. {
  1741. Input[i] = 0; // reset input
  1742. InhInput[i]=0;
  1743. NmdaAmpaInput[i]=0;
  1744. // decay synaptic potentials
  1745. NmdaRisePot[i] *= TauNmdaRiseFac;
  1746. NmdaFallPot[i] *= TauNmdaFallFac;
  1747. AmpaRisePot[i] *= TauAmpaRiseFac;
  1748. AmpaFallPot[i] *= TauAmpaFallFac;
  1749. GabaARisePot[i] *= TauGabaARiseFac;
  1750. GabaAFallPot[i] *= TauGabaAFallFac;
  1751. GabaBRisePot[i] *= TauGabaBRiseFac;
  1752. GabaBFallPot[i] *= TauGabaBFallFac;
  1753. }
  1754. // Dout(dc::layer, "izh9layer::proceede___feddisch");fflush(stdout);
  1755. }
  1756. void izh9layer::SetNmdaAmpaRatio(float ratio)
  1757. {
  1758. NmdaAmpaRatio = ratio;
  1759. }
  1760. void izh9layer::SetGabaABRatio(float ratio)
  1761. {
  1762. NmdaAmpaRatio = ratio;
  1763. }
  1764. void izh9layer::SetTauNmda(float rise, float fall)
  1765. {
  1766. TauNmdaRise = rise;
  1767. TauNmdaFall = fall;
  1768. TauNmdaRiseFac = exp(-dt/TauNmdaRise);
  1769. TauNmdaFallFac = exp(-dt/TauNmdaFall);
  1770. NmdaCorr = DoubleExpCorrectionFactor(TauNmdaRise, TauNmdaFall);
  1771. }
  1772. void izh9layer::SetTauAmpa(float rise, float fall)
  1773. {
  1774. TauAmpaRise = rise;
  1775. TauAmpaFall = fall;
  1776. TauAmpaRiseFac = exp(-dt/TauAmpaRise);
  1777. TauAmpaFallFac = exp(-dt/TauAmpaFall);
  1778. AmpaCorr = DoubleExpCorrectionFactor(TauAmpaRise, TauAmpaFall);
  1779. }
  1780. void izh9layer::SetTauGabaA(float rise, float fall)
  1781. {
  1782. TauGabaARise = rise;
  1783. TauGabaAFall = fall;
  1784. TauGabaARiseFac = exp(-dt/TauGabaARise);
  1785. TauGabaAFallFac = exp(-dt/TauGabaAFall);
  1786. GabaACorr = DoubleExpCorrectionFactor(TauGabaARise, TauGabaAFall);
  1787. }
  1788. void izh9layer::SetTauGabaB(float rise, float fall)
  1789. {
  1790. TauGabaBRise = rise;
  1791. TauGabaBFall = fall;
  1792. TauGabaBRiseFac = exp(-dt/TauGabaBRise);
  1793. TauGabaBFallFac = exp(-dt/TauGabaBFall);
  1794. GabaBCorr = DoubleExpCorrectionFactor(TauGabaBRise, TauGabaBFall);
  1795. }
  1796. int izh9layer::WriteSimInfo(fstream &fw)
  1797. {
  1798. stringstream sstr;
  1799. sstr << "<LayerType value=\"" << "Izhikevich9" << "\"/> \n";
  1800. sstr << "<NoiseAmplitude value=\"" << NoiseAmplitude << "\"/> \n";
  1801. sstr << "<BalancedInhibition value=\"" << BalancedInhibition << "\"/> \n";
  1802. sstr << "<Ampa "
  1803. << "TauRise=\"" << TauAmpaRise << "\" "
  1804. << "TauFall=\"" << TauAmpaFall << "\" "
  1805. << "/> \n";
  1806. sstr << "<GabaA "
  1807. << "TauRise=\"" << TauGabaARise << "\" "
  1808. << "TauFall=\"" << TauGabaAFall << "\" "
  1809. << "ReversePot=\"" << InhReversePot << "\" "
  1810. << "/> \n";
  1811. sstr << "<GabaB "
  1812. << "TauRise=\"" << TauGabaBRise << "\" "
  1813. << "TauFall=\"" << TauGabaBFall << "\" "
  1814. << "ReversePot=\"" << GabaBReversePot << "\" "
  1815. << "/> \n";
  1816. sstr << "<Nmda "
  1817. << "TauRise=\"" << TauNmdaRise << "\" "
  1818. << "TauFall=\"" << TauNmdaFall << "\" "
  1819. << "/> \n";
  1820. izhlayer::WriteSimInfo(fw, sstr.str());
  1821. }
  1822. int izh9layer::StartBinRec(int nobserve, int NNumber)
  1823. {
  1824. int NumObserve = 9*nobserve;
  1825. float** Buffer = new float* [NumObserve];
  1826. for (int i=0;i<nobserve; ++i) Buffer[i] = &(v[i+NNumber]);
  1827. for (int i=0;i<nobserve; ++i) Buffer[i+nobserve] = &(AmpaRisePot[i+NNumber]);
  1828. for (int i=0;i<nobserve; ++i) Buffer[i+2*nobserve] = &(AmpaFallPot[i+NNumber]);
  1829. for (int i=0;i<nobserve; ++i) Buffer[i+3*nobserve] = &(GabaARisePot[i+NNumber]);
  1830. for (int i=0;i<nobserve; ++i) Buffer[i+4*nobserve] = &(GabaAFallPot[i+NNumber]);
  1831. for (int i=0;i<nobserve; ++i) Buffer[i+5*nobserve] = &(NmdaRisePot[i+NNumber]);
  1832. for (int i=0;i<nobserve; ++i) Buffer[i+6*nobserve] = &(NmdaFallPot[i+NNumber]);
  1833. for (int i=0;i<nobserve; ++i) Buffer[i+7*nobserve] = &(GabaBRisePot[i+NNumber]);
  1834. for (int i=0;i<nobserve; ++i) Buffer[i+8*nobserve] = &(GabaBFallPot[i+NNumber]);
  1835. string FileName(MemPotFileName);
  1836. BinRec = new BinRecorder(MacroTimeStep, NumObserve, nobserve, Buffer, dt, (DataDirectory+FileName).c_str());
  1837. }
  1838. /////////////////////////////////////////
  1839. izhshuntlayer::izhshuntlayer(
  1840. int n, IzhParas _izparas, LevyShuntingParas _shuntparas,
  1841. float _InputSat, float _NoiseSigma)
  1842. :izhlayer(n, _izparas, _InputSat),
  1843. NoiseSigma(_NoiseSigma), inh(_shuntparas)
  1844. {
  1845. int i;
  1846. Dout(dc::layer, "IzhShuntLayer Constructor");
  1847. Dout(dc::layer, "InputSaturation = " << InputSaturation << "");
  1848. Input1 = new float[N];
  1849. for (i=0;i<N;++i) Input1[i]=0;
  1850. InhibitionDelay = int(1./dt); // 1 milli second
  1851. Dout(dc::layer, "InhibitionDelay=" << InhibitionDelay << " TimeSteps ");
  1852. mquer = new float [MacroTimeStep + InhibitionDelay + 1];
  1853. squer = new float [MacroTimeStep + InhibitionDelay + 1];
  1854. for (i=0; i<(MacroTimeStep+InhibitionDelay+1); ++i) {
  1855. mquer[i]=0;
  1856. squer[i]=0;
  1857. }
  1858. RunAvgFac = exp(-dt/2.0);
  1859. Dout(dc::layer, "RunAvgFac=" << RunAvgFac << "");
  1860. }
  1861. izhshuntlayer::~izhshuntlayer()
  1862. {
  1863. delete[] Input1;
  1864. delete[] mquer;
  1865. delete[] squer;
  1866. }
  1867. int izhshuntlayer::proceede(int TotalTime)
  1868. {
  1869. int t = TotalTime % MacroTimeStep;
  1870. int i,j,k;
  1871. float CurInput;
  1872. float tmpinp;
  1873. for (int i=1;i<=nris;++i) Input[getrandom(N)]= RandomInputStrength; // random thalamic input
  1874. if (getrandom(1000)< RestProb) Input[getrandom(N)]= RandomInputStrength; // random thalamic input
  1875. last_N_firings = N_firings;
  1876. Iinh = inh.K0+inh.Kffi*squer[t]+inh.Kfbi*mquer[t];
  1877. for (i=0;i<N;i++)
  1878. {
  1879. // ExSynPot[i] += InputSaturation*Input[i]/(Input[i] + 1 + InhSynPot[i]);
  1880. CurInput = inh.K1*Input[i] + inh.K2*Input1[i] + abs(gsl_ran_gaussian(gslr, NoiseSigma));
  1881. tmpinp = InputSaturation*CurInput/(CurInput + Iinh);
  1882. if ((i==10) && (rec != 0)) rec->record(dt*TotalTime, v[i], Iinh);
  1883. squer[t+InhibitionDelay] += dt*Input[i]; // running average of external input
  1884. v[i] +=dt*((0.04*v[i]+F)*v[i]+E-u[i]+ tmpinp);
  1885. u[i] +=A*(B*v[i]-u[i]);
  1886. if (v[i]>=30) // did it fire?
  1887. {
  1888. v[i] = C; // voltage reset
  1889. u[i]+= D; // recovery variable reset
  1890. firings[N_firings ][0]=t;
  1891. firings[N_firings++][1]=i;
  1892. mquer[t+InhibitionDelay] += 1; // running average of layer activity
  1893. if (N_firings == N_firings_max) {
  1894. ThrowTooManySpikes(t);
  1895. }
  1896. }
  1897. }
  1898. mquer[t+InhibitionDelay+1] = mquer[t+InhibitionDelay]*RunAvgFac;
  1899. squer[t+InhibitionDelay+1] = squer[t+InhibitionDelay]*RunAvgFac;
  1900. for (i=0;i<N;i++)
  1901. {
  1902. Input[i] = 0; // reset input
  1903. Input1[i]=0;
  1904. // ExSynPot[i] *= TauSfac; // decay the input potential
  1905. // InhSynPot[i] *= TauSfac; // decay inhibitory input potential
  1906. }
  1907. }
  1908. int izhshuntlayer::prepare(int step)
  1909. {
  1910. int i,j;
  1911. // prepare for the next MacroTimeStep
  1912. layer::prepare(step);
  1913. for (i=0;i<InhibitionDelay+1;i++)
  1914. {
  1915. mquer[i] = mquer[MacroTimeStep+i];
  1916. squer[i] = squer[MacroTimeStep+i];
  1917. }
  1918. for (i=InhibitionDelay+1;i<MacroTimeStep+InhibitionDelay+1;++i)
  1919. {
  1920. mquer[i]=0;
  1921. squer[i]=0;
  1922. }
  1923. }
  1924. int izhshuntlayer::SetKfbi(float _kfbi)
  1925. {
  1926. inh.Kfbi = _kfbi;
  1927. }
  1928. float* izhshuntlayer::GetInputPointer(csimInputChannel InputNumber)
  1929. {
  1930. switch (InputNumber) {
  1931. case csimInputChannel_AMPA:
  1932. Dout(dc::layer, "EG/DG Input");
  1933. return Input;
  1934. break;
  1935. case csimInputChannel_GABAa:
  1936. Dout(dc::layer, "recurrent input");
  1937. return Input1;
  1938. break;
  1939. default:
  1940. return Input;
  1941. break;
  1942. }
  1943. return 0;
  1944. }
  1945. ///////////////////////////////////////////
  1946. PresynIzhShuntLayer::PresynIzhShuntLayer(
  1947. int n, IzhParas _izparas, LevyShuntingParas _shuntparas,
  1948. float _InputSat, float _NoiseSigma)
  1949. :izhshuntlayer(n, _izparas, _shuntparas, _InputSat, _NoiseSigma)
  1950. {
  1951. PresynInhInput = new float[N];
  1952. for (int i=0;i<N;++i) PresynInhInput[i]=0;
  1953. }
  1954. PresynIzhShuntLayer::~PresynIzhShuntLayer()
  1955. {
  1956. delete[] PresynInhInput;
  1957. }
  1958. float* PresynIzhShuntLayer::GetInputPointer(csimInputChannel InputNumber)
  1959. {
  1960. switch (InputNumber) {
  1961. case csimInputChannel_AMPA:
  1962. Dout(dc::layer, "EG/DG Input");
  1963. return Input;
  1964. break;
  1965. case csimInputChannel_GABAa:
  1966. Dout(dc::layer, "recurrent input");
  1967. return Input1;
  1968. break;
  1969. case csimInputChannel_NMDA_AMPA:
  1970. Dout(dc::layer, "Presynaptic Inhibition Input");
  1971. return PresynInhInput;
  1972. default:
  1973. Dout(dc::layer, "EG/DG Input");
  1974. return Input;
  1975. break;
  1976. }
  1977. return 0;
  1978. }
  1979. int PresynIzhShuntLayer::proceede(int TotalTime)
  1980. {
  1981. int t = TotalTime % MacroTimeStep;
  1982. int i,j,k;
  1983. float CurInput;
  1984. float tmpinp;
  1985. for (int i=1;i<=nris;++i) Input[getrandom(N)]= RandomInputStrength; // random thalamic input
  1986. if (getrandom(1000)< RestProb) Input[getrandom(N)]= RandomInputStrength; // random thalamic input
  1987. last_N_firings = N_firings;
  1988. Iinh = inh.K0+inh.Kffi*squer[t]+inh.Kfbi*mquer[t];
  1989. for (i=0;i<N;i++)
  1990. {
  1991. // ExSynPot[i] += InputSaturation*Input[i]/(Input[i] + 1 + InhSynPot[i]);
  1992. CurInput = inh.K1*Input[i] + inh.K2*Input1[i]/(1+PresynInhInput[i]) + abs(gsl_ran_gaussian(gslr, NoiseSigma));
  1993. tmpinp = InputSaturation*CurInput/(CurInput + Iinh);
  1994. if ((i==10) && (rec != 0)) rec->record(dt*TotalTime, v[i], PresynInhInput[i]);
  1995. squer[t+InhibitionDelay] += dt*Input[i]; // running average of external input
  1996. v[i] +=dt*((0.04*v[i]+F)*v[i]+E-u[i]+ tmpinp);
  1997. u[i] +=A*(B*v[i]-u[i]);
  1998. if (v[i]>=30) // did it fire?
  1999. {
  2000. v[i] = C; // voltage reset
  2001. u[i]+= D; // recovery variable reset
  2002. firings[N_firings ][0]=t;
  2003. firings[N_firings++][1]=i;
  2004. mquer[t+InhibitionDelay] += 1; // running average of layer activity
  2005. if (N_firings == N_firings_max) {
  2006. ThrowTooManySpikes(t);
  2007. }
  2008. }
  2009. }
  2010. mquer[t+InhibitionDelay+1] = mquer[t+InhibitionDelay]*RunAvgFac;
  2011. squer[t+InhibitionDelay+1] = squer[t+InhibitionDelay]*RunAvgFac;
  2012. for (i=0;i<N;i++)
  2013. {
  2014. Input[i] = 0; // reset input
  2015. Input1[i]=0;
  2016. PresynInhInput[i] *= RunAvgFac; // decay PresynapticInputPotential
  2017. // ExSynPot[i] *= TauSfac; // decay the input potential
  2018. // InhSynPot[i] *= TauSfac; // decay inhibitory input potential
  2019. }
  2020. }
  2021. //////////////////////////////////
  2022. lif2layer::lif2layer(int n, float tau, float thresh, float k0, float k1, float k2, float kffi, float kfbi, float taus, float _DesiredActivity, float _pylearnrate):
  2023. liflayer(n, tau, thresh, k0, k1, k2,kffi, kfbi, taus)
  2024. {
  2025. int i;
  2026. DesiredActivity = N*_DesiredActivity;
  2027. PyrToInhLearningRate = _pylearnrate/N;
  2028. // initialize weights to inhibitory interneuron
  2029. Dinh = new float[N];
  2030. for (i=0;i<N;++i) Dinh[i]=1.0;
  2031. InhibitoryActivity = new float [MacroTimeStep + InhibitionDelay + 1];
  2032. for (i=0; i<(MacroTimeStep+InhibitionDelay+1); ++i) {
  2033. InhibitoryActivity[i]=0;
  2034. }
  2035. learnpti=true;
  2036. TauInhLearn=2.0;
  2037. InhLearnFac = exp(-dt/TauInhLearn);
  2038. }
  2039. lif2layer::~lif2layer()
  2040. {
  2041. delete[] Dinh;
  2042. delete[] InhibitoryActivity;
  2043. }
  2044. int lif2layer::proceede(int TotalTime)
  2045. {
  2046. int t = TotalTime % MacroTimeStep;
  2047. int i,j,k;
  2048. float CurInput;
  2049. for (int i=1;i<=nris;++i) Input[getrandom(N)]= RandomInputStrength; // random thalamic input
  2050. if (getrandom(1000)< RestProb) Input[getrandom(N)]= RandomInputStrength; // random thalamic input
  2051. last_N_firings = N_firings;
  2052. Iinh = K0+Kffi*squer[t]+Kfbi*InhibitoryActivity[t];
  2053. for (i=0;i<N;i++)
  2054. {
  2055. CurInput = K1*Input[i] + K2*Input1[i];
  2056. u[i] += CurInput/(CurInput+Iinh);
  2057. if ((i==0) && (rec != 0)) rec->record(dt*TotalTime, mquer[t], Dinh[i]);
  2058. squer[t+InhibitionDelay] += dt*Input[i];
  2059. v[i] +=TauMfac*(-v[i] + u[i]);
  2060. if ((v[i] > Threshold) && (t-LastSpike[i] > 2/dt)) // did it fire?
  2061. {
  2062. v[i] -= Threshold; // voltage reset
  2063. LastSpike[i] = t;
  2064. firings[N_firings ][0]=t;
  2065. firings[N_firings++][1]=i;
  2066. mquer[t+InhibitionDelay] += 1;
  2067. InhibitoryActivity[t+InhibitionDelay] += Dinh[i];
  2068. if (learnpti) Dinh[i] += PyrToInhLearningRate*(mquer[t+InhibitionDelay-1]-DesiredActivity);
  2069. // cout << PyrToInhLearningRate*(mquer[t+InhibitionDelay-1]-DesiredActivity) << " ";
  2070. // Dout(dc::layer, "Mquer increased to " << mquer[t+InhibitionDelay] << "");
  2071. if (N_firings == N_firings_max) {
  2072. ThrowTooManySpikes(t);
  2073. }
  2074. }
  2075. mquer[t+InhibitionDelay+1] = mquer[t+InhibitionDelay]*RunAvgFac;
  2076. squer[t+InhibitionDelay+1] = squer[t+InhibitionDelay]*RunAvgFac;
  2077. InhibitoryActivity[t+InhibitionDelay+1] = InhibitoryActivity[t+InhibitionDelay]*InhLearnFac;
  2078. // Dout(dc::layer, "Squer= " << squer[t] << " Mquer= " << mquer[t] << "");
  2079. u[i] *= TauSfac;
  2080. }
  2081. for (i=0;i<N;i++)
  2082. {
  2083. Input[i] = 0.0; // reset the input
  2084. Input1[i] = 0.0;
  2085. }
  2086. }
  2087. int lif2layer::prepare(int sec)
  2088. {
  2089. int i,j;
  2090. // prepare for the next MacroTimeStep
  2091. layer::prepare(sec);
  2092. for (i=0;i<N;++i) LastSpike[i] -= MacroTimeStep;
  2093. for (i=0;i<InhibitionDelay+1;i++)
  2094. {
  2095. mquer[i] = mquer[MacroTimeStep+i];
  2096. squer[i] = squer[MacroTimeStep+i];
  2097. InhibitoryActivity[i] = InhibitoryActivity[MacroTimeStep+i];
  2098. }
  2099. for (i=InhibitionDelay+1;i<MacroTimeStep+InhibitionDelay+1;++i)
  2100. {
  2101. mquer[i]=0;
  2102. squer[i]=0;
  2103. InhibitoryActivity[i]=0;
  2104. }
  2105. float DinhCount=0;
  2106. for (i=0;i<N;++i) DinhCount += Dinh[i];
  2107. cout << " DinhCount=" << DinhCount << " DesAct=" << DesiredActivity << "Act=" << mquer[0] << " ";
  2108. }
  2109. int lif2layer::SetLearnPti(bool set)
  2110. {
  2111. learnpti=set;
  2112. }
  2113. /////////////////////////////////
  2114. MMN01Layer::MMN01Layer(int n, float _TauThres, float _RestingThres, float _ThresInc, float _TauFeeding): layer(n), RestingThreshold(_RestingThres), ThresInc(_ThresInc), inh(0)
  2115. {
  2116. // from class layer:
  2117. // v: FeedingPot
  2118. // u: Threshold
  2119. ThresholdFac = exp(-dt/_TauThres);
  2120. FeedingFac = exp(-dt/_TauFeeding);
  2121. for (int i=0;i<N;++i) {
  2122. v[i]=0;
  2123. u[i]=0;
  2124. }
  2125. }
  2126. MMN01Layer::~MMN01Layer()
  2127. {
  2128. delete[] inh;
  2129. }
  2130. int MMN01Layer::StartBinRec(int nobserve, int StartNumber)
  2131. {
  2132. int NumObserve = 2*nobserve;
  2133. float** Buffer = new float* [NumObserve];
  2134. for (int i=0;i<nobserve; ++i) Buffer[i] = &(v[i]);
  2135. for (int i=0;i<nobserve; ++i) Buffer[i+nobserve] = &(u[i]);
  2136. string FileName(MemPotFileName);
  2137. BinRec = new BinRecorder(MacroTimeStep, NumObserve, nobserve, Buffer, dt, (DataDirectory+FileName).c_str());
  2138. }
  2139. float* MMN01Layer::GetInputPointer(csimInputChannel)
  2140. {
  2141. return v;
  2142. }
  2143. int MMN01Layer::proceede(int TotalTime)
  2144. {
  2145. int t = TotalTime % MacroTimeStep;
  2146. int i,j,k;
  2147. last_N_firings = N_firings;
  2148. if (BinRec) BinRec->record();
  2149. for (i=0;i<N;i++)
  2150. {
  2151. v[i] *= FeedingFac;
  2152. u[i] *= ThresholdFac;
  2153. // if ((i==0) && (rec != 0)) rec->record(dt*TotalTime, v[i], u[i]);
  2154. if (v[i]>=RestingThreshold + u[i]) // did it fire?
  2155. {
  2156. u[i] += ThresInc;
  2157. firings[N_firings ][0]=t;
  2158. firings[N_firings++][1]=i;
  2159. if (N_firings == N_firings_max) {
  2160. ThrowTooManySpikes(t);
  2161. }
  2162. }
  2163. }
  2164. // for (i=0;i<N;i++)
  2165. // {
  2166. // Input[i] = 0; // reset input
  2167. // }
  2168. }
  2169. /////////////////////////////////
  2170. MMN02Layer::MMN02Layer(int n, float _TauThres, float _RestingThres, float _ThresInc, float _TauFeeding, float _TauInhibition): MMN01Layer(n, _TauThres, _RestingThres, _ThresInc, _TauFeeding)
  2171. {
  2172. InhibitionFac = exp(-dt/_TauInhibition);
  2173. inh = new float [N];
  2174. for (int i=0;i<N;++i) {
  2175. inh[i]=0;
  2176. }
  2177. }
  2178. MMN02Layer::~MMN02Layer()
  2179. {
  2180. }
  2181. int MMN02Layer::StartBinRec(int nobserve, int StartNumber)
  2182. {
  2183. int NumObserve = 3*nobserve;
  2184. float** Buffer = new float* [NumObserve];
  2185. for (int i=0;i<nobserve; ++i) Buffer[i] = &(v[i]);
  2186. for (int i=0;i<nobserve; ++i) Buffer[i+nobserve] = &(inh[i]);
  2187. for (int i=0;i<nobserve; ++i) Buffer[i+2*nobserve] = &(u[i]);
  2188. string FileName(MemPotFileName);
  2189. BinRec = new BinRecorder(MacroTimeStep, NumObserve, nobserve, Buffer, dt, (DataDirectory+FileName).c_str());
  2190. }
  2191. float* MMN02Layer::GetInputPointer(csimInputChannel InputNumber)
  2192. {
  2193. switch (InputNumber) {
  2194. case csimInputChannel_AMPA: {
  2195. Dout(dc::layer, "Excitatory Input");
  2196. return v;
  2197. } break;
  2198. case csimInputChannel_GABAa: {
  2199. Dout(dc::layer, "Inhibitory Input");
  2200. return inh;
  2201. } break;
  2202. default:
  2203. return v;
  2204. }
  2205. return 0;
  2206. }
  2207. int MMN02Layer::proceede(int TotalTime)
  2208. {
  2209. int t = TotalTime % MacroTimeStep;
  2210. int i,j,k;
  2211. last_N_firings = N_firings;
  2212. if (BinRec) BinRec->record();
  2213. for (i=0;i<N;i++)
  2214. {
  2215. v[i] *= FeedingFac;
  2216. v[i] += gsl_ran_gaussian(gslr, NoiseSigma);
  2217. u[i] *= ThresholdFac;
  2218. inh[i] *= InhibitionFac;
  2219. // if ((i==0) && (rec != 0)) rec->record(dt*TotalTime, v[i], u[i]);
  2220. if ((v[i]-inh[i])>=RestingThreshold + u[i]) // did it fire?
  2221. {
  2222. u[i] += ThresInc;
  2223. firings[N_firings ][0]=t;
  2224. firings[N_firings++][1]=i;
  2225. if (N_firings == N_firings_max) {
  2226. ThrowTooManySpikes(t);
  2227. }
  2228. }
  2229. }
  2230. }
  2231. ///////////////////////////////////////
  2232. /////////////////////////////////
  2233. MMN03Layer::MMN03Layer(int n, float _TauThres, float _RestingThres, float _ThresInc, float _TauFeeding, float _TauInhibition, float _TauLinking): MMN02Layer(n, _TauThres, _RestingThres, _ThresInc, _TauFeeding, _TauInhibition), TauLinking(_TauLinking)
  2234. {
  2235. Dout(dc::layer, "MMN03Layer::MMN03Layer, n=" << n << "");
  2236. fflush(stdout);
  2237. LinkingFac = exp(-dt/_TauLinking);
  2238. Linking = new float [N];
  2239. for (int i=0;i<N;++i) {
  2240. Linking[i]=0;
  2241. }
  2242. }
  2243. MMN03Layer::~MMN03Layer()
  2244. {
  2245. }
  2246. int MMN03Layer::WriteSimInfo(fstream &fw)
  2247. {
  2248. stringstream sstr;
  2249. sstr << "<LayerType value=\"" << "MMN03" << "\"/> \n";
  2250. sstr << "<TauLinking value=\"" << TauLinking << "\"/> \n";
  2251. layer::WriteSimInfo(fw, sstr.str());
  2252. }
  2253. int MMN03Layer::StartBinRec(int nobserve, int StartNumber)
  2254. {
  2255. int NumObserve = 4*nobserve;
  2256. float** Buffer = new float* [NumObserve];
  2257. for (int i=0;i<nobserve; ++i) Buffer[i] = &(v[i]);
  2258. for (int i=0;i<nobserve; ++i) Buffer[i+nobserve] = &(inh[i]);
  2259. for (int i=0;i<nobserve; ++i) Buffer[i+2*nobserve] = &(u[i]);
  2260. for (int i=0;i<nobserve; ++i) Buffer[i+3*nobserve] = &(Linking[i]);
  2261. string FileName(MemPotFileName);
  2262. BinRec = new BinRecorder(MacroTimeStep, NumObserve, nobserve, Buffer, dt, (DataDirectory+FileName).c_str());
  2263. }
  2264. float* MMN03Layer::GetInputPointer(csimInputChannel InputNumber)
  2265. {
  2266. switch (InputNumber) {
  2267. case csimInputChannel_AMPA: {
  2268. Dout(dc::layer, "Excitatory Input");
  2269. return v;
  2270. } break;
  2271. case csimInputChannel_GABAa: {
  2272. Dout(dc::layer, "Inhibitory Input");
  2273. return inh;
  2274. } break;
  2275. case csimInputChannel_Linking: {
  2276. Dout(dc::layer, "Linking Input");
  2277. return Linking;
  2278. } break;
  2279. case csimInputChannel_NMDA_AMPA: {
  2280. Dout(dc::layer, "NMDA/AMPA input requested, MMN03Layer has no NMDA current, using Linking Input instead");
  2281. return Linking;
  2282. } break;
  2283. default:
  2284. return v;
  2285. }
  2286. return 0;
  2287. }
  2288. int MMN03Layer::proceede(int TotalTime)
  2289. {
  2290. int t = TotalTime % MacroTimeStep;
  2291. int i,j,k;
  2292. last_N_firings = N_firings;
  2293. if (BinRec) BinRec->record();
  2294. for (i=0;i<N;i++)
  2295. {
  2296. v[i] *= FeedingFac; // Feeding potential
  2297. Linking[i] *= LinkingFac; // linking potential
  2298. // v[i] += gsl_ran_gaussian(gslr, NoiseSigma); // Gausssches Rauschen
  2299. u[i] *= ThresholdFac; // dynamische Schwelle
  2300. inh[i] *= InhibitionFac; //inhibitorisches Potential
  2301. if ((((Linking[i]+1)*v[i]-inh[i])+gsl_ran_gaussian(gslr,NoiseSigma)) >=RestingThreshold + u[i]) //did it fire?
  2302. {
  2303. u[i] += ThresInc;
  2304. firings[N_firings ][0]=t;
  2305. firings[N_firings++][1]=i;
  2306. if (N_firings == N_firings_max) {
  2307. ThrowTooManySpikes(t);
  2308. }
  2309. }
  2310. }
  2311. }
  2312. int MMN03Layer::reset(int TotalTime)
  2313. {
  2314. int t = TotalTime % MacroTimeStep;
  2315. for (int i=0;i<N;++i) {
  2316. v[i]=0;
  2317. u[i]=0;
  2318. inh[i]=0;
  2319. Linking[i]=0;
  2320. }
  2321. // delete all spikes which are still in the delay line
  2322. // firings with firing times higher than t-MaximumDelay
  2323. int MaximumDelay = MainSimLoop->GetMaximumDelay();
  2324. int k=N_firings-1;
  2325. while (t-firings[k][0]<MaximumDelay) k--;
  2326. N_firings = k+1;
  2327. }
  2328. /////////////////////////////////////////
  2329. MMN04Layer::MMN04Layer(int n, float _TauThres, float _RestingThres, float _ThresInc, float _TauFeeding, float _TauInhibition, float _TauLinking,float _TauEnduFeeding,float _TauEnduLinking): MMN03Layer(n, _TauThres, _RestingThres, _ThresInc, _TauFeeding, _TauInhibition, _TauLinking), TauEnduFeeding(_TauEnduFeeding), TauEnduLinking(_TauEnduLinking)
  2330. {
  2331. Dout(dc::layer, "MMN04Layer::MMN04Layer, n=" << n << "");
  2332. fflush(stdout);
  2333. EnduFeedingFac = exp(-dt/_TauEnduFeeding);
  2334. EnduLinkingFac = exp(-dt/_TauEnduLinking);
  2335. endu = new float [N];
  2336. enduL = new float [N];
  2337. v_Self = new float [N];
  2338. for (int i=0;i<N;++i) {
  2339. endu[i]=0;
  2340. // enduL[i]=0;
  2341. v_Self[i]=0;
  2342. }
  2343. }
  2344. MMN04Layer::~MMN04Layer()
  2345. {
  2346. }
  2347. int MMN04Layer::WriteSimInfo(fstream &fw)
  2348. {
  2349. stringstream sstr;
  2350. sstr << "<LayerType value=\"" << "MMN04" << "\"/> \n";
  2351. sstr << "<TauEnduFeeding value=\"" << TauEnduFeeding << "\"/> \n";
  2352. sstr << "<TauEnduLinking value=\"" << TauEnduLinking << "\"/> \n";
  2353. layer::WriteSimInfo(fw, sstr.str());
  2354. }
  2355. int MMN04Layer::StartBinRec(int nobserve, int StartNumber)
  2356. {
  2357. int NumObserve = 4*nobserve;
  2358. float** Buffer = new float* [NumObserve];
  2359. for (int i=0;i<nobserve; ++i) Buffer[i] = &(v[i]);
  2360. for (int i=0;i<nobserve; ++i) Buffer[i+nobserve] = &(inh[i]);
  2361. for (int i=0;i<nobserve; ++i) Buffer[i+2*nobserve] = &(u[i]);
  2362. for (int i=0;i<nobserve; ++i) Buffer[i+3*nobserve] = &(Linking[i]);
  2363. for (int i=0;i<nobserve; ++i) Buffer[i+3*nobserve] = &(endu[i]);
  2364. for (int i=0;i<nobserve; ++i) Buffer[i+3*nobserve] = &(enduL[i]);
  2365. string FileName(MemPotFileName);
  2366. BinRec = new BinRecorder(MacroTimeStep, NumObserve, nobserve, Buffer, dt, (DataDirectory+FileName).c_str());
  2367. }
  2368. float* MMN04Layer::GetInputPointer(csimInputChannel InputNumber)
  2369. {
  2370. switch (InputNumber) {
  2371. case csimInputChannel_AMPA: {
  2372. Dout(dc::layer, "Excitatory Input");
  2373. return v;
  2374. } break;
  2375. case csimInputChannel_AMPA2: {
  2376. Dout(dc::layer, "Excitatory Input");
  2377. return v_Self;
  2378. } break;
  2379. case csimInputChannel_GABAa: {
  2380. Dout(dc::layer, "Inhibitory Input");
  2381. return inh;
  2382. } break;
  2383. case csimInputChannel_Linking: {
  2384. Dout(dc::layer, "Linking Input");
  2385. return Linking;
  2386. } break;
  2387. case csimInputChannel_Endu: {
  2388. Dout(dc::layer, "Enduring Input");
  2389. return endu;
  2390. } break;
  2391. case csimInputChannel_EnduLinking: {
  2392. Dout(dc::layer, "Enduring Linking-Input");
  2393. return enduL;
  2394. } break;
  2395. case csimInputChannel_NMDA_AMPA: {
  2396. Dout(dc::layer, "NMDA/AMPA input requested, MMN03Layer has no NMDA current, using Linking Input instead");
  2397. return Linking;
  2398. } break;
  2399. default:
  2400. return v;
  2401. }
  2402. return 0;
  2403. }
  2404. int MMN04Layer::proceede(int TotalTime)
  2405. {
  2406. int t = TotalTime % MacroTimeStep;
  2407. int i,j,k;
  2408. last_N_firings = N_firings;
  2409. if (BinRec) BinRec->record();
  2410. for (i=0;i<N;i++)
  2411. {
  2412. v[i] *= FeedingFac;// Feeding potential
  2413. v_Self[i] *= FeedingFac;
  2414. Linking[i] *= LinkingFac; // linking potential
  2415. // v[i] += gsl_ran_gaussian(gslr, NoiseSigma); // Gausssches Rauschen
  2416. u[i] *= ThresholdFac; // dynamische Schwelle
  2417. inh[i] *= InhibitionFac; //inhibitorisches Potential
  2418. endu[i] *= EnduFeedingFac; // enduring Potential
  2419. //enduL[i] *= EnduLinkingFac; // Enduring Linking Potential
  2420. //Wenn paramater von 0908 betrachtet werden sollen: if (((( (2*Linking[i])*(2*v[i]))+endu[i]+v_Self[i]-inh[i])+gsl_ran_gaussian(gslr,NoiseSigma)) >=RestingThreshold + u[i]) //did it fire?
  2421. if (((3*Linking[i]*2*v[i])+endu[i]+v_Self[i]-inh[i]+gsl_ran_gaussian(gslr,NoiseSigma)) >=RestingThreshold + u[i]) //did it fire?
  2422. {
  2423. u[i] += ThresInc;
  2424. firings[N_firings ][0]=t;
  2425. firings[N_firings++][1]=i;
  2426. if (N_firings == N_firings_max) {
  2427. ThrowTooManySpikes(t);
  2428. }
  2429. }
  2430. }
  2431. }
  2432. int MMN04Layer::reset(int TotalTime)
  2433. {
  2434. int t = TotalTime % MacroTimeStep;
  2435. for (int i=0;i<N;++i) {
  2436. v[i]=0;
  2437. u[i]=0;
  2438. inh[i]=0;
  2439. Linking[i]=0;
  2440. endu[i]=0;
  2441. // enduL[i]=0;
  2442. }
  2443. // delete all spikes which are still in the delay line
  2444. // firings with firing times higher than t-MaximumDelay
  2445. int MaximumDelay = MainSimLoop->GetMaximumDelay();
  2446. int k=N_firings-1;
  2447. while (t-firings[k][0]<MaximumDelay) k--;
  2448. N_firings = k+1;
  2449. }
  2450. MMN05Layer::MMN05Layer(int n, float _TauThres, float _RestingThres, float _ThresInc, float _TauFeeding, float _TauInhibition, float _TauLinking,float _TauEnduFeeding,float _TauEnduLinking): MMN03Layer(n, _TauThres, _RestingThres, _ThresInc, _TauFeeding, _TauInhibition, _TauLinking), TauEnduFeeding(_TauEnduFeeding), TauEnduLinking(_TauEnduLinking)
  2451. {
  2452. Dout(dc::layer, "MMN05Layer::MMN05Layer, n=" << n << "");
  2453. fflush(stdout);
  2454. EnduFeedingFac = exp(-dt/_TauEnduFeeding);
  2455. EnduLinkingFac = exp(-dt/_TauEnduLinking);
  2456. endu = new float [N];
  2457. enduL = new float [N];
  2458. v_Self = new float [N];
  2459. for (int i=0;i<N;++i) {
  2460. endu[i]=0;
  2461. // enduL[i]=0;
  2462. v_Self[i]=0;
  2463. }
  2464. }
  2465. MMN05Layer::~MMN05Layer()
  2466. {
  2467. }
  2468. int MMN05Layer::WriteSimInfo(fstream &fw)
  2469. {
  2470. stringstream sstr;
  2471. sstr << "<LayerType value=\"" << "MMN05" << "\"/> \n";
  2472. sstr << "<TauEnduFeeding value=\"" << TauEnduFeeding << "\"/> \n";
  2473. sstr << "<TauEnduLinking value=\"" << TauEnduLinking << "\"/> \n";
  2474. layer::WriteSimInfo(fw, sstr.str());
  2475. }
  2476. int MMN05Layer::StartBinRec(int nobserve, int StartNumber)
  2477. {
  2478. int NumObserve = 4*nobserve;
  2479. float** Buffer = new float* [NumObserve];
  2480. for (int i=0;i<nobserve; ++i) Buffer[i] = &(v[i]);
  2481. for (int i=0;i<nobserve; ++i) Buffer[i+nobserve] = &(inh[i]);
  2482. for (int i=0;i<nobserve; ++i) Buffer[i+2*nobserve] = &(u[i]);
  2483. for (int i=0;i<nobserve; ++i) Buffer[i+3*nobserve] = &(Linking[i]);
  2484. for (int i=0;i<nobserve; ++i) Buffer[i+3*nobserve] = &(endu[i]);
  2485. for (int i=0;i<nobserve; ++i) Buffer[i+3*nobserve] = &(enduL[i]);
  2486. string FileName(MemPotFileName);
  2487. BinRec = new BinRecorder(MacroTimeStep, NumObserve, nobserve, Buffer, dt, (DataDirectory+FileName).c_str());
  2488. }
  2489. float* MMN05Layer::GetInputPointer(csimInputChannel InputNumber)
  2490. {
  2491. switch (InputNumber) {
  2492. case csimInputChannel_AMPA: {
  2493. Dout(dc::layer, "Excitatory Input");
  2494. return v;
  2495. } break;
  2496. case csimInputChannel_AMPA2: {
  2497. Dout(dc::layer, "Excitatory Input");
  2498. return v_Self;
  2499. } break;
  2500. case csimInputChannel_GABAa: {
  2501. Dout(dc::layer, "Inhibitory Input");
  2502. return inh;
  2503. } break;
  2504. case csimInputChannel_Linking: {
  2505. Dout(dc::layer, "Linking Input");
  2506. return Linking;
  2507. } break;
  2508. case csimInputChannel_Endu: {
  2509. Dout(dc::layer, "Enduring Input");
  2510. return endu;
  2511. } break;
  2512. case csimInputChannel_EnduLinking: {
  2513. Dout(dc::layer, "Enduring Linking-Input");
  2514. return enduL;
  2515. } break;
  2516. case csimInputChannel_NMDA_AMPA: {
  2517. Dout(dc::layer, "NMDA/AMPA input requested, MMN03Layer has no NMDA current, using Linking Input instead");
  2518. return Linking;
  2519. } break;
  2520. default:
  2521. return v;
  2522. }
  2523. return 0;
  2524. }
  2525. int MMN05Layer::proceede(int TotalTime)
  2526. {
  2527. int t = TotalTime % MacroTimeStep;
  2528. int i,j,k;
  2529. last_N_firings = N_firings;
  2530. if (BinRec) BinRec->record();
  2531. for (i=0;i<N;i++)
  2532. {
  2533. v[i] *= FeedingFac;// Feeding potential
  2534. v_Self[i] *= FeedingFac;
  2535. Linking[i] *= LinkingFac; // linking potential
  2536. // v[i] += gsl_ran_gaussian(gslr, NoiseSigma); // Gausssches Rauschen
  2537. u[i] *= ThresholdFac; // dynamische Schwelle
  2538. inh[i] *= InhibitionFac; //inhibitorisches Potential
  2539. endu[i] *= EnduFeedingFac; // enduring Potential
  2540. //enduL[i] *= EnduLinkingFac; // Enduring Linking Potential
  2541. //Wenn paramater von 0908 betrachtet werden sollen: if (((( (2*Linking[i])*(2*v[i]))+endu[i]+v_Self[i]-inh[i])+gsl_ran_gaussian(gslr,NoiseSigma)) >=RestingThreshold + u[i]) //did it fire?
  2542. if ((1+Linking[i])*(v[i]+endu[i]+v_Self[i]-inh[i])+gsl_ran_gaussian(gslr,NoiseSigma) >=RestingThreshold + u[i]) //did it fire?
  2543. {
  2544. u[i] += ThresInc;
  2545. firings[N_firings ][0]=t;
  2546. firings[N_firings++][1]=i;
  2547. if (N_firings == N_firings_max) {
  2548. ThrowTooManySpikes(t);
  2549. }
  2550. }
  2551. }
  2552. }
  2553. int MMN05Layer::reset(int TotalTime)
  2554. {
  2555. int t = TotalTime % MacroTimeStep;
  2556. for (int i=0;i<N;++i) {
  2557. v[i]=0;
  2558. u[i]=0;
  2559. inh[i]=0;
  2560. Linking[i]=0;
  2561. endu[i]=0;
  2562. enduL[i]=0;
  2563. }
  2564. // delete all spikes which are still in the delay line
  2565. // firings with firing times higher than t-MaximumDelay
  2566. int MaximumDelay = MainSimLoop->GetMaximumDelay();
  2567. int k=N_firings-1;
  2568. while (t-firings[k][0]<MaximumDelay) k--;
  2569. N_firings = k+1;
  2570. }
  2571. ///////////////////////////////////////
  2572. AmpaNmdaGabaChannels::AmpaNmdaGabaChannels(
  2573. int N, float _TauAmpaRise, float _TauAmpaFall, float _TauNmdaRise, float _TauNmdaFall
  2574. ,float _TauGabaARise, float _TauGabaAFall, float _TauGabaBRise, float _TauGabaBFall
  2575. ,float _GabaABRatio, float _NmdaAmpaRatio):
  2576. TauAmpaRise(_TauAmpaRise)
  2577. ,TauAmpaFall(_TauAmpaFall)
  2578. ,TauNmdaRise(_TauNmdaRise)
  2579. ,TauNmdaFall(_TauNmdaFall)
  2580. ,TauGabaARise(_TauGabaARise)
  2581. ,TauGabaAFall(_TauGabaAFall)
  2582. ,TauGabaBRise(_TauGabaBRise)
  2583. ,TauGabaBFall(_TauGabaBFall)
  2584. ,GabaABRatio(_GabaABRatio)
  2585. ,NmdaAmpaRatio(_NmdaAmpaRatio)
  2586. ,GabaAReversePot(-70)
  2587. ,GabaBReversePot(-90)
  2588. ,NaReversePot(0)
  2589. ,NNeurons(N)
  2590. {
  2591. MainSimLoop = GetGlobalSimLoop();
  2592. DeltaT = MainSimLoop->GetDeltaT();
  2593. SetTauNmda(TauNmdaRise, TauNmdaFall);
  2594. SetTauAmpa(TauAmpaRise, TauAmpaFall);
  2595. SetTauGabaA(TauGabaARise, TauGabaAFall);
  2596. SetTauGabaB(TauGabaBRise, TauGabaBFall);
  2597. // initialize arrays
  2598. AmpaRisePot = new float [N];
  2599. AmpaFallPot = new float [N];
  2600. AmpaPot = new float [N];
  2601. NmdaRisePot = new float [N];
  2602. NmdaFallPot = new float [N];
  2603. GabaARisePot = new float [N];
  2604. GabaAFallPot = new float [N];
  2605. GabaBRisePot = new float [N];
  2606. GabaBFallPot = new float [N];
  2607. InhInput = new float [N];
  2608. NmdaAmpaInput = new float [N];
  2609. for (int i=0;i<N;++i) {
  2610. AmpaRisePot[i]=0;
  2611. AmpaFallPot[i]=0;
  2612. AmpaPot[i]=0;
  2613. NmdaRisePot[i]=0;
  2614. NmdaFallPot[i]=0;
  2615. GabaARisePot[i]=0;
  2616. GabaAFallPot[i]=0;
  2617. GabaBRisePot[i]=0;
  2618. GabaBFallPot[i]=0;
  2619. InhInput[i]=0;
  2620. NmdaAmpaInput[i]=0;
  2621. }
  2622. }
  2623. AmpaNmdaGabaChannels::~AmpaNmdaGabaChannels()
  2624. {
  2625. delete [] AmpaRisePot;
  2626. delete [] AmpaFallPot;
  2627. delete [] AmpaPot;
  2628. delete [] NmdaRisePot;
  2629. delete [] NmdaFallPot;
  2630. delete [] GabaARisePot;
  2631. delete [] GabaAFallPot;
  2632. delete [] GabaBRisePot;
  2633. delete [] GabaBFallPot;
  2634. delete [] InhInput;
  2635. delete [] NmdaAmpaInput;
  2636. }
  2637. long AmpaNmdaGabaChannels::calcMemConsumption()
  2638. {
  2639. long MemSum=0;
  2640. MemSum += sizeof(float)*NNeurons*11;
  2641. return MemSum;
  2642. }
  2643. void AmpaNmdaGabaChannels::reset()
  2644. {
  2645. for (int i=0;i<NNeurons;++i) {
  2646. AmpaRisePot[i]=0;
  2647. AmpaFallPot[i]=0;
  2648. AmpaPot[i]=0;
  2649. NmdaRisePot[i]=0;
  2650. NmdaFallPot[i]=0;
  2651. GabaARisePot[i]=0;
  2652. GabaAFallPot[i]=0;
  2653. GabaBRisePot[i]=0;
  2654. GabaBFallPot[i]=0;
  2655. InhInput[i]=0;
  2656. NmdaAmpaInput[i]=0;
  2657. }
  2658. }
  2659. void AmpaNmdaGabaChannels::SetTauNmda(float rise, float fall)
  2660. {
  2661. TauNmdaRise = rise;
  2662. TauNmdaFall = fall;
  2663. TauNmdaRiseFac = exp(-DeltaT/TauNmdaRise);
  2664. TauNmdaFallFac = exp(-DeltaT/TauNmdaFall);
  2665. NmdaCorr = DoubleExpCorrectionFactor(TauNmdaRise, TauNmdaFall);
  2666. }
  2667. void AmpaNmdaGabaChannels::SetTauAmpa(float rise, float fall)
  2668. {
  2669. TauAmpaRise = rise;
  2670. TauAmpaFall = fall;
  2671. TauAmpaRiseFac = exp(-DeltaT/TauAmpaRise);
  2672. TauAmpaFallFac = exp(-DeltaT/TauAmpaFall);
  2673. AmpaCorr = DoubleExpCorrectionFactor(TauAmpaRise, TauAmpaFall);
  2674. }
  2675. void AmpaNmdaGabaChannels::SetTauGabaA(float rise, float fall)
  2676. {
  2677. TauGabaARise = rise;
  2678. TauGabaAFall = fall;
  2679. TauGabaARiseFac = exp(-DeltaT/TauGabaARise);
  2680. TauGabaAFallFac = exp(-DeltaT/TauGabaAFall);
  2681. GabaACorr = DoubleExpCorrectionFactor(TauGabaARise, TauGabaAFall);
  2682. }
  2683. void AmpaNmdaGabaChannels::SetTauGabaB(float rise, float fall)
  2684. {
  2685. TauGabaBRise = rise;
  2686. TauGabaBFall = fall;
  2687. TauGabaBRiseFac = exp(-DeltaT/TauGabaBRise);
  2688. TauGabaBFallFac = exp(-DeltaT/TauGabaBFall);
  2689. GabaBCorr = DoubleExpCorrectionFactor(TauGabaBRise, TauGabaBFall);
  2690. }
  2691. void AmpaNmdaGabaChannels::SetNmdaAmpaRatio(float ratio)
  2692. {
  2693. // ratio defined as psp peak ratio at xx mV
  2694. // R*PotNmda*INmda(voltage) == PotAmpa*IAmpa(voltage)*ratio
  2695. // R = PotAmpa*IAmpa(voltage)*ratio / (PotNmda*INmda(voltage))
  2696. // PotNmda == PotAmpa ==>
  2697. // R = IAmpa(voltage)*ratio / INmda(voltage)
  2698. NmdaAmpaEPSPRatio=ratio;
  2699. float voltage = 60; // mV
  2700. float NaRevPot = 0; //mV
  2701. float AmpaCurrent = NaRevPot-voltage; // if conductance gAmpa == 1
  2702. float NmdaCurrent = INmda(voltage);
  2703. NmdaAmpaRatio = AmpaCurrent*NmdaAmpaEPSPRatio/NmdaCurrent;
  2704. }
  2705. void AmpaNmdaGabaChannels::WriteSimInfo(stringstream &sstr)
  2706. {
  2707. sstr << "<Ampa "
  2708. << "TauRise=\"" << TauAmpaRise << "\" "
  2709. << "TauFall=\"" << TauAmpaFall << "\" "
  2710. << "AmpaCorr=\"" << AmpaCorr << "\" "
  2711. << "/> \n";
  2712. sstr << "<GabaA "
  2713. << "TauRise=\"" << TauGabaARise << "\" "
  2714. << "TauFall=\"" << TauGabaAFall << "\" "
  2715. << "ReversePot=\"" << GabaAReversePot << "\" "
  2716. << "/> \n";
  2717. sstr << "<GabaB "
  2718. << "TauRise=\"" << TauGabaBRise << "\" "
  2719. << "TauFall=\"" << TauGabaBFall << "\" "
  2720. << "ReversePot=\"" << GabaBReversePot << "\" "
  2721. << "/> \n";
  2722. sstr << "<Nmda "
  2723. << "TauRise=\"" << TauNmdaRise << "\" "
  2724. << "TauFall=\"" << TauNmdaFall << "\" "
  2725. << "NmdaAmpaRatio=\"" << NmdaAmpaRatio << "\" "
  2726. << "NmdaAmpaEPSPRatio=\"" << NmdaAmpaEPSPRatio << "\" "
  2727. << "/> \n";
  2728. }
  2729. /////////////////////////////
  2730. DecoLifLayer::DecoLifLayer(int n, DecoParas Paras): layer(n), AmpaNmdaGabaChannels(n), RestingPot(Paras.RestingPot), ResetPot(Paras.ResetPot), Threshold(Paras.Threshold), CMembrane(Paras.CMembrane), GLeak(Paras.GLeak), AbsoluteRefractoryPeriod(Paras.AbsoluteRefractoryPeriod), SpikePot(Paras.SpikePot)
  2731. {
  2732. Refractory = new int [N];
  2733. for (int i=0;i<N;++i) {
  2734. v[i] = RestingPot;
  2735. Refractory[i]=0;
  2736. }
  2737. CMembraneFac = 0.001*dt/CMembrane;
  2738. Dout(dc::layer, "cmemfac=" << CMembraneFac << "");
  2739. arf = int(round(AbsoluteRefractoryPeriod/dt));
  2740. #ifdef USE_RNG_THREAD
  2741. // initialize random number generator thread queue
  2742. Dout(dc::layer, "initialize random number generator thread");
  2743. mRndNumQueue = RngParaQueuePool::getRngQueuePool()->getRngQueue(kRngPoisson, PoissonLambda,10,2000);
  2744. #endif //USE_RNG_THREAD
  2745. }
  2746. DecoLifLayer::~DecoLifLayer()
  2747. {
  2748. delete [] Refractory;
  2749. }
  2750. int DecoLifLayer::WriteSimInfo(fstream &fw)
  2751. {
  2752. stringstream sstr;
  2753. sstr << "<LayerType value=\"" << "DecoLif" << "\"/> \n";
  2754. sstr << "<NoiseAmplitude value=\"" << NoiseAmplitude << "\"/> \n";
  2755. sstr << "<BalancedInhibition value=\"" << BalancedInhibition << "\"/> \n";
  2756. sstr << "<RestingPot value=\"" << RestingPot << "\"/> \n";
  2757. sstr << "<ResetPot value=\"" << ResetPot << "\"/> \n";
  2758. sstr << "<Threshold value=\"" << Threshold << "\"/> \n";
  2759. sstr << "<CMembrane value=\"" << CMembrane << "\"/> \n";
  2760. sstr << "<GLeak value=\"" << GLeak << "\"/> \n";
  2761. sstr << "<AbsoluteRefractoryPeriod value=\"" << AbsoluteRefractoryPeriod << "\"/> \n";
  2762. AmpaNmdaGabaChannels::WriteSimInfo(sstr);
  2763. layer::WriteSimInfo(fw, sstr.str());
  2764. }
  2765. int DecoLifLayer::proceede(int TotalTime)
  2766. {
  2767. int t = TotalTime % MacroTimeStep;
  2768. int i,j,k;
  2769. last_N_firings = N_firings;
  2770. if (BinRec) BinRec->record();
  2771. for (i=0;i<N;i++)
  2772. {
  2773. // Input[i] += abs(gsl_ran_gaussian(gslr, NoiseSigma));
  2774. #ifdef USE_RNG_THREAD
  2775. // use random number generator thread
  2776. Input[i] += NoiseAmplitude*mRndNumQueue->getRandomNumber();
  2777. #else
  2778. // use no thread for rng
  2779. Input[i] += NoiseAmplitude*gsl_ran_poisson(gslr, PoissonLambda);
  2780. #endif //USE_RNG_THREAD
  2781. Input[i] += NmdaAmpaInput[i];
  2782. Input[i] *= AmpaCorr;
  2783. InhInput[i] *= GabaACorr;
  2784. NmdaAmpaInput[i] *= NmdaCorr;
  2785. AmpaRisePot[i] += Input[i];
  2786. AmpaFallPot[i] += Input[i];
  2787. NmdaRisePot[i] += NmdaAmpaRatio*NmdaAmpaInput[i];
  2788. NmdaFallPot[i] += NmdaAmpaRatio*NmdaAmpaInput[i];
  2789. GabaARisePot[i] += InhInput[i];
  2790. GabaAFallPot[i] += InhInput[i];
  2791. GabaBRisePot[i] +=GabaABRatio*InhInput[i];
  2792. GabaBFallPot[i] += GabaABRatio*InhInput[i];
  2793. // if (i == 0) cerr << "Nmda=" << NmdaRisePot[i] << " " << NmdaFallPot[i] << "\n";
  2794. // InhSynPot[i] += abs(gsl_ran_gaussian(gslr, NoiseSigma));
  2795. AmpaPot[i] = AmpaFallPot[i] - AmpaRisePot[i];
  2796. float Nmda = NmdaFallPot[i] - NmdaRisePot[i];
  2797. float GabaA = GabaAFallPot[i] - GabaARisePot[i];
  2798. float GabaB = GabaBFallPot[i] - GabaBRisePot[i];
  2799. v[i] += CMembraneFac*(-GLeak*(v[i]-RestingPot)
  2800. - AmpaPot[i]*(v[i]-NaReversePot)
  2801. + INmda(v[i])*Nmda
  2802. - (v[i]-GabaAReversePot)*(GabaA+BalancedInhibition)
  2803. - (v[i]-GabaBReversePot)*GabaB
  2804. );
  2805. if (Refractory[i]>0) {
  2806. --Refractory[i];
  2807. v[i] = ResetPot; // voltage reset
  2808. } else {
  2809. if (v[i]>=Threshold) { // did it fire?
  2810. // if (i == 0) cerr << N_firings << "spike\n"; fflush(stdout);
  2811. // v[i] = ResetPot; // voltage reset
  2812. v[i] = SpikePot; // fake spike for LIF Neuron
  2813. Refractory[i] = arf;
  2814. firings[N_firings ][0]=t;
  2815. firings[N_firings++][1]=i;
  2816. if (N_firings == N_firings_max) {
  2817. ThrowTooManySpikes(t);
  2818. }
  2819. }
  2820. }
  2821. }
  2822. for (i=0;i<N;i++)
  2823. {
  2824. Input[i] = 0; // reset input
  2825. InhInput[i]=0;
  2826. NmdaAmpaInput[i]=0;
  2827. // decay synaptic potentials
  2828. NmdaRisePot[i] *= TauNmdaRiseFac;
  2829. NmdaFallPot[i] *= TauNmdaFallFac;
  2830. AmpaRisePot[i] *= TauAmpaRiseFac;
  2831. AmpaFallPot[i] *= TauAmpaFallFac;
  2832. GabaARisePot[i] *= TauGabaARiseFac;
  2833. GabaAFallPot[i] *= TauGabaAFallFac;
  2834. GabaBRisePot[i] *= TauGabaBRiseFac;
  2835. GabaBFallPot[i] *= TauGabaBFallFac;
  2836. //if (GabaARisePot[i] != 0 && GabaARisePot[i] < numeric_limits<float>::min( )) cerr << "PERFORMANCE-WARNING: denormal floating point number\n";
  2837. }
  2838. }
  2839. int DecoLifLayer::proceedeInThread(int TotalTime)
  2840. {
  2841. int t = TotalTime % MacroTimeStep;
  2842. }
  2843. int DecoLifLayer::calculateInThread(int Start_Index, int Stop_Index)
  2844. {
  2845. int i,j,k;
  2846. last_N_firings = N_firings;
  2847. if (BinRec) BinRec->record();
  2848. for (i=Start_Index;i<Stop_Index;i++)
  2849. {
  2850. // Input[i] += abs(gsl_ran_gaussian(gslr, NoiseSigma));
  2851. Input[i] += NoiseAmplitude*gsl_ran_poisson(gslr, PoissonLambda);
  2852. Input[i] += NmdaAmpaInput[i];
  2853. Input[i] *= AmpaCorr;
  2854. InhInput[i] *= GabaACorr;
  2855. NmdaAmpaInput[i] *= NmdaCorr;
  2856. AmpaRisePot[i] += Input[i];
  2857. AmpaFallPot[i] += Input[i];
  2858. NmdaRisePot[i] += NmdaAmpaRatio*NmdaAmpaInput[i];
  2859. NmdaFallPot[i] += NmdaAmpaRatio*NmdaAmpaInput[i];
  2860. GabaARisePot[i] += InhInput[i];
  2861. GabaAFallPot[i] += InhInput[i];
  2862. GabaBRisePot[i] +=GabaABRatio*InhInput[i];
  2863. GabaBFallPot[i] += GabaABRatio*InhInput[i];
  2864. // if (i == 0) cerr << "Nmda=" << NmdaRisePot[i] << " " << NmdaFallPot[i] << "\n";
  2865. // InhSynPot[i] += abs(gsl_ran_gaussian(gslr, NoiseSigma));
  2866. AmpaPot[i] = AmpaFallPot[i] - AmpaRisePot[i];
  2867. float Nmda = NmdaFallPot[i] - NmdaRisePot[i];
  2868. float GabaA = GabaAFallPot[i] - GabaARisePot[i];
  2869. float GabaB = GabaBFallPot[i] - GabaBRisePot[i];
  2870. v[i] += CMembraneFac*(-GLeak*(v[i]-RestingPot)
  2871. - AmpaPot[i]*(v[i]-NaReversePot)
  2872. + INmda(v[i])*Nmda
  2873. - (v[i]-GabaAReversePot)*(GabaA+BalancedInhibition)
  2874. - (v[i]-GabaBReversePot)*GabaB
  2875. );
  2876. if (Refractory[i]>0) {
  2877. --Refractory[i];
  2878. v[i] = ResetPot; // voltage reset
  2879. } else {
  2880. if (v[i]>=Threshold) { // did it fire?
  2881. // if (i == 0) cerr << N_firings << "spike\n"; fflush(stdout);
  2882. // v[i] = ResetPot; // voltage reset
  2883. v[i] = SpikePot; // fake spike for LIF Neuron
  2884. Refractory[i] = arf;
  2885. // MUTEX for protecting firings!!
  2886. firings[N_firings ][0]=t;
  2887. firings[N_firings++][1]=i;
  2888. if (N_firings == N_firings_max) {
  2889. ThrowTooManySpikes(t);
  2890. }
  2891. }
  2892. }
  2893. }
  2894. for (i=Start_Index;i<Stop_Index;i++)
  2895. {
  2896. Input[i] = 0; // reset input
  2897. InhInput[i]=0;
  2898. NmdaAmpaInput[i]=0;
  2899. // decay synaptic potentials
  2900. NmdaRisePot[i] *= TauNmdaRiseFac;
  2901. NmdaFallPot[i] *= TauNmdaFallFac;
  2902. AmpaRisePot[i] *= TauAmpaRiseFac;
  2903. AmpaFallPot[i] *= TauAmpaFallFac;
  2904. GabaARisePot[i] *= TauGabaARiseFac;
  2905. GabaAFallPot[i] *= TauGabaAFallFac;
  2906. GabaBRisePot[i] *= TauGabaBRiseFac;
  2907. GabaBFallPot[i] *= TauGabaBFallFac;
  2908. if (GabaARisePot[i] != 0 && GabaARisePot[i] < 0.00000000001) cerr << "PERFORMANCE-WARNING: small floating point number\n";
  2909. }
  2910. }
  2911. int DecoLifLayer::reset(int TotalTime)
  2912. {
  2913. int t = TotalTime % MacroTimeStep;
  2914. AmpaNmdaGabaChannels::reset();
  2915. for (int i=0;i<N;++i) {
  2916. Refractory[i]=0;
  2917. v[i] = RestingPot;
  2918. }
  2919. // delete all spikes which are still in the delay line
  2920. // firings with firing times higher than t-MaximumDelay
  2921. int MaximumDelay = SimElement::MainSimLoop->GetMaximumDelay();
  2922. int k=N_firings-1;
  2923. while (t-firings[k][0]<MaximumDelay) k--;
  2924. N_firings = k+1;
  2925. }
  2926. float* DecoLifLayer::GetInputPointer(csimInputChannel InputNumber)
  2927. {
  2928. Dout(dc::layer, "InputNumber=" << int(InputNumber) << "");
  2929. switch (InputNumber) {
  2930. case csimInputChannel_AMPA: {
  2931. Dout(dc::layer, "Excitatory Input");
  2932. return Input;
  2933. } break;
  2934. case csimInputChannel_GABAa: {
  2935. Dout(dc::layer, "Inhibitory Input");
  2936. return InhInput;
  2937. } break;
  2938. case csimInputChannel_NMDA_AMPA: {
  2939. Dout(dc::layer, "Mixed: Excitatory and NMDA-Input");
  2940. return NmdaAmpaInput;
  2941. } break;
  2942. default:
  2943. return Input;
  2944. }
  2945. return 0;
  2946. }
  2947. float* DecoLifLayer::GetPspPointer(csimInputChannel InputNumber)
  2948. {
  2949. switch (InputNumber) {
  2950. case csimInputChannel_AMPA: {
  2951. Dout(dc::layer, "Excitatory Input");
  2952. return AmpaPot;
  2953. } break;
  2954. default:
  2955. return AmpaPot;
  2956. }
  2957. return 0;
  2958. }
  2959. long DecoLifLayer::calcMemoryConsumption()
  2960. {
  2961. long MemSum=0;
  2962. MemSum += calcMemConsumption();
  2963. MemSum += layer::calcMemoryConsumption();
  2964. MemSum += sizeof(int)*N; //int* Refractory;
  2965. }
  2966. /** Starts binary recording of membrane potential and synaptic potentials
  2967. *
  2968. * @param nobserve number of neurons to observe
  2969. * @param NNumber starting number. Neurons in the range [NNumber,NNumber+nobserve-1] are recorded
  2970. * @return
  2971. */
  2972. int DecoLifLayer::StartBinRec(int nobserve, int NNumber)
  2973. {
  2974. int NumObserve = 9*nobserve;
  2975. float** Buffer = new float* [NumObserve];
  2976. for (int i=0;i<nobserve; ++i) Buffer[i] = &(v[i+NNumber]);
  2977. for (int i=0;i<nobserve; ++i) Buffer[i+nobserve] = &(AmpaRisePot[i+NNumber]);
  2978. for (int i=0;i<nobserve; ++i) Buffer[i+2*nobserve] = &(AmpaFallPot[i+NNumber]);
  2979. for (int i=0;i<nobserve; ++i) Buffer[i+3*nobserve] = &(GabaARisePot[i+NNumber]);
  2980. for (int i=0;i<nobserve; ++i) Buffer[i+4*nobserve] = &(GabaAFallPot[i+NNumber]);
  2981. for (int i=0;i<nobserve; ++i) Buffer[i+5*nobserve] = &(NmdaRisePot[i+NNumber]);
  2982. for (int i=0;i<nobserve; ++i) Buffer[i+6*nobserve] = &(NmdaFallPot[i+NNumber]);
  2983. for (int i=0;i<nobserve; ++i) Buffer[i+7*nobserve] = &(GabaBRisePot[i+NNumber]);
  2984. for (int i=0;i<nobserve; ++i) Buffer[i+8*nobserve] = &(GabaBFallPot[i+NNumber]);
  2985. string FileName(MemPotFileName);
  2986. BinRec = new BinRecorder(MacroTimeStep, NumObserve, nobserve, Buffer, dt, (DataDirectory+FileName).c_str());
  2987. }
  2988. //Hodgkin-Huxley-Model-Neuron
  2989. HodgHuxLayer::HodgHuxLayer(int n,float vl,float vna,float vk,float gl,float gna,float gk,float cm,float vshift,float spikedetectionthreshold,float mmin,float mmax,float mstart, int mn) : layer(n), AmpaNmdaGabaChannels(n),gL(gl),gNa(gna),gK(gk),CM(cm),VShift(vshift),Mstart(mstart),MN(mn)
  2990. {
  2991. SpikeDetectionThreshold=spikedetectionthreshold-VShift;
  2992. VL=vl-VShift;
  2993. VNa=vna-VShift;
  2994. VK=vk-VShift;
  2995. Mmin=mmin-VShift;
  2996. Mmax=mmax-VShift;
  2997. hParas[0]=0.07;
  2998. hParas[1]=20;
  2999. hParas[2]=1;
  3000. hParas[3]=30-VShift;
  3001. hParas[4]=0.1;
  3002. hParas[5]=1;
  3003. mParas[0]=0.1;
  3004. mParas[1]=24-VShift;
  3005. mParas[2]=0.1;
  3006. mParas[3]=1;
  3007. mParas[4]=4;
  3008. mParas[5]=18;
  3009. nParas[0]=0.01;
  3010. nParas[1]=10-VShift;
  3011. nParas[2]=0.1;
  3012. nParas[3]=1;
  3013. nParas[4]=0.125;
  3014. nParas[5]=80;
  3015. hAlphaArr=new float[MN];
  3016. mAlphaArr=new float[MN];
  3017. nAlphaArr=new float[MN];
  3018. hBetaArr=new float[MN];
  3019. mBetaArr=new float[MN];
  3020. nBetaArr=new float[MN];
  3021. setxAlphaBeta(HodgHux_h,hParas);
  3022. setxAlphaBeta(HodgHux_m,mParas);
  3023. setxAlphaBeta(HodgHux_n,nParas);
  3024. hNa=new float[N];
  3025. mNa=new float[N];
  3026. nK=u;
  3027. M=v;
  3028. int index=M2index(Mstart);
  3029. for (int i=0;i<N;i++)
  3030. {
  3031. hNa[i]=hAlphaArr[index]/(hAlphaArr[index]+hBetaArr[index]);
  3032. mNa[i]=mAlphaArr[index]/(mAlphaArr[index]+mBetaArr[index]);
  3033. nK[i]=nAlphaArr[index]/(nAlphaArr[index]+nBetaArr[index]);
  3034. M[i]=Mstart;
  3035. }
  3036. alreadySpiked=new bool[N];
  3037. for (int i=0;i<N;i++) alreadySpiked[i]=false;
  3038. NaReversePot=VNa;
  3039. GabaAReversePot=VK;
  3040. GabaBReversePot=VL;
  3041. }
  3042. HodgHuxLayer::~HodgHuxLayer()
  3043. {
  3044. delete[] hAlphaArr;
  3045. delete[] mAlphaArr;
  3046. delete[] nAlphaArr;
  3047. delete[] hBetaArr;
  3048. delete[] mBetaArr;
  3049. delete[] nBetaArr;
  3050. delete[] hNa;
  3051. delete[] mNa;
  3052. delete[] alreadySpiked;
  3053. }
  3054. int HodgHuxLayer::proceede(int t)
  3055. {
  3056. //Dout(dc::layer, "Anfang von proceede Layer"); fflush(stdout);
  3057. //Dout(dc::layer, M[0]);
  3058. if (BinRec) BinRec->record();
  3059. for (int i=0;i<N;i++)
  3060. {
  3061. // float ma,ha,na,mb,hb,nb;
  3062. // na = nParas[0]*(nParas[1]-M[i])/(exp((nParas[1]-M[i])*nParas[2])-nParas[3]);
  3063. // nb = nParas[4]*exp(-(M[i]+VShift)/nParas[5]);
  3064. // ma = mParas[0]*(mParas[1]-M[i])/(exp((mParas[1]-M[i])*mParas[2])-mParas[3]);
  3065. // mb = mParas[4]*exp(-(M[i]+VShift)/mParas[5]);
  3066. // ha = hParas[0]*exp(-(M[i]+VShift)/hParas[1]);
  3067. // hb = hParas[2]/(exp((hParas[3]-M[i])*hParas[4])+hParas[5]);
  3068. // mNa[i]+=dt*(ma*(1-mNa[i])-mb*mNa[i]);
  3069. // hNa[i]+=dt*(ha*(1-hNa[i])-hb*hNa[i]);
  3070. // nK[i]+=dt*(na*(1-nK[i])-nb*nK[i]);
  3071. int index=M2index(M[i]);
  3072. mNa[i]+=dt*(mAlphaArr[index]*(1-mNa[i])-mBetaArr[index]*mNa[i]);
  3073. hNa[i]+=dt*(hAlphaArr[index]*(1-hNa[i])-hBetaArr[index]*hNa[i]);
  3074. nK[i]+=dt*(nAlphaArr[index]*(1-nK[i])-nBetaArr[index]*nK[i]);
  3075. M[i]-=dt/CM*(gL*(M[i]-VL)
  3076. +gNa*(mNa[i])*(mNa[i])*(mNa[i])*(hNa[i])*(M[i]-VNa)
  3077. +gK*(nK[i])*(nK[i])*(nK[i])*(nK[i])*(M[i]-VK)
  3078. // -Input[i]
  3079. );
  3080. //Input[i] += NoiseAmplitude*gsl_ran_poisson(gslr, PoissonLambda);
  3081. Input[i] += NmdaAmpaInput[i];
  3082. //Dout(dc::layer, "Vor ...Corr"); fflush(stdout);
  3083. Input[i] *= AmpaCorr;
  3084. InhInput[i] *= GabaACorr;
  3085. NmdaAmpaInput[i] *= NmdaCorr;
  3086. //Dout(dc::layer, "...Corr klappt"); fflush(stdout);
  3087. AmpaRisePot[i] += Input[i];
  3088. AmpaFallPot[i] += Input[i];
  3089. NmdaRisePot[i] += NmdaAmpaRatio*NmdaAmpaInput[i];
  3090. NmdaFallPot[i] += NmdaAmpaRatio*NmdaAmpaInput[i];
  3091. GabaARisePot[i] += InhInput[i];
  3092. GabaAFallPot[i] += InhInput[i];
  3093. GabaBRisePot[i] +=GabaABRatio*InhInput[i];
  3094. GabaBFallPot[i] += GabaABRatio*InhInput[i];
  3095. //Dout(dc::layer, "...Input[i] klappt"); fflush(stdout);
  3096. AmpaPot[i] = AmpaFallPot[i] - AmpaRisePot[i];
  3097. float Nmda = NmdaFallPot[i] - NmdaRisePot[i];
  3098. float GabaA = GabaAFallPot[i] - GabaARisePot[i];
  3099. float GabaB = GabaBFallPot[i] - GabaBRisePot[i];
  3100. M[i]+=dt/CM*(- AmpaPot[i]*(M[i]-NaReversePot)
  3101. + INmda(M[i])*Nmda
  3102. - (M[i]-GabaAReversePot)*(GabaA+BalancedInhibition)
  3103. - (M[i]-GabaBReversePot)*GabaB
  3104. );
  3105. //Dout(dc::layer, "...Pot klappt"); fflush(stdout);
  3106. if ((M[i]>SpikeDetectionThreshold) && (!alreadySpiked[i]))
  3107. {
  3108. firings[N_firings ][0]=t;
  3109. firings[N_firings++][1]=i;
  3110. alreadySpiked[i]=true;
  3111. }
  3112. if (alreadySpiked[i] && M[i]<SpikeDetectionThreshold) alreadySpiked[i]=false;
  3113. }
  3114. //Dout(dc::layer, "Ende von proceede Layer"); fflush(stdout);
  3115. for (int i=0;i<N;i++)
  3116. {
  3117. Input[i] = 0; // reset input
  3118. InhInput[i]=0;
  3119. NmdaAmpaInput[i]=0;
  3120. // decay synaptic potentials
  3121. NmdaRisePot[i] *= TauNmdaRiseFac;
  3122. NmdaFallPot[i] *= TauNmdaFallFac;
  3123. AmpaRisePot[i] *= TauAmpaRiseFac;
  3124. AmpaFallPot[i] *= TauAmpaFallFac;
  3125. GabaARisePot[i] *= TauGabaARiseFac;
  3126. GabaAFallPot[i] *= TauGabaAFallFac;
  3127. GabaBRisePot[i] *= TauGabaBRiseFac;
  3128. GabaBFallPot[i] *= TauGabaBFallFac;
  3129. }
  3130. //Dout(dc::layer, "wirklich Ende von proceede"); fflush(stdout);
  3131. }
  3132. void HodgHuxLayer::setxAlphaBeta(HodgHuxGate gate,float paras[6])
  3133. {
  3134. int i;
  3135. float vi;
  3136. float (HodgHuxLayer::*parapointer)[6];
  3137. switch (gate) {
  3138. case HodgHux_h:
  3139. for (i=0;i<MN;i++)
  3140. {
  3141. vi=Mmin+(Mmax-Mmin)*(i/(float)MN);
  3142. hAlphaArr[i]=paras[0]*exp(-(vi+VShift)/paras[1]);
  3143. hBetaArr[i]=paras[2]/(exp((paras[3]-vi)*paras[4])+paras[5]);
  3144. parapointer=&HodgHuxLayer::hParas;
  3145. }
  3146. break;
  3147. case HodgHux_m:
  3148. for (i=0;i<MN;i++)
  3149. {
  3150. vi=Mmin+(Mmax-Mmin)*(i/(float)MN);
  3151. mAlphaArr[i]=paras[0]*(paras[1]-vi)/(exp((paras[1]-vi)*paras[2])-paras[3]);
  3152. mBetaArr[i]=paras[4]*exp(-(vi+VShift)/paras[5]);
  3153. parapointer=&HodgHuxLayer::mParas;
  3154. }
  3155. break;
  3156. case HodgHux_n:
  3157. for (i=0;i<MN;i++)
  3158. {
  3159. vi=Mmin+(Mmax-Mmin)*(i/(float)MN);
  3160. nAlphaArr[i]=paras[0]*(paras[1]-vi)/(exp((paras[1]-vi)*paras[2])-paras[3]);
  3161. nBetaArr[i]=paras[4]*exp(-(vi+VShift)/paras[5]);
  3162. parapointer=&HodgHuxLayer::nParas;
  3163. }
  3164. break;
  3165. }
  3166. for (i=0;i<6;i++) (this->*parapointer)[i]=paras[i];
  3167. if (parapointer==&HodgHuxLayer::nParas) cout<<"n ";
  3168. if (parapointer==&HodgHuxLayer::mParas) cout<<"m ";
  3169. if (parapointer==&HodgHuxLayer::hParas) cout<<"h ";
  3170. Dout(dc::layer, paras[0]<<" "<<paras[1]<<" "<<paras[2]<<" "<<paras[3]<<" "<<paras[4]<<" "<<paras[5]);
  3171. Dout(dc::layer, (this->*parapointer)[0]<<" "<<(this->*parapointer)[1]<<" "<<(this->*parapointer)[2]<<" "<<(this->*parapointer)[3]<<" "<<(this->*parapointer)[4]<<" "<<(this->*parapointer)[5]);
  3172. }
  3173. int HodgHuxLayer::M2index(float m)
  3174. {
  3175. int zwischen=(int)( (m-Mmin)/(Mmax-Mmin)*MN );
  3176. //Dout(dc::layer, "Angang von M2index. m="<<m<<" out="<<zwischen);
  3177. if (m<Mmin)
  3178. {
  3179. //Dout(dc::layer, "Ende von M2index. Returned 0."); fflush(stdout);
  3180. return 0;
  3181. }
  3182. else if (m>Mmax)
  3183. {
  3184. //Dout(dc::layer, "Ende von M2index. Returned MN-1."); fflush(stdout);
  3185. return MN-1;
  3186. }
  3187. else
  3188. {
  3189. //Dout(dc::layer, "Ende von M2index. Returned zwischen."); fflush(stdout);
  3190. return (int)( (m-Mmin)/(Mmax-Mmin)*MN );
  3191. }
  3192. }
  3193. float* HodgHuxLayer::GetInputPointer(csimInputChannel InputNumber)
  3194. {
  3195. switch (InputNumber) {
  3196. case csimInputChannel_AMPA: {
  3197. Dout(dc::layer, "Excitatory Input");
  3198. return Input;
  3199. } break;
  3200. case csimInputChannel_GABAa: {
  3201. Dout(dc::layer, "Inhibitory Input");
  3202. return InhInput;
  3203. } break;
  3204. case csimInputChannel_NMDA_AMPA: {
  3205. Dout(dc::layer, "Mixed: Excitatory and NMDA-Input");
  3206. return NmdaAmpaInput;
  3207. } break;
  3208. default:
  3209. return Input;
  3210. }
  3211. return 0;
  3212. }
  3213. int HodgHuxLayer::WriteSimInfo(fstream &fw)
  3214. {
  3215. fw << "<" << seTypeString << " id=\"" << IdNumber << "\" Type=\"" << seType << "\" Name=\"" << Name << "\"> \n";
  3216. fw << " <LayerType value=\"" << "Hodgkin-Huxley" << "\"/> \n";
  3217. fw << " <LayerDimensions N=\"" << N << "\" Nx=\"" << Nx << "\" Ny=\"" << Ny << "\"/> \n";
  3218. fw << "</" << seTypeString << "> \n";
  3219. }
  3220. int HodgHuxLayer::StartBinRec(int nobserve, int NNumber)
  3221. {
  3222. int NumObserve = 6*nobserve;
  3223. float** Buffer = new float* [NumObserve];
  3224. for (int i=0;i<nobserve; ++i) Buffer[i] = &(v[i+NNumber]);
  3225. // for (int i=0;i<nobserve; ++i) Buffer[i+nobserve] = &(hNa[i+NNumber]);
  3226. // for (int i=0;i<nobserve; ++i) Buffer[i+2*nobserve] = &(mNa[i+NNumber]);
  3227. // for (int i=0;i<nobserve; ++i) Buffer[i+3*nobserve] = &(nK[i+NNumber]);
  3228. for (int i=0;i<nobserve; ++i) Buffer[i+nobserve] = &(AmpaPot[i+NNumber]);
  3229. for (int i=0;i<nobserve; ++i) Buffer[i+2*nobserve] = &(GabaARisePot[i+NNumber]);
  3230. for (int i=0;i<nobserve; ++i) Buffer[i+3*nobserve] = &(GabaAFallPot[i+NNumber]);
  3231. for (int i=0;i<nobserve; ++i) Buffer[i+4*nobserve] = &(GabaBRisePot[i+NNumber]);
  3232. for (int i=0;i<nobserve; ++i) Buffer[i+5*nobserve] = &(GabaBFallPot[i+NNumber]);
  3233. string FileName(MemPotFileName);
  3234. BinRec = new BinRecorder(MacroTimeStep, NumObserve, nobserve, Buffer, dt, (DataDirectory+FileName).c_str());
  3235. }
  3236. /////////////////////////////////////////