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