sensorycancel.cpp 22 KB

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