123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358 |
- /** som02.cpp is a learning simulation.
- Learning phases are intermitted by test phases. In Test phases all stimuli of a stimulus set are presented.
- For data analysis spike files and other data files are marked with a postfix according to the loop number:
- TEST0, TEST1
- simulations using som02.cpp were published in:
- Using spatiotemporal correlations to learn topographic maps for invariant object recognition.
- Michler F, Eckhorn R, Wachtler T.
- J Neurophysiol. 2009 Aug;102(2):953-64. Epub 2009 Jun 3.
- */
- #include "sys.hpp"
- #include "debug.hpp"
- #include <iostream>
- #include <math.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <objsimlibrary.hpp>
- #include <anyoption.h>
- #include <valarray>
- #include <time.h>
- #include "version.h"
- void DoNetworkPropertytest(SimLoop* MainSimLoop, VecDepressiveConnection* ConITIT, float StartWeight);
- ////////////////////
- int main(int argc, char** argv)
- {
- Debug(objsim::debug::init());
- turnOffAllDebug();
- Debug( dc::input.on() );
-
- std::string SimName("som02");
- cout << testfunction();
- cout << get_version_info();
- clock_t cpu_start, cpu_end;
- double cpu_time_used;
- ////////////////Begin//ProcessCommandLineArguments//////////////
- cpu_start = clock();
- std::string HomeDir(getenv("HOME"));
- std::string BaseDir(HomeDir+"/prog/objsim");
- std::string ConfigDir(".");
- std::string ConfigFile(ConfigDir+"/settings_"+SimName+".cfg");
- // 'a' = dummy; do not use -a !! (setOption without second para doesn't work!!)
- AnyOptionWrapper *myAnyWrap = new AnyOptionWrapper(argc, argv, ConfigFile.c_str());
- CSimStandardOptions StdOpt(myAnyWrap);
- SimModuleITLayer MITLayer(myAnyWrap);
- MITLayer.SetCmdLineOptions();
- InvarLayer InvarianceLayer(myAnyWrap);
- InvarianceLayer.SetCmdLineOptions();
- // SimModuleMovieInput MInput(myAnyWrap);
- smodMovieInput MInput(myAnyWrap);
- MInput.SetCmdLineOptions();
- AnyWrapParaStringCmdOnly(SimControlName, "");
- AnyWrapParaBool(TestSim, false);
- AnyWrapParaBool(LoadForwardWeights, false);
- //AnyWrapParaInt(ProbeSteps, 4);
- AnyWrapParaFloat(TauRec, 50);
- AnyWrapParaFloat(U_se, 0.08);
- AnyWrapParaFloat(ITExExWeights, 0.1);
- AnyWrapParaFloat(ITExExRange, 0.02);
- AnyWrapParaFloat(FWMaxWeights, 2.20);
- AnyWrapParaFloat(InhLearnRate, 0.00001);
- AnyWrapParaFloat(InhLearnBaseLine, 1);
- //AnyWrapParaFloat(RossumCp, 0.000001);
- //AnyWrapParaFloat(ITNormFrequency, 30);
- AnyWrapParaBool(RandomInputOrder,false);
- AnyWrapParaFloat(TestStimDur, 100);
- AnyWrapParaBool(Teach,false);
- AnyWrapParaFloat(ExExMinDelay, 3);
- AnyWrapParaFloat(ExExMaxDelay, 6);
- AnyWrapParaBool(QuadraticNorm, false);
- AnyWrapParaBool(Learn, true);
- AnyWrapParaBool(Scan, true);
- AnyWrapParaBool(PicSlideWinStimulus, false);
- AnyWrapParaInt(NWeightSaves, 2);
- // 0: save weights every trial, otherwise: number of trials with weight saving
- AnyWrapParaBool(StopSignal,false);
- AnyWrapParaBool(NetworkPropertyTest, false);
- AnyWrapParaBool(ScrambleExExWeights, false); //!< for second revision
- // 0: no test phases, 1: test after last two training phases
- AnyWrapParaInt(TestPhaseMode, 1);
- AnyWrapParaFloat(NetTestStartWeight,1);
- AnyWrapParaString(MovieInputMode, "Default");
- myAnyWrap->process();
- ////////////////End//ProcessCommandLineArguments//////////////
- bool VecCon=true;
- // bool VecCon=false;
- ////////////////Begin//InitializeGlobalSimLoop
- SimLoop* MainSimLoop = InitLibCSim();
- MainSimLoop->SetDataDirectory(StdOpt.DataDirectory.c_str());
- float dt=MainSimLoop->GetDeltaT(); // milli sec
- cout << "int main(): dt = " << dt << "\n";
- myAnyWrap->Save((MainSimLoop->GetDataDirectory() + "/backup_settings").c_str());
- delete myAnyWrap;
- // system(("cp progversion.txt "+MainSimLoop->GetDataDirectory()).c_str());
- // now in libcsim.cpp
- ////////////////End//InitializeGlobalSimLoop
- // bool Learn=true;
- if ((MInput.LearnRate == 0) || TestSim) {
- Learn=false;
- cout << "No Learning\n";
- }
- int i, j, k, sec, t;
- if (TestSim) StdOpt.LoadWeights=true;
- if (StdOpt.LoadWeights)
- {
- LoadForwardWeights=true;
- }
- ////////////////End//ProcessCommandLineArguments//////////////
- //////////////////////////////////////////////
- int InputNx, InputNy, NStimuli;
- //////// Setup IT Module
- layer* ITLayer=MITLayer.Setup(MainSimLoop, 5, StdOpt.LoadWeights, Learn, false, StdOpt.SaveInitialWeights);
- cout << "Setup InvLayer \n";
- fflush(stdout);
- // layer* InvLayer = InvarianceLayer.Setup(ITLayer, false);
- layer* InvLayer = InvarianceLayer.Setup(ITLayer, VecCon, StdOpt.SaveInitialWeights);
- //////////connections
- VecDepressiveConnection *ConITIT;
- if (ITExExWeights > 0) {
- ConITIT = new VecDepressiveConnection(ITLayer, ITLayer,csimInputChannel_NMDA_AMPA, TauRec, U_se);
- ConITIT->SetName("conIT_ExEx");
- if (MITLayer.LoadITWeights) ConITIT->Load();
- // else ConITIT->ConnectGaussianProb(ITExExRange, ITExExWeights, 2, ExExMaxDelay,ExExMinDelay, 0.5, true);
- else ConITIT->ConnectGaussian(ITExExRange, ITExExWeights, ExExMaxDelay,ExExMinDelay, true);
- if (ScrambleExExWeights) ConITIT->ScrambleSynTargets();
- if (StdOpt.SaveInitialWeights) {
- ConITIT->Save();
- }
- MainSimLoop->AddSimElement(ConITIT);
- }
- //////// Setup Input
- cout << "before minput.setup \n";
- fflush(stdout);
- MInput.Setup(csimInputChannel_AMPA, StdOpt.InputStrength, StdOpt.LoadWeights);
- // NStimuli = l1inp->GetNStimuli();
- if (RandomInputOrder) {
- MInput.SetInputMode(csimInputRandom);
- } else {
- MInput.SetInputMode(InputModeFromString(MovieInputMode));
- }
- cout << "after minput.setup \n";
- fflush(stdout);
- cout << "Calling MInput.ConnectTo\n";
- MInput.ConnectTo(ITLayer, LoadForwardWeights, Learn, VecCon, StdOpt.SaveInitialWeights);
- ////////////////////////////////////
- int trial=0;
- int step=0;
- sec =0;
- NStimuli = MInput.NTestStimuli;
- StdOpt.TestNSteps = int((250)*(NStimuli+1)/250.);
- cout << "StdOpt.TestNSteps=" << StdOpt.TestNSteps << "\n";
- if (TestSim) {
- StdOpt.NTrials = 1;
- cout << "Test (recall) ----------------------Simulation\n";
- } else cout << "NOtestsim------------------------\n";
- fflush(stdout);
- int TotalTime=0;
- int WeightSaveBase=StdOpt.NTrials;
- if (NWeightSaves > 0) {
- WeightSaveBase=StdOpt.NTrials/NWeightSaves;
- }
- MainSimLoop->Hallo();
- MainSimLoop->SaveSimInfo();
- int MacroTimeStep = MainSimLoop->GetMacroTimeStep();
- cpu_end=clock();
- cpu_time_used = ((double) (cpu_end - cpu_start)) / CLOCKS_PER_SEC;
- cout << "Network is Initialized. Initialization needed " << cpu_time_used << " seconds \n ";
- cpu_start=clock();
- // network is now initialized
- if (!NetworkPropertyTest) { // normal main sim loop
- // main simulation loop
- for (trial=0; trial<StdOpt.NTrials; ++trial)
- {
- // test phase: test network with stimulus set
- // scan=start sim multiple times with different parameters
- // then only the last two learning periods should be followed by test trials
- if ((TestPhaseMode==1) && ((! Scan) || (trial >(StdOpt.NTrials-3)))) {
- // Invariance layer is turned of only in learning simulations, not in slowlyness test
- MainSimLoop->TurnOffLearning();
- if (Learn) {
- InvarianceLayer.TurnOn();
- }
- MainSimLoop->SetSimTag(("TEST"+stringify(trial)).c_str());
- MInput.SetInputMode(csimInputTest);
- for (step=0;step<StdOpt.TestNSteps;++step)
- {
- cpu_end=clock();
- cpu_time_used = ((double) (cpu_end - cpu_start)) / CLOCKS_PER_SEC;
- cout << "TTest" << trial << " Step=" << step
- << " sec= " << dt*(sec++) << " cputime="
- << cpu_time_used << " sec \n ";
- fflush(stdout);
- // simulation of 1 MacroTimeStep
- for (t=0;t<MacroTimeStep;t++)
- {
- MainSimLoop->proceede(MacroTimeStep*step+t);
- }
- MainSimLoop->prepare(step);
- }
- cout << "removed sim tag\n";
- fflush(stdout);
- MainSimLoop->TurnOnLearning();
- if (RandomInputOrder) {
- MInput.SetInputMode(csimInputRandom);
- } else {
- MInput.SetInputMode(InputModeFromString(MovieInputMode));
- }
- } // if ((TestPhaseMode==1) && ((! Scan) || (trial >(StdOpt.NTrials-3)) || trial == 0 || trial == 1))
- MainSimLoop->SetSimTag("");
- // Invariance layer is turned of only in learning simulations, not in slowlyness test
- if (Learn) {
- InvarianceLayer.TurnOff();
- }
- cout << "TrialNr=" << trial << "\n";
- // l1inp->TurnOn();
- // learn
- for (step=0;step<StdOpt.NSteps;++step)
- {
- cpu_end=clock();
- cpu_time_used = ((double) (cpu_end - cpu_start)) / CLOCKS_PER_SEC;
- cout << "TLearn" << trial << " Step=" << step
- << " sec= " << dt*(sec++) << " cputime="
- << cpu_time_used << " sec \n ";
- fflush(stdout);
- // simulation of one MacroTimeStep
- for (t=0;t<MacroTimeStep;t++)
- {
- MainSimLoop->proceede(MacroTimeStep*step+t);
- }
- cout << "prepare(step)\n";
- fflush(stdout);
- MainSimLoop->prepare(step);
- }
- // SaveWeights
- if (((trial+1) %WeightSaveBase) == 0) {
- cout << "SaveLearningWeights\n";
- fflush(stdout);
- MainSimLoop->SaveLearningWeights(trial);
- }
- if (SimControlName != "") system((BaseDir + "/scripts/mytksend " + SimControlName + " SetTrialNr " +stringify(trial)+ " &").c_str());
- }
- } else {
- DoNetworkPropertytest(MainSimLoop, ConITIT, NetTestStartWeight);
- }
- // delete Layer1;
- // delete Layer2;
- // delete l1l2con;
- // delete l1inp;
- cpu_end=clock();
- cpu_time_used = ((double) (cpu_end - cpu_start)) / CLOCKS_PER_SEC;
- cout << "\n\n***********CpuTimeUsed= " << cpu_time_used << " seconds \n";
- if (StopSignal) system("bluetclbutton v4learn finished &");
- }
- void DoNetworkPropertytest(SimLoop* MainSimLoop, VecDepressiveConnection* ConITIT, float StartWeight)
- {
- // NetworkPropertyTest
- // measure: patch size during input, self sustained patch size
- int NetworkTestNSteps=100;
- float WeightFactor=0.9;
- int StepSize=8;
- int MacroTimeStep = MainSimLoop->GetMacroTimeStep();
- cout << "Starting Network Property Test \n";
- ConITIT->MultiplyAllTargetWeights(StartWeight);
- MainSimLoop->TurnOffLearning();
- for (int step=0;step<NetworkTestNSteps;++step)
- {
- // simulation of one MacroTimeStep
- for (int t=0;t<MacroTimeStep;t++)
- {
- MainSimLoop->proceede(MacroTimeStep*step+t);
- }
- cout << "prepare(step)\n";
- fflush(stdout);
- MainSimLoop->prepare(step);
- if ((step % StepSize) == StepSize-1) {
- StartWeight*=WeightFactor;
- cout << " -------> changing sim parameters, Factor=" << StartWeight << "\n";
- ConITIT->MultiplyAllTargetWeights(WeightFactor);
- }
- }
- }
|