sensorycancel.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  1. #include "sys.hpp"
  2. #include "debug.hpp"
  3. #include <iostream>
  4. #include <math.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <objsimlibrary.hpp>
  8. #include <anyoption.h>
  9. #include <valarray>
  10. #include <time.h>
  11. ////////////////////
  12. const float connectivity = 0.1;
  13. int main(int argc, char** argv)
  14. {
  15. clock_t cpu_start, cpu_end;
  16. double cpu_time_used;
  17. ////////////////Begin//ProcessCommandLineArguments//////////////
  18. cpu_start = clock();
  19. // 'a' = dummy; do not use -a !! (setOption without second para doesn't work!!)
  20. AnyOptionWrapper *myAnyWrap = new AnyOptionWrapper(argc, argv,"settings_sensorycancel.cfg");
  21. float NoiseSigma; myAnyWrap->setOption( "NoiseSigma", 'n', &NoiseSigma, 0);
  22. float InputNoiseSigma; myAnyWrap->setOption( "InputNoiseSigma", 'n', &InputNoiseSigma, 0);
  23. float InhNoiseSigma; myAnyWrap->setOption( "InhNoiseSigma", 'n', &InhNoiseSigma, 0);
  24. float istrength; myAnyWrap->setOption( "InputStrength", 'i', &istrength, 1);
  25. float InitialWeights; myAnyWrap->setOption( "InitialWeights", 'w', &InitialWeights, 0.01);
  26. float InitialFWInhWeights; myAnyWrap->setOption( "InitialFWInhWeights", 'w', &InitialFWInhWeights, 0.02);
  27. float InputSat; myAnyWrap->setOption( "InputSaturation", 'S', &InputSat, 1.0);
  28. float ris; myAnyWrap->setOption( "RandomInputStrength", 'r', &ris, 10.0);
  29. float WeightSum; myAnyWrap->setOption( "WeightSum", 'u', &WeightSum, 1);
  30. bool TestSim; myAnyWrap->setFlag ("Test", 'T', &TestSim);
  31. bool LoadWeights; myAnyWrap->setFlag ( "LoadWeights", 'L', &LoadWeights);
  32. bool LoadITWeights; myAnyWrap->setFlag ( "LoadITWeights", 'a', &LoadITWeights);
  33. bool LoadForwardWeights; myAnyWrap->setFlag ( "LoadForwardWeights", 'a', &LoadForwardWeights);
  34. float LtpInc; myAnyWrap->setOption( "LtpInc", 'c', &LtpInc, 0.7);
  35. int MaxTrials; myAnyWrap->setOption("MaxTrials", 'a', &MaxTrials, 80);
  36. int probesteps=0; myAnyWrap->setOption("ProbeSteps", 'a', &probesteps, 4);
  37. // int learnsteps= 150;
  38. int learnsteps= 20; myAnyWrap->setOption("LearnSteps", 'a', &learnsteps, 20);
  39. // float TauRec; myAnyWrap->setOption("TauRec", 'a', &TauRec, 50);
  40. // float U_se; myAnyWrap->setOption("U_se", 'a', &U_se, 0.05);
  41. float BInpInhWeight; myAnyWrap->setOption("BInpInhWeight", 'a', &BInpInhWeight, 0.03);
  42. float MaxFWInhWeights; myAnyWrap->setOption("MaxFWInhWeights", 'a', &MaxFWInhWeights, 0.1);
  43. float FwdInhLinkingWeight; myAnyWrap->setOption("FwdInhLinkingWeight", 'a', &FwdInhLinkingWeight, 0.1);
  44. float ExInhWeight; myAnyWrap->setOption("ExInhWeight", 'a', &ExInhWeight, 0.1);
  45. float InhExWeight; myAnyWrap->setOption("InhExWeight", 'a', &InhExWeight, 0.2);
  46. float ITExInhWeight; myAnyWrap->setOption("ITExInhWeight", 'a', &ITExInhWeight, 0.1);
  47. float ITInhExWeight; myAnyWrap->setOption("ITInhExWeight", 'a', &ITInhExWeight, 0.2);
  48. float ITExExWeight; myAnyWrap->setOption("ITExExWeight", 'a', &ITExExWeight, 0.1);
  49. float ITExCInhWeight; myAnyWrap->setOption("ITExCInhWeight", 'a', &ITExCInhWeight, 0.001);
  50. float ITCInhExWeight; myAnyWrap->setOption("ITCInhExWeight", 'a', &ITCInhExWeight, 0.005);
  51. float ITFBInhWeight; myAnyWrap->setOption("ITFBInhWeight", 'a', &ITFBInhWeight, 0.005);
  52. float FBInhWeight; myAnyWrap->setOption("FBInhWeight", 'a', &FBInhWeight, 0.005);
  53. float ITSelfInhibitionWeight; myAnyWrap->setOption("ITSelfInhibitionWeight", 'a', &ITSelfInhibitionWeight, 0.01);
  54. float LearnRate; myAnyWrap->setOption("LearnRate", 'a', &LearnRate, 0.0001);
  55. float InhLearnRate; myAnyWrap->setOption("InhLearnRate", 'a', &InhLearnRate, 0.00001);
  56. float InhLearnBaseLine; myAnyWrap->setOption("InhLearnBaseLine", 'a', &InhLearnBaseLine, 1);
  57. float FBInhLearnRate; myAnyWrap->setOption("FBInhLearnRate", 'a', &FBInhLearnRate, 0.001);
  58. float Cdep; myAnyWrap->setOption("Cdep", 'a', &Cdep, 0.00001);
  59. float FBInhMaxWeight;myAnyWrap->setOption("FBInhMaxWeight", 'a', &FBInhMaxWeight, 1.0);
  60. float RossumCp; myAnyWrap->setOption("RossumCp", 'a', &RossumCp, 0.000001);
  61. float ITNormFrequency; myAnyWrap->setOption("ITNormFrequency", 'a', &ITNormFrequency, 30);
  62. bool RandomInputOrder; myAnyWrap->setFlag ("RandomInputOrder", 'a', &RandomInputOrder);
  63. float StimDur; myAnyWrap->setOption("StimDur", 'a', &StimDur, 30);
  64. float IsiDur; myAnyWrap->setOption("IsiDur", 'a', &IsiDur, 30);
  65. float TestStimDur; myAnyWrap->setOption("TestStimDur", 'a', &TestStimDur, 100);
  66. bool Teach; myAnyWrap->setFlag ("Teach", 'a', &Teach);
  67. bool XContinuous; myAnyWrap->setFlag ("XContinuous", 'a', &XContinuous);
  68. float ExExRange; myAnyWrap->setOption("ExExRange", 'a', &ExExRange, 0.02);
  69. float ExInhRange; myAnyWrap->setOption("ExInhRange", 'a', &ExInhRange, 0.02);
  70. float InhExRange; myAnyWrap->setOption("InhExRange", 'a', &InhExRange, 0.08);
  71. float ExExMinDelay; myAnyWrap->setOption("ExExMinDelay", 'a', &ExExMinDelay, 3);
  72. float ExExMaxDelay; myAnyWrap->setOption("ExExMaxDelay", 'a', &ExExMaxDelay, 6);
  73. std::string DataDirectory; myAnyWrap->setOption("DataDirectory", 'a', &DataDirectory, "/home/frank/data/");
  74. float SelfInhMaxWeight; myAnyWrap->setOption("SelfInhMaxWeight", 'a', &SelfInhMaxWeight, 6);
  75. float SelfInhMinWeight; myAnyWrap->setOption("SelfInhMinWeight", 'a', &SelfInhMinWeight, 1);
  76. float SelfInhLearnTauDec; myAnyWrap->setOption("SelfInhLearnTauDec", 'a', &SelfInhLearnTauDec, 20);
  77. float SelfInhBaseLine; myAnyWrap->setOption("SelfInhBaseLine", 'a', &SelfInhBaseLine, 0.1);
  78. float SelfLearnRate; myAnyWrap->setOption("SelfLearnRate", 'a', &SelfLearnRate, 0.0001);
  79. float SelfInhWeightSum; myAnyWrap->setOption("SelfInhWeightSum", 'a', &SelfInhWeightSum, 5);
  80. myAnyWrap->process();
  81. delete myAnyWrap;
  82. ////////////////End//ProcessCommandLineArguments//////////////
  83. ////////////////Begin//InitializeGlobalSimLoop
  84. SimLoop* MainSimLoop = InitLibCSim();
  85. // MainSimLoop->SetDataDirectory("/home/frank/data/sim/csim/v4learn/");
  86. MainSimLoop->SetDataDirectory(DataDirectory.c_str());
  87. float dt=MainSimLoop->GetDeltaT(); // milli sec
  88. cout << "int main(): dt = " << dt << "\n";
  89. ////////////////End//InitializeGlobalSimLoop
  90. bool Learn=true;
  91. if ((LearnRate == 0) || TestSim) {
  92. Learn=false;
  93. cout << "No Learning\n";
  94. }
  95. int i, j, k, sec, t;
  96. // lif2layer *ca3layer;
  97. // ca3layer=new lif2layer(N, dt, 20, 0.0033, 1, 4,4,ffi,fbi,2, 0.004, 10);
  98. if (TestSim) LoadWeights=true;
  99. if (LoadWeights)
  100. {
  101. LoadITWeights=true;
  102. LoadForwardWeights=true;
  103. }
  104. ////////////////End//ProcessCommandLineArguments//////////////
  105. //////////////////////////////////////////////
  106. // ObjMovie MyMovie("../../../movies/crystal_all_dirchange.idlmov");
  107. // ObjMovie MyMovie("../../../movies/tetraeder02.idlmov");
  108. // ObjMovie MyMovie("../../../movies/verticalbar.idlmov");
  109. // ObjMovie MyMovie("../../../movies/horizontalbar.idlmov");
  110. // ObjMovie MyMovie("../../../movies/twobar_o3.idlmov");
  111. // ObjMovie MyMovie("../../../movies/twooris.idlmov");
  112. // ObjMovie MyMovie("../../../movies/16oris.idlmov");
  113. // ObjMovie MyMovie("../../../movies/16bars.idlmov");
  114. // ObjMovie MyMovie("../../../movies/winkel.idlmov");
  115. // ObjMovie MyMovie("../../../data/movies/winkelbars256.idlmov");
  116. // ObjMovie MyMovie("../../../data/movies/winkelbars64.idlmov");
  117. ObjMovie MyMovie("../../../data/movies/winkelbars2.idlmov");
  118. // generate InputLayers
  119. typedef izhlayer TInputLayer;
  120. TInputLayer* TmpInputLayer;
  121. vector<TInputLayer*> InputLayerList;
  122. //////// Setup Input Layer
  123. int InputNx, InputNy;
  124. InputNx=InputNy=20;
  125. izh2layer* BlobInputLayer = new izh2layer(InputNx*InputNy, IzhParaIntegrator, InputSat);
  126. BlobInputLayer->SetName("BInpLayer");
  127. BlobInputLayer->SetupPositions(InputNx, InputNy, true);
  128. BlobInputLayer->SetRandomInputStrength(0);
  129. BlobInputLayer->SetNoiseSigma(InputNoiseSigma);
  130. BlobInputLayer->SetTauInh(7.0);
  131. MainSimLoop->AddSimElement(BlobInputLayer);
  132. //////// Setup IT Module
  133. int ITNx, ITNy;
  134. ITNx = ITNy = 8;
  135. // ITNx = 1; ITNy = 2;
  136. IzhParas IzhLowDIntegrator (0.02, -0.1, -55, 2, 108, 4.1, 0.0);
  137. // izh3layer* ITLayer = new izh3layer(ITNx*ITNy, IzhLowDIntegrator,InputSat);
  138. izh3layer* ITLayer = new izh3layer(ITNx*ITNy, IzhParaIntegrator,InputSat);
  139. ITLayer->SetName("ITLayer");
  140. ITLayer->SetupPositions(ITNx,ITNy,true);
  141. ITLayer->SetRandomInputStrength(0);
  142. ITLayer->SetNoiseSigma(NoiseSigma);
  143. ITLayer->SetTauInh(5.0);
  144. ITLayer->StartBinRec(2);
  145. MainSimLoop->AddSimElement(ITLayer);
  146. int ITInhNx, ITInhNy;
  147. ITInhNx = ITInhNy = ITNx/2;
  148. // izh3layer* ITInhLayer = new izh3layer(ITInhNx*ITInhNy, IzhParaFastSpiking,InputSat);
  149. izh3layer* ITInhLayer = 0;
  150. if ((ITInhExWeight > 0) || (ITExInhWeight > 0)) {
  151. ITInhLayer = new izh3layer(ITInhNx*ITInhNy, IzhParaClass2,InputSat);
  152. ITInhLayer->SetName("ITInhLayer");
  153. ITInhLayer->SetupPositions(ITInhNx,ITInhNy,true);
  154. ITInhLayer->SetRandomInputStrength(0);
  155. ITInhLayer->SetNoiseSigma(InhNoiseSigma);
  156. ITInhLayer->SetTauEx(15);
  157. MainSimLoop->AddSimElement(ITInhLayer);
  158. }
  159. int ITCommonInhNx, ITCommonInhNy;
  160. ITCommonInhNx = ITCommonInhNy = 2;
  161. izh3layer* ITCommonInhLayer = new izh3layer(ITCommonInhNx*ITCommonInhNy, IzhParaFastSpiking,InputSat);
  162. // izh3layer* ITCommonInhLayer = new izh3layer(ITCommonInhNx*ITCommonInhNy, IzhParaClass2,InputSat);
  163. ITCommonInhLayer->SetName("ITCommonInhLayer");
  164. ITCommonInhLayer->SetupPositions(ITCommonInhNx,ITCommonInhNy,true);
  165. ITCommonInhLayer->SetRandomInputStrength(0);
  166. ITCommonInhLayer->SetNoiseSigma(0);
  167. ITCommonInhLayer->SetTauEx(10);
  168. MainSimLoop->AddSimElement(ITCommonInhLayer);
  169. //////////connections
  170. FacilitativeConnection *ConITSelfInh=0;
  171. if (ITSelfInhibitionWeight > 0) {
  172. // connection *ConITSelfInh = new connection(ITLayer, ITLayer, csimInputChannel_GABAa, true); // inputNumber=0
  173. ConITSelfInh = new FacilitativeConnection(ITLayer, ITLayer, csimInputChannel_GABAa, 60, 0.005, 50, 0.01); // inputNumber=0
  174. ConITSelfInh->SetNonSelf(true);
  175. ConITSelfInh->SetName("conIT_SelfInh");
  176. if (LoadITWeights) ConITSelfInh->Load();
  177. else {
  178. ConITSelfInh->ConnectFull(ITSelfInhibitionWeight, 1,0);
  179. // ConITSelfInh->ConnectRandom(0.4, ITSelfInhibitionWeight, 1,0);
  180. // DistanceProfile* profile = new CircleDistanceProfile(1000, 0.2);
  181. // ConITSelfInh->ConnectProfile(profile, ITSelfInhibitionWeight, 1,0, true);
  182. // ConITSelfInh->ConnectRandom(0.2, ITSelfInhibitionWeight, 1,0);
  183. }
  184. ConITSelfInh->StartBinRec(1);
  185. if (Learn && (SelfLearnRate >0)) {
  186. LearnHebbLP2* LearnSelfITInh = new LearnHebbLP2(
  187. ConITSelfInh, SelfInhMaxWeight, SelfInhLearnTauDec,
  188. SelfInhBaseLine, SelfLearnRate);
  189. LearnSelfITInh->SetMinWeight(SelfInhMinWeight);
  190. ConITSelfInh->SetLearnObj(LearnSelfITInh);
  191. }
  192. // ConstSumNormalize* SelfInhNorm=0;
  193. // if (Learn) {
  194. // SelfInhNorm = new ConstSumNormalize(SelfInhWeightSum, false);
  195. // SelfInhNorm->AddConnection(ConITSelfInh);
  196. // // SelfInhNorm->CalcInitWeightSum();
  197. // SelfInhNorm->NormalizeAll();
  198. // MainSimLoop->AddSimElement(SelfInhNorm);
  199. // }
  200. ConITSelfInh->Save();
  201. ConITSelfInh->SetAutoSave(false);
  202. MainSimLoop->AddSimElement(ConITSelfInh);
  203. }
  204. if (ITExCInhWeight > 0) {
  205. connection *ConITExCInh = new connection(ITLayer, ITCommonInhLayer, csimInputChannel_AMPA); // inputNumber=0
  206. ConITExCInh->SetName("conIT_ExCInh");
  207. if (LoadITWeights) ConITExCInh->Load();
  208. else {
  209. ConITExCInh->ConnectFull(ITExCInhWeight, 1,0);
  210. }
  211. ConITExCInh->Save();
  212. MainSimLoop->AddSimElement(ConITExCInh);
  213. }
  214. // if (ITCInhExWeight > 0) {
  215. // connection *ConITCInhEx = new connection(ITCommonInhLayer, ITLayer, 1);
  216. // ConITCInhEx->SetName("conIT_CInhEx");
  217. // if (LoadITWeights) ConITCInhEx->Load();
  218. // else {
  219. // ConITCInhEx->ConnectFull(ITCInhExWeight, 1,0);
  220. // }
  221. // ConITCInhEx->Save();
  222. // MainSimLoop->AddSimElement(ConITCInhEx);
  223. // }
  224. float InhLearnTauDec=30;
  225. float InhLearnTauPre=30;
  226. float InhLearnTauPost=100;
  227. float FBInhMaxWeights=3;
  228. connection *ConITFbInh =0;
  229. if (ITFBInhWeight > 0) {
  230. ConITFbInh = new connection(ITCommonInhLayer, BlobInputLayer, csimInputChannel_GABAa);
  231. ConITFbInh->SetName("conIT_FBInh");
  232. if (LoadITWeights) ConITFbInh->Load();
  233. else {
  234. ConITFbInh->ConnectFull(ITFBInhWeight, 1,0);
  235. }
  236. if (Learn && (FBInhLearnRate>0)) {
  237. ConITFbInh->SetLearnObj(
  238. new LearnFBInh(ConITFbInh,
  239. FBInhMaxWeight, InhLearnTauPre,InhLearnTauPost, FBInhLearnRate, Cdep));
  240. // new LearnHebbLP2(ConITFbInh,
  241. // FBInhMaxWeights, InhLearnTauDec, 0.1, LearnRate));
  242. // // new LearnRossum1(ConITFBInh, RossumCp, 0.003, 0.0002));
  243. }
  244. ConITFbInh->Save();
  245. ConITFbInh->SetAutoSave(false);
  246. MainSimLoop->AddSimElement(ConITFbInh);
  247. }
  248. connection *ConInpIT = new connection(BlobInputLayer, ITLayer, csimInputChannel_AMPA, false);
  249. // FacilitativeConnection *ConInpIT = new FacilitativeConnection(BlobInputLayer, ITLayer, 0, 300, 0.003, 50, 0.002);
  250. ConInpIT->SetName("conForward");
  251. if (LoadForwardWeights) ConInpIT->Load();
  252. else {
  253. ConInpIT->ConnectFull(InitialWeights, 2,0);
  254. }
  255. // ConInpIT->StartBinRec(InputNx/4+InputNx*InputNy/2);
  256. float MaxWeights=2.2;
  257. float LearnTauDec=20;
  258. float PostLearnTauDec=10;
  259. float BaseLine = exp(-2*StimDur/LearnTauDec);
  260. if (Learn) ConInpIT->SetLearnObj(
  261. // new LearnHebbLP2(ConInpIT,
  262. // MaxWeights, LearnTauDec, BaseLine, LearnRate));
  263. // new LearnRossum1(ConInpIT, RossumCp, 0.003, 0.0002));
  264. new LearnHebbLP3(ConInpIT, MaxWeights, LearnTauDec,
  265. PostLearnTauDec, BaseLine, LearnRate, true));
  266. // new LearnRossum1(ConInpIT, RossumCp, 0.003, 0.00005));
  267. ConInpIT->Save();
  268. ConInpIT->SetAutoSave(false);
  269. MainSimLoop->AddSimElement(ConInpIT);
  270. ConstSumNormalize* norm=0;
  271. if (Learn) {
  272. norm = new ConstSumNormalize(WeightSum, true);
  273. norm->AddConnection(ConInpIT);
  274. norm->NormalizeAll();
  275. MainSimLoop->AddSimElement(norm);
  276. }
  277. // FiringRateNormalize* norm=0;
  278. // if (Learn) {
  279. // norm = new FiringRateNormalize(1.3, 0.999, 100);
  280. // norm->AddConnection(ConInpIT);
  281. // MainSimLoop->AddSimElement(norm);
  282. // }
  283. // ConstSFNormalize* norm=0;
  284. // if (Learn && ConInpIT && (ITNormFrequency>0)) {
  285. // norm = new ConstSFNormalize(ITNormFrequency, 0.0005, 100);
  286. // norm->AddConnection(ConInpIT);
  287. // MainSimLoop->AddSimElement(norm);
  288. // }
  289. connection *ConInhInpIT = 0;
  290. if (InitialFWInhWeights>0) {
  291. float InhRossumCp=0.05*InitialFWInhWeights;
  292. ConInhInpIT = new connection(BlobInputLayer, ITLayer, csimInputChannel_GABAa);
  293. ConInhInpIT->SetName("conInhForward");
  294. if (LoadForwardWeights) ConInhInpIT->Load();
  295. else {
  296. ConInhInpIT->ConnectFull(InitialFWInhWeights, 2,0);
  297. }
  298. if (InhLearnRate > 0) ConInhInpIT->SetLearnObj(
  299. new LearnHebbLP2(ConInhInpIT,
  300. MaxFWInhWeights, InhLearnTauDec, InhLearnBaseLine, -InhLearnRate, false));
  301. // new LearnAntiRossum1(ConInhInpIT, InhRossumCp, 0.003, 0.001));
  302. ConInhInpIT->Save();
  303. ConInhInpIT->SetAutoSave(false);
  304. MainSimLoop->AddSimElement(ConInhInpIT);
  305. ConstSFNormalize* FWInhNorm=0;
  306. if (Learn) {
  307. FWInhNorm = new ConstSFNormalize(15, -0.001, 40);
  308. FWInhNorm->AddConnection(ConInhInpIT);
  309. MainSimLoop->AddSimElement(FWInhNorm);
  310. }
  311. }
  312. connection *ConITFBInh = 0;
  313. // if (FBInhWeight > 0)
  314. // {
  315. // ConITFBInh = new connection(ITLayer, BlobInputLayer, 1);
  316. // ConITFBInh->SetName("conFBInh");
  317. // ConITFBInh->ConnectFull(FBInhWeight, 2,0);
  318. // float LearnInhTauDec=30;
  319. // if (Learn) ConITFBInh->SetLearnObj(
  320. // new LearnFBInh(ConITFBInh,
  321. // FBInhMaxWeight, LearnInhTauDec,LearnInhTauDec, FBInhLearnRate, Cdep));
  322. // // new LearnHebbLP2(ConITFBInh,
  323. // // MaxWeights, LearnInhTauDec, 0.5, LearnRate));
  324. // // new LearnRossum1(ConITFBInh, RossumCp, 0.003, 0.0002));
  325. // ConITFBInh->Save();
  326. // ConITFBInh->SetAutoSave(false);
  327. // MainSimLoop->AddSimElement(ConITFBInh);
  328. // // ConstSumNormalize* norm=0;
  329. // // if (Learn) {
  330. // // norm = new ConstSumNormalize(WeightSum, false);
  331. // // norm->AddConnection(ConITFBInh);
  332. // // norm->NormalizeAll();
  333. // // MainSimLoop->AddSimElement(norm);
  334. // // }
  335. // }
  336. ////////// Setup Input
  337. float l1inpStimDur=StimDur;
  338. float Radius=0.2;
  339. bool Tune=false;
  340. input* l1inp;
  341. enum InputType {InpHighOverlap, InpNoOverlap, OnePicture};
  342. InputType CurInputType=OnePicture;
  343. // InputType CurInputType=InpNoOverlap;
  344. switch (CurInputType) {
  345. case InpHighOverlap:
  346. {
  347. PictureSequenceInput* TuneInp = new PictureSequenceInput(BlobInputLayer, csimInputChannel_AMPA, istrength, l1inpStimDur, 1*l1inpStimDur);
  348. vector<vector<float> > StimulusArray;
  349. int NStim=4;
  350. for (int i=0;i<NStim;++i) {
  351. vector<float> CurStimArray(InputNx*InputNy);
  352. for (int xx=0;xx<InputNx;++xx)
  353. for (int yy=0;yy<InputNy/2;++yy)
  354. CurStimArray[xx + InputNx*yy]=1;
  355. for (int yy=InputNy/2;yy<InputNy;++yy)
  356. for (int xx=InputNx*i/NStim;xx<InputNx*(i+1)/NStim;++xx)
  357. CurStimArray[xx + InputNx*yy]=1;
  358. StimulusArray.push_back(CurStimArray);
  359. }
  360. TuneInp->SetPictureArray(StimulusArray);
  361. TuneInp->SetName("HighOverlapInput");
  362. // TuneInp->SetTestMode(l1inpStimDur, 2*l1inpStimDur);
  363. TuneInp->SetMode(csimInputRandom);
  364. // TuneInp->SetMode(csimInputTest);
  365. MainSimLoop->AddSimElement(TuneInp);
  366. l1inp=TuneInp;
  367. }
  368. break;
  369. case InpNoOverlap:
  370. {
  371. PictureSequenceInput* TuneInp = new PictureSequenceInput(BlobInputLayer, csimInputChannel_AMPA, istrength, l1inpStimDur, 1*l1inpStimDur);
  372. vector<vector<float> > StimulusArray;
  373. int NStim=4;
  374. for (int i=0;i<NStim;++i) {
  375. vector<float> CurStimArray(InputNx*InputNy);
  376. for (int yy=InputNy/2;yy<InputNy;++yy)
  377. for (int xx=InputNx*i/NStim;xx<InputNx*(i+1)/NStim;++xx)
  378. CurStimArray[xx + InputNx*yy]=1;
  379. StimulusArray.push_back(CurStimArray);
  380. }
  381. TuneInp->SetPictureArray(StimulusArray);
  382. TuneInp->SetName("HighOverlapInput");
  383. // TuneInp->SetTestMode(l1inpStimDur, 0.2*l1inpStimDur);
  384. // TuneInp->SetMode(csimInputTest);
  385. TuneInp->SetMode(csimInputRandom);
  386. MainSimLoop->AddSimElement(TuneInp);
  387. l1inp=TuneInp;
  388. }
  389. break;
  390. case OnePicture:
  391. {
  392. PictureSequenceInput* WinkelInput = new PictureSequenceInput(BlobInputLayer, csimInputChannel_AMPA, istrength, l1inpStimDur, IsiDur);
  393. WinkelInput->SetPictureArray(&MyMovie);
  394. WinkelInput->SetName("WinkelInput");
  395. WinkelInput->SetMode(csimInputRandom);
  396. // WinkelInput->SetRandomNext(true);
  397. MainSimLoop->AddSimElement(WinkelInput);
  398. l1inp = WinkelInput;
  399. }
  400. break;
  401. default: cout << "nothing";
  402. }
  403. ////////////////////////////////////
  404. int trial, step;
  405. sec =0;
  406. if (TestSim) {
  407. probesteps=200;
  408. learnsteps= 0; // 80;
  409. MaxTrials=1;
  410. cout << "Test (recall) ----------------------Simulation\n";
  411. // l1inp->SetTestMode(100,1000);
  412. } else cout << "NOtestsim------------------------\n";
  413. fflush(stdout);
  414. int TotalTime=0;
  415. MainSimLoop->Hallo();
  416. MainSimLoop->SaveSimInfo();
  417. for (trial=0; trial<MaxTrials; ++trial)
  418. {
  419. cout << "TrialNr=" << trial << "\n";
  420. // l1inp->TurnOn();
  421. // learn
  422. for(step=0;step<learnsteps;++step)
  423. {
  424. cpu_end=clock();
  425. cpu_time_used = ((double) (cpu_end - cpu_start)) / CLOCKS_PER_SEC;
  426. cout << "T" << trial << " Step=" << step
  427. << " sec= " << dt*(sec++) << " cputime="
  428. << cpu_time_used << " sec \n "; fflush(stdout);
  429. for (t=0;t<1000;t++) // simulation of 1 sec
  430. {
  431. MainSimLoop->proceede(1000*step+t);
  432. }
  433. MainSimLoop->prepare(step);
  434. }
  435. // SaveWeights
  436. ConInpIT->Save(trial);
  437. if (ConITFbInh) ConITFbInh->Save(trial);
  438. if (ConITSelfInh) ConITSelfInh->Save(trial);
  439. if (ConInhInpIT) ConInhInpIT->Save(trial);
  440. // probe
  441. // change input, turn off learning, turn off normalization
  442. // cout << "probe\n";
  443. // if (Learn) {
  444. // ConInpIT->SetLearn(false);
  445. // if (ConInhInpIT) ConInhInpIT->SetLearn(false);
  446. // if (norm) norm->TurnOff();
  447. // }
  448. // MainSimLoop->SetSimTag("TEST");
  449. // for(step=0;step<probesteps;++step)
  450. // {
  451. // cpu_end=clock();
  452. // cpu_time_used = ((double) (cpu_end - cpu_start)) / CLOCKS_PER_SEC;
  453. // cout << "sec= " << dt*(sec++) << "cputime=" << cpu_time_used << " sec \n "; fflush(stdout);
  454. // for (t=0;t<1000;t++) // simulation of 1 sec
  455. // {
  456. // MainSimLoop->proceede(1000*step+t);
  457. // }
  458. // MainSimLoop->prepare(step);
  459. // }
  460. // if (Learn) {
  461. // ConInpIT->SetLearn(true);
  462. // if (ConInhInpIT) ConInhInpIT->SetLearn(true);
  463. // if (norm) norm->TurnOn();
  464. // }
  465. MainSimLoop->SetSimTag("");
  466. }
  467. ConInpIT->Save();
  468. if (ConITFbInh) ConITFbInh->Save();
  469. if (ConITSelfInh) ConITSelfInh->Save();
  470. if (ConInhInpIT) ConInhInpIT->Save();
  471. // delete Layer1;
  472. // delete Layer2;
  473. // delete l1l2con;
  474. // delete l1inp;
  475. cpu_end=clock();
  476. cpu_time_used = ((double) (cpu_end - cpu_start)) / CLOCKS_PER_SEC;
  477. cout << "\n\n***********CpuTimeUsed= " << cpu_time_used << " seconds \n";
  478. system("bluetclbutton v4learn finished &");
  479. }