Auryn simulator  v0.8.1-206-gb56e451
Plastic Spiking Neural Network Simulator
Macros | Functions
sim_bg_scaling2.cpp File Reference
#include "auryn.h"
Include dependency graph for sim_bg_scaling2.cpp:

Macros

#define N_REC_WEIGHTS   5000
 Example simulation that simulates a balanced network with triplet STDP with homeostatic scaling. More...
 
#define NE   20000
 
#define NI   5000
 

Functions

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

Macro Definition Documentation

◆ N_REC_WEIGHTS

#define N_REC_WEIGHTS   5000

Example simulation that simulates a balanced network with triplet STDP with homeostatic scaling.

This simulation code is based on the code used in Zenke, F., Hennequin, G., and Gerstner, W. (2013). Synaptic Plasticity in Neural Networks Needs Homeostasis with a Fast Rate Detector. PLoS Comput Biol 9, e1003330.

◆ NE

#define NE   20000

◆ NI

#define NI   5000

Function Documentation

◆ main()

int main ( int  ac,
char *  av[] 
)
41 {
42 
43  double w = 0.16;
44  double w_ext = w;
45  double wmax = 1;
46 
47  double w_ee = w;
48  double w_ei = w;
49 
50  double gamma = 1.0;
51  double w_ie = gamma;
52  double w_ii = gamma;
53 
54 
55  double sparseness = 0.05;
56  double kappa = 3;
57 
58  bool quiet = false;
59  bool wmatdump = false;
60  double simtime = 3600.;
61  double stimtime = simtime;
62  double wmat_interval = 600.;
63  double wstim = 0.1;
64 
65  double stimfreq = 100;
66 
67  bool corr = false;
68  bool adapt = false;
69  bool noisyweights = false;
70  bool fast = false;
71  AurynWeight wdecay = w;
72 
73  double tau_hom = 50.;
74  double eta = 1;
75  double beta_scaling = 1;
76 
77  int n_strengthen = 0;
78 
79  string dir = "/tmp";
80  string stimfile = "";
81  string label = "";
82  string infilename = "";
83 
84  const char * file_prefix = "bg_scaling";
85  char strbuf [255];
86  string msg;
87 
88  int errcode = 0;
89 
90  try {
91 
92  po::options_description desc("Allowed options");
93  desc.add_options()
94  ("help", "produce help message")
95  ("quiet", "quiet mode")
96  ("load", po::value<string>(), "input weight matrix")
97  ("wmat", "wmat dump mode")
98  ("eta", po::value<double>(), "learning rate")
99  ("scaling", po::value<double>(), "learning rate")
100  ("tau_hom", po::value<double>(), "homeostatic time constant")
101  ("kappa", po::value<double>(), "target rate")
102  ("simtime", po::value<double>(), "simulation time")
103  ("dir", po::value<string>(), "output dir")
104  ("label", po::value<string>(), "output label")
105  ("we", po::value<double>(), "we")
106  ("strengthen", po::value<int>(), "connections to strengthen by 10")
107  ("stimfile", po::value<string>(), "stimulus ras file")
108  ("wstim", po::value<double>(), "weight of stimulus connections")
109  ("stimtime", po::value<double>(), "time of stimulus on")
110  ("adapt", "adapting excitatory neurons")
111  ("corr", "add correlated inputs")
112  ("stimfreq", po::value<double>(), "CorrelatedPoissonGroup frequency default = 100")
113  ("noisyweights", "enables noisyweights for mean field checks")
114  ("fast", "turn off some of the monitors to run faster")
115  ;
116 
117  po::variables_map vm;
118  po::store(po::parse_command_line(ac, av, desc), vm);
119  po::notify(vm);
120 
121  if (vm.count("help")) {
122  std::cout << desc << "\n";
123  return 1;
124  }
125 
126  if (vm.count("quiet")) {
127  quiet = true;
128  }
129 
130  if (vm.count("load")) {
131  std::cout << "load from matrix "
132  << vm["load"].as<string>() << ".\n";
133  infilename = vm["load"].as<string>();
134  }
135 
136  if (vm.count("wmat")) {
137  wmatdump = true;
138  std::cout << "wmat dump mode" << std::endl;
139  }
140 
141  if (vm.count("eta")) {
142  std::cout << "eta set to "
143  << vm["eta"].as<double>() << ".\n";
144  eta = vm["eta"].as<double>();
145  }
146 
147  if (vm.count("scaling")) {
148  std::cout << "scaling set to "
149  << vm["scaling"].as<double>() << ".\n";
150  beta_scaling = vm["scaling"].as<double>();
151  }
152 
153  if (vm.count("tau_hom")) {
154  std::cout << "tau_hom set to "
155  << vm["tau_hom"].as<double>() << ".\n";
156  tau_hom = vm["tau_hom"].as<double>();
157  }
158 
159  if (vm.count("kappa")) {
160  std::cout << "kappa set to "
161  << vm["kappa"].as<double>() << ".\n";
162  kappa = vm["kappa"].as<double>();
163  }
164 
165  if (vm.count("simtime")) {
166  std::cout << "simtime set to "
167  << vm["simtime"].as<double>() << ".\n";
168  simtime = vm["simtime"].as<double>();
169  stimtime = simtime;
170  }
171 
172  if (vm.count("corr")) {
173  std::cout << "enabling corr " << std::endl;
174  corr = true;
175  }
176 
177  if (vm.count("stimfreq")) {
178  std::cout << "stimfreq set to "
179  << vm["stimfreq"].as<double>() << ".\n";
180  stimfreq = vm["stimfreq"].as<double>();
181  }
182 
183  if (vm.count("dir")) {
184  std::cout << "dir set to "
185  << vm["dir"].as<string>() << ".\n";
186  dir = vm["dir"].as<string>();
187  }
188 
189  if (vm.count("label")) {
190  std::cout << "label set to "
191  << vm["label"].as<string>() << ".\n";
192  label = vm["label"].as<string>();
193  }
194 
195  if (vm.count("we")) {
196  std::cout << "we set to "
197  << vm["we"].as<double>() << ".\n";
198  w_ee = vm["we"].as<double>();
199  }
200 
201  if (vm.count("strengthen")) {
202  std::cout << "strengthen set to "
203  << vm["strengthen"].as<int>() << ".\n";
204  n_strengthen = vm["strengthen"].as<int>();
205  }
206 
207  if (vm.count("stimfile")) {
208  std::cout << "stimfile set to "
209  << vm["stimfile"].as<string>() << ".\n";
210  stimfile = vm["stimfile"].as<string>();
211  }
212 
213  if (vm.count("wstim")) {
214  std::cout << "wstim set to "
215  << vm["wstim"].as<double>() << ".\n";
216  wstim = vm["wstim"].as<double>();
217  }
218 
219  if (vm.count("stimtime")) {
220  std::cout << "stimtime set to "
221  << vm["stimtime"].as<double>() << ".\n";
222  stimtime = vm["stimtime"].as<double>();
223  }
224 
225  if (vm.count("adapt")) {
226  std::cout << "adaptation on " << std::endl;
227  adapt = true;
228  }
229 
230  if (vm.count("noisyweights")) {
231  std::cout << "noisyweights on " << std::endl;
232  noisyweights = true;
233  }
234 
235  if (vm.count("fast")) {
236  std::cout << "fast on " << std::endl;
237  fast = true;
238  }
239  }
240  catch(std::exception& e) {
241  std::cerr << "error: " << e.what() << "\n";
242  return 1;
243  }
244  catch(...) {
245  std::cerr << "Exception of unknown type!\n";
246  }
247 
248 
249  // double primetime = 3.0/(beta_scaling*eta*1.24488e-5);
250  double primetime = 3.0*tau_hom;
251 
252 
253  auryn_init(ac, av);
254 
255  if (!infilename.empty()) {
256  std::stringstream iss;
257  iss << infilename << "." << sys->mpi_rank();
258  infilename = iss.str();
259  }
260 
261  logger->msg("Setting up neuron groups ...",PROGRESS,true);
262 
263 
264  NeuronGroup * neurons_e;
265  if ( adapt )
266  neurons_e = new AIFGroup(20000);
267  else
268  neurons_e = new IFGroup(20000);
269  IFGroup * neurons_i = new IFGroup(5000);
270 
271  // initialize membranes
272  neurons_i->set_tau_mem(10e-3);
273  neurons_e->random_mem(-60e-3,10e-3);
274  neurons_i->random_mem(-60e-3,10e-3);
275 
276 
277  SpikingGroup * poisson = new PoissonGroup(2500,2);
278  SparseConnection * con_exte = new SparseConnection(poisson, neurons_e, w_ext, sparseness, GLUT);
279 
280 
281 
282  msg = "Setting up I connections ...";
283  logger->msg(msg,PROGRESS,true);
284  SparseConnection * con_ie = new SparseConnection(neurons_i,neurons_e,
285  w_ie,sparseness,GABA);
286  SparseConnection * con_ii = new SparseConnection(neurons_i,neurons_i,
287  w_ii,sparseness,GABA);
288 
289  msg = "Setting up E connections ...";
290  logger->msg(msg,PROGRESS,true);
291  SparseConnection * con_ei = new SparseConnection(neurons_e,neurons_i,
292  w_ei, sparseness,GLUT);
293 
294  TripletScalingConnection * con_ee;
295 
296  if (infilename.empty()) {
297  con_ee = new TripletScalingConnection(neurons_e,neurons_e,
298  w_ee, sparseness,tau_hom,eta,kappa,beta_scaling,wmax,GLUT);
299  if ( noisyweights )
300  con_ee->random_data(w_ee,w_ee/4);
301  for ( int i = 0 ; i < n_strengthen ; ++i ) {
302  con_ee->set_data(i,i*(wmax/n_strengthen));
303  }
304  }
305  else {
306  string str;
307  str = infilename;
308  str += ".wmat";
309  std::stringstream oss;
310  oss << "Loading weight matrix from " << str;
311  logger->msg(oss.str(),PROGRESS,true);
312  con_ee = new TripletScalingConnection(neurons_e,neurons_e,
313  str.c_str(),tau_hom,eta,kappa,beta_scaling,wmax,GLUT);
314 
315 
316  str = infilename;
317  str += ".e.nstate";
318  neurons_e->load_from_file(str.c_str());
319  str = infilename;
320  str += ".i.nstate";
321  neurons_i->load_from_file(str.c_str());
322 
323  }
324 
325  msg = "Initializing traces ...";
326  logger->msg(msg,PROGRESS,true);
327  con_ee->set_hom_trace(kappa);
328 
329  // TODO
330  // con_ee->w->set_col(0,2*w_ee);
331 
332  msg = "Setting up monitors ...";
333  logger->msg(msg,PROGRESS,true);
334 
335  if (wmatdump) {
336  sprintf(strbuf, "%s/%s_e%.2et%.2f%s.%d.weight", dir.c_str(), file_prefix, beta_scaling, tau_hom, label.c_str(), sys->mpi_rank());
337  WeightMatrixMonitor * wmatmon = new WeightMatrixMonitor( con_ee, strbuf , wmat_interval );
338  }
339 
340  if ( !fast ) {
341  sprintf(strbuf, "%s/%s_e%.2et%.2f%s.%d.%c.ras", dir.c_str(), file_prefix, beta_scaling, tau_hom, label.c_str(), sys->mpi_rank(), 'e');
342  SpikeMonitor * smon_e = new SpikeMonitor( neurons_e, strbuf , 2500);
343 
344  sprintf(strbuf, "%s/%s_e%.2et%.2f%s.%d.%c.prate", dir.c_str(), file_prefix, beta_scaling, tau_hom, label.c_str(), sys->mpi_rank(), 'e');
345  PopulationRateMonitor * pmon_e = new PopulationRateMonitor( neurons_e, strbuf, 1.0 );
346  }
347 
348  sprintf(strbuf, "%s/%s_e%.2et%.2f%s.%d.syn", dir.c_str(), file_prefix, beta_scaling, tau_hom, label.c_str(), sys->mpi_rank());
349  WeightMonitor * wmon = new WeightMonitor( con_ee, strbuf, 0.1 );
350  wmon->add_equally_spaced(20);
351 
352  RateChecker * chk = new RateChecker( neurons_e , -0.1 , 20.*kappa , 100e-3);
353 
354 
355 
356  FileInputGroup * filegroup;
357  SparseConnection * con_stim;
358  if (!stimfile.empty()) {
359  msg = "Setting up stimulus ...";
360  logger->msg(msg,PROGRESS,true);
361  filegroup = new FileInputGroup(2000,stimfile.c_str(),true,1);
362  con_stim = new SparseConnection( filegroup, neurons_e, GLUT);
363  con_stim->set_name("Stimulus Connection");
364  con_stim->allocate_manually(4*500*100*sparseness);
365  con_stim->connect_block_random(wstim, sparseness, 0, 500, 0, 100);
366  con_stim->connect_block_random(wstim, sparseness, 500, 1000, 100, 200);
367  con_stim->connect_block_random(wstim, sparseness, 1000, 1500, 200, 300);
368  con_stim->connect_block_random(wstim, sparseness, 1500, 2000, 300, 400);
369  con_stim->finalize();
370 
371  logger->msg("Saving weight matrix ...",PROGRESS,true);
372  sprintf(strbuf, "%s/%s_e%.2et%.2f%s.%d_stim.wmat", dir.c_str(), file_prefix, beta_scaling, tau_hom, label.c_str(), sys->mpi_rank());
373  con_stim->write_to_file(strbuf);
374  }
375 
376  if (primetime>0) {
377  msg = "Priming ...";
378  // con_ee->set_beta(400);
379  logger->msg(msg,PROGRESS,true);
380  con_ee->stdp_active = false;
381  sys->run(primetime,true);
382  }
383  if ( corr ) {
384  const NeuronID size = 500;
385  const NeuronID psize = 100;
386 
387  std::stringstream oss;
388  oss << " Activating correlated input ... ";
389  logger->msg(oss.str(),PROGRESS,true);
390 
391  if (eta > 0)
392  con_ee->stdp_active = true;
393  // con_exte->set_block(0,2500,0,size,0);
394 
395  CorrelatedPoissonGroup * corr_e = new CorrelatedPoissonGroup(size,stimfreq,psize,10);
396  // CorrelatedPoissonGroup * corr_i = new CorrelatedPoissonGroup(size,50,50,10e-3);
397  corr_e->set_amplitude(50.);
398  corr_e->set_timescale(100e-3);
399  // corr->set_offset(2);
400 
401  // SparseConnection * con_corr_e = new SparseConnection(corr_e,neurons_e,corr_file.c_str(),GLUT);
402  IdentityConnection * con_corr_e = new IdentityConnection(corr_e, neurons_e, w);
403 
404  // disabling external random input
405  con_exte->set_block(0,2500,0,size,0.0);
406 
407  // set up Weight monitor
408 
409  sprintf(strbuf, "%s/%s_e%.2et%.2f%s.%d.%c.ras", dir.c_str(), file_prefix, beta_scaling, tau_hom, label.c_str(), sys->mpi_rank(), 'c');
410  SpikeMonitor * smon_c = new SpikeMonitor( corr_e, strbuf , size );
411 
412  }
413 
414  logger->msg("Simulating ...",PROGRESS,true);
415  con_ee->set_beta(beta_scaling);
416  if (eta > 0)
417  con_ee->stdp_active = true;
418 
419  if (!sys->run(simtime,true))
420  errcode = 1;
421 
422 
423 
424  logger->msg("Saving neurons state ...",PROGRESS,true);
425  sprintf(strbuf, "%s/%s_e%.2et%.2f%s.%d.e.nstate", dir.c_str(), file_prefix, beta_scaling, tau_hom, label.c_str(), sys->mpi_rank());
426  neurons_e->write_to_file(strbuf);
427  sprintf(strbuf, "%s/%s_e%.2et%.2f%s.%d.i.nstate", dir.c_str(), file_prefix, beta_scaling, tau_hom, label.c_str(), sys->mpi_rank());
428  neurons_i->write_to_file(strbuf);
429 
430  logger->msg("Saving weight matrix ...",PROGRESS,true);
431  sprintf(strbuf, "%s/%s_e%.2et%.2f%s.%d.wmat", dir.c_str(), file_prefix, beta_scaling, tau_hom, label.c_str(), sys->mpi_rank());
432  con_ee->write_to_file(strbuf);
433 
434  // save lifetime
435  sprintf(strbuf, "%s/%s_e%.2et%.2f%s.%d.lifetime", dir.c_str(), file_prefix, beta_scaling, tau_hom, label.c_str(), sys->mpi_rank());
436  std::ofstream killfile;
437  killfile.open(strbuf);
438  killfile << sys->get_time()-primetime << std::endl;
439  killfile.close();
440 
441  if (errcode)
442  auryn_abort(errcode);
443 
444  logger->msg("Freeing ...",PROGRESS,true);
445  auryn_free();
446  return errcode;
447 }
void auryn_free()
Cleanly shuts down Auryn simulation environment.
Definition: auryn_global.cpp:107
Reads spikes from a ras file and emits them as SpikingGroup in a simulation.
Definition: FileInputGroup.h:46
void set_block(NeuronID lo_row, NeuronID hi_row, NeuronID lo_col, NeuronID hi_col, AurynWeight weight)
Sets all weights of existing connections in a block spanned by the first 4 parameters to the value gi...
Definition: SparseConnection.cpp:307
void set_timescale(AurynDouble scale)
Definition: CorrelatedPoissonGroup.cpp:175
Standard Glutamatergic (excitatory) transmission.
Definition: auryn_definitions.h:139
virtual bool load_from_file(const char *filename)
Reads current states of SpikingGroup to human-readible textfile if implemented in derived class...
Definition: SpikingGroup.cpp:585
virtual void set_data(NeuronID i, AurynWeight value)
Sets weight value of a given element referenced by its index in the data array.
Definition: SparseConnection.cpp:661
void random_mem(AurynState mean=-60e-3, AurynState sigma=5e-3)
Definition: NeuronGroup.cpp:81
unsigned int mpi_rank()
Returns current rank.
Definition: System.cpp:1009
bool stdp_active
Definition: TripletScalingConnection.h:84
Abstract base class of all objects producing spikes.
Definition: SpikingGroup.h:67
AurynFloat AurynWeight
Unit of synaptic weights.
Definition: auryn_definitions.h:159
void set_amplitude(AurynDouble ampl)
Definition: CorrelatedPoissonGroup.cpp:163
A Checker class that tracks population firing rate as a moving average and breaks a run if it goes ou...
Definition: RateChecker.h:59
The base class to create sparse random connections.
Definition: SparseConnection.h:66
Logger * logger
Global pointer to instance of Logger which needs to be initialized in every simulation main program...
Definition: auryn_global.cpp:36
The standard Monitor object to record spikes from a SpikingGroup and write them to a text file...
Definition: SpikeMonitor.h:52
void set_tau_mem(AurynFloat taum)
Sets the membrane time constant.
Definition: IFGroup.cpp:154
Saves the weight matrix of a given connection in regular time intervals.
Definition: WeightMatrixMonitor.h:41
A PoissonGroup with multiple subpopulations that co-modulate their firing rate according to an Ornste...
Definition: CorrelatedPoissonGroup.h:48
void auryn_abort(int errcode)
Terminates Auryn simulation abnormally.
Definition: auryn_global.cpp:113
void random_data(AurynWeight mean, AurynWeight sigma)
Synonym for random_data.
Definition: SparseConnection.cpp:208
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
A simple extension of IFGroup with spike triggered adaptation.
Definition: AIFGroup.h:37
AurynDouble get_time()
Gets the current system time in [s].
Definition: System.cpp:226
void set_hom_trace(AurynFloat freq)
Definition: TripletScalingConnection.cpp:123
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 set_beta(AurynFloat beta)
Definition: TripletScalingConnection.cpp:254
Standard Gabaergic (inhibitory) transmission.
Definition: auryn_definitions.h:140
void msg(std::string text, LogMessageType type=NOTIFICATION, bool global=false, int line=-1, std::string srcfile="")
Definition: Logger.cpp:74
Definition: TripletScalingConnection.h:33
Abstract base class for all neuron groups.
Definition: NeuronGroup.h:45
Definition: Logger.h:41
void set_name(std::string s)
Set connection name.
Definition: SpikingGroup.cpp:507
bool write_to_file(ForwardMatrix *m, string filename)
Writes rank specific weight matrix on the same rank to a file.
Definition: SparseConnection.cpp:690
Monitor class to record population firing rates.
Definition: PopulationRateMonitor.h:46
virtual bool write_to_file(const char *filename)
Writes current states of SpikingGroup to human-readible textfile if implemented in derived class...
Definition: SpikingGroup.cpp:549
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
Implements the standard integrate and file model used in Auryn.
Definition: IFGroup.h:47
Provides a unity matrix like connectivity.
Definition: IdentityConnection.h:47
Here is the call graph for this function: