Auryn simulator  v0.8.1-206-gb56e451
Plastic Spiking Neural Network Simulator
Functions
sim_stdp.cpp File Reference

Example simulation of a single postsynaptic neuron with Poisson input and pair-based additive STDP. More...

#include "auryn.h"
Include dependency graph for sim_stdp.cpp:

Functions

int main (int ac, char *av[])
 

Detailed Description

Example simulation of a single postsynaptic neuron with Poisson input and pair-based additive STDP.

The default parameters are set such that postsynaptic firing rates stabilize.

Output files:

Function Documentation

◆ main()

int main ( int  ac,
char *  av[] 
)
42 {
43 
44  string dir = ".";
45  string file_prefix = "poisson";
46 
47  char strbuf [255];
48  string msg;
49 
50  double simtime = 100.;
51 
52  NeuronID nbinputs = 1000;
53  NeuronID size = 10;
54  unsigned int seed = 1;
55  double kappa = 5.;
56  AurynWeight winit = 0.01;
57 
58  double eta = 1.0e-3; // learning rate
59  double tau_pre = 20e-3; // stdp window decay (pre-post part)
60  double tau_post = 20e-3; // stdp window decay (post-pre part)
61 
62  int errcode = 0;
63 
64  try {
65 
66  po::options_description desc("Allowed options");
67  desc.add_options()
68  ("help", "produce help message")
69  ("dir", po::value<string>(), "output directory")
70  ("simtime", po::value<double>(), "simulation time")
71  ("eta", po::value<double>(), "learning rate")
72  ("winit", po::value<double>(), "initial weight")
73  ("kappa", po::value<double>(), "presynaptic firing rate")
74  ("nbinputs", po::value<int>(), "number of Poisson inputs")
75  ("size", po::value<int>(), "number of neurons")
76  ("seed", po::value<int>(), "random seed")
77  ;
78 
79  po::variables_map vm;
80  po::store(po::parse_command_line(ac, av, desc), vm);
81  po::notify(vm);
82 
83  if (vm.count("help")) {
84  std::cout << desc << "\n";
85  return 1;
86  }
87 
88  if (vm.count("kappa")) {
89  std::cout << "kappa set to "
90  << vm["kappa"].as<double>() << ".\n";
91  kappa = vm["kappa"].as<double>();
92  }
93 
94  if (vm.count("dir")) {
95  std::cout << "dir set to "
96  << vm["dir"].as<string>() << ".\n";
97  dir = vm["dir"].as<string>();
98  }
99 
100  if (vm.count("simtime")) {
101  std::cout << "simtime set to "
102  << vm["simtime"].as<double>() << ".\n";
103  simtime = vm["simtime"].as<double>();
104  }
105 
106  if (vm.count("eta")) {
107  std::cout << "eta set to "
108  << vm["eta"].as<double>() << ".\n";
109  eta = vm["eta"].as<double>();
110  }
111 
112  if (vm.count("winit")) {
113  std::cout << "winit set to "
114  << vm["winit"].as<double>() << ".\n";
115  winit = vm["winit"].as<double>();
116  }
117 
118  if (vm.count("nbinputs")) {
119  std::cout << "nbinputs set to "
120  << vm["nbinputs"].as<int>() << ".\n";
121  nbinputs = vm["nbinputs"].as<int>();
122  }
123 
124  if (vm.count("size")) {
125  std::cout << "size set to "
126  << vm["size"].as<int>() << ".\n";
127  size = vm["size"].as<int>();
128  }
129 
130  if (vm.count("seed")) {
131  std::cout << "seed set to "
132  << vm["seed"].as<int>() << ".\n";
133  seed = vm["seed"].as<int>();
134  }
135  }
136  catch(std::exception& e) {
137  std::cerr << "error: " << e.what() << "\n";
138  return 1;
139  }
140  catch(...) {
141  std::cerr << "Exception of unknown type!\n";
142  }
143 
144  // Init Auryn
145  auryn_init(ac, av, dir, "sim_stdp");
146  sys->set_master_seed(seed);
147 
148  // Neurons
149  PoissonGroup * poisson = new PoissonGroup(nbinputs, kappa);
150  TIFGroup * neurons = new TIFGroup(size);
151 
152  // point online rate monitor to neurons
154 
155  // Connections
156  float sparseness = 1.0;
157  STDPConnection * stdp_con = new STDPConnection(poisson, neurons, winit, sparseness, tau_pre, tau_post );
158  stdp_con->A = -1.20*tau_post/tau_pre*eta; // post-pre
159  stdp_con->B = eta; // pre-post
160  stdp_con->set_min_weight(0.0);
161  stdp_con->set_max_weight(1.0);
162 
163  // Monitors
164  // Record output firing rate (sample every 1s)
165  PopulationRateMonitor * pmon_e = new PopulationRateMonitor( neurons, sys->fn("prate"), 1.0 );
166 
167  // Record mean synaptic weight
168  WeightStatsMonitor * wsmon = new WeightStatsMonitor( stdp_con, sys->fn("msyn") );
169 
170  // Record individual synaptic weights (sample every 10s)
171  WeightMonitor * wmon = new WeightMonitor( stdp_con, sys->fn("syn"), 10.0 );
172  wmon->add_equally_spaced(100); // record 100 synapses
173 
174  // Check that rates do not drop below 1e-3Hz or increase beyond 100
175  RateChecker * chk = new RateChecker( neurons, 1e-3 , 100 , 10);
176 
177  // Run simulation
178  if (!sys->run(simtime)) errcode = 1;
179 
180  // Close Auryn
181  logger->msg("Freeing ...",PROGRESS,true);
182  auryn_free();
183  return errcode;
184 }
void auryn_free()
Cleanly shuts down Auryn simulation environment.
Definition: auryn_global.cpp:107
AurynFloat B
Definition: STDPConnection.h:61
NeuronID get_uid()
Get the unique ID of the class.
Definition: SpikingGroup.cpp:265
AurynFloat A
Definition: STDPConnection.h:60
AurynFloat AurynWeight
Unit of synaptic weights.
Definition: auryn_definitions.h:159
A Checker class that tracks population firing rate as a moving average and breaks a run if it goes ou...
Definition: RateChecker.h:59
void add_equally_spaced(NeuronID number, NeuronID z=0)
Adds number of elements to the recording list that are equally spaced in the data vector of the conne...
Definition: WeightMonitor.cpp:145
Logger * logger
Global pointer to instance of Logger which needs to be initialized in every simulation main program...
Definition: auryn_global.cpp:36
Double STDP All-to-All Connection.
Definition: STDPConnection.h:40
virtual void set_max_weight(AurynWeight maximum_weight)
Sets maximum weight (for plastic connections).
Definition: SparseConnection.cpp:203
System * sys
Global pointer to instance of System which needs to be initialized in every simulation main program...
Definition: auryn_global.cpp:37
A SpikingGroup that creates poissonian spikes with a given rate.
Definition: PoissonGroup.h:52
void set_master_seed(unsigned int seed=123)
Set master seed.
Definition: System.cpp:1014
Conductance based LIF neuron model with absolute refractoriness as used in Vogels and Abbott 2005...
Definition: TIFGroup.h:38
virtual void set_min_weight(AurynWeight minimum_weight)
Sets minimum weight (for plastic connections).
Definition: SparseConnection.cpp:198
void set_online_rate_monitor_id(unsigned int id=0)
Sets the SpikingGroup used to display the rate estimate in the progressbar.
Definition: System.cpp:939
void auryn_init(int ac, char *av[], string dir, string simulation_name, string logfile_prefix, LogMessageType filelog_level, LogMessageType consolelog_level)
Initalizes MPI and the Auryn simulation environment.
Definition: auryn_global.cpp:84
void msg(std::string text, LogMessageType type=NOTIFICATION, bool global=false, int line=-1, std::string srcfile="")
Definition: Logger.cpp:74
Definition: Logger.h:41
string fn(std::string extension)
Format output file name.
Definition: System.cpp:689
Records mean and standard deviation of a weight matrix in predefined intervals.
Definition: WeightStatsMonitor.h:42
Monitor class to record population firing rates.
Definition: PopulationRateMonitor.h:46
Monitors the evolution of a single or a set of weights.
Definition: WeightMonitor.h:65
unsigned int NeuronID
NeuronID is an unsigned integeger type used to index neurons in Auryn.
Definition: auryn_definitions.h:151
Here is the call graph for this function: