/** 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 #include #include #include #include #include #include #include #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-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;stepproceede(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;stepproceede(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;stepproceede(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); } } }