-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Welcome to the NeuronNet wiki!
The simulator is based on the Hodgkin and Huxley’s model: Conductance based spike initiation and propagation, a single neuron model. The connections, or synapses, use a Hodgkin and Huxley derived model similar to synaptic transmission. Finally, these two models are programmatically connected to represent a functional biological network. Offline calculations are used to create calcium traces and finally create a calcium imaging video.
The simulator is a simple wrapper like class that manages the simulation of the networks.
The simulator object is created using
from Engine.ENNet import Simulator
sim = Simulator()
From now on, networks can be added or created, recorders can be added and both networks and recorders can be retrieved. The most important function of the simulator is
simulate(self, duration_ms, network=None, poolSize=None)
This function starts the simulation of the selected network or if None, all networks. This is done with x in parallel, where x is poolSize or the amount of cores found. Note that when using parallel processing, your script must begin with
if __name__ == '__main__':
The network class contains all the data regarding a network. It has two dictionaries with neurons and connections and also stores the time step, current time and the timeline. This class can be saved and reopened to continue simulating at a later date. The network class also contains all the logic for simulation.
__init__(self, neuronFun, neuronDict, synapseFun, synapseDict, dt, networkx=None, verbose=False, etaInterval=30, debugVerbose=False, progressCallback=None)
The class initialization requires a few things:
• neuronFun: The (default!) step or update function for the neuron. Defined in ENN_Models.py or local
• neuronDict: The (default!) starting dictionary to be processed by neuronFun
• synapseFun & synapseDict: Same as neuronFun and neuronDict
• dt: Network stepsize in ms
• networkx: Initializes the structure of the network using a networkx class. Extra information contained in the networkx class is copied to the (default) neuronDict. Different types of neurons and connections (edges) in the networkx object are not allowed.
• Verbose: Simulation information about the remaining time while simulating.
• etaInterval: every x seconds a time estimate for the simulation. If verbose==True
• debugVerbose: Outputs all timings & maybe more (total update time of neurons, synapses and recorders & combined time).
• progressCallback: Unused.
This example shows how to run a simulation with a simple model and plot the resulting Vm, u and I
` import networkx as nx import pylab as pl
from Engine.ENN_Models import * from Engine.ENNet import *
if name == 'main': # Use networkx library to create nodes and edges (neurons and synapses) N = 4000 # Set network size # Generate random network G = nx.fast_gnp_random_graph(N, p=0.15)
nx.draw_networkx(G,with_labels=True)
pl.show()
# Set time step size
dt = 0.05
# Create sim class
sim = Simulator()
# Create a neuron and synapse using the modelname
neuron = neuronIzh
synapse = erwinSynapse
gausNeuron = neuronGauss
neuronDict = {
'v':-65,
'u':0,
'I':0,
'a':0.02,
'b':0.2,
'c':-50,
'd':2
}
synapseDict = {
'I':([0] * int(1 / dt)),
'i':0,
'threshold': 10,
'w': 3 #Mathematisch gewicht (v*w) Zie synapse
}
gaussDict = {
'mu': 30,
'mean': 12,
'v': 0,
'I':0,
'u':0
}
# Create network with neurons of specified type and behavior
# And synapses of specified type and behavior
# Every network can have its own time step (dt)
network = Network(networkx=G, neuronFun=neuron, neuronDict=neuronDict, synapseFun=synapse, synapseDict=synapseDict,
dt=dt)
# Add one gaussian generator 'neuron' and link it to neuronId 0
neuron_id = network.addNeuron(neuronDict=gaussDict,neuronFun=gausNeuron)
network.connect(sourceId = neuron_id , destinationId = 0) # neuron id --> neuron 0
# You can also remove a neuron from the network.
# Effectivly removing all synapses as well
#network.deleteNeuron(id=3)
# you can get all neuron ids!
nIDs = network.getNeuronIDs() # All IDs from network
# Add network
id1 = sim.addNetwork(network)
# The same network, only tunneled through the simulator (all functions are availible, its just a reference to the network)
#id2 = sim.createNetwork(G,neuronClass = neuron,synapseClass = synapse,dt=dt) #returns network ID
#neuron_id2 = sim.getNetwork(networkId = id2).addNeuron(gausNeuron)
#sim.getNetwork(id2).connect(neuron_id2,1) # neuron_id2 --> neuron 1
# create recorders
m1 = Recorder(networkId = id1, neuronIds=range(40), variables=['v', 'I', 'u'],withTime=True) # withTime gives it a timeline variable.
#m2 = Recorder(networkId = id2, neuronIds=range(0,N), variables=['v', 'I', 'u']) #m1 already has a timeline
# Add recorders to network
m1id = sim.addRecorder(recorder=m1)
#m2id = sim.addRecorder(recorder=m2)
# You can use m1 variable (since its a reference)
# But you can recall one with the ID as well
#m1 = sim.getRecorder(recorderId = m1id)
#start simulation
t = clock()
sim.simulate(duration_ms = 100) #100ms ignoreWarnings (default) = false (will give warning if you change variables after simulation
print(clock()-t)
# you can change neurons and variables here and simulate again. No matter! (though you will get warnings)
for i in m1['v'].keys():
pl.subplot(3,1,1)
pl.plot(m1.timeline,m1['v'][i])
pl.hold(True)
pl.subplot(312)
pl.plot(m1.timeline,m1['u'][i])
pl.hold(True)
pl.subplot(313)
pl.plot(m1.timeline,m1['I'][i])
pl.hold(True)
pl.show()
`