Changes for page Code description
Last modified by galluzziandrea on 2022/06/20 12:33
From version 8.1
edited by galluzziandrea
on 2021/12/09 14:58
on 2021/12/09 14:58
Change comment:
There is no comment for this version
To version 9.1
edited by galluzziandrea
on 2021/12/09 15:04
on 2021/12/09 15:04
Change comment:
There is no comment for this version
Summary
-
Page properties (1 modified, 0 added, 0 removed)
Details
- Page properties
-
- Content
-
... ... @@ -323,6 +323,197 @@ 323 323 endbuild = time.time() 324 324 {{/code}} 325 325 326 +=== Connecting the network nodes: neuronal populations, Poisson processes and spike detectors === 327 + 328 +{{code language="python"}} 329 +#############################------------------------------------------------------------------------ 330 +print("Connecting ") 331 +#############################------------------------------------------------------------------------ 332 + 333 +startconnect = time.time() 334 +Connessioni=[] 335 +Medie=[] 336 + 337 +#create and define the connections between the populations of neurons and the poisson generators 338 +#and between the populations of neurons and the spike detectors with the parameters extracted from the.ini files 339 + 340 +for i in range(0,int(InfoBuild[0])): 341 + nest.Connect(NoisePop[i], NeuronPop[i], syn_spec={'synapse_model': 'static_synapse_hpc', 342 + 'delay': dt, 343 + 'weight': nest.math.redraw(nest.random.normal(mean=float(InfoConnectNoise[i+1][0]), 344 + std=(float(InfoConnectNoise[i+1][1])*float(InfoConnectNoise[i+1][0]))), 345 + min=0., max=float('Inf')) 346 + }) 347 + nest.Connect(NeuronPop[i][:int(InfoBuild[i+1][0])], DetectorPop[i], syn_spec={"weight": 1.0, "delay": dt}) 348 + 349 +#create and define the connections between the populations of neurons with the parameters extracted from the.ini files 350 + 351 +for i in range(0,len(InfoConnectPop[1:])): 352 + 353 + conn=nest.Connect(NeuronPop[int(InfoConnectPop[i+1][1])], NeuronPop[int(InfoConnectPop[i+1][0])], 354 + {'rule': 'pairwise_bernoulli', 355 + 'p':float(InfoConnectPop[i+1][2]) }, 356 + syn_spec={'synapse_model': 'static_synapse_hpc', 357 + 'delay':nest.math.redraw(nest.random.exponential(beta=float(1./(2.99573227355/(float(InfoConnectPop[i+1][4])-float(InfoConnectPop[i+1][3]))))), 358 + min= numpy.max([dt,float(1./float(InfoConnectPop[i+1][4]))]), 359 + max= float(1./(float(InfoConnectPop[i+1][3])-dt/2))), 360 + 361 + 'weight':nest.random.normal(mean=float(InfoConnectPop[i+1][6]), 362 + std=math.fabs(float(InfoConnectPop[i+1][6])*float(InfoConnectPop[i+1][7])))}) 363 + 364 + 365 +endconnect = time.time() 366 +{{/code}} 367 + 368 +=== === 369 + 370 +=== === 371 + 372 +=== Simulating: neuronal time evolution. === 373 + 374 +=== === 375 + 376 +{{code language="python"}} 377 + #############################------------------------------------------------------------------------ 378 + print("Simulating") 379 + #############################------------------------------------------------------------------------ 380 + ################################################################################################################################################################### 381 + if Salva: 382 + print("I m going to save the data") 383 + #x=str(iterazioni) 384 + f = open(FileName,"w") 385 + if len(InfoProtocol): 386 + print("I m going to split the simulation") 387 + tempo=0 388 + for contatore in range(0,len(InfoProtocol)): 389 + appoggio1=int((tempo+InfoProtocol[contatore][0])/1000.) 390 + appoggio2=int(tempo/1000.) 391 + appoggio3=tempo+InfoProtocol[contatore][0] 392 + if (appoggio1-appoggio2)>=1: 393 + T1=(1+appoggio2)*1000-tempo 394 + nest.Simulate(T1) 395 + #Save the Data!!!! 396 + ########################################################### 397 + Equilibri=[] 398 + for i in range(0,int(InfoBuild[0])): 399 + Equilibri.append([]) 400 + a=nest.GetStatus(DetectorPop[i])[0]["events"]["times"] 401 + if len(a)>0: 402 + Trange=(1000*int(numpy.min(a)/1000.),1000*int(numpy.min(a)/1000.)+1000) 403 + hist,Tbin=numpy.histogram(a,200,(Trange[0],Trange[1])) 404 + Equilibri[i]=hist*1000./(5.*int(InfoBuild[i+1][0])) 405 + else: 406 + Trange=(1000*int(tempo/1000.),1000*int(tempo/1000.)+1000) 407 + hist=numpy.zeros(200) 408 + Tbin=numpy.linspace(Trange[0],Trange[1],num=201) 409 + Equilibri[i]=hist 410 + nest.SetStatus(DetectorPop[i],{'n_events':0}) 411 + for j in range(0,len(hist)): 412 + f.write(str(Tbin[j])+" ") 413 + for i in range(0,int(InfoBuild[0])): 414 + f.write(str(Equilibri[i][j])+" ") 415 + f.write("\n ") 416 + ########################################################### 417 + tempo=tempo+T1 418 + for contatore2 in range(1,(appoggio1-appoggio2)): 419 + nest.Simulate(1000.) 420 + #Save the Data!!!! 421 + ########################################################### 422 + Equilibri=[] 423 + for i in range(0,int(InfoBuild[0])): 424 + Equilibri.append([]) 425 + a=nest.GetStatus(DetectorPop[i])[0]["events"]["times"] 426 + if len(a)>0: 427 + Trange=(1000*int(numpy.min(a)/1000.),1000*int(numpy.min(a)/1000.)+1000) 428 + hist,Tbin=numpy.histogram(a,200,(Trange[0],Trange[1])) 429 + Equilibri[i]=hist*1000./(5.*int(InfoBuild[i+1][0])) 430 + else: 431 + Trange=(1000*int(tempo/1000.),1000*int(tempo/1000.)+1000) 432 + hist=numpy.zeros(200) 433 + Tbin=numpy.linspace(Trange[0],Trange[1],num=201) 434 + Equilibri[i]=hist 435 + nest.SetStatus(DetectorPop[i],{'n_events':0}) 436 + for j in range(0,len(hist)): 437 + f.write(str(Tbin[j])+" ") 438 + for i in range(0,int(InfoBuild[0])): 439 + f.write(str(Equilibri[i][j])+" ") 440 + f.write("\n ") 441 + tempo=tempo+1000. 442 + T2=appoggio3-tempo 443 + nest.Simulate(T2); 444 + tempo=tempo+T2; 445 + else: 446 + nest.Simulate(InfoProtocol[contatore][0]) 447 + temp=InfoProtocol[contatore][0] 448 + tempo=tempo+temp 449 + if InfoProtocol[contatore][2]==4: 450 + nest.SetStatus(NoisePop[InfoProtocol[contatore][1]],params={"rate": float(InfoBuild[1+InfoProtocol[contatore][1]][2]*InfoProtocol[contatore][3])}) 451 + if InfoProtocol[contatore][2]==12: 452 + nest.SetStatus(NeuronPop[InfoProtocol[contatore][1]], params={"b": float(InfoProtocol[contatore][3])}) 453 + else: 454 + nest.Simulate(simtime) 455 + tempo=simtime 456 + if (simtime-tempo)>0.: 457 + nest.Simulate(simtime-tempo) 458 + 459 + 460 + endsimulate = time.time() 461 + f.close() 462 + else: 463 + if len(InfoProtocol): 464 + tempo=0 465 + for contatore in range(0,len(InfoProtocol)): 466 + nest.Simulate(InfoProtocol[contatore][0]) 467 + temp=InfoProtocol[contatore][0] 468 + tempo=tempo+temp 469 + if InfoProtocol[contatore][2]==4: 470 + nest.SetStatus(NoisePop[InfoProtocol[contatore][1]],params={"rate": float(InfoBuild[1+InfoProtocol[contatore][1]][2]*InfoProtocol[contatore][3])}) 471 + #print "Population:", InfoProtocol[contatore][1] ,";Parameter:", InfoProtocol[contatore][2] ,"; Value: ",InfoProtocol[contatore][3] 472 + if InfoProtocol[contatore][2]==12: 473 + nest.SetStatus(NeuronPop[InfoProtocol[contatore][1]], params={"b": float(InfoProtocol[contatore][3])}) 474 + #print "Population:", InfoProtocol[contatore][1] ,";Parameter:", InfoProtocol[contatore][2] ,"; Value: ",InfoProtocol[contatore][3] 475 + 476 + else: 477 + nest.Simulate(simtime) 478 + tempo=simtime 479 + if (simtime-tempo)>0.: 480 + nest.Simulate(simtime-tempo) 481 + endsimulate = time.time() 482 + 483 + 484 + ################################################################################################################################################################### 485 + 486 + #############################------------------------------------------------------------------------ 487 + #print some information from the simulation 488 + #############################------------------------------------------------------------------------ 489 + 490 + num_synapses = nest.GetDefaults('static_synapse_hpc')["num_connections"] 491 + build_time = endbuild - startbuild 492 + connect_time = endconnect - startconnect 493 + sim_time = endsimulate - endconnect 494 + 495 + N_neurons=0 496 + for i in range(0,int(InfoBuild[0])): 497 + N_neurons=N_neurons+int(InfoBuild[i+1][0]) 498 + 499 + print(" Network simulation (Python) neuron type:",InfoPerseo[0]) 500 + print("Number of neurons : {0}".format(N_neurons)) 501 + print("Number of synapses: {0}".format(num_synapses)) 502 + print("Building time : %.2f s" % build_time) 503 + print("Connecting time : %.2f s" % connect_time) 504 + print("Simulation time : %.2f s" % sim_time) 505 + 506 +Fine=time.time() 507 +print ("Total Simulation time : %.2f s" % (Fine-Inizio)) 508 +{{/code}} 509 + 510 +=== === 511 + 326 326 === Results === 327 327 514 + 515 + 516 + 517 + 518 + 328 328 ==== ====
- Introduction (path and modules):
- Check where I am and place myself in the right folder:
- Import the modules necessary for the simulation:
- Define necessary classes to import the Initialization Files:
- Import the initialization files:
- Defining general and nest.kernel parameters
- Building the network: neuronal populations , Poisson processes and spike detectors
- Connecting the network nodes: neuronal populations, Poisson processes and spike detectors
- Simulating: neuronal time evolution.
- Results: