Auryn simulator  v0.8.1-206-gb56e451
Plastic Spiking Neural Network Simulator
Macros | Functions
sim_stim_homtriplet.cpp File Reference
#include "auryn.h"
Include dependency graph for sim_stim_homtriplet.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 = 50;
66 
67  bool corr = false;
68  bool adapt = false;
69  bool noisyweights = false;
70  bool fast = false;
71 
72  double tau_hom = 50.;
73  double eta = 1;
74  double beta_scaling = 0; // scaling time constant (not needed for homtrip)
75 
76  int n_strengthen = 0;
77 
78  string dir = "/tmp";
79  string stimfile = "";
80  string label = "";
81  string infilename = "";
82 
83  const char * file_prefix = "bg_homtriplet";
84  char strbuf [255];
85  string msg;
86 
87  int errcode = 0;
88 
89  try {
90  po::options_description desc("Allowed options");
91  desc.add_options()
92  ("help", "produce help message")
93  ("quiet", "quiet mode")
94  ("load", po::value<string>(), "input weight matrix")
95  ("wmat", "wmat dump mode")
96  ("eta", po::value<double>(), "learning rate")
97  ("scaling", po::value<double>(), "learning rate")
98  ("tau_hom", po::value<double>(), "homeostatic time constant")
99  ("kappa", po::value<double>(), "target rate")
100  ("simtime", po::value<double>(), "simulation time")
101  ("dir", po::value<string>(), "output dir")
102  ("label", po::value<string>(), "output label")
103  ("we", po::value<double>(), "we")
104  ("strengthen", po::value<int>(), "connections to strengthen by 10")
105  ("stimfile", po::value<string>(), "stimulus ras file")
106  ("wstim", po::value<double>(), "weight of stimulus connections")
107  ("stimtime", po::value<double>(), "time of stimulus on")
108  ("adapt", "adapting excitatory neurons")
109  ("corr", "add correlated inputs")
110  ("stimfreq", po::value<double>(), "CorrelatedPoissonGroup frequency default = 100")
111  ("noisyweights", "enables noisyweights for mean field checks")
112  ("fast", "turn off some of the monitors to run faster")
113  ;
114 
115  po::variables_map vm;
116  po::store(po::parse_command_line(ac, av, desc), vm);
117  po::notify(vm);
118 
119  if (vm.count("help")) {
120  std::cout << desc << "\n";
121  return 1;
122  }
123 
124  if (vm.count("quiet")) {
125  quiet = true;
126  }
127 
128  if (vm.count("load")) {
129  std::cout << "load from matrix "
130  << vm["load"].as<string>() << ".\n";
131  infilename = vm["load"].as<string>();
132  }
133 
134  if (vm.count("wmat")) {
135  wmatdump = true;
136  std::cout << "wmat dump mode" << std::endl;
137  }
138 
139  if (vm.count("eta")) {
140  std::cout << "eta set to "
141  << vm["eta"].as<double>() << ".\n";
142  eta = vm["eta"].as<double>();
143  }
144 
145  if (vm.count("scaling")) {
146  std::cout << "scaling set to "
147  << vm["scaling"].as<double>() << ".\n";
148  beta_scaling = vm["scaling"].as<double>();
149  }
150 
151  if (vm.count("tau_hom")) {
152  std::cout << "tau_hom set to "
153  << vm["tau_hom"].as<double>() << ".\n";
154  tau_hom = vm["tau_hom"].as<double>();
155  }
156 
157  if (vm.count("kappa")) {
158  std::cout << "kappa set to "
159  << vm["kappa"].as<double>() << ".\n";
160  kappa = vm["kappa"].as<double>();
161  }
162 
163  if (vm.count("simtime")) {
164  std::cout << "simtime set to "
165  << vm["simtime"].as<double>() << ".\n";
166  simtime = vm["simtime"].as<double>();
167  stimtime = simtime;
168  }
169 
170  if (vm.count("corr")) {
171  std::cout << "enabling corr " << std::endl;
172  corr = true;
173  }
174 
175  if (vm.count("stimfreq")) {
176  std::cout << "stimfreq set to "
177  << vm["stimfreq"].as<double>() << ".\n";
178  stimfreq = vm["stimfreq"].as<double>();
179  }
180 
181  if (vm.count("dir")) {
182  std::cout << "dir set to "
183  << vm["dir"].as<string>() << ".\n";
184  dir = vm["dir"].as<string>();
185  }
186 
187  if (vm.count("label")) {
188  std::cout << "label set to "
189  << vm["label"].as<string>() << ".\n";
190  label = vm["label"].as<string>();
191  }
192 
193  if (vm.count("we")) {
194  std::cout << "we set to "
195  << vm["we"].as<double>() << ".\n";
196  w_ee = vm["we"].as<double>();
197  }
198 
199  if (vm.count("strengthen")) {
200  std::cout << "strengthen set to "
201  << vm["strengthen"].as<int>() << ".\n";
202  n_strengthen = vm["strengthen"].as<int>();
203  }
204 
205  if (vm.count("stimfile")) {
206  std::cout << "stimfile set to "
207  << vm["stimfile"].as<string>() << ".\n";
208  stimfile = vm["stimfile"].as<string>();
209  }
210 
211  if (vm.count("wstim")) {
212  std::cout << "wstim set to "
213  << vm["wstim"].as<double>() << ".\n";
214  wstim = vm["wstim"].as<double>();
215  }
216 
217  if (vm.count("stimtime")) {
218  std::cout << "stimtime set to "
219  << vm["stimtime"].as<double>() << ".\n";
220  stimtime = vm["stimtime"].as<double>();
221  }
222 
223  if (vm.count("adapt")) {
224  std::cout << "adaptation on " << std::endl;
225  adapt = true;
226  }
227 
228  if (vm.count("noisyweights")) {
229  std::cout << "noisyweights on " << std::endl;
230  noisyweights = true;
231  }
232 
233  if (vm.count("fast")) {
234  std::cout << "fast on " << std::endl;
235  fast = true;
236  }
237  }
238  catch(std::exception& e) {
239  std::cerr << "error: " << e.what() << "\n";
240  return 1;
241  }
242  catch(...) {
243  std::cerr << "Exception of unknown type!\n";
244  }
245 
246 
247  // double primetime = 3.0/(beta_scaling*eta*1.24488e-5);
248  double primetime = 3.0*tau_hom;
249 
250 
251  auryn_init(ac, av);
252 
253  if (!infilename.empty()) {
254  std::stringstream iss;
255  iss << infilename << "." << sys->mpi_rank();
256  infilename = iss.str();
257  }
258 
259  logger->msg("Setting up neuron groups ...",PROGRESS,true);
260 
261 
262  NeuronGroup * neurons_e;
263  if ( adapt )
264  neurons_e = new AIFGroup(20000);
265  else
266  neurons_e = new IFGroup(20000);
267  IFGroup * neurons_i = new IFGroup(5000);
268 
269  // initialize membranes
270  neurons_i->set_tau_mem(10e-3);
271  neurons_e->random_mem(-60e-3,10e-3);
272  neurons_i->random_mem(-60e-3,10e-3);
273 
274 
275  SpikingGroup * poisson = new PoissonGroup(2500,2);
276  // SparseConnection * con_exte = new SparseConnection(poisson, neurons_e, w_ext, sparseness, GLUT);
277  TripletConnection * con_exte = new TripletConnection(poisson, neurons_e, w_ext, sparseness, tau_hom, eta, kappa, wmax, GLUT);
278 
279 
280 
281  msg = "Setting up I connections ...";
282  logger->msg(msg,PROGRESS,true);
283  SparseConnection * con_ie = new SparseConnection(neurons_i,neurons_e,
284  w_ie,sparseness,GABA);
285  SparseConnection * con_ii = new SparseConnection(neurons_i,neurons_i,
286  w_ii,sparseness,GABA);
287 
288  msg = "Setting up E connections ...";
289  logger->msg(msg,PROGRESS,true);
290  SparseConnection * con_ei = new SparseConnection(neurons_e,neurons_i,
291  w_ei, sparseness,GLUT);
292 
293  TripletConnection * con_ee;
294 
295  con_ee = new TripletConnection(neurons_e,neurons_e,
296  w_ee, sparseness,tau_hom,eta,kappa,wmax,GLUT);
297  if ( noisyweights )
298  con_ee->random_data(w_ee,w_ee/4);
299  for ( int i = 0 ; i < n_strengthen ; ++i ) {
300  con_ee->set_data(i,i*(wmax/n_strengthen));
301  }
302 
303 
304  // TODO
305  // con_ee->w->set_col(0,2*w_ee);
306 
307  msg = "Setting up monitors ...";
308  logger->msg(msg,PROGRESS,true);
309 
310  if (wmatdump) {
311  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());
312  WeightMatrixMonitor * wmatmon = new WeightMatrixMonitor( con_ee, strbuf , wmat_interval );
313  }
314 
315  if ( !fast ) {
316  sprintf(strbuf, "%s/%s_e%.2et%.2f%s.%d.%c.spk", dir.c_str(), file_prefix, beta_scaling, tau_hom, label.c_str(), sys->mpi_rank(), 'e');
317  BinarySpikeMonitor * smon_e = new BinarySpikeMonitor( neurons_e, strbuf , 2500);
318 
319  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');
320  PopulationRateMonitor * pmon_e = new PopulationRateMonitor( neurons_e, strbuf, 0.2 );
321  }
322 
323  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());
324  WeightMonitor * wmon = new WeightMonitor( con_ee, strbuf, 0.1 );
325  wmon->add_equally_spaced(20);
326 
327  RateChecker * chk = new RateChecker( neurons_e , -0.1 , 20.*kappa , 100e-3);
328 
329 
330 
331  FileInputGroup * filegroup;
332  SparseConnection * con_stim;
333  if (!stimfile.empty()) {
334  msg = "Setting up stimulus ...";
335  logger->msg(msg,PROGRESS,true);
336  filegroup = new FileInputGroup(2000,stimfile.c_str(),true,1);
337  con_stim = new SparseConnection( filegroup, neurons_e, GLUT);
338  con_stim->set_name("Stimulus Connection");
339  con_stim->allocate_manually(4*500*100*sparseness);
340  con_stim->connect_block_random(wstim, sparseness, 0, 500, 0, 100);
341  con_stim->connect_block_random(wstim, sparseness, 500, 1000, 100, 200);
342  con_stim->connect_block_random(wstim, sparseness, 1000, 1500, 200, 300);
343  con_stim->connect_block_random(wstim, sparseness, 1500, 2000, 300, 400);
344  con_stim->finalize();
345 
346  logger->msg("Saving weight matrix ...",PROGRESS,true);
347  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());
348  con_stim->write_to_file(strbuf);
349  }
350 
351 
352  // set up correlated input
353  const NeuronID size = 500;
354  const NeuronID psize = 100;
355  const NeuronID ngroups = 3;
356 
357  std::stringstream oss;
358  oss << " Activating correlated input ... ";
359  logger->msg(oss.str(),PROGRESS,true);
360 
361  CorrelatedPoissonGroup * corr_e = new CorrelatedPoissonGroup(psize*ngroups,stimfreq,psize,5);
362  const double ampl = 5.0;
363  corr_e->set_amplitude(ampl);
364  corr_e->set_target_amplitude(ampl);
365  corr_e->set_timescale(100e-3);
366  // corr->set_offset(2);
367 
368  // SparseConnection * con_corr_e = new SparseConnection(corr_e,neurons_e,corr_file.c_str(),GLUT);
369  TripletConnection * con_corr_e = new TripletConnection(corr_e, neurons_e, w, sparseness, tau_hom, eta, kappa, wmax, GLUT);
370  con_corr_e->set_all(0.0);
371  for ( int i = 0 ; i < ngroups ; ++i ) {
372  con_corr_e->set_block( i*psize, (i+1)*psize, i*psize, (i+1)*psize, w_ext );
373  con_exte->set_block( i*psize, (i+1)*psize, i*psize, (i+1)*psize, 1e-3 );
374  }
375 
376  sprintf(strbuf, "%s/%s_e%.2et%.2f%s.%d.c.syn", dir.c_str(), file_prefix, beta_scaling, tau_hom, label.c_str(), sys->mpi_rank());
377  WeightMonitor * wmonc = new WeightMonitor( con_corr_e, strbuf, 0.1 );
378  wmonc->add_equally_spaced(20);
379 
380  // disabling external random input
381  // con_exte->set_block(0,2500,0,size,0.0);
382 
383  // set up Weight monitor
384 
385  sprintf(strbuf, "%s/%s_e%.2et%.2f%s.%d.%c.spk", dir.c_str(), file_prefix, beta_scaling, tau_hom, label.c_str(), sys->mpi_rank(), 'c');
386  BinarySpikeMonitor * smon_c = new BinarySpikeMonitor( corr_e, strbuf , size );
387 
388  msg = "Initializing traces ...";
389  logger->msg(msg,PROGRESS,true);
390  con_ee->set_hom_trace(kappa);
391  con_exte->set_hom_trace(kappa);
392  con_corr_e->set_hom_trace(kappa);
393 
394  if (primetime>0) {
395  msg = "Priming ...";
396  // con_ee->set_beta(400);
397  logger->msg(msg,PROGRESS,true);
398  con_ee->stdp_active = false;
399  con_exte->stdp_active = false;
400  con_corr_e->stdp_active = false;
401  sys->run(primetime,true);
402  }
403 
404  logger->msg("Simulating ...",PROGRESS,true);
405  if (eta > 0) {
406  con_ee->stdp_active = true;
407  con_exte->stdp_active = true;
408  con_corr_e->stdp_active = true;
409  }
410 
411  if (!sys->run(simtime,true))
412  errcode = 1;
413 
414 
415 
416  logger->msg("Saving neurons state ...",PROGRESS,true);
417  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());
418  neurons_e->write_to_file(strbuf);
419  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());
420  neurons_i->write_to_file(strbuf);
421 
422  logger->msg("Saving weight matrix ...",PROGRESS,true);
423  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());
424  con_ee->write_to_file(strbuf);
425 
426  sprintf(strbuf, "%s/%s_e%.2et%.2f%s.%d.c.wmat", dir.c_str(), file_prefix, beta_scaling, tau_hom, label.c_str(), sys->mpi_rank());
427  con_corr_e->write_to_file(strbuf);
428 
429  sprintf(strbuf, "%s/%s_e%.2et%.2f%s.%d.in.wmat", dir.c_str(), file_prefix, beta_scaling, tau_hom, label.c_str(), sys->mpi_rank());
430  con_exte->write_to_file(strbuf);
431 
432  // save lifetime
433  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());
434  std::ofstream killfile;
435  killfile.open(strbuf);
436  killfile << sys->get_time()-primetime << std::endl;
437  killfile.close();
438 
439  if (errcode)
440  auryn_abort(errcode);
441 
442  logger->msg("Freeing ...",PROGRESS,true);
443  auryn_free();
444  return errcode;
445 }
void set_hom_trace(AurynFloat freq)
Definition: TripletConnection.cpp:127
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
The standard Monitor object to record spikes from a SpikingGroup and write them to a binary file...
Definition: BinarySpikeMonitor.h:48
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
void set_target_amplitude(AurynDouble ampl)
Definition: CorrelatedPoissonGroup.cpp:169
Abstract base class of all objects producing spikes.
Definition: SpikingGroup.h:67
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
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 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
virtual void set_all(AurynWeight weight)
Sets all weights of existing connections to the given value.
Definition: SparseConnection.cpp:335
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 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
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
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
Here is the call graph for this function: