examples:sim_poisson
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revisionNext revisionBoth sides next revision | ||
examples:sim_poisson [2013/12/09 14:50] – created zenke | examples:sim_poisson [2015/08/26 23:13] – zenke | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== | + | ====== |
- | Since Auryn simulations are executable c programs there is quite some overhead (see below). However since the header logic is usually | + | Simulates an array of Poisson processes to illustrate the use of [[manual: |
- | <code cpp> | + | Full source |
- | PoissonGroup * poisson = new PoissonGroup(size, | + | |
- | poisson-> | + | |
- | + | ===== Running | |
- | sprintf(strbuf, | + | |
- | SpikeMonitor * smon_e = new SpikeMonitor( poisson, strbuf, size); | + | |
- | + | ||
- | sprintf(strbuf, | + | |
- | PopulationRateMonitor * pmon_e = new PopulationRateMonitor( poisson, strbuf, 1.0 ); | + | |
- | + | ||
- | RateChecker * chk = new RateChecker( poisson , -1 , 20.*kappa , 10); | + | |
- | if (!sys-> | + | |
- | errcode | + | |
- | </code> | + | |
- | Running | + | Running |
<code shell> | <code shell> | ||
- | bash-4.1$ ./ | + | zenke@foobar: |
- | seed set to 1231231. | + | [=========================] 100% t=1.0s f=5.1 Hz |
- | [=========================] 100% t=10.0 s f=21.3 Hz | + | |
( 0) Freeing ... | ( 0) Freeing ... | ||
</ | </ | ||
- | In addition | + | In addition the script will create a [[manual: |
- | ====== The full script ====== | + | ===== Visualizing the output |
+ | Our simulation has written its output (1 second of Poisson spiking from 1000 Poisson neurons firing at 5Hz) to '' | ||
+ | If you have gnuplot installed you can take a quick peek using the command line | ||
+ | < | ||
+ | echo "plot ' | ||
+ | </ | ||
+ | from within gnuplot | ||
+ | <code gnuplot> | ||
+ | plot ' | ||
+ | </ | ||
+ | Either way the output will look similar to this: | ||
+ | {{ : | ||
- | <code cpp> | ||
- | #include < | ||
- | #include < | ||
- | #include < | ||
- | #include < | ||
- | #include < | + | ===== Randomness and seeding the random number generator ===== |
- | #include < | + | |
- | #include < | + | |
- | #include < | + | |
- | #include " | + | If you run the code again, you will notice that Auryn will generate the same spikes. This is due to the fact that it uses pseudo random numbers which is good for debugging. If you want to generate a different Poisson spike trains try running the code with a random seed. In this simulation this can be done with a command line parameter, but typically this will be done automatically somewhere in your code. |
- | #include " | + | |
- | #include " | + | |
- | #include " | + | |
- | #include " | + | |
- | #include " | + | |
- | #include " | + | |
- | #include " | + | |
- | using namespace std; | + | <code shell> |
+ | zenke@foobar: | ||
+ | [=========================] 100% t=1.0s | ||
+ | ( 0) Freeing ... | ||
+ | </ | ||
- | namespace po = boost:: | ||
- | namespace mpi = boost::mpi; | ||
- | int main(int ac, char* av[]) | + | ===== Some more options ===== |
- | { | + | |
- | string dir = "./"; | + | This simple simulation has some more parameters. To see which ones they are, you can call the script with |
- | string file_prefix = "poisson"; | + | <code shell> |
+ | zenke@foobar: | ||
+ | Allowed options: | ||
+ | --help | ||
+ | --simtime arg | ||
+ | --kappa arg poisson | ||
+ | --size arg poisson group size | ||
+ | --seed arg random seed | ||
+ | < | ||
+ | As you can see you can easily change a few key parameters of the simulation such as runtime, or the Poisson firing rate. It's always a good idea to export some paramters of your code through command line arguments. How this is done will become clearer in the examples. Things that require less flexibility, | ||
- | char strbuf [255]; | + | ====== The code behind all this ====== |
- | string msg; | + | |
- | NeuronID size = 1000; | + | Let's look at the code inside. |
- | NeuronID seed = 1; | + | You find the source for simulations in the directory '' |
- | double kappa = 5.; | + | |
- | double simtime = 10.; | + | |
- | int errcode | + | <code cpp> |
+ | PoissonGroup * poisson | ||
+ | poisson-> | ||
+ | </ | ||
+ | The the program first creates a pointer of type '' | ||
+ | The call of the member '' | ||
- | try { | + | <code cpp> |
+ | sprintf(strbuf, | ||
+ | SpikeMonitor * smon_e = new SpikeMonitor( poisson, strbuf, size); | ||
+ | </ | ||
+ | which creates a [[manual: | ||
- | po:: | + | <code cpp> |
- | | + | sprintf(strbuf, "%s/ |
- | (" | + | PopulationRateMonitor * pmon_e = new PopulationRateMonitor( poisson, strbuf, 1.0 ); |
- | (" | + | </code> |
- | (" | + | Here the logic is similar as before. The rate monitor needs a source and a filename. The third parameter in this case specifies the binning of the population rate in seconds and it is optional. |
- | (" | + | |
- | | + | |
- | ; | + | |
- | po::variables_map vm; | + | Before we finally get to run the simulation we have to specify a [[manual:checker]]. Checkers are special lightweight online-monitors. They can communicate with the [[manual:System]] simulation environment and interrupt a run if something goes horribly wrong. This secenario is not unlikely when putting plasticity in recurrent neural networks. Although strictly speaking we do not have to expect this from our simple Poisson group, it is good practice to already get used to it here. We define a [[manual:RateChecker]] which will kill a run if the rate of '' |
- | po::store(po:: | + | <code cpp> |
- | | + | RateChecker * chk = new RateChecker( poisson |
+ | </ | ||
- | if (vm.count(" | + | Finally the simulation is run by issuing '' |
- | | + | <code cpp> |
- | return 1; | + | if (!sys-> |
- | } | + | errcode = 1; |
- | + | ||
- | + | ||
- | if (vm.count(" | + | |
- | cout << "kappa set to " | + | |
- | << | + | |
- | kappa = vm[" | + | |
- | } | + | |
- | + | ||
- | if (vm.count(" | + | |
- | cout << " | + | |
- | << | + | |
- | simtime = vm[" | + | |
- | } | + | |
- | + | ||
- | if (vm.count(" | + | |
- | cout << "size set to " | + | |
- | << | + | |
- | size = vm[" | + | |
- | } | + | |
- | + | ||
- | if (vm.count(" | + | |
- | cout << "seed set to " | + | |
- | << | + | |
- | seed = vm[" | + | |
- | } | + | |
- | } | + | |
- | catch(exception& | + | |
- | cerr << " | + | |
- | return 1; | + | |
- | } | + | |
- | catch(...) { | + | |
- | cerr << " | + | |
- | } | + | |
- | + | ||
- | // BEGIN Global stuff | + | |
- | mpi:: | + | |
- | mpi:: | + | |
- | communicator = & | + | |
- | + | ||
- | sprintf(strbuf, | + | |
- | string logfile = strbuf; | + | |
- | logger = new Logger(logfile, | + | |
- | + | ||
- | sys = new System(& | + | |
- | // END Global stuff | + | |
- | + | ||
- | PoissonGroup * poisson = new PoissonGroup(size, | + | |
- | poisson-> | + | |
- | + | ||
- | sprintf(strbuf, | + | |
- | SpikeMonitor * smon_e = new SpikeMonitor( poisson, strbuf, size); | + | |
- | + | ||
- | sprintf(strbuf, | + | |
- | PopulationRateMonitor * pmon_e = new PopulationRateMonitor( poisson, strbuf, 1.0 ); | + | |
- | + | ||
- | RateChecker * chk = new RateChecker( poisson , -1 , 20.*kappa , 10); | + | |
- | if (!sys-> | + | |
- | errcode = 1; | + | |
- | + | ||
- | logger-> | + | |
- | delete sys; | + | |
- | + | ||
- | if (errcode) | + | |
- | env.abort(errcode); | + | |
- | return errcode; | + | |
- | } | + | |
</ | </ | ||
+ | here '' | ||
+ | The full source code can be found here [[https:// | ||
examples/sim_poisson.txt · Last modified: 2016/02/04 17:39 by zenke