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

Simulation code based on the code used in Zenke et al. (2013). More...

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

Macros

#define N_REC_WEIGHTS   5000
 

Functions

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

Detailed Description

Simulation code based on the code used in Zenke et al. (2013).

Simulation code 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. It simulates a network with 25k integrate and fire neurons and a minimal homeostatic triplet model with a sliding threshold.

Macro Definition Documentation

◆ N_REC_WEIGHTS

#define N_REC_WEIGHTS   5000

Function Documentation

◆ main()

int main ( int  ac,
char *  av[] 
)
44 {
45 
46  double w = 0.16;
47  double w_ext = w;
48  double wmax = 1.0;
49 
50  double w_ee = w;
51  double w_ei = w;
52 
53  double gamma = 1.0;
54  double w_ie = gamma;
55  double w_ii = gamma;
56 
57  NeuronID ne = 20000;
58  NeuronID ni = ne/4;
59 
60 
61  double sparseness = 0.05;
62  double kappa = 3.;
63 
64  bool quiet = false;
65  bool verbose = false;
66  bool scaling = false;
67  bool wmatdump = false;
68  bool loadbalance = false;
69 
70  bool wall = false;
71 
72  double tau_chk = 100e-3;
73  double simtime = 3600.;
74  double stimtime = simtime;
75  double wmat_interval = 600.;
76 
77  double ampa_nmda_ratio = 1.0;
78  double wstim = 0.1;
79 
80  NeuronID psize = 200;
81  NeuronID hsize = 100;
82  NeuronID offset = 0;
83 
84  std::string patfile = "";
85  std::string prefile = "";
86  std::string currentfile = "";
87 
88  double stimfreq = 10;
89 
90  bool corr = false;
91  int plen = 3;
92  int hlen = 3;
93 
94  double ampl = 1.0;
95  bool recall = false;
96  bool decay = false;
97  bool adapt = false;
98  bool noisyweights = false;
99  bool switchweights = false;
100  bool ei_plastic = false;
101 
102  double bg_rate = 2;
103  bool fast = false;
104  AurynWeight wdecay = w;
105  double tau_decay = 3600.;
106 
107  double tau_hom = 50.;
108  double eta = 1;
109  double onperiod = 2;
110  double offperiod = 30;
111  double scale = 1;
112 
113  int n_strengthen = 0;
114 
115  std::vector<Connection*> corr_connections;
116  std::string dir = ".";
117  std::string stimfile = "";
118  std::string label = "";
119  std::string infilename = "";
120 
121  const char * file_prefix = "bg2";
122  char strbuf [255];
123  std::string msg;
124 
125  int errcode = 0;
126 
127  try {
128 
129  po::options_description desc("Allowed options");
130  desc.add_options()
131  ("help", "produce help message")
132  ("quiet", "quiet mode")
133  ("verbose", "verbose mode")
134  ("scaling", "scaling mode")
135  ("balance", "activate load balance")
136  ("load", po::value<std::string>(), "input weight matrix")
137  ("patfile", po::value<std::string>(), "pattern file for StimulusGroup")
138  ("prefile", po::value<std::string>(), "pattern file for loading patterns")
139  ("onperiod", po::value<double>(), "mean stimulus on period")
140  ("offperiod", po::value<double>(), "mean stimulus off period")
141  ("wmat", "wmat dump mode")
142  ("eta", po::value<double>(), "learning rate")
143  ("bgrate", po::value<double>(), "PoissonGroup external firing rate")
144  ("sparseness", po::value<double>(), "overall network sparseness")
145  ("scale", po::value<double>(), "learning rate")
146  ("tau_hom", po::value<double>(), "homeostatic time constant")
147  ("kappa", po::value<double>(), "target rate")
148  ("simtime", po::value<double>(), "simulation time")
149  ("dir", po::value<std::string>(), "output dir")
150  ("label", po::value<std::string>(), "output label")
151  ("wee", po::value<double>(), "wee")
152  ("wei", po::value<double>(), "wei")
153  ("wie", po::value<double>(), "wie")
154  ("wii", po::value<double>(), "wii")
155  ("wmax", po::value<double>(), "wmax")
156  ("ampa", po::value<double>(), "ampa nmda ratio")
157  ("strengthen", po::value<int>(), "connections to strengthen by 10")
158  ("ne", po::value<int>(), "no of exc units")
159  ("stimfile", po::value<std::string>(), "stimulus ras file")
160  ("wstim", po::value<double>(), "weight of stimulus connections")
161  ("stimtime", po::value<double>(), "time of stimulus on")
162  ("decay", "decay triplet connections")
163  ("corr", "add correlated inputs")
164  ("ampl", po::value<double>(), "recall stim amplitude")
165  ("psize", po::value<int>(), "block size for correlated inputs")
166  ("plen", po::value<int>(), "number of blocks feed-forward")
167  ("hsize", po::value<int>(), "block size for correlated inputs (hebbian assembly)")
168  ("hlen", po::value<int>(), "number of blocks Hebbian")
169  ("offset", po::value<int>(), " offset for corr stim")
170  ("recall", "add correlated inputs to first patterns")
171  ("stimfreq", po::value<double>(), "CorrelatedPoissonGroup frequency default = 100")
172  ("dconstant", po::value<double>(), "decay time constant for decaying triplet connections")
173  ("wdecay", po::value<double>(), "wdecay for decay triplet connections")
174  ("chk", po::value<double>(), "checker time constant")
175  ("adapt", "adapting excitatory neurons")
176  ("wall", "enable monitoring of wall clock time")
177  ("noisyweights", "enables noisyweights for mean field checks")
178  ("switchweights", "switches first weights in each weight matrix")
179  ("fast", "turn off some of the monitors to run faster")
180  ("eiplastic", "make EI connection plastic")
181  ;
182 
183  po::variables_map vm;
184  po::store(po::parse_command_line(ac, av, desc), vm);
185  po::notify(vm);
186 
187  if (vm.count("help")) {
188  std::cout << desc << "\n";
189  return 1;
190  }
191 
192  if (vm.count("quiet")) {
193  quiet = true;
194  }
195 
196  if (vm.count("verbose")) {
197  verbose = true;
198  }
199 
200  if (vm.count("scaling")) {
201  scaling = true;
202  }
203 
204  if (vm.count("balance")) {
205  std::cout << "load balancing active" << std::endl;
206  loadbalance = true;
207  }
208 
209  if (vm.count("load")) {
210  std::cout << "load from matrix "
211  << vm["load"].as<std::string>() << ".\n";
212  infilename = vm["load"].as<std::string>();
213  }
214 
215  if (vm.count("patfile")) {
216  std::cout << "PatternFile is "
217  << vm["patfile"].as<std::string>() << ".\n";
218  patfile = vm["patfile"].as<std::string>();
219  }
220 
221  if (vm.count("prefile")) {
222  std::cout << "Preload patternfile is "
223  << vm["prefile"].as<std::string>() << ".\n";
224  prefile = vm["prefile"].as<std::string>();
225  }
226 
227  if (vm.count("wmat")) {
228  wmatdump = true;
229  std::cout << "wmat dump mode" << std::endl;
230  }
231 
232  if (vm.count("onperiod")) {
233  std::cout << "onperiod set to "
234  << vm["onperiod"].as<double>() << ".\n";
235  onperiod = vm["onperiod"].as<double>();
236  }
237 
238  if (vm.count("offperiod")) {
239  std::cout << "offperiod set to "
240  << vm["offperiod"].as<double>() << ".\n";
241  offperiod = vm["offperiod"].as<double>();
242  }
243 
244  if (vm.count("eta")) {
245  std::cout << "eta set to "
246  << vm["eta"].as<double>() << ".\n";
247  eta = vm["eta"].as<double>();
248  }
249 
250  if (vm.count("bgrate")) {
251  std::cout << "bgrate set to "
252  << vm["bgrate"].as<double>() << ".\n";
253  bg_rate = vm["bgrate"].as<double>();
254  }
255 
256  if (vm.count("sparseness")) {
257  std::cout << "sparseness set to "
258  << vm["sparseness"].as<double>() << ".\n";
259  sparseness = vm["sparseness"].as<double>();
260  }
261 
262  if (vm.count("scale")) {
263  std::cout << "scale set to "
264  << vm["scale"].as<double>() << ".\n";
265  scale = vm["scale"].as<double>();
266  }
267 
268  if (vm.count("tau_hom")) {
269  std::cout << "tau_hom set to "
270  << vm["tau_hom"].as<double>() << ".\n";
271  tau_hom = vm["tau_hom"].as<double>();
272  }
273 
274  if (vm.count("kappa")) {
275  std::cout << "kappa set to "
276  << vm["kappa"].as<double>() << ".\n";
277  kappa = vm["kappa"].as<double>();
278  }
279 
280  if (vm.count("simtime")) {
281  std::cout << "simtime set to "
282  << vm["simtime"].as<double>() << ".\n";
283  simtime = vm["simtime"].as<double>();
284  stimtime = simtime;
285  }
286 
287  if (vm.count("dir")) {
288  std::cout << "dir set to "
289  << vm["dir"].as<std::string>() << ".\n";
290  dir = vm["dir"].as<std::string>();
291  }
292 
293  if (vm.count("label")) {
294  std::cout << "label set to "
295  << vm["label"].as<std::string>() << ".\n";
296  label = vm["label"].as<std::string>();
297  }
298 
299  if (vm.count("wee")) {
300  std::cout << "wee set to "
301  << vm["wee"].as<double>() << ".\n";
302  w_ee = vm["wee"].as<double>();
303  }
304 
305  if (vm.count("wei")) {
306  std::cout << "wei set to "
307  << vm["wei"].as<double>() << ".\n";
308  w_ei = vm["wei"].as<double>();
309  }
310 
311  if (vm.count("wie")) {
312  std::cout << "wie set to "
313  << vm["wie"].as<double>() << ".\n";
314  w_ie = vm["wie"].as<double>();
315  }
316 
317  if (vm.count("wii")) {
318  std::cout << "wii set to "
319  << vm["wii"].as<double>() << ".\n";
320  w_ii = vm["wii"].as<double>();
321  }
322 
323  if (vm.count("wmax")) {
324  std::cout << "wmax set to "
325  << vm["wmax"].as<double>() << ".\n";
326  wmax = vm["wmax"].as<double>();
327  }
328 
329  if (vm.count("ampa")) {
330  std::cout << "ampa set to "
331  << vm["ampa"].as<double>() << ".\n";
332  ampa_nmda_ratio = vm["ampa"].as<double>();
333  }
334 
335  if (vm.count("strengthen")) {
336  std::cout << "strengthen set to "
337  << vm["strengthen"].as<int>() << ".\n";
338  n_strengthen = vm["strengthen"].as<int>();
339  }
340 
341  if (vm.count("ne")) {
342  std::cout << "ne set to "
343  << vm["ne"].as<int>() << ".\n";
344  ne = vm["ne"].as<int>();
345  ni = ne/4;
346  }
347 
348  if (vm.count("stimfile")) {
349  std::cout << "stimfile set to "
350  << vm["stimfile"].as<std::string>() << ".\n";
351  stimfile = vm["stimfile"].as<std::string>();
352  }
353 
354  if (vm.count("wstim")) {
355  std::cout << "wstim set to "
356  << vm["wstim"].as<double>() << ".\n";
357  wstim = vm["wstim"].as<double>();
358  }
359 
360  if (vm.count("stimtime")) {
361  std::cout << "stimtime set to "
362  << vm["stimtime"].as<double>() << ".\n";
363  stimtime = vm["stimtime"].as<double>();
364  }
365 
366  if (vm.count("corr")) {
367  std::cout << "enabling corr " << std::endl;
368  corr = true;
369  }
370 
371  if (vm.count("ampl")) {
372  std::cout << "ampl set to "
373  << vm["ampl"].as<double>() << ".\n";
374  ampl = vm["ampl"].as<double>();
375  }
376 
377  if (vm.count("psize")) {
378  std::cout << "psize set to "
379  << vm["psize"].as<int>() << ".\n";
380  psize = vm["psize"].as<int>();
381  }
382 
383  if (vm.count("plen")) {
384  std::cout << "plen set to "
385  << vm["plen"].as<int>() << ".\n";
386  plen = vm["plen"].as<int>();
387  }
388 
389  if (vm.count("hsize")) {
390  std::cout << "hsize set to "
391  << vm["hsize"].as<int>() << ".\n";
392  hsize = vm["hsize"].as<int>();
393  }
394 
395  if (vm.count("hlen")) {
396  std::cout << "hlen set to "
397  << vm["hlen"].as<int>() << ".\n";
398  hlen = vm["hlen"].as<int>();
399  }
400 
401  if (vm.count("offset")) {
402  std::cout << "offset set to "
403  << vm["offset"].as<int>() << ".\n";
404  offset = vm["offset"].as<int>();
405  }
406 
407  if (vm.count("recall")) {
408  std::cout << "enabling recall " << std::endl;
409  recall = true;
410  }
411 
412  if (vm.count("stimfreq")) {
413  std::cout << "stimfreq set to "
414  << vm["stimfreq"].as<double>() << ".\n";
415  stimfreq = vm["stimfreq"].as<double>();
416  }
417 
418  if (vm.count("decay")) {
419  std::cout << "weight decay on " << std::endl;
420  decay = true;
421  }
422 
423  if (vm.count("dconstant")) {
424  std::cout << "dconstant set to "
425  << vm["dconstant"].as<double>() << ".\n";
426  tau_decay = vm["dconstant"].as<double>();
427  }
428 
429  if (vm.count("wdecay")) {
430  std::cout << "wdecay set to "
431  << vm["wdecay"].as<double>() << ".\n";
432  wdecay = vm["wdecay"].as<double>();
433  }
434 
435  if (vm.count("chk")) {
436  std::cout << "chk set to "
437  << vm["chk"].as<double>() << ".\n";
438  tau_chk = vm["chk"].as<double>();
439  }
440 
441  if (vm.count("adapt")) {
442  std::cout << "adaptation on " << std::endl;
443  adapt = true;
444  }
445 
446  if (vm.count("wall")) {
447  std::cout << "real time wall clock monitoring enabled " << std::endl;
448  wall = true;
449  }
450 
451  if (vm.count("noisyweights")) {
452  std::cout << "noisyweights on " << std::endl;
453  noisyweights = true;
454  }
455 
456  if (vm.count("switchweights")) {
457  std::cout << "switchweights on " << std::endl;
458  switchweights = true;
459  }
460 
461  if (vm.count("fast")) {
462  std::cout << "fast on " << std::endl;
463  fast = true;
464  }
465 
466  if (vm.count("eiplastic")) {
467  std::cout << "eiplastic on " << std::endl;
468  ei_plastic = true;
469  }
470  }
471  catch(std::exception& e) {
472  std::cerr << "error: " << e.what() << "\n";
473  return 1;
474  }
475  catch(...) {
476  std::cerr << "Exception of unknown type!\n";
477  }
478 
479  if (scale != 1.) {
480  eta *= scale;
481  tau_hom /= scale;
482  simtime /= scale;
483  std::cout << "scaled by " << scale << std::endl;
484  }
485 
486  double primetime = 3*tau_hom;
487 
488 
489  sprintf(strbuf, "%s_e%.2et%.2f%s", file_prefix, eta, tau_hom, label.c_str());
490  std::string logfile_prefix = strbuf;
491 
492  auryn_init(ac, av, dir, "sim_background", logfile_prefix);
493 
495  if ( verbose ) logger->set_logfile_loglevel( EVERYTHING );
496 
497 
498  if (!infilename.empty()) {
499  std::stringstream iss;
500  iss << infilename << "." << sys->mpi_rank();
501  infilename = iss.str();
502  }
503 
504  logger->msg("Setting up neuron groups ...",PROGRESS,true);
505 
506 
507  NeuronGroup * neurons_e;
508  if ( adapt ) {
509  neurons_e = new AIFGroup(ne);
510  ((AIFGroup*)neurons_e)->set_ampa_nmda_ratio(ampa_nmda_ratio);
511  ((AIFGroup*)neurons_e)->dg_adapt1=1.0;
512  } else {
513  if ( loadbalance )
514  neurons_e = new IFGroup(ne);
515  else
516  neurons_e = new IFGroup(ne);
517  ((IFGroup*)neurons_e)->set_ampa_nmda_ratio(ampa_nmda_ratio);
518  }
519  IFGroup * neurons_i = new IFGroup(ni);
520 
521  // initialize membranes
522  neurons_i->set_tau_mem(10e-3);
523  neurons_e->random_mem(-60e-3,10e-3);
524  neurons_i->random_mem(-60e-3,10e-3);
525 
526  ((IFGroup*)neurons_i)->set_ampa_nmda_ratio(ampa_nmda_ratio);
527 
528 
529  SpikingGroup * poisson = new PoissonGroup(2500,bg_rate);
530  SparseConnection * con_exte = new SparseConnection(poisson, neurons_e, w_ext, sparseness, GLUT);
531 
532  msg = "Setting up I connections ...";
533  logger->msg(msg,PROGRESS,true);
534  SparseConnection * con_ie = new SparseConnection(neurons_i,neurons_e,
535  w_ie,sparseness,GABA);
536  SparseConnection * con_ii = new SparseConnection(neurons_i,neurons_i,
537  w_ii,sparseness,GABA);
538 
539  msg = "Setting up E connections ...";
540  logger->msg(msg,PROGRESS,true);
541  SparseConnection * con_ei;
542  if ( !ei_plastic ) {
543  con_ei = new SparseConnection(neurons_e,neurons_i,
544  w_ei, sparseness,GLUT);
545  } else {
546  if (infilename.empty()) {
547  con_ei = new TripletConnection(neurons_e,neurons_i,
548  w_ei, sparseness,
549  tau_hom, eta, kappa, wmax, GLUT);
550  } else {
551  std::string str;
552  str = infilename;
553  str += ".ei.wmat";
554  std::stringstream oss;
555  oss << "Loading weight matrix from " << str;
556  logger->msg(oss.str(),PROGRESS,true);
557  con_ei = new TripletConnection(neurons_e,neurons_i,
558  str.c_str(),
559  tau_hom, eta, kappa, wmax, GLUT);
560  }
561  }
562 
563  TripletConnection * con_ee;
564 
565  if (infilename.empty()) {
566  if (decay)
567  con_ee = new TripletDecayConnection(neurons_e,neurons_e,
568  w_ee, sparseness,
569  tau_hom, eta, tau_decay,
570  kappa, wdecay, wmax, GLUT);
571  else
572  con_ee = new TripletConnection(neurons_e,neurons_e,
573  w_ee, sparseness,
574  tau_hom, eta, kappa, wmax, GLUT);
575 
576  // con_ee->set_min_weight(wmin);
577  if ( noisyweights )
578  con_ee->random_data(w_ee,w_ee/4);
579  for ( int i = 0 ; i < n_strengthen ; ++i ) {
580  con_ee->set_data(i,i*(wmax/n_strengthen));
581  }
582  }
583  else {
584  std::string str;
585  str = infilename;
586  str += ".wmat";
587  std::stringstream oss;
588  oss << "Loading weight matrix from " << str;
589  logger->msg(oss.str(),PROGRESS,true);
590  if (decay)
591  con_ee = new TripletDecayConnection(neurons_e,neurons_e,
592  str.c_str(),tau_hom,eta,tau_decay,kappa,wdecay,wmax,GLUT);
593  else
594  con_ee = new TripletConnection(neurons_e,neurons_e,
595  str.c_str(),tau_hom,eta,kappa,wmax,GLUT);
596 
597 
598  sprintf(strbuf, "%s.e.nstate", infilename.c_str());
599  neurons_e->load_from_file(strbuf);
600  sprintf(strbuf, "%s.i.nstate", infilename.c_str());
601  neurons_i->load_from_file(strbuf);
602 
603  // primetime = 0;
604  }
605 
606  // SparseConnection * con_exti = new SparseConnection(sys, poisson, neurons_i, w_ext, sparseness, GLUT);
607 
608  msg = "Initializing traces ...";
609  logger->msg(msg,PROGRESS,true);
610  con_ee->set_hom_trace(kappa);
611  con_ee->seed(23);
612 
613  // TODO
614  // con_ee->w->set_col(0,2*w_ee);
615 
616  msg = "Setting up monitors ...";
617  logger->msg(msg,PROGRESS,true);
618 
619  if (wmatdump) {
620  sprintf(strbuf, "%s/%s_e%.2et%.2f%s.%d.weight", dir.c_str(), file_prefix, eta, tau_hom, label.c_str(), sys->mpi_rank());
621  WeightMatrixMonitor * wmatmon = new WeightMatrixMonitor( con_ee, strbuf , wmat_interval );
622  }
623 
624  if ( !fast ) {
625  sprintf(strbuf, "%s/%s_e%.2et%.2f%s.%d.syn", dir.c_str(), file_prefix, eta, tau_hom, label.c_str(), sys->mpi_rank());
626  WeightMonitor * wmon = new WeightMonitor( con_ee, strbuf, 10 );
627  for ( int i = 0 ; i < 5 ; ++i ) {
628  for ( int j = 0 ; j < 5 ; ++j ) {
629  std::vector<neuron_pair> sublist = con_ee->get_block(i*psize,(i+1)*psize,j*psize,(j+1)*psize);
630  sublist.resize(50); // only record a maximum of 50 connections from each block
631  wmon->add_to_list(sublist);
632  }
633  }
634 
635  sprintf(strbuf, "%s/%s_e%.2et%.2f%s.%d.%c.ras", dir.c_str(), file_prefix, eta, tau_hom, label.c_str(), sys->mpi_rank(), 'e');
636  SpikeMonitor * smon_e = new SpikeMonitor( neurons_e, strbuf , 2500);
637 
638  // sprintf(strbuf, "%s/%s_e%.2et%.2f%s.%d.%c.ras", dir.c_str(), file_prefix, eta, tau_hom, label.c_str(), sys->mpi_rank(), 'p');
639  // SpikeMonitor * smon_p = new SpikeMonitor( poisson, strbuf , 2500);
640  }
641 
642  sprintf(strbuf, "%s/%s_e%.2et%.2f%s.%d.%c.prate", dir.c_str(), file_prefix, eta, tau_hom, label.c_str(), sys->mpi_rank(), 'e');
643  PopulationRateMonitor * pmon_e = new PopulationRateMonitor( neurons_e, strbuf, 1.0 );
644 
645  if ( wall ) {
646  sprintf(strbuf, "%s/%s_e%.2et%.2f%s.%d.rt", dir.c_str(), file_prefix, eta, tau_hom, label.c_str(), sys->mpi_rank());
647  RealTimeMonitor * rtmon = new RealTimeMonitor( strbuf );
648  }
649 
650  // sprintf(strbuf, "%s/%s_e%.2et%.2f%s.%d.%c.prate", dir.c_str(), file_prefix, eta, tau_hom, label.c_str(), sys->mpi_rank(), 'i');
651  // PopulationRateMonitor * pmon_i = new PopulationRateMonitor( neurons_i, strbuf, 1.0 );
652 
653  // sprintf(strbuf, "%s/%s_e%.2et%.2f%s.%d.%c.mem", dir.c_str(), file_prefix, eta, tau_hom, label.c_str(), sys->mpi_rank(), 'e');
654  // VoltageMonitor * vmon_e = new VoltageMonitor( neurons_e, 33, strbuf );
655 
656  // sprintf(strbuf, "%s/%s_e%.2et%.2f%s.%d.%c.ras", dir.c_str(), file_prefix, eta, tau_hom, label.c_str(), sys->mpi_rank(), 'i');
657  // SpikeMonitor * smon_i = new SpikeMonitor( neurons_i, strbuf , 500);
658 
659  RateChecker * chk = new RateChecker( neurons_e , 0.1 , 20.*kappa , tau_chk);
660  // To add a weight checker uncomment the following line
661  // WeightChecker * wchk = new WeightChecker( con_ee, 0.159, 0.161 );
662 
663  // Use the same time constant for the online rate estimate in the progress bar
666 
667 
668 
669  if ( scaling && (errcode==0) ) {
670  std::stringstream oss;
671  oss << "Changing cell input ... ";
672  logger->msg(oss.str(),PROGRESS,true);
673 
674  sprintf(strbuf, "%s/%s_e%.2et%.2f%s.%d.pat", dir.c_str(), file_prefix, eta, tau_hom, label.c_str(), sys->mpi_rank());
675  PatternMonitor * patmon = new PatternMonitor(neurons_e,strbuf,patfile.c_str(), 10, 1.);
676  PatternStimulator * patstim = new PatternStimulator(neurons_e,currentfile.c_str(),patfile.c_str());
677 
678  sprintf(strbuf, "%s/%s_e%.2et%.2f%s.%d.scal", dir.c_str(), file_prefix, eta, tau_hom, label.c_str(), sys->mpi_rank());
679  WeightMonitor * wmon_scal = new WeightMonitor( con_ee, 0, 0, strbuf, 1, ELEMENTLIST);
680  wmon_scal->add_to_list( con_ee->get_pre_partners(0) );
681  wmon_scal->add_to_list( con_ee->get_pre_partners(10) );
682 
683  }
684 
685  // if ( corr ) {
686  // sprintf(strbuf, "%s/%s_e%.2et%.2f%s.%d.%c.pat", dir.c_str(), file_prefix, eta, tau_hom, label.c_str(), sys->mpi_rank(), 'c');
687  // PatternMonitor * pmon_c = new PatternMonitor( neurons_e, strbuf,corr_pat_file.c_str() );
688  // }
689 
690  const double amplitude_fwd = 9.0*ampl;
691  const double amplitude_heb = 3.0*ampl;
692 
693  CorrelatedPoissonGroup * corr_e;
694  CorrelatedPoissonGroup * corr_e2;
695 
696  NeuronID extsize = 500;
697  double strength = 0.2;
698 
699  if ( corr ) {
700 
701  std::stringstream oss;
702  oss << "Activating correlated input ... ";
703  logger->msg(oss.str(),PROGRESS,true);
704 
705  if (eta > 0)
706  con_ee->stdp_active = true;
707 
708 
709  if ( psize*plen ) {
710  corr_e = new CorrelatedPoissonGroup(extsize*plen,stimfreq,extsize,10e-3);
711  corr_e->set_amplitude(amplitude_fwd);
712  corr_e->set_timescale(5e-3);
713  // IdentityConnection * con_corr_e = new IdentityConnection(corr_e,neurons_e,w);
714  SparseConnection * con_corr_e = new SparseConnection(corr_e,neurons_e,GLUT);
715  con_corr_e->allocate_manually( plen*extsize*psize*sparseness*1.05 );
716  con_corr_e->w->clear();
717  for ( int i = 0 ; i < plen ; ++i )
718  con_corr_e->connect_block_random(w,sparseness,(i)*extsize,offset+(i+1)*extsize,(i)*psize,offset+(i+1)*psize);
719  con_corr_e->finalize();
720  corr_connections.push_back(con_corr_e);
721  SparseConnection * con_corr_i = new SparseConnection(corr_e,neurons_i,w*strength,sparseness*plen*psize/ni,GLUT);
722 
723  // set up Weight monitor
724  sprintf(strbuf, "%s/%s_e%.2et%.2f%s.%d.%c.ras", dir.c_str(), file_prefix, eta, tau_hom, label.c_str(), sys->mpi_rank(), 'c');
725  SpikeMonitor * smon_c = new SpikeMonitor( corr_e, strbuf , psize );
726  }
727 
728  if ( hsize*hlen ) {
729  corr_e2 = new CorrelatedPoissonGroup(extsize*hlen,stimfreq,extsize,10);
730  corr_e2->set_amplitude(amplitude_heb);
731  corr_e2->set_timescale(100e-3);
732  SparseConnection * con_corr_e2 = new SparseConnection(corr_e2,neurons_e,GLUT);
733  con_corr_e2->allocate_manually( hlen*extsize*hsize*sparseness*1.05 );
734  con_corr_e2->w->clear();
735  for ( int i = 0 ; i < hlen ; ++i )
736  con_corr_e2->connect_block_random(w,sparseness,(i)*extsize,(i+1)*extsize,offset+(i)*hsize+plen*psize,offset+(i+1)*hsize+plen*psize);
737  con_corr_e2->finalize();
738  corr_connections.push_back(con_corr_e2);
739  SparseConnection * con_corr_i2 = new SparseConnection(corr_e2,neurons_i,w*strength,sparseness*hlen*hsize/ni,GLUT);
740  }
741 
742  // disabling external random input
743  con_exte->set_block(0,2500,0,plen*psize+hlen*hsize,0.0);
744 
745  } else {
746  if ( recall ) {
747 
748  std::stringstream oss;
749  oss << "Activating recall input ... ";
750  logger->msg(oss.str(),PROGRESS,true);
751 
752  if ( psize*plen ) {
753  corr_e = new CorrelatedPoissonGroup(extsize*plen,stimfreq,extsize,10e-3);
754  corr_e->set_amplitude(amplitude_fwd);
755  corr_e->set_timescale(5e-3);
756  // IdentityConnection * con_corr_e = new IdentityConnection(corr_e,neurons_e,w);
757  SparseConnection * con_corr_e = new SparseConnection(corr_e,neurons_e,GLUT);
758  con_corr_e->allocate_manually( plen*extsize*psize*sparseness*1.05 );
759  con_corr_e->w->clear();
760  for ( int i = 0 ; i < plen ; ++i )
761  con_corr_e->connect_block_random(w,sparseness,(i)*extsize,offset+(i+1)*extsize,(i)*psize,offset+(i+1)*psize);
762  con_corr_e->finalize();
763  corr_connections.push_back(con_corr_e);
764  // SparseConnection * con_corr_i = new SparseConnection(corr_e,neurons_i,w*strength,sparseness*plen*psize/ni,GLUT);
765 
766  // set up Weight monitor
767  sprintf(strbuf, "%s/%s_e%.2et%.2f%s.%d.%c.ras", dir.c_str(), file_prefix, eta, tau_hom, label.c_str(), sys->mpi_rank(), 'c');
768  SpikeMonitor * smon_c = new SpikeMonitor( corr_e, strbuf , psize );
769  }
770 
771  if ( hsize*hlen ) {
772  corr_e2 = new CorrelatedPoissonGroup(extsize*hlen,stimfreq,extsize,10);
773  corr_e2->set_amplitude(amplitude_heb);
774  corr_e2->set_timescale(100e-3);
775  SparseConnection * con_corr_e2 = new SparseConnection(corr_e2,neurons_e,GLUT);
776  con_corr_e2->allocate_manually( hlen*extsize*hsize*sparseness*1.05 );
777  con_corr_e2->w->clear();
778  for ( int i = 0 ; i < hlen ; ++i )
779  con_corr_e2->connect_block_random(w,sparseness,(i)*extsize,(i+1)*extsize,offset+(i)*hsize+plen*psize,offset+(i+1)*hsize+plen*psize);
780  con_corr_e2->finalize();
781  corr_connections.push_back(con_corr_e2);
782  // SparseConnection * con_corr_i2 = new SparseConnection(corr_e2,neurons_i,w*strength,sparseness*hlen*hsize/ni,GLUT);
783  }
784 
785  // disabling external random input
786  // con_exte->set_block(0,2500,psize,2*psize,0.0);
787  }
788  }
789 
790 // preload patterns
791 if ( prefile != "" ) {
792  logger->msg("Preloading patterns ...",PROGRESS,true);
793  // con_ee->random_data(w_ee,w_ee);
794  con_ee->load_patterns(prefile, wmax, true, false);
795  // con_ee->sparse_set_data(0.9,0);
796 }
797 
798 // adding patterns
799 if ( patfile != "" ) {
800  logger->msg("Preparing stimulus ...",PROGRESS,true);
801  sprintf(strbuf, "%s/%s_e%.2et%.2f%s.%d.stim", dir.c_str(), file_prefix, eta, tau_hom, label.c_str(), sys->mpi_rank());
802  StimulusGroup * stimgroup = new StimulusGroup(ne,patfile,strbuf);
803  stimgroup->set_mean_on_period(onperiod);
804  stimgroup->set_mean_off_period(offperiod);
805  IdentityConnection * con_stim = new IdentityConnection(stimgroup,neurons_e,w_ext);
806 }
807 
808  if (primetime>0) {
809  msg = "Priming ...";
810  logger->msg(msg,PROGRESS,true);
811  con_ee->stdp_active = false;
812  sys->run(primetime,true);
813  }
814 
815  if ( corr || recall ) {
816  if ( psize*plen )
817  corr_e->set_target_amplitude(amplitude_fwd);
818  if ( hsize*hlen )
819  corr_e2->set_target_amplitude(amplitude_heb);
820  }
821 
822  logger->msg("Simulating ...",PROGRESS,true);
823  if (eta > 0) {
824  con_ee->stdp_active = true;
825  }
826 
827  if (!sys->run(simtime,true))
828  errcode = 1;
829 
830 
831 
832  if (!fast) {
833  logger->msg("Saving neurons state ...",PROGRESS,true);
834  sprintf(strbuf, "%s/%s_e%.2et%.2f%s.%d.e.nstate", dir.c_str(), file_prefix, eta, tau_hom, label.c_str(), sys->mpi_rank());
835  neurons_e->write_to_file(strbuf);
836  sprintf(strbuf, "%s/%s_e%.2et%.2f%s.%d.i.nstate", dir.c_str(), file_prefix, eta, tau_hom, label.c_str(), sys->mpi_rank());
837  neurons_i->write_to_file(strbuf);
838 
839  logger->msg("Saving weight matrix ...",PROGRESS,true);
840  sprintf(strbuf, "%s/%s_e%.2et%.2f%s.%d.wmat", dir.c_str(), file_prefix, eta, tau_hom, label.c_str(), sys->mpi_rank());
841  con_ee->write_to_file(strbuf);
842 
843  sprintf(strbuf, "%s/%s_e%.2et%.2f%s.%d.ei.wmat", dir.c_str(), file_prefix, eta, tau_hom, label.c_str(), sys->mpi_rank());
844  con_ei->write_to_file(strbuf);
845 
846  for ( int i = 0 ; i < corr_connections.size() ; ++i ) {
847  sprintf(strbuf, "%s/%s_e%.2et%.2f%s.%d.%d.wmat", dir.c_str(), file_prefix, eta, tau_hom, label.c_str(), i, sys->mpi_rank());
848  corr_connections[i]->write_to_file(strbuf);
849  }
850  }
851 
852  // save lifetime
853  sprintf(strbuf, "%s/%s_e%.2et%.2f%s.%d.lifetime", dir.c_str(), file_prefix, eta, tau_hom, label.c_str(), sys->mpi_rank());
854  std::ofstream killfile;
855  killfile.open(strbuf);
856  killfile << sys->get_time()-primetime << std::endl;
857  killfile.close();
858 
859 
860  if ( sys->mpi_rank() == 0 ) {
861  logger->msg("Saving elapsed time ..." ,PROGRESS,true);
862  char filenamebuf [255];
863  sprintf(filenamebuf, "%s/elapsed.dat", dir.c_str());
864  std::ofstream timefile;
865  timefile.open(filenamebuf);
866  timefile << sys->get_last_elapsed_time() << std::endl;
867  timefile.close();
868  }
869 
870 
871  if (errcode) {
872  auryn_abort(errcode);
873  }
874 
875  logger->msg("Freeing ...",PROGRESS,true);
876  auryn_free();
877 
878  return errcode;
879 }
void set_hom_trace(AurynFloat freq)
Definition: TripletConnection.cpp:127
void auryn_free()
Cleanly shuts down Auryn simulation environment.
Definition: auryn_global.cpp:107
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
void set_logfile_loglevel(LogMessageType level=NOTIFICATION)
Sets loglevel for file output.
Definition: Logger.cpp:63
void random_mem(AurynState mean=-60e-3, AurynState sigma=5e-3)
Definition: NeuronGroup.cpp:81
ForwardMatrix * w
A pointer that points per default to the ComplexMatrix that stores the connectinos.
Definition: SparseConnection.h:147
unsigned int mpi_rank()
Returns current rank.
Definition: System.cpp:1009
Monitor class to record the system time in every timestep.
Definition: RealTimeMonitor.h:45
void set_target_amplitude(AurynDouble ampl)
Definition: CorrelatedPoissonGroup.cpp:169
double get_last_elapsed_time()
Returns last elapsed time in seconds.
Definition: System.cpp:956
void seed(NeuronID randomseed)
This function seeds the pseudo random number generator for all random fill operatios.
Definition: SparseConnection.cpp:155
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
Monitor class to record population firing rates.
Definition: PatternMonitor.h:47
bool stdp_active
Toggles stdp active/inactive. When inactive traces are still updated, but weights are not...
Definition: TripletConnection.h:153
Logger * logger
Global pointer to instance of Logger which needs to be initialized in every simulation main program...
Definition: auryn_global.cpp:36
Implements triplet STDP with metaplasticity as described by Pfister and Gerstner 2006.
Definition: TripletConnection.h:48
void connect_block_random(AurynWeight weight, AurynDouble sparseness, NeuronID lo_row, NeuronID hi_row, NeuronID lo_col, NeuronID hi_col, bool skip_diag=false)
Underlying sparse fill method.
Definition: SparseConnection.cpp:360
The standard Monitor object to record spikes from a SpikingGroup and write them to a text file...
Definition: SpikeMonitor.h:52
Definition: Logger.h:41
void set_tau_mem(AurynFloat taum)
Sets the membrane time constant.
Definition: IFGroup.cpp:154
void set_online_rate_monitor_tau(AurynDouble tau=100e-3)
Sets the timeconstant to compute the online rate average for the status bar.
Definition: System.cpp:925
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 clear()
Clears matrix.
Definition: ComplexMatrix.h:460
void auryn_abort(int errcode)
Terminates Auryn simulation abnormally.
Definition: auryn_global.cpp:113
void allocate_manually(AurynLong expected_size)
Is used whenever memory has to be allocated manually. Automatically adjusts for number of ranks and f...
Definition: SparseConnection.cpp:192
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
The Monitor records from selected synapses stored in a list. This is the default behavior.
Definition: WeightMonitor.h:47
A simple extension of IFGroup with spike triggered adaptation.
Definition: AIFGroup.h:37
Provides a poisson stimulus at random intervals in one or more predefined subsets of the group that a...
Definition: StimulusGroup.h:50
Implements triplet STDP with an exponential weight decay.
Definition: TripletDecayConnection.h:45
AurynDouble get_time()
Gets the current system time in [s].
Definition: System.cpp:226
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
Stimulator class to inject timeseries of currents to patterns (subpopulations) of neurons...
Definition: PatternStimulator.h:44
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
void load_patterns(string filename, AurynWeight strength, int nb_max_patterns=10000, bool overwrite=false, bool chainmode=false)
Reads first n patterns from a .pat file and adds them as Hebbian assemblies onto an existing weight m...
Definition: SparseConnection.cpp:1057
std::vector< neuron_pair > get_block(NeuronID lo_row, NeuronID hi_row, NeuronID lo_col, NeuronID hi_col)
Returns a vector of ConnectionsID of a block specified by the arguments.
Definition: SparseConnection.cpp:1100
Definition: Logger.h:41
Abstract base class for all neuron groups.
Definition: NeuronGroup.h:45
Definition: Logger.h:41
virtual void finalize()
Finalizes connection after random or manual initialization of the weights.
Definition: SparseConnection.cpp:499
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
std::string string
Standard library string type which is imported into Auryn namespace.
Definition: auryn_definitions.h:156
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
std::vector< neuron_pair > get_pre_partners(NeuronID j)
Returns a vector of ConnectionsID of presynaptic parterns of neuron i.
Definition: SparseConnection.cpp:1131
Here is the call graph for this function: