Auryn simulator

Simulator for spiking neural networks with synaptic plasticity

User Tools

Site Tools


examples:sim_poisson

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
examples:sim_poisson [2015/08/26 22:57] – Adds description of command line params zenkeexamples:sim_poisson [2016/02/04 17:39] (current) – typo zenke
Line 2: Line 2:
  
 Simulates an array of Poisson processes to illustrate the use of [[manual:PoissonGroup]]. The output is written to a [[manual:ras]] file in the same directory. Simulates an array of Poisson processes to illustrate the use of [[manual:PoissonGroup]]. The output is written to a [[manual:ras]] file in the same directory.
 +
 +Full source code: [[https://github.com/fzenke/auryn/blob/master/examples/sim_poisson.cpp]]
 +
 +
 +===== Running code =====
  
 Running the example program ''sim_poisson'' yields an output like this one Running the example program ''sim_poisson'' yields an output like this one
Line 14: Line 19:
 ===== Visualizing the output ===== ===== Visualizing the output =====
  
-Our simulation has written its output (1 second of Poisson spiking from 1000 Poisson neurons firing at 5Hz) to ''poisson.0.ras'', a human-readable [[manual:ras]] file which contains the Poisson spikes. You can peep into the file using a text editor. However, to visualize the  data you need a plotter. I generally like using [[gnuplot]], but any other plotting software which allows reading time series data from columnar ASCII files will do (e.g. [[matplotlib]] in conjunction with [[numpy]]).+Our simulation has written its output (1 second of Poisson spiking from 1000 Poisson neurons firing at 5Hz) to ''poisson.0.ras'', a human-readable [[manual:ras]] file which contains the Poisson spikes. You can peek into the file using a text editor. However, to visualize the  data you need a plotter. I generally like using [[gnuplot]], but any other plotting software which allows reading time series data from columnar ASCII files will do (e.g. [[matplotlib]] in conjunction with [[numpy]]).
 If you have gnuplot installed you can take a quick peek using the command line If you have gnuplot installed you can take a quick peek using the command line
 <code> <code>
Line 49: Line 54:
   --size arg            poisson group size   --size arg            poisson group size
   --seed arg            random seed   --seed arg            random seed
-<code>+</code>
 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, such as the structure of your simulation itself will be fixed in the simulation file, which is a file with C++ code. Let's have a look at this code in the present example now. 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, such as the structure of your simulation itself will be fixed in the simulation file, which is a file with C++ code. Let's have a look at this code in the present example now.
  
Line 87: Line 92:
 </code> </code>
 here ''run'' takes at least one parameter which is the simulation time ''simtime''. That is one second in this example. The second parameter is optional. The ''false'' in the example tells run to ignore the RateChecker that we painfully added in the last step. This does not make much sense here, but neither did the Checker in the first place. We will see that the switch is useful in other examples such as [[sim_background]], where one can avoid checking during a transient priming period. here ''run'' takes at least one parameter which is the simulation time ''simtime''. That is one second in this example. The second parameter is optional. The ''false'' in the example tells run to ignore the RateChecker that we painfully added in the last step. This does not make much sense here, but neither did the Checker in the first place. We will see that the switch is useful in other examples such as [[sim_background]], where one can avoid checking during a transient priming period.
-===== The full program ===== 
- 
- 
-<code cpp> 
-#include <iostream> 
-#include <iomanip> 
-#include <stdlib.h> 
-#include <string> 
- 
-#include <boost/program_options.hpp> 
-#include <boost/mpi/environment.hpp> 
-#include <boost/mpi/communicator.hpp> 
-#include <boost/mpi.hpp> 
- 
-#include "auryn_global.h" 
-#include "auryn_definitions.h" 
-#include "System.h" 
-#include "Logger.h" 
-#include "PoissonGroup.h" 
-#include "SpikeMonitor.h" 
-#include "PopulationRateMonitor.h" 
-#include "RateChecker.h" 
- 
-using namespace std; 
- 
-namespace po = boost::program_options; 
-namespace mpi = boost::mpi; 
- 
-int main(int ac, char* av[])  
-{ 
- 
- string dir = "./"; 
- string file_prefix = "poisson"; 
- 
- char strbuf [255]; 
- string msg; 
- 
- NeuronID size = 1000; 
- NeuronID seed = 1; 
- double kappa = 5.; 
- double simtime = 10.; 
- 
- int errcode = 0; 
- 
-    try { 
- 
-        po::options_description desc("Allowed options"); 
-        desc.add_options() 
-            ("help", "produce help message") 
-            ("simtime", po::value<double>(), "simulation time") 
-            ("kappa", po::value<double>(), "poisson group rate") 
-            ("size", po::value<int>(), "poisson group size") 
-            ("seed", po::value<int>(), "random seed") 
-        ; 
- 
-        po::variables_map vm;         
-        po::store(po::parse_command_line(ac, av, desc), vm); 
-        po::notify(vm);     
- 
-        if (vm.count("help")) { 
-            cout << desc << "\n"; 
-            return 1; 
-        } 
- 
- 
-        if (vm.count("kappa")) { 
-            cout << "kappa set to "  
-                 << vm["kappa"].as<double>() << ".\n"; 
- kappa = vm["kappa"].as<double>(); 
-        }  
- 
-        if (vm.count("simtime")) { 
-            cout << "simtime set to "  
-                 << vm["simtime"].as<double>() << ".\n"; 
- simtime = vm["simtime"].as<double>(); 
-        }  
- 
-        if (vm.count("size")) { 
-            cout << "size set to "  
-                 << vm["size"].as<int>() << ".\n"; 
- size = vm["size"].as<int>(); 
-        }  
- 
-        if (vm.count("seed")) { 
-            cout << "seed set to "  
-                 << vm["seed"].as<int>() << ".\n"; 
- seed = vm["seed"].as<int>(); 
-        }  
-    } 
-    catch(exception& e) { 
-        cerr << "error: " << e.what() << "\n"; 
-        return 1; 
-    } 
-    catch(...) { 
-        cerr << "Exception of unknown type!\n"; 
-    } 
- 
- // BEGIN Global stuff 
- mpi::environment env(ac, av); 
- mpi::communicator world; 
- communicator = &world; 
- 
- sprintf(strbuf, "%s/%s.%d.log", dir.c_str(), file_prefix.c_str(), world.rank()); 
- string logfile = strbuf; 
- logger = new Logger(logfile,world.rank(),PROGRESS,EVERYTHING); 
- 
- sys = new System(&world); 
- // END Global stuff 
- 
- PoissonGroup * poisson = new PoissonGroup(size,kappa); 
- poisson->seed(seed); 
- 
- sprintf(strbuf, "%s/%s.%d.ras", dir.c_str(), file_prefix.c_str(), world.rank() ); 
- SpikeMonitor * smon_e = new SpikeMonitor( poisson, strbuf, size); 
- 
- sprintf(strbuf, "%s/%s.%d.prate", dir.c_str(), file_prefix.c_str(), world.rank() ); 
- PopulationRateMonitor * pmon_e = new PopulationRateMonitor( poisson, strbuf, 1.0 ); 
- 
- RateChecker * chk = new RateChecker( poisson , -1 , 20.*kappa , 10); 
- if (!sys->run(simtime,false))  
- errcode = 1; 
- 
- logger->msg("Freeing ...",PROGRESS,true); 
- delete sys; 
- 
- if (errcode) 
- env.abort(errcode); 
- return errcode; 
-} 
-</code> 
- 
  
 +The full source code can be found here [[https://github.com/fzenke/auryn/blob/master/examples/sim_poisson.cpp]]
  
examples/sim_poisson.1440629865.txt.gz · Last modified: 2015/08/26 22:57 by zenke