simmodules.cpp 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386
  1. #include "sys.hpp" // for libcwd
  2. #include "debug.hpp" // for libcwd
  3. #include "objsimlibrary.hpp"
  4. #include "simmodule.hpp"
  5. #include "simmodules.hpp"
  6. ////////////////
  7. SimModuleITLayer::SimModuleITLayer(AnyOptionWrapper* _opt): SimModule(_opt), CompInh(_opt), ITLayer(0), ConITSelfInh(0)
  8. {
  9. }
  10. SimModuleITLayer::~SimModuleITLayer()
  11. {
  12. cout << "Destructor SimModuleITLayer::~SimModuleITLayer()\n";
  13. if (ConITSelfInh) {
  14. ConITSelfInh->Save();
  15. delete ConITSelfInh;
  16. }
  17. delete ITLayer;
  18. }
  19. void SimModuleITLayer::SetCmdLineOptions()
  20. {
  21. myAnyWrap->setOption( "ITNx", 'a', &ITNx, 4);
  22. myAnyWrap->setOption( "ITNy", 'a', &ITNy, 4);
  23. myAnyWrap->setOption("ITTauInhibition", 'a', &ITTauInhibition, 5.0);
  24. // myAnyWrap->setOption("ITTauFeeding", 'a', &ITTauFeeding, 5);
  25. myAnyWrap->setOption("NmdaAmpaRatio", 'a', &NmdaAmpaRatio, 0.3);
  26. myAnyWrap->setFlag( "LoadITWeights", 'a', &LoadITWeights);
  27. myAnyWrap->setOption("ITLateralInhibitionWeight", 'a', &ITLateralInhibitionWeight, 0.01);
  28. myAnyWrap->setFlag( "ITSelfInhFacilitation", 'a', &ITSelfInhFacilitation);
  29. myAnyWrap->setOption( "ITSelfLearnRate", 'a', &ITSelfLearnRate,0.0001);
  30. myAnyWrap->setOption("LatInhDistance", 'a', &LatInhDistance, 0.3);
  31. myAnyWrap->setOption("SelfInhCdep", 'a', &SelfInhCdep, 0.0001);
  32. myAnyWrap->setOption("SelfInhMaxWeight", 'a', &SelfInhMaxWeight, 6);
  33. myAnyWrap->setOption("SelfInhMinWeight", 'a', &SelfInhMinWeight, 1);
  34. CompInh.SetCmdLineOptions();
  35. }
  36. layer* SimModuleITLayer::Setup(SimLoop *MainSimLoop, int NeuronType, bool LoadWeights, bool Learn, bool InhResetable, bool SaveInitialWeights)
  37. {
  38. if (LoadWeights) {
  39. LoadITWeights=true;
  40. }
  41. IzhParas IzhLowDIntegrator (0.02, -0.1, -55, 2, 108, 4.1, 0.0);
  42. csimNeuronType NType;
  43. if (NeuronType<csimNumberNTypes) NType=csimNeuronType(NeuronType);
  44. NType = csimNType_DecoLif; // remove this
  45. switch (NType) {
  46. case csimNType_Izhikevich8:
  47. {
  48. float NmdaAmpaRatio=0.3;
  49. izh8layer* tmplayer = new izh8layer(ITNx*ITNy, IzhParaRegularSpiking);
  50. tmplayer->SetTauGaba(1.0, ITTauInhibition);
  51. tmplayer->SetTauGaba(13.5, 100); // remove this
  52. tmplayer->SetTauAmpa(0.5, 2.4);
  53. tmplayer->SetTauNmda(10, 100);
  54. tmplayer->SetNoiseAmplitude(0.259545);
  55. tmplayer->SetBalancedInhibition(1.58025);
  56. // tmplayer->TuneNoiseAmplitude(100);
  57. // tmplayer->TuneBalancedInhibition(3);
  58. tmplayer->SetNmdaAmpaRatio(NmdaAmpaRatio);
  59. ITLayer = tmplayer;
  60. }
  61. break;
  62. case csimNType_Izhikevich8_integrator:
  63. {
  64. float NmdaAmpaRatio=0.3;
  65. izh8layer* tmplayer = new izh8layer(ITNx*ITNy, IzhParaIntegrator2);
  66. tmplayer->SetTauGaba(1.0, ITTauInhibition);
  67. tmplayer->SetTauGaba(13.5, 100); // remove this
  68. tmplayer->SetTauAmpa(0.5, 2.4);
  69. tmplayer->SetTauNmda(10, 100);
  70. tmplayer->SetNoiseAmplitude(0.172989);
  71. tmplayer->SetBalancedInhibition(1.48085);
  72. // tmplayer->TuneNoiseAmplitude(100);
  73. // tmplayer->TuneBalancedInhibition(3);
  74. tmplayer->SetNmdaAmpaRatio(NmdaAmpaRatio);
  75. ITLayer = tmplayer;
  76. }
  77. break;
  78. case csimNType_Izhikevich9:
  79. {
  80. float NmdaAmpaRatio=0.3;
  81. // izh9layer* tmplayer = new izh9layer(ITNx*ITNy, IzhParaRegularSpiking);
  82. izh9layer* tmplayer = new izh9layer(ITNx*ITNy, IzhParaIntegrator2);
  83. // tmplayer->SetTauGaba(1.0, ITTauInhibition);
  84. // tmplayer->SetTauGabaA(13.5, 100); // remove this
  85. tmplayer->SetTauAmpa(0.5, 2.4);
  86. tmplayer->SetTauNmda(10, 100);
  87. tmplayer->SetNoiseAmplitude(0.172989);
  88. tmplayer->SetBalancedInhibition(2.07651);
  89. // tmplayer->TuneNoiseAmplitude(100);
  90. // tmplayer->TuneBalancedInhibition(3);
  91. tmplayer->SetNmdaAmpaRatio(NmdaAmpaRatio);
  92. ITLayer = tmplayer;
  93. }
  94. break;
  95. case csimNType_DecoLif:
  96. {
  97. float NmdaAmpaRatio=0.3;
  98. // izh9layer* tmplayer = new izh9layer(ITNx*ITNy, IzhParaRegularSpiking);
  99. DecoLifLayer* tmplayer = new DecoLifLayer(ITNx*ITNy, DecoParaExcitatory);
  100. // tmplayer->SetTauGaba(1.0, ITTauInhibition);
  101. // tmplayer->SetTauGabaA(13.5, 100); // remove this
  102. // tmplayer->SetTauAmpa(0.5, 2.4);
  103. // tmplayer->SetTauNmda(10, 100);
  104. // tmplayer->TuneNoiseAmplitude(3);
  105. const float DECO_LIF_NOISE_3_HZ = 0.05294; // Noise: 3 Hz Background Firing Rate
  106. tmplayer->SetNoiseAmplitude(DECO_LIF_NOISE_3_HZ);
  107. // tmplayer->TuneNoiseAmplitude(100);
  108. // tmplayer->TuneBalancedInhibition(3);
  109. // tmplayer->SetNoiseAmplitude(0.0769104); // Noise: 100 Hz Background Firing Rate
  110. // tmplayer->SetBalancedInhibition(11.7664); // Reduce Background Firing Rate to 3 Hz
  111. tmplayer->SetNmdaAmpaRatio(NmdaAmpaRatio);
  112. ITLayer = tmplayer;
  113. }
  114. break;
  115. }
  116. ITLayer->SetName("RepresentationLayer");
  117. ITLayer->SetupPositions(ITNx,ITNy,true);
  118. ITLayer->SetRandomInputStrength(0);
  119. // ITLayer->StartBinRec(2);
  120. MainSimLoop->AddSimElement(ITLayer);
  121. // Setup ITSelfInhibition
  122. bool VecCon=true;
  123. layer* InhLayer = CompInh.Setup(ITLayer, LoadITWeights, VecCon, SaveInitialWeights);
  124. InhLayer->SetResetable(InhResetable);
  125. // ConITSelfInh=0;
  126. // if (ITLateralInhibitionWeight > 0) {
  127. // if (ITSelfInhFacilitation) {
  128. // FacilitativeConnection *tmpCon = new FacilitativeConnection(ITLayer, ITLayer, csimInputChannel_GABAa, 60, 0.005, 50, 0.01); // inputNumber=0
  129. // ConITSelfInh = tmpCon;
  130. // } else {
  131. // connection *tmpCon = new connection(ITLayer, ITLayer, csimInputChannel_GABAa, true); // inputNumber=0
  132. // ConITSelfInh = tmpCon;
  133. // }
  134. // ConITSelfInh->SetNonSelf(true);
  135. // ConITSelfInh->SetName("conSelfInh");
  136. // if (LoadITWeights) ConITSelfInh->Load();
  137. // else {
  138. // ConITSelfInh->ConnectFull(ITLateralInhibitionWeight, 0,0);
  139. // // ConITSelfInh->ConnectRandom(0.4, ITLateralInhibitionWeight, 1,0);
  140. // // DistanceProfile* profile = new CircleDistanceProfile(1000, LatInhDistance);
  141. // // ConITSelfInh->ConnectProfile(profile, ITLateralInhibitionWeight, 0,0, true);
  142. // // ConITSelfInh->ConnectRandom(0.2, ITLateralInhibitionWeight, 1,0);
  143. // }
  144. // float SelfInhMinWeight=0;
  145. // float InhLearnTauPost=100;
  146. // float InhLearnTauPre=30;
  147. // if (Learn && (ITSelfLearnRate >0)) {
  148. // LearnFBInh* LearnSelfITInh = new LearnFBInh(ConITSelfInh,
  149. // SelfInhMaxWeight, InhLearnTauPre, InhLearnTauPost, ITSelfLearnRate, SelfInhCdep);
  150. // // LearnHebbLP2* LearnSelfITInh = new LearnHebbLP2(
  151. // // ConITSelfInh, SelfInhMaxWeight, SelfInhLearnTauDec,
  152. // // SelfInhBaseLine, ITSelfLearnRate);
  153. // LearnSelfITInh->SetMinWeight(SelfInhMinWeight);
  154. // ConITSelfInh->SetLearnObj(LearnSelfITInh);
  155. // }
  156. // ConITSelfInh->Save();
  157. // ConITSelfInh->SetAutoSave(false);
  158. // MainSimLoop->AddSimElement(ConITSelfInh);
  159. // }
  160. return ITLayer;
  161. }
  162. void SimModuleITLayer::SetInhExWeightStrength(float NewInhExStrength)
  163. {
  164. CompInh.SetInhExWeightStrength(NewInhExStrength);
  165. }
  166. SpikeTrain* SimModuleITLayer::ItSpikeTrain()
  167. {
  168. if (ITLayer) {
  169. return ITLayer->GetSpikeTrain();
  170. } else {
  171. cerr << "ERROR in SimModuleITLayer::ItSpikeTrain(): this should not happen. ITLayer not initialized?\n";
  172. return 0;
  173. }
  174. };
  175. ////////////////////////
  176. InvarLayer::InvarLayer(AnyOptionWrapper* _opt): SimModule(_opt), MapLayer(0), VecCon(false)
  177. {
  178. NType = csimNType_DecoLif; // remove this
  179. Nx=Ny=10;
  180. }
  181. InvarLayer::~InvarLayer()
  182. {
  183. delete LInvar;
  184. delete conMapLInvar;
  185. }
  186. void InvarLayer::TurnOn()
  187. {
  188. LInvar->TurnOn();
  189. conMapLInvar->TurnOn();
  190. }
  191. void InvarLayer::TurnOff()
  192. {
  193. LInvar->TurnOff();
  194. conMapLInvar->TurnOff();
  195. }
  196. void InvarLayer::SetCmdLineOptions()
  197. {
  198. myAnyWrap->setOption((SimModuleName + "FWConStrength").c_str(), 'a', &FWConStrength, 0);
  199. }
  200. layer* InvarLayer::Setup(layer* MapLayer, bool _veccon, bool SaveInitialWeights)
  201. {
  202. VecCon=_veccon;
  203. MainSimLoop = GetGlobalSimLoop();
  204. if (FWConStrength > 0) {
  205. // Setup Invar Layer
  206. switch (NType) {
  207. case csimNType_DecoLif:
  208. {
  209. float NmdaAmpaRatio=0.3;
  210. DecoLifLayer* tmplayer = new DecoLifLayer(Nx*Ny, DecoParaExcitatory);
  211. tmplayer->SetName((SimModuleName+"InvarLayer").c_str());
  212. tmplayer->SetNoiseAmplitude(0.05294); // Noise: 3 Hz Background Firing Rate
  213. tmplayer->SetNmdaAmpaRatio(NmdaAmpaRatio);
  214. tmplayer->SetupPositions(Nx, Ny, true);
  215. MainSimLoop->AddSimElement(tmplayer);
  216. LInvar = tmplayer;
  217. }
  218. break;
  219. }
  220. // Setup Forward Connections from MapLayer to Invar Layer
  221. float ConRange=0.2;
  222. if (VecCon) {
  223. VecConnection* tmpcon = new VecConnection(MapLayer, LInvar, csimInputChannel_AMPA);
  224. tmpcon->ConnectGaussian(ConRange, FWConStrength, 1,0, true);
  225. conMapLInvar=tmpcon;
  226. } else {
  227. connection* tmpcon = new connection(MapLayer, LInvar, csimInputChannel_AMPA);
  228. tmpcon->ConnectGaussian(ConRange, FWConStrength, 1,0, true);
  229. conMapLInvar=tmpcon;
  230. }
  231. conMapLInvar->SetName((SimModuleName+"conMapToInvar").c_str());
  232. if (SaveInitialWeights) {
  233. conMapLInvar->Save();
  234. }
  235. MainSimLoop->AddSimElement(conMapLInvar);
  236. }
  237. return LInvar; // if (FWConStrength == 0) LInvar stays "0"
  238. }
  239. //////////////////////////
  240. SimMod_CompetitiveInhibition::SimMod_CompetitiveInhibition(AnyOptionWrapper* _opt): SimModule(_opt), NInhNeurons(100), InhLayer(0), conInhEx(0), conInhInh(0), conExInh(0)
  241. {
  242. }
  243. void SimMod_CompetitiveInhibition::SetCmdLineOptions()
  244. {
  245. std::string ModName("CInh");
  246. myAnyWrap->setOption((ModName + "NInhNeurons").c_str(), 'a', &NInhNeurons, 100);
  247. myAnyWrap->setOption((ModName + "NExInhConnections").c_str(), 'a', &NExInhConnections, 10);
  248. myAnyWrap->setOption((ModName + "NInhExConnections").c_str(), 'a', &NInhExConnections, 10);
  249. myAnyWrap->setOption((ModName + "NInhInhConnections").c_str(), 'a', &NInhInhConnections, 10);
  250. myAnyWrap->setOption((ModName + "ExInhStrength").c_str(), 'a', &ExInhStrength, 0.1);
  251. myAnyWrap->setOption((ModName + "InhExStrength").c_str(), 'a', &InhExStrength, 0.1);
  252. myAnyWrap->setOption((ModName + "InhInhStrength").c_str(), 'a', &InhInhStrength, 0.1);
  253. myAnyWrap->setOption((ModName + "NmdaAmpaRatio").c_str(), 'a', &NmdaAmpaRatio, 0.1);
  254. }
  255. layer* SimMod_CompetitiveInhibition::Setup(layer* ExLayer, bool LoadWeights, bool VecCon, bool SaveInitialWeights)
  256. {
  257. // first: create inhibitory layer
  258. MainSimLoop = GetGlobalSimLoop();
  259. int InhNx, InhNy;
  260. InhNx = NInhNeurons;
  261. InhNy = 1;
  262. layer* InhLayer;
  263. csimNeuronType NType = csimNType_DecoLif;
  264. switch (NType) {
  265. case csimNType_Izhikevich9:
  266. {
  267. // izh9layer* tmplayer = new izh9layer(NInhNeurons, IzhParaRegularSpiking);
  268. izh9layer* tmplayer = new izh9layer(NInhNeurons, IzhParaIntegrator2);
  269. tmplayer->SetupPositions(InhNx, InhNy, true);
  270. // tmplayer->SetTauGaba(1.0, ITTauInhibition);
  271. // tmplayer->SetTauGabaA(13.5, 100); // remove this
  272. tmplayer->SetTauAmpa(0.5, 2.4);
  273. tmplayer->SetTauNmda(10, 100);
  274. tmplayer->SetNoiseAmplitude(0.172989);
  275. tmplayer->SetBalancedInhibition(2.07651);
  276. // tmplayer->TuneNoiseAmplitude(100);
  277. // tmplayer->TuneBalancedInhibition(3);
  278. tmplayer->SetNmdaAmpaRatio(NmdaAmpaRatio);
  279. tmplayer->SetName("InhibitionLayer");
  280. MainSimLoop->AddSimElement(tmplayer);
  281. InhLayer = tmplayer;
  282. }
  283. break;
  284. case csimNType_DecoLif:
  285. {
  286. float NmdaAmpaRatio=0.3;
  287. DecoLifLayer* tmplayer = new DecoLifLayer(NInhNeurons, DecoParaInhibitory);
  288. tmplayer->SetupPositions(InhNx, InhNy, true);
  289. // tmplayer->SetTauGaba(1.0, ITTauInhibition);
  290. // tmplayer->SetTauGabaA(13.5, 100); // remove this
  291. tmplayer->SetTauAmpa(0.5, 2.4);
  292. tmplayer->SetTauNmda(10, 100);
  293. tmplayer->SetNoiseAmplitude(0.0504967);
  294. tmplayer->SetBalancedInhibition(4.52554);
  295. // tmplayer->TuneNoiseAmplitude(100);
  296. // tmplayer->TuneBalancedInhibition(3);
  297. tmplayer->SetNmdaAmpaRatio(NmdaAmpaRatio);
  298. tmplayer->SetName("InhibitionLayer");
  299. MainSimLoop->AddSimElement(tmplayer);
  300. InhLayer = tmplayer;
  301. }
  302. break;
  303. }
  304. // InhLayer->StartBinRec(2);
  305. // setup Ex->Inh connections
  306. {
  307. if (NExInhConnections > ExLayer->N) {
  308. NExInhConnections = ExLayer->N;
  309. }
  310. if (VecCon) {
  311. VecConnection* tmpcon = new VecConnection(ExLayer, InhLayer, csimInputChannel_NMDA_AMPA);
  312. tmpcon->ConnectRandomIncomming(NExInhConnections,ExInhStrength,1,0,true);
  313. conExInh=tmpcon;
  314. } else {
  315. connection* tmpcon = new connection(ExLayer, InhLayer, csimInputChannel_NMDA_AMPA);
  316. tmpcon->ConnectRandom2(NExInhConnections,ExInhStrength,1,0,true);
  317. conExInh=tmpcon;
  318. }
  319. conExInh->SetName("conExInh");
  320. if (SaveInitialWeights) {
  321. conExInh->Save();
  322. }
  323. MainSimLoop->AddSimElement(conExInh);
  324. }
  325. // setup Inh->Ex connections
  326. {
  327. if (NInhExConnections > InhLayer->N) {
  328. NInhExConnections = InhLayer->N;
  329. }
  330. if (VecCon) {
  331. VecConnection* tmpcon = new VecConnection(InhLayer, ExLayer, csimInputChannel_GABAa);
  332. tmpcon->SetName("conInhEx");
  333. if (LoadWeights) {
  334. tmpcon->Load();
  335. } else {
  336. tmpcon->ConnectRandomIncomming(NInhExConnections,InhExStrength,1,0,true);
  337. }
  338. conInhEx=tmpcon;
  339. } else {
  340. connection* tmpcon = new connection(InhLayer, ExLayer, csimInputChannel_GABAa);
  341. tmpcon->SetName("conInhEx");
  342. if (LoadWeights) {
  343. tmpcon->Load();
  344. } else {
  345. tmpcon->ConnectRandom2(NInhExConnections,InhExStrength,1,0,true);
  346. }
  347. conInhEx=tmpcon;
  348. }
  349. if (SaveInitialWeights) {
  350. conInhEx->Save();
  351. }
  352. MainSimLoop->AddSimElement(conInhEx);
  353. }
  354. // setup Inh->Inh connections
  355. {
  356. if (NInhInhConnections > InhLayer->N) {
  357. NInhInhConnections = InhLayer->N;
  358. }
  359. if (VecCon) {
  360. VecConnection* tmpcon = new VecConnection(InhLayer, InhLayer, csimInputChannel_GABAa);
  361. tmpcon->SetName("conInhInh");
  362. if (LoadWeights) {
  363. tmpcon->Load();
  364. } else {
  365. tmpcon->ConnectRandomIncomming(NInhInhConnections,InhInhStrength,1,0,true);
  366. }
  367. conInhInh = tmpcon;
  368. } else {
  369. connection* tmpcon = new connection(InhLayer, InhLayer, csimInputChannel_GABAa);
  370. tmpcon->SetName("conInhInh");
  371. if (LoadWeights) {
  372. tmpcon->Load();
  373. } else {
  374. tmpcon->ConnectRandom2(NInhInhConnections,InhInhStrength,1,0,true);
  375. }
  376. conInhInh = tmpcon;
  377. }
  378. if (SaveInitialWeights) {
  379. conInhInh->Save();
  380. }
  381. MainSimLoop->AddSimElement(conInhInh);
  382. }
  383. return InhLayer;
  384. }
  385. void SimMod_CompetitiveInhibition::SetAllInhExWeights(float WeightValue)
  386. {
  387. if (conInhEx) {
  388. conInhEx->SetAllWeights(WeightValue);
  389. }
  390. }
  391. /**
  392. * set strength of connections from inhibitory neurons to excitatory neurons to new value
  393. * new value is stored in InhExStrength
  394. * @param NewInhExStrength
  395. */
  396. void SimMod_CompetitiveInhibition::SetInhExWeightStrength(float NewInhExStrength)
  397. {
  398. if (InhExStrength == 0 || !conInhEx) {return;} // error handling
  399. conInhEx->MultiplyAllTargetWeights(NewInhExStrength/InhExStrength);
  400. InhExStrength=NewInhExStrength;
  401. }
  402. /////////////////////////////////
  403. SimModuleInput::SimModuleInput(AnyOptionWrapper* _opt): SimModule(_opt), MovieDir(GetDefaultMovieDir())
  404. {
  405. }
  406. void SimModuleInput::SetCmdLineOptions()
  407. {
  408. myAnyWrap->setOption( "StimulusSet", 'a', &StimulusSet, 3);
  409. myAnyWrap->setOption( "StimulusNumber", 'a', &StimulusNumber, 0);
  410. myAnyWrap->setOption( "StimFileName", 'a', &StimFileName, "");
  411. myAnyWrap->setOption( "StimSequence", 'a', &StimSequence, "oripos.sequence");
  412. myAnyWrap->setOption( "StimDur", 'a', &StimDur, 200);
  413. myAnyWrap->setOption( "IsiDur", 'a', &IsiDur, 20);
  414. myAnyWrap->setFlag ("XContinuous", 'a', &XContinuous);
  415. }
  416. input* SimModuleInput::Setup(layer* TargetLayer, csimInputChannel InputNumber, float InputStrength)
  417. {
  418. MainSimLoop = GetGlobalSimLoop();
  419. // enum SimMod_StimSetType {Test, Parametric, Scan, FileName};
  420. input* l1inp;
  421. switch (SType) {
  422. case Test:
  423. {
  424. int FltNr=0;
  425. float Isi2Dur=0;
  426. int TestStimDur=249;
  427. int TestIsiDur= 1;
  428. cout << "Test all Stimuli systematically, NX=" << NXParas << "NY=" << NYParas << "\n";
  429. ScanObjMovieInput* MovieInput = new ScanObjMovieInput(
  430. TargetLayer, InputNumber, MyMovie, FltNr, InputStrength, StimDur, NXParas, NYParas,XContinuous, NXParas, IsiDur, Isi2Dur);
  431. MovieInput->SetXCircle(true);
  432. MovieInput->SetYCircle(true);
  433. cout << "before setname simmodules.cpp\n";fflush(stdout);
  434. MovieInput->SetName("MovieScanInput");
  435. cout << "before adding to mainsimloop simmodules.cpp\n";fflush(stdout);
  436. MainSimLoop->AddSimElement(MovieInput);
  437. cout << "after adding to mainsimloop simmodules.cpp\n";fflush(stdout);
  438. XYpairList StimList;
  439. for (int x=0;x<NXParas;++x) for (int y=0;y<NYParas;++y) {
  440. // cout << "x=" << 4*x << " y=" << 4*y << "\n";
  441. if (!XContinuous) {
  442. StimList.push_back(XYpair(x,y));
  443. } else {
  444. StimList.push_back(XYpair(y,x));
  445. }
  446. }
  447. MovieInput->InitializeTestMode(&StimList, TestStimDur,TestIsiDur);
  448. l1inp = MovieInput;
  449. }
  450. break;
  451. case Parametric: ;
  452. case Scan:;
  453. break;
  454. case MovieScan:
  455. {
  456. PictureSequenceInput* WinkelInput = new PictureSequenceInput(TargetLayer, InputNumber,InputStrength, StimDur, IsiDur);
  457. WinkelInput->SetPictureArray(MyMovie);
  458. WinkelInput->SetName("WinkelInput");
  459. WinkelInput->SetMode(csimInputRandom);
  460. // WinkelInput->SetRandomNext(true);
  461. MainSimLoop->AddSimElement(WinkelInput);
  462. l1inp = WinkelInput;
  463. }
  464. break;
  465. case FileName:
  466. {
  467. int FltNr=0;
  468. float Isi2Dur=0;
  469. int TestStimDur=249;
  470. int TestIsiDur= 1;
  471. cout << "NX=" << NXParas << "NY=" << NYParas << "\n";
  472. ScanObjMovieInput* MovieInput = new ScanObjMovieInput(
  473. TargetLayer, InputNumber, MyMovie, FltNr, InputStrength, StimDur, NXParas, NYParas,XContinuous, NXParas, IsiDur, Isi2Dur);
  474. MovieInput->SetXCircle(true);
  475. MovieInput->SetYCircle(true);
  476. cout << "before setname simmodules.cpp\n";fflush(stdout);
  477. MovieInput->SetName("MovieScanInput");
  478. cout << "before adding to mainsimloop simmodules.cpp\n";fflush(stdout);
  479. MainSimLoop->AddSimElement(MovieInput);
  480. cout << "after adding to mainsimloop simmodules.cpp\n";fflush(stdout);
  481. XYpairList StimList;
  482. for (int x=0;x<NXParas;++x) for (int y=0;y<NYParas;++y) {
  483. // cout << "x=" << 4*x << " y=" << 4*y << "\n";
  484. if (!XContinuous) {
  485. StimList.push_back(XYpair(x,y));
  486. } else {
  487. StimList.push_back(XYpair(y,x));
  488. }
  489. }
  490. MovieInput->InitializeTestMode(&StimList, TestStimDur,TestIsiDur);
  491. l1inp = MovieInput;
  492. }
  493. break;
  494. case IdlMovieFile:
  495. {
  496. int FltNr=0;
  497. float Isi2Dur=0;
  498. int TestStimDur=249;
  499. int TestIsiDur= 1;
  500. ObjMovieInput* MovieInput = new ObjMovieInput(
  501. TargetLayer, InputNumber, MyMovie, FltNr, InputStrength, StimDur, IsiDur);
  502. MovieInput->SetName("MovieInput");
  503. MainSimLoop->AddSimElement(MovieInput);
  504. // MovieInput->InitializeTestMode(&StimList, TestStimDur,TestIsiDur);
  505. l1inp = MovieInput;
  506. }
  507. break;
  508. case Sequence:
  509. {
  510. StimulusSequence* MySequence = new StimulusSequence((MovieDir + StimSequence).c_str());
  511. int FltNr=0;
  512. SequenceObjMovieInput* MovieInput = new SequenceObjMovieInput(
  513. TargetLayer, InputNumber, MyMovie, MySequence,
  514. FltNr, InputStrength, StimDur, 500);
  515. MainSimLoop->AddSimElement(MovieInput);
  516. l1inp = MovieInput;
  517. }
  518. break;
  519. case Ascii:
  520. {
  521. // StimulusSequence* MySequence = new StimulusSequence((MovieDir+"text.sequence").c_str());
  522. StimulusSequence* MySequence = new StimulusSequence((MovieDir+"abcdefgh.sequence").c_str());
  523. int FltNr=0;
  524. SequenceObjMovieInput* MovieInput = new SequenceObjMovieInput(
  525. TargetLayer, InputNumber, MyMovie, MySequence,
  526. FltNr, InputStrength, StimDur, 500);
  527. MainSimLoop->AddSimElement(MovieInput);
  528. l1inp = MovieInput;
  529. }
  530. break;
  531. default: cout << "nothing";
  532. }
  533. return l1inp;
  534. }
  535. void SimModuleInput::LoadMovie(int &InputNx, int &InputNy, int &NStimuli)
  536. {
  537. if (StimulusSet<SimMod_NumberStimSetTypes) SType=SimMod_StimSetType(StimulusSet);
  538. std::string MetaFileName = MovieDir + StimFileName + ".meta.xml";
  539. MovieMetaFile MetaFile(MetaFileName.c_str());
  540. std::string MovieFileName;
  541. if (MetaFile.Loaded) {
  542. MovieFileName = MetaFile.MovieFileName;
  543. } else {
  544. cout << "MovieMetaFile not loaded\n";
  545. MovieFileName = StimFileName + ".idlmov";
  546. cout << "using movie file name: MovieFileName\n";
  547. }
  548. std::string StimName;
  549. {
  550. StimName = MovieDir + MovieFileName;
  551. cout << "Load movie: " << StimName << "\n";
  552. }
  553. MyMovie = new ObjMovie(StimName.c_str());
  554. InputNx = MyMovie->GetOutputWidth(0);
  555. InputNy = MyMovie->GetOutputHeight(0);
  556. NStimuli = MyMovie->GetNFrames();
  557. if (MetaFile.Loaded) {
  558. NXParas = MetaFile.NXParas;
  559. NYParas = MetaFile.NYParas;
  560. } else {
  561. NXParas = NStimuli; // assume 1d stimulus set
  562. NYParas = NXParas;
  563. cout << "Set NXParas to NStimuli=" << NStimuli << " and NYParas=1\n";
  564. fflush(stdout);
  565. // NXParas = int(sqrt(float(NStimuli))); // assume square number of stimuli
  566. // NYParas = NXParas;
  567. }
  568. }
  569. ///Input/////////////////////////
  570. ///////////////////////////////////////
  571. SimModuleMovieInput::SimModuleMovieInput(AnyOptionWrapper* _opt)
  572. : SimModule(_opt), NTestStimuli(0), CommonInhibition(true), InhLayer(0), MovieDir(GetDefaultMovieDir())
  573. {
  574. }
  575. SimModuleMovieInput::~SimModuleMovieInput()
  576. {
  577. if (InhLayer) {
  578. delete InhLayer;
  579. }
  580. // this could be done in the SimModule destructor for the LayerList, ConnectionList, ...
  581. }
  582. void SimModuleMovieInput::SetCmdLineOptions()
  583. {
  584. myAnyWrap->setOption( "StimFileName", 'a', &StimFileName, "");
  585. // myAnyWrap->setOption( "StimSequence", 'a', &StimSequence, "oripos.sequence");
  586. myAnyWrap->setOption( "StimDur", 'a', &StimDur, 200);
  587. myAnyWrap->setOption( "IsiDur", 'a', &IsiDur, 20);
  588. myAnyWrap->setFlag ("XContinuous", 'a', &XContinuous);
  589. myAnyWrap->setOption( "LearnRate", 'a', &LearnRate, 0.002);
  590. myAnyWrap->setOption( "InitialWeights", 'a', &InitialWeights, 0.1);
  591. myAnyWrap->setOption("FRateNormThreshold", 'a', &FRateNormThreshold, 30);
  592. myAnyWrap->setOption( "InputExInhWeights", 'a', &ExInhWeights, 0.5);
  593. myAnyWrap->setOption( "InputInhExWeights", 'a', &InhExWeights, 0.5);
  594. myAnyWrap->setOption( "TestStepSize", 'a', &TestStepSize, 1);
  595. myAnyWrap->setFlag ("RewireForwardCon", 'a', &RewireForwardCon);
  596. }
  597. void SimModuleMovieInput::LoadMovie()
  598. {
  599. std::string MetaFileName = MovieDir + StimFileName + ".meta.xml";
  600. MovieMetaFile MetaFile(MetaFileName.c_str());
  601. std::string MovieFileName = MetaFile.MovieFileName;
  602. std::string StimName;
  603. {
  604. StimName = MovieDir + MovieFileName;
  605. cout << "Load movie: " << StimName << "\n";
  606. }
  607. MyMovie = new ObjMovie(StimName.c_str());
  608. InputNx = MyMovie->GetOutputWidth(0);
  609. InputNy = MyMovie->GetOutputHeight(0);
  610. NStimuli = MyMovie->GetNFrames();
  611. NFilters = MyMovie->GetNFilters();
  612. if (MetaFile.Loaded) {
  613. NXParas = MetaFile.NXParas;
  614. NYParas = MetaFile.NYParas;
  615. } else {
  616. NXParas = int(sqrt(float(NStimuli))); // assume square number of stimuli
  617. NYParas = NXParas;
  618. }
  619. }
  620. void SimModuleMovieInput::SetTestMode()
  621. {
  622. if (InputList != 0) {
  623. for (InputIterator it = InputList->begin(); it!=InputList->end();++it) {
  624. (*it)->SetMode(csimInputTest);
  625. }
  626. }
  627. }
  628. void SimModuleMovieInput::SetInputMode(InputMode mode)
  629. {
  630. if (InputList != 0) {
  631. for (InputIterator it = InputList->begin(); it!=InputList->end();++it) {
  632. (*it)->SetMode(mode);
  633. }
  634. }
  635. }
  636. int SimModuleMovieInput::Setup(csimInputChannel InputNumber, float InputStrength, bool LoadWeights)
  637. {
  638. MainSimLoop = GetGlobalSimLoop();
  639. // enum SimMod_StimSetType {Test, Parametric, Scan, FileName};
  640. LoadMovie();
  641. CommonInhibition = true;
  642. bool OnOffInput = true;
  643. if (NFilters <2) {
  644. OnOffInput=false;
  645. CommonInhibition=false;
  646. }
  647. if (OnOffInput) {
  648. NLayers = 2*NFilters;
  649. } else {
  650. NLayers = NFilters;
  651. }
  652. cout << "SimModuleMovieInput::Setup: NLayers=" << NLayers << "\n";
  653. LayerList = new TLayerList;
  654. InputList = new TInputList;
  655. int LayerNr;
  656. {
  657. csimNeuronType NType;
  658. NType = csimNType_DecoLif; // remove this
  659. if (CommonInhibition) { // setup inhibition layer
  660. DecoLifLayer* tmplayer = new DecoLifLayer(InputNx*InputNy, DecoParaInhibitory);
  661. tmplayer->SetName("InputInhLayer");
  662. tmplayer->SetupPositions(InputNx, InputNy, true);
  663. // tmplayer->StartBinRec(1);
  664. MainSimLoop->AddSimElement(tmplayer);
  665. InhLayer = tmplayer;
  666. }
  667. switch (NType) {
  668. case csimNType_DecoLif:
  669. {
  670. float NmdaAmpaRatio=0.3;
  671. for (LayerNr=0;LayerNr<NLayers;++LayerNr) {
  672. DecoLifLayer* tmplayer = new DecoLifLayer(InputNx*InputNy, DecoParaExcitatory);
  673. // tmplayer->SetTauGaba(1.0, ITTauInhibition);
  674. // tmplayer->SetTauGabaA(13.5, 100); // remove this
  675. // tmplayer->SetTauAmpa(0.5, 2.4);
  676. // tmplayer->SetTauNmda(10, 100);
  677. // tmplayer->TuneNoiseAmplitude(3);
  678. tmplayer->SetNoiseAmplitude(0.05294); // Noise: 3 Hz Background Firing Rate
  679. // tmplayer->TuneNoiseAmplitude(100);
  680. // tmplayer->TuneBalancedInhibition(3);
  681. // tmplayer->SetNoiseAmplitude(0.0769104); // Noise: 100 Hz Background Firing Rate
  682. // tmplayer->SetBalancedInhibition(11.7664); // Reduce Background Firing Rate to 3 Hz
  683. tmplayer->SetNmdaAmpaRatio(NmdaAmpaRatio);
  684. tmplayer->SetName(("InputLayer"+ stringify(LayerNr)).c_str());
  685. tmplayer->SetupPositions(InputNx, InputNy, true);
  686. MainSimLoop->AddSimElement(tmplayer);
  687. LayerList->push_back(tmplayer);
  688. if ((CommonInhibition) && (InhLayer != 0)) {
  689. // Ex->Inh Connection 1-zu-1
  690. connection *tmpcon = new connection(tmplayer, InhLayer, csimInputChannel_AMPA);
  691. tmpcon->SetName(("InpL"+ stringify(LayerNr)+"ExInh").c_str());
  692. // tmpcon->ConnectSelf(ExInhWeights, 0,0);
  693. if (LoadWeights) {
  694. tmpcon->Load();
  695. } else {
  696. tmpcon->ConnectGaussian(0.1,ExInhWeights, 0,0);
  697. }
  698. tmpcon->Save();
  699. MainSimLoop->AddSimElement(tmpcon);
  700. tmpcon = new connection(InhLayer, tmplayer, csimInputChannel_GABAa);
  701. tmpcon->SetName(("InpL"+ stringify(LayerNr)+"InhEx").c_str());
  702. tmpcon->ConnectSelf(InhExWeights, 0,0);
  703. tmpcon->Save();
  704. MainSimLoop->AddSimElement(tmpcon);
  705. // Inh->Ex Connection 1-zu-1
  706. }
  707. }
  708. }
  709. break;
  710. }
  711. input* l1inp;
  712. int FltNr=0;
  713. float Isi2Dur=0;
  714. int TestStimDur=249;
  715. int TestIsiDur= 1;
  716. cout << "NX=" << NXParas << "NY=" << NYParas << "\n";
  717. cout << "before setname simmodules.cpp\n";fflush(stdout);
  718. cout << "before adding to mainsimloop simmodules.cpp\n";fflush(stdout);
  719. cout << "after adding to mainsimloop simmodules.cpp\n";fflush(stdout);
  720. NTestStimuli=0;
  721. XYpairList StimList;
  722. if (XContinuous) {
  723. for (int x=0;x<NXParas;++x)
  724. for (int y=0;y<NYParas;++y) {
  725. if (((y % TestStepSize) == 0) && ((x % TestStepSize) == 0)) {
  726. StimList.push_back(XYpair(x,y));
  727. ++NTestStimuli;
  728. }
  729. }
  730. } else {
  731. for (int y=0;y<NYParas;++y)
  732. for (int x=0;x<NXParas;++x) {
  733. if (((y % TestStepSize) == 0) && ((x % TestStepSize) == 0)) {
  734. StimList.push_back(XYpair(x,y));
  735. ++NTestStimuli;
  736. }
  737. }
  738. }
  739. cout << "SimModuleMovieInput::Setup: NTestStimiuli=" << NTestStimuli << "\n";
  740. for (LayerNr=0;LayerNr<NLayers;++LayerNr) {
  741. int PosNeg=1;
  742. FltNr = LayerNr;
  743. if (OnOffInput) {
  744. FltNr = LayerNr/2;
  745. int OnOff = LayerNr % 2;
  746. PosNeg = 1 - 2*OnOff;
  747. }
  748. ScanObjMovieInput* MovieInput = new ScanObjMovieInput(
  749. (*LayerList)[LayerNr], InputNumber, MyMovie, FltNr, PosNeg*InputStrength, StimDur, NXParas, NYParas,XContinuous, NXParas, IsiDur, Isi2Dur);
  750. MovieInput->SetXCircle(true);
  751. MovieInput->SetYCircle(true);
  752. MovieInput->SetName(("MovieScanInput"+stringify(LayerNr)).c_str());
  753. MovieInput->InitializeTestMode(&StimList, TestStimDur,TestIsiDur);
  754. MovieInput->SetMode(csimInputDefault);
  755. InputList->push_back(MovieInput);
  756. MainSimLoop->AddSimElement(MovieInput);
  757. }
  758. }
  759. return 0;
  760. }
  761. void SimModuleMovieInput::ConnectTo(layer* ToLayer, bool LoadForwardWeights, bool Learn)
  762. {
  763. cout << "ConnectTo " << ToLayer->Name << "\n";
  764. int LayerNr=0;
  765. if (LayerList) {
  766. ConnectionList = new TconnectionList;
  767. for (LayerIterator it = LayerList->begin(); it!=LayerList->end();++it) {
  768. connection *tmpcon = new connection((*it), ToLayer, csimInputChannel_AMPA);
  769. // DepressiveConnection *tmpcon = new DepressiveConnection((*it), ToLayer, csimInputChannel_AMPA, TauRec, U_se);
  770. tmpcon->SetName(("conForward"+stringify(LayerNr)).c_str());
  771. if (LoadForwardWeights) tmpcon->Load();
  772. else {
  773. tmpcon->SetNonSelf(false);
  774. if (RewireForwardCon) {
  775. float connectivity=0.4;
  776. tmpcon->ConnectRandom(connectivity, InitialWeights, 2,0);
  777. tmpcon->SetRewiring(0.0001, connectivity);
  778. } else {
  779. tmpcon->ConnectFull(InitialWeights, 2,0);
  780. }
  781. }
  782. float MaxWeights=2.2;
  783. float LearnTauDec=20;
  784. float PostLearnTauDec=10;
  785. float BaseLine = exp(-2*StimDur/LearnTauDec); // was war die Intention hier?
  786. if (Learn) tmpcon->SetLearnObj(
  787. // new LearnHebbLP2(tmpcon,
  788. // MaxWeights, LearnTauDec, BaseLine, LearnRate));
  789. new LearnHebbLP3(tmpcon, MaxWeights, LearnTauDec,
  790. PostLearnTauDec, BaseLine, LearnRate, true));
  791. // new LearnRossum1(tmpcon, RossumCp, 0.003, 0.00005));
  792. MainSimLoop->AddSimElement(tmpcon);
  793. tmpcon->Save();
  794. tmpcon->SetAutoSave(false);
  795. ConnectionList->push_back(tmpcon);
  796. ++LayerNr;
  797. }
  798. // Normalization
  799. FiringRateNormalize2* norm=0;
  800. if (Learn) {
  801. // FiringRateNormalization
  802. norm = new FiringRateNormalize2(FRateNormThreshold, 0.001, 10);
  803. norm->SetName("cnormForward");
  804. for (connectionIterator it = ConnectionList->begin(); it!=ConnectionList->end();++it) {
  805. norm->AddConnection(*it);
  806. }
  807. MainSimLoop->AddSimElement(norm);
  808. }
  809. } else {
  810. cout << "No Layer List \n";
  811. }
  812. }
  813. ///SimModuleMovieInput/////////////////////////
  814. ///////////////////////////////////////
  815. smodMovieInput::smodMovieInput(AnyOptionWrapper* _opt)
  816. : SimModule(_opt), NTestStimuli(0), CommonInhibition(true), InhLayer(0), MovieDir(GetDefaultMovieDir())
  817. {
  818. cout << "smodMovieInput::smodMovieInput()\n";
  819. }
  820. smodMovieInput::~smodMovieInput()
  821. {
  822. if (InhLayer) {
  823. delete InhLayer;
  824. }
  825. // this could be done in the SimModule destructor for the LayerList, ConnectionList, ...
  826. }
  827. void smodMovieInput::SetCmdLineOptions()
  828. {
  829. myAnyWrap->setOption( "StimFileName", 'a', &StimFileName, "");
  830. myAnyWrap->setOption( "TestStimFileName", 'a', &TestStimFileName, "");
  831. myAnyWrap->setOption( "SequenceFileName", 'a', &SequenceFileName, "");
  832. myAnyWrap->setOption( "StimDur", 'a', &StimDur, 200);
  833. myAnyWrap->setOption( "IsiDur", 'a', &IsiDur, 20);
  834. myAnyWrap->setFlag ( "XContinuous", 'a', &XContinuous);
  835. myAnyWrap->setOption( "LearnRate", 'a', &LearnRate, 0.002);
  836. myAnyWrap->setOption( "InitialWeights", 'a', &InitialWeights, 0.1);
  837. myAnyWrap->setOption( "FRateNormThreshold", 'a', &FRateNormThreshold, 30);
  838. myAnyWrap->setOption( "InputExInhWeights", 'a', &ExInhWeights, 0.5);
  839. myAnyWrap->setOption( "InputInhExWeights", 'a', &InhExWeights, 0.5);
  840. myAnyWrap->setOption( "TestStepSize", 'a', &TestStepSize, 1);
  841. myAnyWrap->setFlag ( "RewireForwardCon", 'a', &RewireForwardCon);
  842. myAnyWrap->setOption( "TauDecLearnPre", 'a', &TauDecLearnPre, 20);
  843. myAnyWrap->setOption( "TauDecLearnPost", 'a', &TauDecLearnPost, 10);
  844. myAnyWrap->setFlag ( "OnOffInput", 'a', &OnOffInput, false);
  845. }
  846. void smodMovieInput::LoadMovie(string _StimFileName)
  847. {
  848. std::string MetaFileName = MovieDir + _StimFileName + ".meta.xml";
  849. MovieMetaFile MetaFile(MetaFileName.c_str());
  850. std::string MovieFileName;
  851. if (MetaFile.Loaded)
  852. {
  853. MovieFileName = MetaFile.MovieFileName;
  854. cout << "MovieFileName=" << MovieFileName << "\n";
  855. } else
  856. {
  857. cout << "MovieMetaFile not loaded\n";
  858. MovieFileName = _StimFileName + ".idlmov";
  859. cout << "using movie file name: " << MovieFileName << "\n";
  860. }
  861. std::string StimName;
  862. {
  863. StimName = MovieDir + MovieFileName;
  864. cout << "Load movie: " << StimName << "\n";
  865. }
  866. MyMovie = new ObjMovie(StimName.c_str());
  867. InputNx = MyMovie->GetOutputWidth(0);
  868. InputNy = MyMovie->GetOutputHeight(0);
  869. NStimuli = MyMovie->GetNFrames();
  870. NFilters = MyMovie->GetNFilters();
  871. if (MetaFile.Loaded)
  872. {
  873. NXParas = MetaFile.NXParas;
  874. NYParas = MetaFile.NYParas;
  875. } else
  876. {
  877. NXParas = int(sqrt(float(NStimuli))); // assume square number of stimuli
  878. NYParas = NXParas;
  879. }
  880. }
  881. void smodMovieInput::SetTestMode()
  882. {
  883. if (InputList != 0) {
  884. for (InputIterator it = InputList->begin(); it!=InputList->end();++it) {
  885. (*it)->SetMode(csimInputTest);
  886. }
  887. }
  888. }
  889. void smodMovieInput::SetInputMode(InputMode mode)
  890. {
  891. if (InputList != 0) {
  892. for (InputIterator it = InputList->begin(); it!=InputList->end();++it) {
  893. (*it)->SetMode(mode);
  894. }
  895. }
  896. }
  897. void smodMovieInput::SetNoiseAmplitude(float sigma)
  898. {
  899. for (TLayerList::iterator it=LayerList->begin();it!=LayerList->end();++it) {
  900. (*it)->SetNoiseAmplitude(sigma);
  901. }
  902. }
  903. int smodMovieInput::Setup(csimInputChannel InputNumber, float InputStrength, bool LoadWeights)
  904. {
  905. MainSimLoop = GetGlobalSimLoop();
  906. // enum SimMod_StimSetType {Test, Parametric, Scan, FileName};
  907. LoadMovie(StimFileName);
  908. CommonInhibition = false;
  909. if (OnOffInput) {
  910. NLayers = 2*NFilters;
  911. } else {
  912. NLayers = NFilters;
  913. }
  914. cout << "smodMovieInput::Setup: NLayers=" << NLayers << "\n";
  915. LayerList = new TLayerList;
  916. InputList = new TInputList;
  917. int LayerNr;
  918. {
  919. csimNeuronType NType;
  920. NType = csimNType_DecoLif; // remove this
  921. if (CommonInhibition) { // setup inhibition layer
  922. DecoLifLayer* tmplayer = new DecoLifLayer(InputNx*InputNy, DecoParaInhibitory);
  923. tmplayer->SetName("InputInhLayer");
  924. tmplayer->SetupPositions(InputNx, InputNy, true);
  925. // tmplayer->StartBinRec(1);
  926. MainSimLoop->AddSimElement(tmplayer);
  927. InhLayer = tmplayer;
  928. }
  929. switch (NType) {
  930. case csimNType_DecoLif:
  931. {
  932. float NmdaAmpaRatio=0.3;
  933. // Quelle fuer NMDA/AMPA-Verhaeltnis:
  934. // \cite{Krukowski2001_thalamocortical_nmda}
  935. // \cite{Crair1995_ltp_thalamocortical_synapses}
  936. for (LayerNr=0;LayerNr<NLayers;++LayerNr) {
  937. int FltNr = LayerNr;
  938. if (OnOffInput) {
  939. FltNr = LayerNr/2;
  940. int OnOff = LayerNr % 2;
  941. }
  942. DecoLifLayer* tmplayer = new DecoLifLayer((MyMovie->GetOutputWidth(FltNr))*(MyMovie->GetOutputHeight(FltNr)), DecoParaExcitatory);
  943. // tmplayer->SetTauGaba(1.0, ITTauInhibition);
  944. // tmplayer->SetTauGabaA(13.5, 100); // remove this
  945. // tmplayer->SetTauAmpa(0.5, 2.4);
  946. // tmplayer->SetTauNmda(10, 100);
  947. // tmplayer->TuneNoiseAmplitude(3);
  948. tmplayer->SetNoiseAmplitude(0.05294); // Noise: 3 Hz Background Firing Rate
  949. // tmplayer->TuneNoiseAmplitude(100);
  950. // tmplayer->TuneBalancedInhibition(3);
  951. // tmplayer->SetNoiseAmplitude(0.0769104); // Noise: 100 Hz Background Firing Rate
  952. // tmplayer->SetBalancedInhibition(11.7664); // Reduce Background Firing Rate to 3 Hz
  953. tmplayer->SetNmdaAmpaRatio(NmdaAmpaRatio);
  954. tmplayer->SetName(("InputLayer"+ stringify(LayerNr)).c_str());
  955. tmplayer->SetupPositions(InputNx, InputNy, true);
  956. MainSimLoop->AddSimElement(tmplayer);
  957. LayerList->push_back(tmplayer);
  958. if ((CommonInhibition) && (InhLayer != 0)) {
  959. // Ex->Inh Connection 1-zu-1
  960. connection *tmpcon = new connection(tmplayer, InhLayer, csimInputChannel_AMPA);
  961. tmpcon->SetName(("InpL"+ stringify(LayerNr)+"ExInh").c_str());
  962. // tmpcon->ConnectSelf(ExInhWeights, 0,0);
  963. if (LoadWeights) {
  964. tmpcon->Load();
  965. } else {
  966. tmpcon->ConnectGaussian(0.1,ExInhWeights, 0,0);
  967. }
  968. tmpcon->Save();
  969. MainSimLoop->AddSimElement(tmpcon);
  970. tmpcon = new connection(InhLayer, tmplayer, csimInputChannel_GABAa);
  971. tmpcon->SetName(("InpL"+ stringify(LayerNr)+"InhEx").c_str());
  972. tmpcon->ConnectSelf(InhExWeights, 0,0);
  973. tmpcon->Save();
  974. MainSimLoop->AddSimElement(tmpcon);
  975. // Inh->Ex Connection 1-zu-1
  976. }
  977. }
  978. }
  979. break;
  980. }
  981. input* l1inp;
  982. int FltNr=0;
  983. float Isi2Dur=0;
  984. int TestStimDur=249;
  985. int TestIsiDur= 1;
  986. cout << "NX=" << NXParas << "NY=" << NYParas << "\n";
  987. cout << "teststepsize = " << TestStepSize << "\n";
  988. NTestStimuli=0;
  989. XYpairList StimList;
  990. if (XContinuous) {
  991. for (int x=0;x<NXParas;++x)
  992. for (int y=0;y<NYParas;++y) {
  993. if (((y % TestStepSize) == 0) && ((x % TestStepSize) == 0)) {
  994. StimList.push_back(XYpair(x,y));
  995. ++NTestStimuli;
  996. }
  997. }
  998. } else {
  999. int ystart = NYParas/2;
  1000. int xstart = NXParas/2;
  1001. for (int y=ystart;y>=0;--y) {
  1002. for (int x=xstart;x>=0;--x)
  1003. {
  1004. if (((y % TestStepSize) == 0) && ((x % TestStepSize) == 0)) {
  1005. StimList.push_back(XYpair(x,y));
  1006. ++NTestStimuli;
  1007. }
  1008. }
  1009. for (int x=NXParas-1;x>xstart;--x)
  1010. {
  1011. if (((y % TestStepSize) == 0) && ((x % TestStepSize) == 0)) {
  1012. StimList.push_back(XYpair(x,y));
  1013. ++NTestStimuli;
  1014. }
  1015. }
  1016. }
  1017. for (int y=NYParas;y>ystart;--y) {
  1018. for (int x=xstart;x>=0;--x)
  1019. {
  1020. if (((y % TestStepSize) == 0) && ((x % TestStepSize) == 0)) {
  1021. StimList.push_back(XYpair(x,y));
  1022. ++NTestStimuli;
  1023. }
  1024. }
  1025. for (int x=NXParas-1;x>xstart;--x)
  1026. {
  1027. if (((y % TestStepSize) == 0) && ((x % TestStepSize) == 0)) {
  1028. StimList.push_back(XYpair(x,y));
  1029. ++NTestStimuli;
  1030. }
  1031. }
  1032. }
  1033. }
  1034. cout << "smodMovieInput::Setup: NTestStimiuli=" << NTestStimuli << "\n";
  1035. for (LayerNr=0;LayerNr<NLayers;++LayerNr) {
  1036. int PosNeg=1;
  1037. FltNr = LayerNr;
  1038. if (OnOffInput) {
  1039. FltNr = LayerNr/2;
  1040. int OnOff = LayerNr % 2;
  1041. PosNeg = 1 - 2*OnOff;
  1042. }
  1043. ScanObjMovieInput* MovieInput = new ScanObjMovieInput(
  1044. (*LayerList)[LayerNr], InputNumber, MyMovie, FltNr, PosNeg*InputStrength, StimDur, NXParas, NYParas,XContinuous, NXParas, IsiDur, Isi2Dur);
  1045. MovieInput->SetXCircle(true);
  1046. MovieInput->SetYCircle(true);
  1047. MovieInput->SetName(("MovieScanInput"+stringify(LayerNr)).c_str());
  1048. MovieInput->InitializeTestMode(&StimList, TestStimDur,TestIsiDur);
  1049. if (!SequenceFileName.empty()) {
  1050. string SequenceFilePath = MovieDir + SequenceFileName;
  1051. cout << "SequenceFilePath = " << SequenceFilePath << "\n"; fflush(stdout);
  1052. MovieInput->loadStimulusSequence(SequenceFilePath.c_str());
  1053. }
  1054. MovieInput->SetMode(csimInputDefault);
  1055. InputList->push_back(MovieInput);
  1056. MainSimLoop->AddSimElement(MovieInput);
  1057. }
  1058. }
  1059. return 0;
  1060. }
  1061. void smodMovieInput::ChangeMovie(ObjMovie* _NewMovie)
  1062. {
  1063. for (int LayerNr=0;LayerNr<NLayers;++LayerNr) {
  1064. int PosNeg=1;
  1065. int FltNr = LayerNr;
  1066. if (OnOffInput) {
  1067. FltNr = LayerNr/2;
  1068. int OnOff = LayerNr % 2;
  1069. PosNeg = 1 - 2*OnOff;
  1070. }
  1071. ScanObjMovieInput* MovieInput = dynamic_cast<ScanObjMovieInput*>((*InputList)[LayerNr]);
  1072. if (MovieInput) {
  1073. MovieInput->SetMovieFile(_NewMovie, FltNr);
  1074. } else {
  1075. cerr << "ERROR in smodMovieInput::ChangeMovie. Dynamic cast failed.\n";
  1076. }
  1077. }
  1078. }
  1079. void smodMovieInput::ConnectTo(layer* ToLayer, bool LoadForwardWeights, bool Learn, bool VecCon, bool SaveInitialWeights)
  1080. {
  1081. cout << "ConnectTo " << ToLayer->Name << "\n";
  1082. float connectivity=0.6; // for rewiring
  1083. float RewireThreshold=0.05*InitialWeights;
  1084. float RewInitialWeights=1.2*RewireThreshold;
  1085. int LayerNr=0;
  1086. if (LayerList) {
  1087. ConnectionList = new TconnectionList;
  1088. VConnectionList = new TVConList;
  1089. for (LayerIterator it = LayerList->begin(); it!=LayerList->end();++it) {
  1090. // learn parameter
  1091. float MaxWeights=2.2;
  1092. float LearnTauDec=TauDecLearnPre;
  1093. float PostLearnTauDec=TauDecLearnPost;
  1094. // float LearnTauDec=20;
  1095. // float PostLearnTauDec=10;
  1096. float BaseLine = exp(-2*StimDur/LearnTauDec); // was war die Intention hier?
  1097. if (VecCon) {
  1098. VecConnection *tmpcon = new VecConnection((*it), ToLayer, csimInputChannel_AMPA);
  1099. tmpcon->SetName(("conForward"+stringify(LayerNr)).c_str());
  1100. if (LoadForwardWeights) tmpcon->Load();
  1101. else {
  1102. tmpcon->SetNonSelf(false);
  1103. if (RewireForwardCon) {
  1104. tmpcon->ConnectRandomIncomming(connectivity, InitialWeights, 2,0);
  1105. } else {
  1106. tmpcon->ConnectFull(InitialWeights, 2,0);
  1107. }
  1108. }
  1109. if (Learn) tmpcon->SetLearnObj(
  1110. new VecLearnHebbLP3(tmpcon, MaxWeights, LearnTauDec,
  1111. PostLearnTauDec, BaseLine, LearnRate, true));
  1112. MainSimLoop->AddSimElement(tmpcon);
  1113. if (SaveInitialWeights) {
  1114. tmpcon->Save();
  1115. }
  1116. tmpcon->SetAutoSave(false);
  1117. VConnectionList->push_back(tmpcon);
  1118. ++LayerNr;
  1119. } else {
  1120. connection *tmpcon = new connection((*it), ToLayer, csimInputChannel_AMPA);
  1121. // DepressiveConnection *tmpcon = new DepressiveConnection((*it), ToLayer, csimInputChannel_AMPA, TauRec, U_se);
  1122. tmpcon->SetName(("conForward"+stringify(LayerNr)).c_str());
  1123. if (LoadForwardWeights) tmpcon->Load();
  1124. else {
  1125. tmpcon->SetNonSelf(false);
  1126. if (RewireForwardCon) {
  1127. tmpcon->ConnectRandom(connectivity, InitialWeights, 2,0);
  1128. tmpcon->SetRewiring(RewireThreshold, connectivity);
  1129. } else {
  1130. tmpcon->ConnectFull(InitialWeights, 2,0);
  1131. }
  1132. }
  1133. if (Learn) tmpcon->SetLearnObj(
  1134. // new LearnHebbLP2(tmpcon,
  1135. // MaxWeights, LearnTauDec, BaseLine, LearnRate));
  1136. new LearnHebbLP3(tmpcon, MaxWeights, LearnTauDec,
  1137. PostLearnTauDec, BaseLine, LearnRate, true));
  1138. // new LearnRossum1(tmpcon, RossumCp, 0.003, 0.00005));
  1139. MainSimLoop->AddSimElement(tmpcon);
  1140. if (SaveInitialWeights) {
  1141. tmpcon->Save();
  1142. }
  1143. tmpcon->SetAutoSave(false);
  1144. ConnectionList->push_back(tmpcon);
  1145. ++LayerNr;
  1146. }
  1147. }
  1148. // Normalization
  1149. if (VecCon) {
  1150. VecFiringRateNormalize2* norm=0;
  1151. if (Learn) {
  1152. // FiringRateNormalization
  1153. norm = new VecFiringRateNormalize2(FRateNormThreshold, 0.001, 10);
  1154. norm->SetName("cnormForward");
  1155. cout << "Adding connections to norm obj\n";fflush(stdout);
  1156. for (VConIterator it = VConnectionList->begin(); it!=VConnectionList->end();++it) {
  1157. norm->AddConnection(*it);
  1158. }
  1159. if (RewireForwardCon) {
  1160. norm->SetRewiring(RewireThreshold, connectivity, RewInitialWeights);
  1161. }
  1162. MainSimLoop->AddSimElement(norm);
  1163. }
  1164. } else {
  1165. FiringRateNormalize2* norm=0;
  1166. if (Learn) {
  1167. // FiringRateNormalization
  1168. norm = new FiringRateNormalize2(FRateNormThreshold, 0.001, 10);
  1169. norm->SetName("cnormForward");
  1170. for (connectionIterator it = ConnectionList->begin(); it!=ConnectionList->end();++it) {
  1171. norm->AddConnection(*it);
  1172. }
  1173. MainSimLoop->AddSimElement(norm);
  1174. }
  1175. }
  1176. } else {
  1177. cout << "No Layer List \n";
  1178. }
  1179. }
  1180. ///smodMovieInput/////////////////////////