#include "sys.hpp" // for libcwd #include "debug.hpp" // for libcwd #include "objsimlibrary.hpp" #include "simmodule.hpp" #include "simmodules.hpp" //////////////// SimModuleITLayer::SimModuleITLayer(AnyOptionWrapper* _opt): SimModule(_opt), CompInh(_opt), ITLayer(0), ConITSelfInh(0) { } SimModuleITLayer::~SimModuleITLayer() { cout << "Destructor SimModuleITLayer::~SimModuleITLayer()\n"; if (ConITSelfInh) { ConITSelfInh->Save(); delete ConITSelfInh; } delete ITLayer; } void SimModuleITLayer::SetCmdLineOptions() { myAnyWrap->setOption( "ITNx", 'a', &ITNx, 4); myAnyWrap->setOption( "ITNy", 'a', &ITNy, 4); myAnyWrap->setOption("ITTauInhibition", 'a', &ITTauInhibition, 5.0); // myAnyWrap->setOption("ITTauFeeding", 'a', &ITTauFeeding, 5); myAnyWrap->setOption("NmdaAmpaRatio", 'a', &NmdaAmpaRatio, 0.3); myAnyWrap->setFlag( "LoadITWeights", 'a', &LoadITWeights); myAnyWrap->setOption("ITLateralInhibitionWeight", 'a', &ITLateralInhibitionWeight, 0.01); myAnyWrap->setFlag( "ITSelfInhFacilitation", 'a', &ITSelfInhFacilitation); myAnyWrap->setOption( "ITSelfLearnRate", 'a', &ITSelfLearnRate,0.0001); myAnyWrap->setOption("LatInhDistance", 'a', &LatInhDistance, 0.3); myAnyWrap->setOption("SelfInhCdep", 'a', &SelfInhCdep, 0.0001); myAnyWrap->setOption("SelfInhMaxWeight", 'a', &SelfInhMaxWeight, 6); myAnyWrap->setOption("SelfInhMinWeight", 'a', &SelfInhMinWeight, 1); CompInh.SetCmdLineOptions(); } layer* SimModuleITLayer::Setup(SimLoop *MainSimLoop, int NeuronType, bool LoadWeights, bool Learn, bool InhResetable, bool SaveInitialWeights) { if (LoadWeights) { LoadITWeights=true; } IzhParas IzhLowDIntegrator (0.02, -0.1, -55, 2, 108, 4.1, 0.0); csimNeuronType NType; if (NeuronTypeSetTauGaba(1.0, ITTauInhibition); tmplayer->SetTauGaba(13.5, 100); // remove this tmplayer->SetTauAmpa(0.5, 2.4); tmplayer->SetTauNmda(10, 100); tmplayer->SetNoiseAmplitude(0.259545); tmplayer->SetBalancedInhibition(1.58025); // tmplayer->TuneNoiseAmplitude(100); // tmplayer->TuneBalancedInhibition(3); tmplayer->SetNmdaAmpaRatio(NmdaAmpaRatio); ITLayer = tmplayer; } break; case csimNType_Izhikevich8_integrator: { float NmdaAmpaRatio=0.3; izh8layer* tmplayer = new izh8layer(ITNx*ITNy, IzhParaIntegrator2); tmplayer->SetTauGaba(1.0, ITTauInhibition); tmplayer->SetTauGaba(13.5, 100); // remove this tmplayer->SetTauAmpa(0.5, 2.4); tmplayer->SetTauNmda(10, 100); tmplayer->SetNoiseAmplitude(0.172989); tmplayer->SetBalancedInhibition(1.48085); // tmplayer->TuneNoiseAmplitude(100); // tmplayer->TuneBalancedInhibition(3); tmplayer->SetNmdaAmpaRatio(NmdaAmpaRatio); ITLayer = tmplayer; } break; case csimNType_Izhikevich9: { float NmdaAmpaRatio=0.3; // izh9layer* tmplayer = new izh9layer(ITNx*ITNy, IzhParaRegularSpiking); izh9layer* tmplayer = new izh9layer(ITNx*ITNy, IzhParaIntegrator2); // tmplayer->SetTauGaba(1.0, ITTauInhibition); // tmplayer->SetTauGabaA(13.5, 100); // remove this tmplayer->SetTauAmpa(0.5, 2.4); tmplayer->SetTauNmda(10, 100); tmplayer->SetNoiseAmplitude(0.172989); tmplayer->SetBalancedInhibition(2.07651); // tmplayer->TuneNoiseAmplitude(100); // tmplayer->TuneBalancedInhibition(3); tmplayer->SetNmdaAmpaRatio(NmdaAmpaRatio); ITLayer = tmplayer; } break; case csimNType_DecoLif: { float NmdaAmpaRatio=0.3; // izh9layer* tmplayer = new izh9layer(ITNx*ITNy, IzhParaRegularSpiking); DecoLifLayer* tmplayer = new DecoLifLayer(ITNx*ITNy, DecoParaExcitatory); // tmplayer->SetTauGaba(1.0, ITTauInhibition); // tmplayer->SetTauGabaA(13.5, 100); // remove this // tmplayer->SetTauAmpa(0.5, 2.4); // tmplayer->SetTauNmda(10, 100); // tmplayer->TuneNoiseAmplitude(3); const float DECO_LIF_NOISE_3_HZ = 0.05294; // Noise: 3 Hz Background Firing Rate tmplayer->SetNoiseAmplitude(DECO_LIF_NOISE_3_HZ); // tmplayer->TuneNoiseAmplitude(100); // tmplayer->TuneBalancedInhibition(3); // tmplayer->SetNoiseAmplitude(0.0769104); // Noise: 100 Hz Background Firing Rate // tmplayer->SetBalancedInhibition(11.7664); // Reduce Background Firing Rate to 3 Hz tmplayer->SetNmdaAmpaRatio(NmdaAmpaRatio); ITLayer = tmplayer; } break; } ITLayer->SetName("RepresentationLayer"); ITLayer->SetupPositions(ITNx,ITNy,true); ITLayer->SetRandomInputStrength(0); // ITLayer->StartBinRec(2); MainSimLoop->AddSimElement(ITLayer); // Setup ITSelfInhibition bool VecCon=true; layer* InhLayer = CompInh.Setup(ITLayer, LoadITWeights, VecCon, SaveInitialWeights); InhLayer->SetResetable(InhResetable); // ConITSelfInh=0; // if (ITLateralInhibitionWeight > 0) { // if (ITSelfInhFacilitation) { // FacilitativeConnection *tmpCon = new FacilitativeConnection(ITLayer, ITLayer, csimInputChannel_GABAa, 60, 0.005, 50, 0.01); // inputNumber=0 // ConITSelfInh = tmpCon; // } else { // connection *tmpCon = new connection(ITLayer, ITLayer, csimInputChannel_GABAa, true); // inputNumber=0 // ConITSelfInh = tmpCon; // } // ConITSelfInh->SetNonSelf(true); // ConITSelfInh->SetName("conSelfInh"); // if (LoadITWeights) ConITSelfInh->Load(); // else { // ConITSelfInh->ConnectFull(ITLateralInhibitionWeight, 0,0); // // ConITSelfInh->ConnectRandom(0.4, ITLateralInhibitionWeight, 1,0); // // DistanceProfile* profile = new CircleDistanceProfile(1000, LatInhDistance); // // ConITSelfInh->ConnectProfile(profile, ITLateralInhibitionWeight, 0,0, true); // // ConITSelfInh->ConnectRandom(0.2, ITLateralInhibitionWeight, 1,0); // } // float SelfInhMinWeight=0; // float InhLearnTauPost=100; // float InhLearnTauPre=30; // if (Learn && (ITSelfLearnRate >0)) { // LearnFBInh* LearnSelfITInh = new LearnFBInh(ConITSelfInh, // SelfInhMaxWeight, InhLearnTauPre, InhLearnTauPost, ITSelfLearnRate, SelfInhCdep); // // LearnHebbLP2* LearnSelfITInh = new LearnHebbLP2( // // ConITSelfInh, SelfInhMaxWeight, SelfInhLearnTauDec, // // SelfInhBaseLine, ITSelfLearnRate); // LearnSelfITInh->SetMinWeight(SelfInhMinWeight); // ConITSelfInh->SetLearnObj(LearnSelfITInh); // } // ConITSelfInh->Save(); // ConITSelfInh->SetAutoSave(false); // MainSimLoop->AddSimElement(ConITSelfInh); // } return ITLayer; } void SimModuleITLayer::SetInhExWeightStrength(float NewInhExStrength) { CompInh.SetInhExWeightStrength(NewInhExStrength); } SpikeTrain* SimModuleITLayer::ItSpikeTrain() { if (ITLayer) { return ITLayer->GetSpikeTrain(); } else { cerr << "ERROR in SimModuleITLayer::ItSpikeTrain(): this should not happen. ITLayer not initialized?\n"; return 0; } }; //////////////////////// InvarLayer::InvarLayer(AnyOptionWrapper* _opt): SimModule(_opt), MapLayer(0), VecCon(false) { NType = csimNType_DecoLif; // remove this Nx=Ny=10; } InvarLayer::~InvarLayer() { delete LInvar; delete conMapLInvar; } void InvarLayer::TurnOn() { LInvar->TurnOn(); conMapLInvar->TurnOn(); } void InvarLayer::TurnOff() { LInvar->TurnOff(); conMapLInvar->TurnOff(); } void InvarLayer::SetCmdLineOptions() { myAnyWrap->setOption((SimModuleName + "FWConStrength").c_str(), 'a', &FWConStrength, 0); } layer* InvarLayer::Setup(layer* MapLayer, bool _veccon, bool SaveInitialWeights) { VecCon=_veccon; MainSimLoop = GetGlobalSimLoop(); if (FWConStrength > 0) { // Setup Invar Layer switch (NType) { case csimNType_DecoLif: { float NmdaAmpaRatio=0.3; DecoLifLayer* tmplayer = new DecoLifLayer(Nx*Ny, DecoParaExcitatory); tmplayer->SetName((SimModuleName+"InvarLayer").c_str()); tmplayer->SetNoiseAmplitude(0.05294); // Noise: 3 Hz Background Firing Rate tmplayer->SetNmdaAmpaRatio(NmdaAmpaRatio); tmplayer->SetupPositions(Nx, Ny, true); MainSimLoop->AddSimElement(tmplayer); LInvar = tmplayer; } break; } // Setup Forward Connections from MapLayer to Invar Layer float ConRange=0.2; if (VecCon) { VecConnection* tmpcon = new VecConnection(MapLayer, LInvar, csimInputChannel_AMPA); tmpcon->ConnectGaussian(ConRange, FWConStrength, 1,0, true); conMapLInvar=tmpcon; } else { connection* tmpcon = new connection(MapLayer, LInvar, csimInputChannel_AMPA); tmpcon->ConnectGaussian(ConRange, FWConStrength, 1,0, true); conMapLInvar=tmpcon; } conMapLInvar->SetName((SimModuleName+"conMapToInvar").c_str()); if (SaveInitialWeights) { conMapLInvar->Save(); } MainSimLoop->AddSimElement(conMapLInvar); } return LInvar; // if (FWConStrength == 0) LInvar stays "0" } ////////////////////////// SimMod_CompetitiveInhibition::SimMod_CompetitiveInhibition(AnyOptionWrapper* _opt): SimModule(_opt), NInhNeurons(100), InhLayer(0), conInhEx(0), conInhInh(0), conExInh(0) { } void SimMod_CompetitiveInhibition::SetCmdLineOptions() { std::string ModName("CInh"); myAnyWrap->setOption((ModName + "NInhNeurons").c_str(), 'a', &NInhNeurons, 100); myAnyWrap->setOption((ModName + "NExInhConnections").c_str(), 'a', &NExInhConnections, 10); myAnyWrap->setOption((ModName + "NInhExConnections").c_str(), 'a', &NInhExConnections, 10); myAnyWrap->setOption((ModName + "NInhInhConnections").c_str(), 'a', &NInhInhConnections, 10); myAnyWrap->setOption((ModName + "ExInhStrength").c_str(), 'a', &ExInhStrength, 0.1); myAnyWrap->setOption((ModName + "InhExStrength").c_str(), 'a', &InhExStrength, 0.1); myAnyWrap->setOption((ModName + "InhInhStrength").c_str(), 'a', &InhInhStrength, 0.1); myAnyWrap->setOption((ModName + "NmdaAmpaRatio").c_str(), 'a', &NmdaAmpaRatio, 0.1); } layer* SimMod_CompetitiveInhibition::Setup(layer* ExLayer, bool LoadWeights, bool VecCon, bool SaveInitialWeights) { // first: create inhibitory layer MainSimLoop = GetGlobalSimLoop(); int InhNx, InhNy; InhNx = NInhNeurons; InhNy = 1; layer* InhLayer; csimNeuronType NType = csimNType_DecoLif; switch (NType) { case csimNType_Izhikevich9: { // izh9layer* tmplayer = new izh9layer(NInhNeurons, IzhParaRegularSpiking); izh9layer* tmplayer = new izh9layer(NInhNeurons, IzhParaIntegrator2); tmplayer->SetupPositions(InhNx, InhNy, true); // tmplayer->SetTauGaba(1.0, ITTauInhibition); // tmplayer->SetTauGabaA(13.5, 100); // remove this tmplayer->SetTauAmpa(0.5, 2.4); tmplayer->SetTauNmda(10, 100); tmplayer->SetNoiseAmplitude(0.172989); tmplayer->SetBalancedInhibition(2.07651); // tmplayer->TuneNoiseAmplitude(100); // tmplayer->TuneBalancedInhibition(3); tmplayer->SetNmdaAmpaRatio(NmdaAmpaRatio); tmplayer->SetName("InhibitionLayer"); MainSimLoop->AddSimElement(tmplayer); InhLayer = tmplayer; } break; case csimNType_DecoLif: { float NmdaAmpaRatio=0.3; DecoLifLayer* tmplayer = new DecoLifLayer(NInhNeurons, DecoParaInhibitory); tmplayer->SetupPositions(InhNx, InhNy, true); // tmplayer->SetTauGaba(1.0, ITTauInhibition); // tmplayer->SetTauGabaA(13.5, 100); // remove this tmplayer->SetTauAmpa(0.5, 2.4); tmplayer->SetTauNmda(10, 100); tmplayer->SetNoiseAmplitude(0.0504967); tmplayer->SetBalancedInhibition(4.52554); // tmplayer->TuneNoiseAmplitude(100); // tmplayer->TuneBalancedInhibition(3); tmplayer->SetNmdaAmpaRatio(NmdaAmpaRatio); tmplayer->SetName("InhibitionLayer"); MainSimLoop->AddSimElement(tmplayer); InhLayer = tmplayer; } break; } // InhLayer->StartBinRec(2); // setup Ex->Inh connections { if (NExInhConnections > ExLayer->N) { NExInhConnections = ExLayer->N; } if (VecCon) { VecConnection* tmpcon = new VecConnection(ExLayer, InhLayer, csimInputChannel_NMDA_AMPA); tmpcon->ConnectRandomIncomming(NExInhConnections,ExInhStrength,1,0,true); conExInh=tmpcon; } else { connection* tmpcon = new connection(ExLayer, InhLayer, csimInputChannel_NMDA_AMPA); tmpcon->ConnectRandom2(NExInhConnections,ExInhStrength,1,0,true); conExInh=tmpcon; } conExInh->SetName("conExInh"); if (SaveInitialWeights) { conExInh->Save(); } MainSimLoop->AddSimElement(conExInh); } // setup Inh->Ex connections { if (NInhExConnections > InhLayer->N) { NInhExConnections = InhLayer->N; } if (VecCon) { VecConnection* tmpcon = new VecConnection(InhLayer, ExLayer, csimInputChannel_GABAa); tmpcon->SetName("conInhEx"); if (LoadWeights) { tmpcon->Load(); } else { tmpcon->ConnectRandomIncomming(NInhExConnections,InhExStrength,1,0,true); } conInhEx=tmpcon; } else { connection* tmpcon = new connection(InhLayer, ExLayer, csimInputChannel_GABAa); tmpcon->SetName("conInhEx"); if (LoadWeights) { tmpcon->Load(); } else { tmpcon->ConnectRandom2(NInhExConnections,InhExStrength,1,0,true); } conInhEx=tmpcon; } if (SaveInitialWeights) { conInhEx->Save(); } MainSimLoop->AddSimElement(conInhEx); } // setup Inh->Inh connections { if (NInhInhConnections > InhLayer->N) { NInhInhConnections = InhLayer->N; } if (VecCon) { VecConnection* tmpcon = new VecConnection(InhLayer, InhLayer, csimInputChannel_GABAa); tmpcon->SetName("conInhInh"); if (LoadWeights) { tmpcon->Load(); } else { tmpcon->ConnectRandomIncomming(NInhInhConnections,InhInhStrength,1,0,true); } conInhInh = tmpcon; } else { connection* tmpcon = new connection(InhLayer, InhLayer, csimInputChannel_GABAa); tmpcon->SetName("conInhInh"); if (LoadWeights) { tmpcon->Load(); } else { tmpcon->ConnectRandom2(NInhInhConnections,InhInhStrength,1,0,true); } conInhInh = tmpcon; } if (SaveInitialWeights) { conInhInh->Save(); } MainSimLoop->AddSimElement(conInhInh); } return InhLayer; } void SimMod_CompetitiveInhibition::SetAllInhExWeights(float WeightValue) { if (conInhEx) { conInhEx->SetAllWeights(WeightValue); } } /** * set strength of connections from inhibitory neurons to excitatory neurons to new value * new value is stored in InhExStrength * @param NewInhExStrength */ void SimMod_CompetitiveInhibition::SetInhExWeightStrength(float NewInhExStrength) { if (InhExStrength == 0 || !conInhEx) {return;} // error handling conInhEx->MultiplyAllTargetWeights(NewInhExStrength/InhExStrength); InhExStrength=NewInhExStrength; } ///////////////////////////////// SimModuleInput::SimModuleInput(AnyOptionWrapper* _opt): SimModule(_opt), MovieDir(GetDefaultMovieDir()) { } void SimModuleInput::SetCmdLineOptions() { myAnyWrap->setOption( "StimulusSet", 'a', &StimulusSet, 3); myAnyWrap->setOption( "StimulusNumber", 'a', &StimulusNumber, 0); myAnyWrap->setOption( "StimFileName", 'a', &StimFileName, ""); myAnyWrap->setOption( "StimSequence", 'a', &StimSequence, "oripos.sequence"); myAnyWrap->setOption( "StimDur", 'a', &StimDur, 200); myAnyWrap->setOption( "IsiDur", 'a', &IsiDur, 20); myAnyWrap->setFlag ("XContinuous", 'a', &XContinuous); } input* SimModuleInput::Setup(layer* TargetLayer, csimInputChannel InputNumber, float InputStrength) { MainSimLoop = GetGlobalSimLoop(); // enum SimMod_StimSetType {Test, Parametric, Scan, FileName}; input* l1inp; switch (SType) { case Test: { int FltNr=0; float Isi2Dur=0; int TestStimDur=249; int TestIsiDur= 1; cout << "Test all Stimuli systematically, NX=" << NXParas << "NY=" << NYParas << "\n"; ScanObjMovieInput* MovieInput = new ScanObjMovieInput( TargetLayer, InputNumber, MyMovie, FltNr, InputStrength, StimDur, NXParas, NYParas,XContinuous, NXParas, IsiDur, Isi2Dur); MovieInput->SetXCircle(true); MovieInput->SetYCircle(true); cout << "before setname simmodules.cpp\n";fflush(stdout); MovieInput->SetName("MovieScanInput"); cout << "before adding to mainsimloop simmodules.cpp\n";fflush(stdout); MainSimLoop->AddSimElement(MovieInput); cout << "after adding to mainsimloop simmodules.cpp\n";fflush(stdout); XYpairList StimList; for (int x=0;xInitializeTestMode(&StimList, TestStimDur,TestIsiDur); l1inp = MovieInput; } break; case Parametric: ; case Scan:; break; case MovieScan: { PictureSequenceInput* WinkelInput = new PictureSequenceInput(TargetLayer, InputNumber,InputStrength, StimDur, IsiDur); WinkelInput->SetPictureArray(MyMovie); WinkelInput->SetName("WinkelInput"); WinkelInput->SetMode(csimInputRandom); // WinkelInput->SetRandomNext(true); MainSimLoop->AddSimElement(WinkelInput); l1inp = WinkelInput; } break; case FileName: { int FltNr=0; float Isi2Dur=0; int TestStimDur=249; int TestIsiDur= 1; cout << "NX=" << NXParas << "NY=" << NYParas << "\n"; ScanObjMovieInput* MovieInput = new ScanObjMovieInput( TargetLayer, InputNumber, MyMovie, FltNr, InputStrength, StimDur, NXParas, NYParas,XContinuous, NXParas, IsiDur, Isi2Dur); MovieInput->SetXCircle(true); MovieInput->SetYCircle(true); cout << "before setname simmodules.cpp\n";fflush(stdout); MovieInput->SetName("MovieScanInput"); cout << "before adding to mainsimloop simmodules.cpp\n";fflush(stdout); MainSimLoop->AddSimElement(MovieInput); cout << "after adding to mainsimloop simmodules.cpp\n";fflush(stdout); XYpairList StimList; for (int x=0;xInitializeTestMode(&StimList, TestStimDur,TestIsiDur); l1inp = MovieInput; } break; case IdlMovieFile: { int FltNr=0; float Isi2Dur=0; int TestStimDur=249; int TestIsiDur= 1; ObjMovieInput* MovieInput = new ObjMovieInput( TargetLayer, InputNumber, MyMovie, FltNr, InputStrength, StimDur, IsiDur); MovieInput->SetName("MovieInput"); MainSimLoop->AddSimElement(MovieInput); // MovieInput->InitializeTestMode(&StimList, TestStimDur,TestIsiDur); l1inp = MovieInput; } break; case Sequence: { StimulusSequence* MySequence = new StimulusSequence((MovieDir + StimSequence).c_str()); int FltNr=0; SequenceObjMovieInput* MovieInput = new SequenceObjMovieInput( TargetLayer, InputNumber, MyMovie, MySequence, FltNr, InputStrength, StimDur, 500); MainSimLoop->AddSimElement(MovieInput); l1inp = MovieInput; } break; case Ascii: { // StimulusSequence* MySequence = new StimulusSequence((MovieDir+"text.sequence").c_str()); StimulusSequence* MySequence = new StimulusSequence((MovieDir+"abcdefgh.sequence").c_str()); int FltNr=0; SequenceObjMovieInput* MovieInput = new SequenceObjMovieInput( TargetLayer, InputNumber, MyMovie, MySequence, FltNr, InputStrength, StimDur, 500); MainSimLoop->AddSimElement(MovieInput); l1inp = MovieInput; } break; default: cout << "nothing"; } return l1inp; } void SimModuleInput::LoadMovie(int &InputNx, int &InputNy, int &NStimuli) { if (StimulusSetGetOutputWidth(0); InputNy = MyMovie->GetOutputHeight(0); NStimuli = MyMovie->GetNFrames(); if (MetaFile.Loaded) { NXParas = MetaFile.NXParas; NYParas = MetaFile.NYParas; } else { NXParas = NStimuli; // assume 1d stimulus set NYParas = NXParas; cout << "Set NXParas to NStimuli=" << NStimuli << " and NYParas=1\n"; fflush(stdout); // NXParas = int(sqrt(float(NStimuli))); // assume square number of stimuli // NYParas = NXParas; } } ///Input///////////////////////// /////////////////////////////////////// SimModuleMovieInput::SimModuleMovieInput(AnyOptionWrapper* _opt) : SimModule(_opt), NTestStimuli(0), CommonInhibition(true), InhLayer(0), MovieDir(GetDefaultMovieDir()) { } SimModuleMovieInput::~SimModuleMovieInput() { if (InhLayer) { delete InhLayer; } // this could be done in the SimModule destructor for the LayerList, ConnectionList, ... } void SimModuleMovieInput::SetCmdLineOptions() { myAnyWrap->setOption( "StimFileName", 'a', &StimFileName, ""); // myAnyWrap->setOption( "StimSequence", 'a', &StimSequence, "oripos.sequence"); myAnyWrap->setOption( "StimDur", 'a', &StimDur, 200); myAnyWrap->setOption( "IsiDur", 'a', &IsiDur, 20); myAnyWrap->setFlag ("XContinuous", 'a', &XContinuous); myAnyWrap->setOption( "LearnRate", 'a', &LearnRate, 0.002); myAnyWrap->setOption( "InitialWeights", 'a', &InitialWeights, 0.1); myAnyWrap->setOption("FRateNormThreshold", 'a', &FRateNormThreshold, 30); myAnyWrap->setOption( "InputExInhWeights", 'a', &ExInhWeights, 0.5); myAnyWrap->setOption( "InputInhExWeights", 'a', &InhExWeights, 0.5); myAnyWrap->setOption( "TestStepSize", 'a', &TestStepSize, 1); myAnyWrap->setFlag ("RewireForwardCon", 'a', &RewireForwardCon); } void SimModuleMovieInput::LoadMovie() { std::string MetaFileName = MovieDir + StimFileName + ".meta.xml"; MovieMetaFile MetaFile(MetaFileName.c_str()); std::string MovieFileName = MetaFile.MovieFileName; std::string StimName; { StimName = MovieDir + MovieFileName; cout << "Load movie: " << StimName << "\n"; } MyMovie = new ObjMovie(StimName.c_str()); InputNx = MyMovie->GetOutputWidth(0); InputNy = MyMovie->GetOutputHeight(0); NStimuli = MyMovie->GetNFrames(); NFilters = MyMovie->GetNFilters(); if (MetaFile.Loaded) { NXParas = MetaFile.NXParas; NYParas = MetaFile.NYParas; } else { NXParas = int(sqrt(float(NStimuli))); // assume square number of stimuli NYParas = NXParas; } } void SimModuleMovieInput::SetTestMode() { if (InputList != 0) { for (InputIterator it = InputList->begin(); it!=InputList->end();++it) { (*it)->SetMode(csimInputTest); } } } void SimModuleMovieInput::SetInputMode(InputMode mode) { if (InputList != 0) { for (InputIterator it = InputList->begin(); it!=InputList->end();++it) { (*it)->SetMode(mode); } } } int SimModuleMovieInput::Setup(csimInputChannel InputNumber, float InputStrength, bool LoadWeights) { MainSimLoop = GetGlobalSimLoop(); // enum SimMod_StimSetType {Test, Parametric, Scan, FileName}; LoadMovie(); CommonInhibition = true; bool OnOffInput = true; if (NFilters <2) { OnOffInput=false; CommonInhibition=false; } if (OnOffInput) { NLayers = 2*NFilters; } else { NLayers = NFilters; } cout << "SimModuleMovieInput::Setup: NLayers=" << NLayers << "\n"; LayerList = new TLayerList; InputList = new TInputList; int LayerNr; { csimNeuronType NType; NType = csimNType_DecoLif; // remove this if (CommonInhibition) { // setup inhibition layer DecoLifLayer* tmplayer = new DecoLifLayer(InputNx*InputNy, DecoParaInhibitory); tmplayer->SetName("InputInhLayer"); tmplayer->SetupPositions(InputNx, InputNy, true); // tmplayer->StartBinRec(1); MainSimLoop->AddSimElement(tmplayer); InhLayer = tmplayer; } switch (NType) { case csimNType_DecoLif: { float NmdaAmpaRatio=0.3; for (LayerNr=0;LayerNrSetTauGaba(1.0, ITTauInhibition); // tmplayer->SetTauGabaA(13.5, 100); // remove this // tmplayer->SetTauAmpa(0.5, 2.4); // tmplayer->SetTauNmda(10, 100); // tmplayer->TuneNoiseAmplitude(3); tmplayer->SetNoiseAmplitude(0.05294); // Noise: 3 Hz Background Firing Rate // tmplayer->TuneNoiseAmplitude(100); // tmplayer->TuneBalancedInhibition(3); // tmplayer->SetNoiseAmplitude(0.0769104); // Noise: 100 Hz Background Firing Rate // tmplayer->SetBalancedInhibition(11.7664); // Reduce Background Firing Rate to 3 Hz tmplayer->SetNmdaAmpaRatio(NmdaAmpaRatio); tmplayer->SetName(("InputLayer"+ stringify(LayerNr)).c_str()); tmplayer->SetupPositions(InputNx, InputNy, true); MainSimLoop->AddSimElement(tmplayer); LayerList->push_back(tmplayer); if ((CommonInhibition) && (InhLayer != 0)) { // Ex->Inh Connection 1-zu-1 connection *tmpcon = new connection(tmplayer, InhLayer, csimInputChannel_AMPA); tmpcon->SetName(("InpL"+ stringify(LayerNr)+"ExInh").c_str()); // tmpcon->ConnectSelf(ExInhWeights, 0,0); if (LoadWeights) { tmpcon->Load(); } else { tmpcon->ConnectGaussian(0.1,ExInhWeights, 0,0); } tmpcon->Save(); MainSimLoop->AddSimElement(tmpcon); tmpcon = new connection(InhLayer, tmplayer, csimInputChannel_GABAa); tmpcon->SetName(("InpL"+ stringify(LayerNr)+"InhEx").c_str()); tmpcon->ConnectSelf(InhExWeights, 0,0); tmpcon->Save(); MainSimLoop->AddSimElement(tmpcon); // Inh->Ex Connection 1-zu-1 } } } break; } input* l1inp; int FltNr=0; float Isi2Dur=0; int TestStimDur=249; int TestIsiDur= 1; cout << "NX=" << NXParas << "NY=" << NYParas << "\n"; cout << "before setname simmodules.cpp\n";fflush(stdout); cout << "before adding to mainsimloop simmodules.cpp\n";fflush(stdout); cout << "after adding to mainsimloop simmodules.cpp\n";fflush(stdout); NTestStimuli=0; XYpairList StimList; if (XContinuous) { for (int x=0;xSetXCircle(true); MovieInput->SetYCircle(true); MovieInput->SetName(("MovieScanInput"+stringify(LayerNr)).c_str()); MovieInput->InitializeTestMode(&StimList, TestStimDur,TestIsiDur); MovieInput->SetMode(csimInputDefault); InputList->push_back(MovieInput); MainSimLoop->AddSimElement(MovieInput); } } return 0; } void SimModuleMovieInput::ConnectTo(layer* ToLayer, bool LoadForwardWeights, bool Learn) { cout << "ConnectTo " << ToLayer->Name << "\n"; int LayerNr=0; if (LayerList) { ConnectionList = new TconnectionList; for (LayerIterator it = LayerList->begin(); it!=LayerList->end();++it) { connection *tmpcon = new connection((*it), ToLayer, csimInputChannel_AMPA); // DepressiveConnection *tmpcon = new DepressiveConnection((*it), ToLayer, csimInputChannel_AMPA, TauRec, U_se); tmpcon->SetName(("conForward"+stringify(LayerNr)).c_str()); if (LoadForwardWeights) tmpcon->Load(); else { tmpcon->SetNonSelf(false); if (RewireForwardCon) { float connectivity=0.4; tmpcon->ConnectRandom(connectivity, InitialWeights, 2,0); tmpcon->SetRewiring(0.0001, connectivity); } else { tmpcon->ConnectFull(InitialWeights, 2,0); } } float MaxWeights=2.2; float LearnTauDec=20; float PostLearnTauDec=10; float BaseLine = exp(-2*StimDur/LearnTauDec); // was war die Intention hier? if (Learn) tmpcon->SetLearnObj( // new LearnHebbLP2(tmpcon, // MaxWeights, LearnTauDec, BaseLine, LearnRate)); new LearnHebbLP3(tmpcon, MaxWeights, LearnTauDec, PostLearnTauDec, BaseLine, LearnRate, true)); // new LearnRossum1(tmpcon, RossumCp, 0.003, 0.00005)); MainSimLoop->AddSimElement(tmpcon); tmpcon->Save(); tmpcon->SetAutoSave(false); ConnectionList->push_back(tmpcon); ++LayerNr; } // Normalization FiringRateNormalize2* norm=0; if (Learn) { // FiringRateNormalization norm = new FiringRateNormalize2(FRateNormThreshold, 0.001, 10); norm->SetName("cnormForward"); for (connectionIterator it = ConnectionList->begin(); it!=ConnectionList->end();++it) { norm->AddConnection(*it); } MainSimLoop->AddSimElement(norm); } } else { cout << "No Layer List \n"; } } ///SimModuleMovieInput///////////////////////// /////////////////////////////////////// smodMovieInput::smodMovieInput(AnyOptionWrapper* _opt) : SimModule(_opt), NTestStimuli(0), CommonInhibition(true), InhLayer(0), MovieDir(GetDefaultMovieDir()) { cout << "smodMovieInput::smodMovieInput()\n"; } smodMovieInput::~smodMovieInput() { if (InhLayer) { delete InhLayer; } // this could be done in the SimModule destructor for the LayerList, ConnectionList, ... } void smodMovieInput::SetCmdLineOptions() { myAnyWrap->setOption( "StimFileName", 'a', &StimFileName, ""); myAnyWrap->setOption( "TestStimFileName", 'a', &TestStimFileName, ""); myAnyWrap->setOption( "SequenceFileName", 'a', &SequenceFileName, ""); myAnyWrap->setOption( "StimDur", 'a', &StimDur, 200); myAnyWrap->setOption( "IsiDur", 'a', &IsiDur, 20); myAnyWrap->setFlag ( "XContinuous", 'a', &XContinuous); myAnyWrap->setOption( "LearnRate", 'a', &LearnRate, 0.002); myAnyWrap->setOption( "InitialWeights", 'a', &InitialWeights, 0.1); myAnyWrap->setOption( "FRateNormThreshold", 'a', &FRateNormThreshold, 30); myAnyWrap->setOption( "InputExInhWeights", 'a', &ExInhWeights, 0.5); myAnyWrap->setOption( "InputInhExWeights", 'a', &InhExWeights, 0.5); myAnyWrap->setOption( "TestStepSize", 'a', &TestStepSize, 1); myAnyWrap->setFlag ( "RewireForwardCon", 'a', &RewireForwardCon); myAnyWrap->setOption( "TauDecLearnPre", 'a', &TauDecLearnPre, 20); myAnyWrap->setOption( "TauDecLearnPost", 'a', &TauDecLearnPost, 10); myAnyWrap->setFlag ( "OnOffInput", 'a', &OnOffInput, false); } void smodMovieInput::LoadMovie(string _StimFileName) { std::string MetaFileName = MovieDir + _StimFileName + ".meta.xml"; MovieMetaFile MetaFile(MetaFileName.c_str()); std::string MovieFileName; if (MetaFile.Loaded) { MovieFileName = MetaFile.MovieFileName; cout << "MovieFileName=" << MovieFileName << "\n"; } else { cout << "MovieMetaFile not loaded\n"; MovieFileName = _StimFileName + ".idlmov"; cout << "using movie file name: " << MovieFileName << "\n"; } std::string StimName; { StimName = MovieDir + MovieFileName; cout << "Load movie: " << StimName << "\n"; } MyMovie = new ObjMovie(StimName.c_str()); InputNx = MyMovie->GetOutputWidth(0); InputNy = MyMovie->GetOutputHeight(0); NStimuli = MyMovie->GetNFrames(); NFilters = MyMovie->GetNFilters(); if (MetaFile.Loaded) { NXParas = MetaFile.NXParas; NYParas = MetaFile.NYParas; } else { NXParas = int(sqrt(float(NStimuli))); // assume square number of stimuli NYParas = NXParas; } } void smodMovieInput::SetTestMode() { if (InputList != 0) { for (InputIterator it = InputList->begin(); it!=InputList->end();++it) { (*it)->SetMode(csimInputTest); } } } void smodMovieInput::SetInputMode(InputMode mode) { if (InputList != 0) { for (InputIterator it = InputList->begin(); it!=InputList->end();++it) { (*it)->SetMode(mode); } } } void smodMovieInput::SetNoiseAmplitude(float sigma) { for (TLayerList::iterator it=LayerList->begin();it!=LayerList->end();++it) { (*it)->SetNoiseAmplitude(sigma); } } int smodMovieInput::Setup(csimInputChannel InputNumber, float InputStrength, bool LoadWeights) { MainSimLoop = GetGlobalSimLoop(); // enum SimMod_StimSetType {Test, Parametric, Scan, FileName}; LoadMovie(StimFileName); CommonInhibition = false; if (OnOffInput) { NLayers = 2*NFilters; } else { NLayers = NFilters; } cout << "smodMovieInput::Setup: NLayers=" << NLayers << "\n"; LayerList = new TLayerList; InputList = new TInputList; int LayerNr; { csimNeuronType NType; NType = csimNType_DecoLif; // remove this if (CommonInhibition) { // setup inhibition layer DecoLifLayer* tmplayer = new DecoLifLayer(InputNx*InputNy, DecoParaInhibitory); tmplayer->SetName("InputInhLayer"); tmplayer->SetupPositions(InputNx, InputNy, true); // tmplayer->StartBinRec(1); MainSimLoop->AddSimElement(tmplayer); InhLayer = tmplayer; } switch (NType) { case csimNType_DecoLif: { float NmdaAmpaRatio=0.3; // Quelle fuer NMDA/AMPA-Verhaeltnis: // \cite{Krukowski2001_thalamocortical_nmda} // \cite{Crair1995_ltp_thalamocortical_synapses} for (LayerNr=0;LayerNrGetOutputWidth(FltNr))*(MyMovie->GetOutputHeight(FltNr)), DecoParaExcitatory); // tmplayer->SetTauGaba(1.0, ITTauInhibition); // tmplayer->SetTauGabaA(13.5, 100); // remove this // tmplayer->SetTauAmpa(0.5, 2.4); // tmplayer->SetTauNmda(10, 100); // tmplayer->TuneNoiseAmplitude(3); tmplayer->SetNoiseAmplitude(0.05294); // Noise: 3 Hz Background Firing Rate // tmplayer->TuneNoiseAmplitude(100); // tmplayer->TuneBalancedInhibition(3); // tmplayer->SetNoiseAmplitude(0.0769104); // Noise: 100 Hz Background Firing Rate // tmplayer->SetBalancedInhibition(11.7664); // Reduce Background Firing Rate to 3 Hz tmplayer->SetNmdaAmpaRatio(NmdaAmpaRatio); tmplayer->SetName(("InputLayer"+ stringify(LayerNr)).c_str()); tmplayer->SetupPositions(InputNx, InputNy, true); MainSimLoop->AddSimElement(tmplayer); LayerList->push_back(tmplayer); if ((CommonInhibition) && (InhLayer != 0)) { // Ex->Inh Connection 1-zu-1 connection *tmpcon = new connection(tmplayer, InhLayer, csimInputChannel_AMPA); tmpcon->SetName(("InpL"+ stringify(LayerNr)+"ExInh").c_str()); // tmpcon->ConnectSelf(ExInhWeights, 0,0); if (LoadWeights) { tmpcon->Load(); } else { tmpcon->ConnectGaussian(0.1,ExInhWeights, 0,0); } tmpcon->Save(); MainSimLoop->AddSimElement(tmpcon); tmpcon = new connection(InhLayer, tmplayer, csimInputChannel_GABAa); tmpcon->SetName(("InpL"+ stringify(LayerNr)+"InhEx").c_str()); tmpcon->ConnectSelf(InhExWeights, 0,0); tmpcon->Save(); MainSimLoop->AddSimElement(tmpcon); // Inh->Ex Connection 1-zu-1 } } } break; } input* l1inp; int FltNr=0; float Isi2Dur=0; int TestStimDur=249; int TestIsiDur= 1; cout << "NX=" << NXParas << "NY=" << NYParas << "\n"; cout << "teststepsize = " << TestStepSize << "\n"; NTestStimuli=0; XYpairList StimList; if (XContinuous) { for (int x=0;x=0;--y) { for (int x=xstart;x>=0;--x) { if (((y % TestStepSize) == 0) && ((x % TestStepSize) == 0)) { StimList.push_back(XYpair(x,y)); ++NTestStimuli; } } for (int x=NXParas-1;x>xstart;--x) { if (((y % TestStepSize) == 0) && ((x % TestStepSize) == 0)) { StimList.push_back(XYpair(x,y)); ++NTestStimuli; } } } for (int y=NYParas;y>ystart;--y) { for (int x=xstart;x>=0;--x) { if (((y % TestStepSize) == 0) && ((x % TestStepSize) == 0)) { StimList.push_back(XYpair(x,y)); ++NTestStimuli; } } for (int x=NXParas-1;x>xstart;--x) { if (((y % TestStepSize) == 0) && ((x % TestStepSize) == 0)) { StimList.push_back(XYpair(x,y)); ++NTestStimuli; } } } } cout << "smodMovieInput::Setup: NTestStimiuli=" << NTestStimuli << "\n"; for (LayerNr=0;LayerNrSetXCircle(true); MovieInput->SetYCircle(true); MovieInput->SetName(("MovieScanInput"+stringify(LayerNr)).c_str()); MovieInput->InitializeTestMode(&StimList, TestStimDur,TestIsiDur); if (!SequenceFileName.empty()) { string SequenceFilePath = MovieDir + SequenceFileName; cout << "SequenceFilePath = " << SequenceFilePath << "\n"; fflush(stdout); MovieInput->loadStimulusSequence(SequenceFilePath.c_str()); } MovieInput->SetMode(csimInputDefault); InputList->push_back(MovieInput); MainSimLoop->AddSimElement(MovieInput); } } return 0; } void smodMovieInput::ChangeMovie(ObjMovie* _NewMovie) { for (int LayerNr=0;LayerNr((*InputList)[LayerNr]); if (MovieInput) { MovieInput->SetMovieFile(_NewMovie, FltNr); } else { cerr << "ERROR in smodMovieInput::ChangeMovie. Dynamic cast failed.\n"; } } } void smodMovieInput::ConnectTo(layer* ToLayer, bool LoadForwardWeights, bool Learn, bool VecCon, bool SaveInitialWeights) { cout << "ConnectTo " << ToLayer->Name << "\n"; float connectivity=0.6; // for rewiring float RewireThreshold=0.05*InitialWeights; float RewInitialWeights=1.2*RewireThreshold; int LayerNr=0; if (LayerList) { ConnectionList = new TconnectionList; VConnectionList = new TVConList; for (LayerIterator it = LayerList->begin(); it!=LayerList->end();++it) { // learn parameter float MaxWeights=2.2; float LearnTauDec=TauDecLearnPre; float PostLearnTauDec=TauDecLearnPost; // float LearnTauDec=20; // float PostLearnTauDec=10; float BaseLine = exp(-2*StimDur/LearnTauDec); // was war die Intention hier? if (VecCon) { VecConnection *tmpcon = new VecConnection((*it), ToLayer, csimInputChannel_AMPA); tmpcon->SetName(("conForward"+stringify(LayerNr)).c_str()); if (LoadForwardWeights) tmpcon->Load(); else { tmpcon->SetNonSelf(false); if (RewireForwardCon) { tmpcon->ConnectRandomIncomming(connectivity, InitialWeights, 2,0); } else { tmpcon->ConnectFull(InitialWeights, 2,0); } } if (Learn) tmpcon->SetLearnObj( new VecLearnHebbLP3(tmpcon, MaxWeights, LearnTauDec, PostLearnTauDec, BaseLine, LearnRate, true)); MainSimLoop->AddSimElement(tmpcon); if (SaveInitialWeights) { tmpcon->Save(); } tmpcon->SetAutoSave(false); VConnectionList->push_back(tmpcon); ++LayerNr; } else { connection *tmpcon = new connection((*it), ToLayer, csimInputChannel_AMPA); // DepressiveConnection *tmpcon = new DepressiveConnection((*it), ToLayer, csimInputChannel_AMPA, TauRec, U_se); tmpcon->SetName(("conForward"+stringify(LayerNr)).c_str()); if (LoadForwardWeights) tmpcon->Load(); else { tmpcon->SetNonSelf(false); if (RewireForwardCon) { tmpcon->ConnectRandom(connectivity, InitialWeights, 2,0); tmpcon->SetRewiring(RewireThreshold, connectivity); } else { tmpcon->ConnectFull(InitialWeights, 2,0); } } if (Learn) tmpcon->SetLearnObj( // new LearnHebbLP2(tmpcon, // MaxWeights, LearnTauDec, BaseLine, LearnRate)); new LearnHebbLP3(tmpcon, MaxWeights, LearnTauDec, PostLearnTauDec, BaseLine, LearnRate, true)); // new LearnRossum1(tmpcon, RossumCp, 0.003, 0.00005)); MainSimLoop->AddSimElement(tmpcon); if (SaveInitialWeights) { tmpcon->Save(); } tmpcon->SetAutoSave(false); ConnectionList->push_back(tmpcon); ++LayerNr; } } // Normalization if (VecCon) { VecFiringRateNormalize2* norm=0; if (Learn) { // FiringRateNormalization norm = new VecFiringRateNormalize2(FRateNormThreshold, 0.001, 10); norm->SetName("cnormForward"); cout << "Adding connections to norm obj\n";fflush(stdout); for (VConIterator it = VConnectionList->begin(); it!=VConnectionList->end();++it) { norm->AddConnection(*it); } if (RewireForwardCon) { norm->SetRewiring(RewireThreshold, connectivity, RewInitialWeights); } MainSimLoop->AddSimElement(norm); } } else { FiringRateNormalize2* norm=0; if (Learn) { // FiringRateNormalization norm = new FiringRateNormalize2(FRateNormThreshold, 0.001, 10); norm->SetName("cnormForward"); for (connectionIterator it = ConnectionList->begin(); it!=ConnectionList->end();++it) { norm->AddConnection(*it); } MainSimLoop->AddSimElement(norm); } } } else { cout << "No Layer List \n"; } } ///smodMovieInput/////////////////////////