Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

minimal.cpp 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /**
  2. \brief minimal.cpp is a minimal reference simulation to show how to use the objsimlibrary
  3. \author Frank Michler
  4. */
  5. #include "sys.hpp"
  6. #include "debug.hpp"
  7. #include <iostream>
  8. #include <math.h>
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <objsimlibrary.hpp>
  12. #include <anyoption.h>
  13. #include <valarray>
  14. #include <time.h>
  15. ////////////////////
  16. int main(int argc, char** argv)
  17. {
  18. std::string SimName("minimal");
  19. cout << testfunction();
  20. clock_t cpu_start, cpu_end;
  21. double cpu_time_used;
  22. ////////////////Begin//ProcessCommandLineArguments//////////////
  23. cpu_start = clock();
  24. // define some directories
  25. std::string HomeDir(getenv("HOME"));
  26. std::string BaseDir(HomeDir+"/prog/objsim");
  27. std::string ConfigDir(HomeDir+"/prog/objsim/"+SimName);
  28. std::string ConfigFile(ConfigDir+"/settings_"+SimName+".cfg");
  29. // 'a' = dummy; do not use -a !! (setOption without second para doesn't work!!)
  30. /**
  31. AnyOptionWrapper takes care of simulation parameters
  32. 1. names of variables and default parameters are defined.
  33. 2. if the config file "settings_<SimName>" has an entry with the same name as one of the defined variables,
  34. the variable is set to the value in the config file.
  35. 3. if a command line parameter with the same name as one of the variables is given, the corresponding variable
  36. is set to the command line value value.
  37. As an example look at "AnyWrapParaInt(InputNx, 10);"
  38. AnyWrapParaInt is a macro for defining an integer parameter
  39. InputNx is used as the name of the variable, as the identifyer string in the config file settings_minimal.cfg
  40. and as the identifyer for the command line argument.
  41. The default value for InputNx is 10. This value is used when no config file entry and no command line argument
  42. with this name is given. If the config file contains the line "InputNx : 8", InputNx is set to 8.
  43. If furthermore, the executable is called with InputNx as command line parameter:
  44. "simminimal --InputNx 12", InputNx is set to 12.
  45. If command line option MakeDefaultConfig is set (it is a flag, so you don't give a value):
  46. "simminimal --MakeDefaultConfig --InputNx 12"
  47. then the values of all parameters will be written in the config file settings_minimal.cfg.
  48. (fm) 10.11.2008
  49. */
  50. AnyOptionWrapper *myAnyWrap = new AnyOptionWrapper(argc, argv, ConfigFile.c_str());
  51. CSimStandardOptions StdOpt(myAnyWrap);
  52. AnyWrapParaStringCmdOnly(SimControlName, "");
  53. AnyWrapParaFloat(WeightStrength, 0.5);
  54. AnyWrapParaFloat(Connectivity, 0.1);
  55. AnyWrapParaInt(InputNx, 10);
  56. AnyWrapParaInt(InputNy, 10);
  57. myAnyWrap->process();
  58. ////////////////End//ProcessCommandLineArguments//////////////
  59. ////////////////Begin//InitializeGlobalSimLoop
  60. SimLoop* MainSimLoop = InitLibCSim();
  61. MainSimLoop->SetDataDirectory(StdOpt.DataDirectory.c_str());
  62. float dt=MainSimLoop->GetDeltaT(); // milli sec
  63. cout << "int main(): dt = " << dt << "\n";
  64. myAnyWrap->Save((MainSimLoop->GetDataDirectory() + "/backup_settings").c_str());
  65. delete myAnyWrap;
  66. system(("cp progversion.txt "+MainSimLoop->GetDataDirectory()).c_str());
  67. ////////////////End//InitializeGlobalSimLoop
  68. int i, j, k, sec, t;
  69. ////////////////End//ProcessCommandLineArguments//////////////
  70. //////////////////////////////////////////////
  71. //////// Setup Neuron Layer
  72. izh8layer* MyLayer = new izh8layer(InputNx*InputNy, IzhParaThalamoCortical);
  73. MyLayer->SetName("MyLayer");
  74. MyLayer->SetupPositions(InputNx, InputNy, true);
  75. // MyLayer->TuneNoiseAmplitude(3);
  76. MyLayer->SetNoiseAmplitude(0.0035926);
  77. MainSimLoop->AddSimElement(MyLayer);
  78. ////////// Setup connections
  79. connection *MyConnection = new connection(MyLayer, MyLayer, csimInputChannel_AMPA);
  80. MyConnection->SetName("MyConnection");
  81. if (!StdOpt.LoadWeights || (MyConnection->Load() != 0)) {
  82. MyConnection->ConnectRandom(Connectivity, WeightStrength);
  83. }
  84. MyConnection->Save();
  85. MainSimLoop->AddSimElement(MyConnection);
  86. ////////// Setup Input
  87. vector<vector<float> > StimulusArray;
  88. int NStim=2;
  89. float PatternSize=1./float(NStim);
  90. for (int i=0;i<NStim;++i) {
  91. vector<float> CurStimArray(InputNx*InputNy);
  92. int DiffStart = int(i*PatternSize*InputNx*InputNy);
  93. int DiffStop = int((i+1)*PatternSize*InputNx*InputNy);
  94. if ((DiffStart <=InputNx*InputNy) && (DiffStop <=InputNx*InputNy)) {
  95. for (int xx=DiffStart;xx<DiffStop;++xx) {
  96. CurStimArray[xx]=1;
  97. }
  98. }
  99. StimulusArray.push_back(CurStimArray);
  100. }
  101. PictureSequenceInput *MyInput = new PictureSequenceInput(MyLayer, csimInputChannel_AMPA, StdOpt.InputStrength, 100,50,5,20);
  102. MyInput->SetPictureArray(StimulusArray);
  103. MyInput->SetName("TwoPatternInput");
  104. // Input->SetMode(csimInputRandom);
  105. MainSimLoop->AddSimElement(MyInput);
  106. ////////////////////////////////////
  107. int trial, step;
  108. sec =0;
  109. int TotalTime=0;
  110. MainSimLoop->Hallo();
  111. MainSimLoop->SaveSimInfo();
  112. cout << "StdOpt.NTrials" << StdOpt.NTrials << "StdOpt.NSteps" << StdOpt.NSteps << "\n";
  113. fflush(stdout);
  114. for (trial=0; trial<StdOpt.NTrials; ++trial)
  115. {
  116. cout << "TrialNr=" << trial << "\n";fflush(stdout);
  117. // learn
  118. for(step=0;step<StdOpt.NSteps;++step)
  119. {
  120. cpu_end=clock();
  121. cpu_time_used = ((double) (cpu_end - cpu_start)) / CLOCKS_PER_SEC;
  122. cout << "T" << trial << " Step=" << step
  123. << " sec= " << dt*(sec++) << " cputime="
  124. << cpu_time_used << " sec \n "; fflush(stdout);
  125. for (t=0;t<1000;t++) // simulation of 1 sec
  126. {
  127. MainSimLoop->proceede(1000*step+t);
  128. }
  129. MainSimLoop->prepare(step);
  130. }
  131. if (SimControlName != "") system((BaseDir + "/scripts/mytksend " + SimControlName + " SetTrialNr " +stringify(trial)+ " &").c_str());
  132. }
  133. cpu_end=clock();
  134. cpu_time_used = ((double) (cpu_end - cpu_start)) / CLOCKS_PER_SEC;
  135. cout << "\n\n***********CpuTimeUsed= " << cpu_time_used << " seconds \n";
  136. if (StdOpt.SimFinishButton) system((BaseDir + "/scripts/bluetclbutton Simulation finished &").c_str());
  137. }