/** * Begin the simulation. */ void startSimulation() { uint32_t currentStep = init(); tInit.toggleEnd(); if (output) { std::cout << "initialization time: " << tInit.printInterval() << " = " << (int) (tInit.getInterval() / 1000.) << " sec" << std::endl; } TimeIntervall tSimCalculation; TimeIntervall tRound; double roundAvg = 0.0; /* dump initial step if simulation starts without restart */ if (currentStep == 0) dumpOneStep(currentStep); else currentStep--; //we dump before calculation, thus we must go on step back if we do a restart movingWindowCheck(currentStep); //if we restart at any step check if we must slide /* dump 0% output */ dumpTimes(tSimCalculation, tRound, roundAvg, currentStep); while (currentStep < runSteps) { tRound.toggleStart(); runOneStep(currentStep); tRound.toggleEnd(); roundAvg += tRound.getInterval(); currentStep++; /*output after a round*/ dumpTimes(tSimCalculation, tRound, roundAvg, currentStep); movingWindowCheck(currentStep); /*dump after simulated step*/ dumpOneStep(currentStep); } //simulatation end Environment<>::get().Manager().waitForAllTasks(); tSimCalculation.toggleEnd(); if (output) { std::cout << "calculation simulation time: " << tSimCalculation.printInterval() << " = " << (int) (tSimCalculation.getInterval() / 1000.) << " sec" << std::endl; } }
int maass() { /* зависимость выходной частоты от тока в первом эксперименте зависимость порога от характера сигнала зависимость порога от реализации зависимость частоты выходного сигнала от порога использовать сигнал кости */ srand(time(NULL)); double timeMax = 50.0; double dt = 0.01; double dumpPeriod = 10.0; Node::dt = dt; std::vector<Node *> generators; std::vector<Synapse *> synapses1; std::vector<Synapse *> synapses2; std::cout<<"Creating neurons..."<<std::endl; Node node1 = Node("leaky iaf"); node1.I_stim = genran::uniform(14.5, 15.5); node1.addPsWaveType(PsWave(3.0), "current", 1.0); // exc input node1.addPsWaveType(PsWave(6.0), "current", -1.0); // inh input node1.initialiseSpikeBuffer(dt); Node node2 = Node("leaky iaf"); node2.I_stim = node1.I_stim; node2.addPsWaveType(PsWave(3.0), "current", 1.0); // exc input node2.addPsWaveType(PsWave(6.0), "current", -1.0); // inh input node2.initialiseSpikeBuffer(dt); std::cout<<"Creating generators..."<<std::endl; for (int i=0; i < 90; i++){ generators.push_back(new Node("poisson generator")); Synapse* synapse1 = new Synapse("stdp and tm", &node1, "hard boundaries"); synapse1->setPreset(0); // excitatory constants synapse1->control(0); // disable stdp and shuffle tm synapse1->reset(); topology::connectN2N(generators.back(), &node1, synapse1); synapses1.push_back(synapse1); Synapse* synapse2 = synapse1->duplicate(&node2); //copy everything synapse2->control(1); // enable stdp with gamma, don't touch tm synapse2->reset(); topology::connectN2N(generators.back(), &node2, synapse2); synapses2.push_back(synapse2); std::cout<<"\t\t generators created: "<< i << "%\r"; } for (int i=0; i < 10; i++){ generators.push_back(new Node("poisson generator")); Synapse* synapse1 = new Synapse("stdp and tm", &node1, "hard boundaries"); synapse1->setPreset(2); // inhibitory constants synapse1->control(0); // disable stdp and shuffle tm synapse1->reset(); synapse1->waveType = 1; // inhibitory topology::connectN2N(generators.back(), &node1, synapse1); // synapses1.push_back(synapse1); Synapse* synapse2 = synapse1->duplicate(&node2); //copy everything topology::connectN2N(generators.back(), &node2, synapse2); // synapses2.push_back(synapse2); std::cout<<"\t\t generators created: "<< i+90 << "%\r"; } std::cout<<std::endl; std::cout<<"Start output..."<<std::endl; Output output; output.openSpikeFile(); output.openSynapticWeightFile("data/target.txt"); output.synapses = synapses1; output.printSynapticWeights(0.0); output.closeSynapticWeightFile(); output.openSynapticWeightFile("data/start.txt"); output.synapses = synapses2; output.printSynapticWeights(0.0); output.closeSynapticWeightFile(); output.printEssentialData(timeMax); std::string s; std::stringbuf dumpTimesBuffer; std::ostream dumpTimes (&dumpTimesBuffer); std::cout<<"Starting simulation..."<<std::endl; for (double t = 0.0; t <= timeMax+dt; t += dt){ for (unsigned i=0; i<generators.size(); i++) if (generators.at(i)->step(t)) output.push(t, i); //generator numbers range from 0 to 99 if (node2.step(t)) output.push(t, 199); if (node1.step(t) and not node2.isSpiking(t)){ node2.forceSpike(t); output.push(t, 151); } if (isPeriodNow(t, dumpPeriod, dt) and t>0.0){ s = std::string("data/dump_") + std::to_string(t)+ ".txt"; dumpTimes << s <<std::endl; output.openSynapticWeightFile(s); output.print(t); output.closeSynapticWeightFile(); } std::cout<<"Finished "<< t / timeMax <<" of the simulation.\t\t\r"; } std::cout<<std::endl; output.close(); std::cout<<"Finish output..."<<std::endl; output.openSynapticWeightFile("data/finish.txt"); output.printSynapticWeights(timeMax); output.closeSynapticWeightFile(); std::ofstream dumpTimesFile; dumpTimesFile.open("data/dump_times.txt", std::ofstream::out); dumpTimesFile << dumpTimesBuffer.str(); dumpTimesFile.close(); return 0; }
/** * Begin the simulation. */ void startSimulation() { init(); // translate checkpointPeriod string into checkpoint intervals seqCheckpointPeriod = pluginSystem::toTimeSlice( checkpointPeriod ); for (uint32_t nthSoftRestart = 0; nthSoftRestart <= softRestarts; ++nthSoftRestart) { resetAll(0); uint32_t currentStep = fillSimulation(); Environment<>::get().SimulationDescription().setCurrentStep( currentStep ); tInit.toggleEnd(); if (output) { std::cout << "initialization time: " << tInit.printInterval() << " = " << (int) (tInit.getInterval() / 1000.) << " sec" << std::endl; } TimeIntervall tSimCalculation; TimeIntervall tRound; double roundAvg = 0.0; /* Since in the main loop movingWindow is called always before the dump, we also call it here for consistency. * This becomes only important, if movingWindowCheck does more than merely checking for a slide. * TO DO in a new feature: Turn this into a general hook for pre-checks (window slides are just one possible action). */ movingWindowCheck(currentStep); /* dump initial step if simulation starts without restart */ if (!restartRequested) { dumpOneStep(currentStep); } /* dump 0% output */ dumpTimes(tSimCalculation, tRound, roundAvg, currentStep); /** \todo currently we assume this is the only point in the simulation * that is allowed to manipulate `currentStep`. Else, one needs to * add and act on changed values via * `SimulationDescription().getCurrentStep()` in this loop */ while (currentStep < Environment<>::get().SimulationDescription().getRunSteps()) { tRound.toggleStart(); runOneStep(currentStep); tRound.toggleEnd(); roundAvg += tRound.getInterval(); /* NEXT TIMESTEP STARTS HERE */ currentStep++; Environment<>::get().SimulationDescription().setCurrentStep( currentStep ); /* output times after a round */ dumpTimes(tSimCalculation, tRound, roundAvg, currentStep); movingWindowCheck(currentStep); /* dump at the beginning of the simulated step */ dumpOneStep(currentStep); } // simulatation end Environment<>::get().Manager().waitForAllTasks(); tSimCalculation.toggleEnd(); if (output) { std::cout << "calculation simulation time: " << tSimCalculation.printInterval() << " = " << (int) (tSimCalculation.getInterval() / 1000.) << " sec" << std::endl; } } // softRestarts loop }