def RobotConnect4L(Ns, Nm): """ Construct four layers of Izhikevich neurons and connect them together. Layers 0 and 1 comprise sensory neurons, while layers 2 and 3 comprise motor neurons. Sensory neurons excite contralateral motor neurons causing seeking behaviour. Layers are heterogenous populations of Izhikevich neurons with slightly different parameter values. Inputs: Ns -- Number of neurons in sensory layers Nm -- Number of neurons in motor layers """ F = 50.0 / np.sqrt(Ns) # Scaling factor Dmax = 5 # Maximum conduction delay N = 2 * Ns + 2 * Nm net = IzNetwork(N, Dmax) r = rn.rand(N) a = 0.02 * np.ones(N) b = 0.2 * np.ones(N) c = -65 + 15 * (r**2) d = 8 - 6 * (r**2) oneBlock = np.ones((Ns, Nm)) # Block [i,j] is the connection from layer i to layer j W = np.bmat([[ np.zeros((Ns, Ns)), np.zeros((Ns, Ns)), np.zeros((Ns, Nm)), F * oneBlock ], [ np.zeros((Ns, Ns)), np.zeros((Ns, Ns)), F * oneBlock, np.zeros((Ns, Nm)) ], [ np.zeros((Ns, Nm)), np.zeros((Ns, Nm)), np.zeros((Nm, Nm)), np.zeros((Nm, Nm)) ], [ np.zeros((Ns, Nm)), np.zeros((Ns, Nm)), np.zeros((Nm, Nm)), np.zeros((Nm, Nm)) ]]) D = Dmax * np.ones((N, N), dtype=int) net.setParameters(a, b, c, d) net.setDelays(D) net.setWeights(W) return net
def Connect2L(N0, N1): """ Constructs two layers of Izhikevich neurons and connects them together. Layers are arrays of N neurons. Parameters for regular spiking neurons extracted from: http://www.izhikevich.org/publications/spikes.htm """ F = 50 / np.sqrt(N1) # Scaling factor D = 5 # Conduction delay Dmax = 10 # Maximum conduction delay net = IzNetwork([N0, N1], Dmax) # Neuron parameters # Each layer comprises a heterogenous set of neurons, with a small spread # of parameter values, so that they exhibit some dynamical variation # (To get a homogenous population of canonical "regular spiking" neurons, # multiply r by zero.) # Layer 0 (regular spiking) r = rn.rand(N1) net.layer[0].N = N0 net.layer[0].a = 0.02 * np.ones(N0) net.layer[0].b = 0.20 * np.ones(N0) net.layer[0].c = -65 + 15 * (r**2) net.layer[0].d = 8 - 6 * (r**2) # Layer 1 (regular spiking) r = rn.rand(N1) net.layer[1].N = N1 net.layer[1].a = 0.02 * np.ones(N1) net.layer[1].b = 0.20 * np.ones(N1) net.layer[1].c = -65 + 15 * (r**2) net.layer[1].d = 8 - 6 * (r**2) ## Connectivity matrix (synaptic weights) # layer[i].S[j] is the connectivity matrix from layer j to layer i # S(i,j) is the strength of the connection from neuron j to neuron i net.layer[1].S[0] = np.ones([N1, N0]) net.layer[1].factor[0] = F net.layer[1].delay[0] = D * np.ones([N1, N0], dtype=int) return net
def RobotConnect4L(Ns, Nm): """ Construct four layers of Izhikevich neurons and connect them together. Layers 0 and 1 comprise sensory neurons, while layers 2 and 3 comprise motor neurons. Sensory neurons excite contralateral motor neurons causing seeking behaviour. Layers are heterogenous populations of Izhikevich neurons with slightly different parameter values. Inputs: Ns -- Number of neurons in sensory layers Nm -- Number of neurons in motor layers """ F = 50.0/np.sqrt(Ns) # Scaling factor Dmax = 5 # Maximum conduction delay N = 2*Ns + 2*Nm net = IzNetwork(N, Dmax) r = rn.rand(N) a = 0.02*np.ones(N) b = 0.2*np.ones(N) c = -65 + 15*(r**2) d = 8 - 6*(r**2) oneBlock = np.ones((Ns, Nm)) # Block [i,j] is the connection from layer i to layer j W = np.bmat([[np.zeros((Ns,Ns)), np.zeros((Ns, Ns)), np.zeros((Ns,Nm)), F*oneBlock], [np.zeros((Ns,Ns)), np.zeros((Ns, Ns)), F*oneBlock, np.zeros((Ns,Nm))], [np.zeros((Ns,Nm)), np.zeros((Ns, Nm)), np.zeros((Nm,Nm)), np.zeros((Nm,Nm))], [np.zeros((Ns,Nm)), np.zeros((Ns, Nm)), np.zeros((Nm,Nm)), np.zeros((Nm,Nm))]]) D = Dmax*np.ones((N,N), dtype=int) net.setParameters(a, b, c, d) net.setDelays(D) net.setWeights(W) return net
from jpype import * import os import numpy.random as rn import sys sys.path.append('../q1') from IzNetwork import IzNetwork from Plot import * path = os.getcwd() + "/infodynamics.jar" startJVM(getDefaultJVMPath(), "-Djava.class.path=" + path) p = rn.random() runtime = 60000 IN = IzNetwork(p, runtime) IN.run() print("{},{}".format(p, analyseFirings(IN.firings))) shutdownJVM()
def RobotConnectAvoidance(Ns, Nm): """ Construct four layers of Izhikevich neurons and connect them together, just as RobotConnect4L. Layers 0 and 1 comprise sensory neurons, while layers 2 and 3 comprise motor neurons. In this case, sensory neurons excite ipsilateral motor neurons causing avoidance behaviour. Inputs: Ns -- Number of neurons in sensory layers Nm -- Number of neurons in motor layers """ F = 50.0 / np.sqrt(Ns) # Scaling factor D = 4 # Conduction delay Dmax = 5 # Maximum conduction delay net = IzNetwork([Ns, Ns, Nm, Nm], Dmax) # Layer 0 (Left sensory neurons) r = rn.rand(Ns) net.layer[0].N = Ns net.layer[0].a = 0.02 * np.ones(Ns) net.layer[0].b = 0.20 * np.ones(Ns) net.layer[0].c = -65 + 15 * (r**2) net.layer[0].d = 8 - 6 * (r**2) # Layer 1 (Right sensory neurons) r = rn.rand(Ns) net.layer[1].N = Ns net.layer[1].a = 0.02 * np.ones(Ns) net.layer[1].b = 0.20 * np.ones(Ns) net.layer[1].c = -65 + 15 * (r**2) net.layer[1].d = 8 - 6 * (r**2) # Layer 2 (Left motor neurons) r = rn.rand(Nm) net.layer[2].N = Nm net.layer[2].a = 0.02 * np.ones(Nm) net.layer[2].b = 0.20 * np.ones(Nm) net.layer[2].c = -65 + 15 * (r**2) net.layer[2].d = 8 - 6 * (r**2) # Layer 3 (Right motor neurons) r = rn.rand(Nm) net.layer[3].N = Nm net.layer[3].a = 0.02 * np.ones(Nm) net.layer[3].b = 0.20 * np.ones(Nm) net.layer[3].c = -65 + 15 * (r**2) net.layer[3].d = 8 - 6 * (r**2) # Connectivity matrix (synaptic weights) # layer[i].S[j] is the connectivity matrix from layer j to layer i # s[i,j] is the streght of the connection from neuron j to neuron i # Connect 0 to 2 and 1 to 3 for seeking behaviour net.layer[2].S[0] = np.ones([Nm, Ns]) net.layer[2].factor[0] = F net.layer[2].delay[0] = D * np.ones([Nm, Ns], dtype=int) net.layer[3].S[1] = np.ones([Nm, Ns]) net.layer[3].factor[1] = F net.layer[3].delay[1] = D * np.ones([Nm, Ns], dtype=int) return net
def BuildNetwork(rewiringProb): """ Create a network with ExiNumrewiringProberMod*moduleNum excitatory Izhikevich neurons with 200 Inhibitory neurons, respectively. """ moduleNum = 8 ExiNumPerMod = 100 ExiModConnNum = 1000 InhiNum = 200 InhiToExciNum = 4 N = moduleNum * ExiNumPerMod + InhiNum Dmax = 20 # Max synaptic delay, in ms net = IzNetwork(N, Dmax) EtoESF = 17.0 EtoISF = 50.0 ItoESF = 2.0 ItoISF = 1.0 EtoEW = lambda: 1.0 EtoIW = lambda: rn.rand() ItoEW = lambda: -rn.rand() ItoIW = lambda: -rn.rand() # Build Excitatory modules Modules = np.zeros([moduleNum, ExiNumPerMod, ExiNumPerMod]) EtoEMatrix = np.zeros([ExiNumPerMod * moduleNum, ExiNumPerMod * moduleNum]) for i in range(moduleNum): Module = BuildExcitoryModule(ExiNumPerMod, ExiModConnNum, EtoEW) Modules[i, :, :] = Module startX = i * ExiNumPerMod endX = startX + ExiNumPerMod EtoEMatrix[startX:endX, startX:endX] = Module # Rewiring Excitatory modules EtoEMx = EtoEMatrix[0:ExiNumPerMod * moduleNum, 0:ExiNumPerMod * moduleNum] for i in range(moduleNum): originalModule = Modules[i] for xCor in range(ExiNumPerMod): for yCor in range(ExiNumPerMod): if originalModule[xCor, yCor] > 0.0: if rn.rand() < rewiringProb: moduleIndex = rn.randint(0, 8, dtype="int") while moduleIndex == i: moduleIndex = rn.randint(0, 8, dtype="int") NeuronIndex = rn.randint(0, 100, dtype="int") xIndex = i * ExiNumPerMod + xCor yIndex = i * ExiNumPerMod + yCor # Delete original Wire EtoEMx[xIndex, yIndex] = 0.0 # Rewire newYIndex = moduleIndex * ExiNumPerMod + NeuronIndex EtoEMx[xIndex, newYIndex] = EtoEW() EtoEMatrix[0:ExiNumPerMod * moduleNum, 0:ExiNumPerMod * moduleNum] = EtoEMx # Connect Excitatory to Inhibitory Neurons EtoIMatrix = np.zeros([ExiNumPerMod * moduleNum, InhiNum]) randomInhiIndex = rn.choice(InhiNum, size=InhiNum, replace=False) for inhibitory in range(InhiNum): index = randomInhiIndex[inhibitory] for j in range(InhiToExciNum): EtoIMatrix[4 * index + j, inhibitory] = EtoIW() ItoEMatrix = np.zeros([InhiNum, ExiNumPerMod * moduleNum]) for i in range(InhiNum): for j in range(ExiNumPerMod * moduleNum): ItoEMatrix[i, j] = ItoEW() ItoIMatrix = np.zeros([InhiNum, InhiNum]) for i in range(InhiNum): for j in range(InhiNum): ItoIMatrix[i, j] = ItoIW() # Build network as a block matrix. Block [i,j] is the connection from # neuron i to neuron j WeightMatrix = np.bmat([[EtoESF * EtoEMatrix, EtoISF * EtoIMatrix], [ItoESF * ItoEMatrix, ItoISF * ItoIMatrix]]) WeightMatrix = np.array(WeightMatrix) # Plot connectivity matrix plt.matshow(WeightMatrix, vmin=-2.0, vmax=50.0) plt.show() CDMatrix = np.ones([N, N], dtype="int") for i in range(N): for j in range(N): if WeightMatrix[i, j] > 0.0: if i < ExiNumPerMod * moduleNum and j < ExiNumPerMod * moduleNum: randomDelay = rn.randint(0, 20, dtype="int") CDMatrix[i, j] = CDMatrix[i, j] + randomDelay # Plot connection delay matrix # plt.matshow(CDMatrix, vmin=1.0, vmax=20.0) # plt.show() # All neurons are heterogeneous excitatory or inhibitory regular spiking As = np.zeros([ 1000, ]) Bs = np.zeros([ 1000, ]) Cs = np.zeros([ 1000, ]) Ds = np.zeros([ 1000, ]) for i in range(1000): # print is r = rn.rand() if i < 800: # Exi Ea = 0.02 Eb = 0.2 Ec = -65 + 15 * (r**2) Ed = 8 - 6 * (r**2) As[i] = Ea Bs[i] = Eb Cs[i] = Ec Ds[i] = Ed else: # Inhibitory Ia = 0.02 + 0.08 * r Ib = 0.25 - 0.05 * r Ic = -65 Id = 2 As[i] = Ia Bs[i] = Ib Cs[i] = Ic Ds[i] = Id net.setWeights(WeightMatrix) net.setDelays(CDMatrix) net.setParameters(np.array(As), np.array(Bs), np.array(Cs), np.array(Ds)) return net
def Sync2Connect(N1, N2): """ Constructs two populations of neurons (comprising two layers each) that oscillate in the gamma range using PING, and that can be couped together to study various synchronisation phenomena Coupling the excitatory populations causes the populations to synhronise 180 degrees out of phase with each other if they have the same natural frequency. Coupling the inhibitory populations causes complete synchronisation with zero phase lag, even if they have slightly different natural frequencies. """ # Conduction delays - 2 for 56Hz, 5 for 40Hz, 8 for 32Hz D1 = 6 D2 = 4 D = 5 # conduction delay for inter-population connections net = IzNetwork([N1, N2, N1, N2], max(D1, D2) + 1) # Neuron parameters # Each layer comprises a heterogenous set of neurons, with a small spread # of parameter values, so that they exhibit some dynamical variation # Layer 0 (excitatory - regular spiking) r = rn.rand(N1) net.layer[0].N = N1 net.layer[0].a = 0.02 * np.ones(N1) net.layer[0].b = 0.20 * np.ones(N1) net.layer[0].c = -65 + 15*(r**2) net.layer[0].d = 8 - 6*(r**2) # Layer 1 (inhibitory - fast spiking) r = rn.rand(N2) net.layer[1].N = N2 net.layer[1].a = 0.02 + 0.08*r net.layer[1].b = 0.25 - 0.05*r net.layer[1].c = -65 * np.ones(N2) net.layer[1].d = 2 * np.ones(N2) # Layer 2 (excitatory - regular spiking) r = rn.rand(N1) net.layer[2].N = N1 net.layer[2].a = 0.02 * np.ones(N1) net.layer[2].b = 0.20 * np.ones(N1) net.layer[2].c = -65 + 15*(r**2) net.layer[2].d = 8 - 6*(r**2) # Layer 3 (inhibitory - fast spiking) r = rn.rand(N2) net.layer[3].N = N2 net.layer[3].a = 0.02 + 0.08*r net.layer[3].b = 0.25 - 0.05*r net.layer[3].c = -65 * np.ones(N2) net.layer[3].d = 2 * np.ones(N2) # Connectivity matrix (synaptic weights) # layer{i}.S{j} is the connectivity matrix from layer j to layer i # s(i,j) is the strength of the connection from neuron j to neuron i # Excitatory to inhibitory connections net.layer[1].S[0] = rn.rand(N2, N1) net.layer[3].S[2] = rn.rand(N2, N1) # Inhibitory to excitatory connections net.layer[0].S[1] = -1.0*rn.rand(N1, N2) net.layer[2].S[3] = -1.0*rn.rand(N1, N2) # Excitatory to excitatory connections net.layer[0].S[0] = 1*(rn.rand(N1, N1) < 0.01) net.layer[2].S[2] = 1*(rn.rand(N1, N1) < 0.01) # Inhibitory to inhibitory connections net.layer[1].S[1] = -1.0*rn.rand(N2, N2) net.layer[3].S[3] = -1.0*rn.rand(N2, N2) # Coupling between populations (excitatory to excitatory) net.layer[2].S[0] = 1*(rn.rand(N1, N1) < 0.01) net.layer[0].S[2] = 1*(rn.rand(N1, N1) < 0.01) # Coupling between populations (excitatory to inhibitory) net.layer[3].S[0] = 1*(rn.rand(N2, N1) < 0.01) net.layer[1].S[2] = 1*(rn.rand(N2, N1) < 0.01) ## Scaling factors # Within oscillator 1 net.layer[1].factor[0] = 2 net.layer[0].factor[1] = 2 net.layer[0].factor[0] = 17 # use 5 if excitatory couplings exist net.layer[1].factor[1] = 2 # Within oscillator 2 net.layer[3].factor[2] = 2 net.layer[2].factor[3] = 2 net.layer[2].factor[2] = 17 # use 5 if excitatory couplings exist net.layer[3].factor[3] = 2 # Excit-Excit coupling. Deactivated by default net.layer[2].factor[0] = 0 net.layer[0].factor[2] = 0 # Excit-Inhib coupling net.layer[3].factor[0] = 12 net.layer[1].factor[2] = 12 ## Conduction delays # Within oscillator 1 net.layer[1].delay[0] = D1 * np.ones([N2, N1]) net.layer[0].delay[1] = D1 * np.ones([N1, N2]) net.layer[0].delay[0] = D1 * np.ones([N1, N1]) net.layer[1].delay[1] = D1 * np.ones([N2, N2]) # Within oscillator 2 net.layer[3].delay[2] = D2 * np.ones([N2, N1]) net.layer[2].delay[3] = D2 * np.ones([N1, N2]) net.layer[2].delay[2] = D2 * np.ones([N1, N1]) net.layer[3].delay[3] = D2 * np.ones([N2, N2]) net.layer[2].delay[0] = D * np.ones([N1, N1]) net.layer[0].delay[2] = D * np.ones([N1, N1]) net.layer[3].delay[0] = D * np.ones([N2, N1]) net.layer[1].delay[2] = D * np.ones([N2, N1]) return net
def RobotConnect4L(Ns, Nm, Ni): """ Construct six layers of Izhikevich neurons and connect them together. Layers 0 and 1 comprise sensory neurons, while layers 2 and 3 comprise motor neurons, and layers 4 and 5 comprise inhibitory neurons. Sensory neurons excite contralateral motor neurons causing seeking behaviour. Layers are heterogenous populations of Izhikevich neurons with slightly different parameter values. Inputs: Ns -- Number of neurons in sensory layers Nm -- Number of neurons in motor layers Ni -- Number of neurons in inhibitory layers """ F = 50.0/np.sqrt(Ns) # Scaling factor D = 4 # Conduction delay Dmax = 5 # Maximum conduction delay net = IzNetwork([Ns, Ns, Nm, Nm, Ni, Ni], Dmax) # Layer 0 (Left sensory neurons) r = rn.rand(Ns) net.layer[0].N = Ns net.layer[0].a = 0.02 * np.ones(Ns) net.layer[0].b = 0.20 * np.ones(Ns) net.layer[0].c = -65 + 15*(r**2) net.layer[0].d = 8 - 6*(r**2) # Layer 1 (Right sensory neurons) r = rn.rand(Ns) net.layer[1].N = Ns net.layer[1].a = 0.02 * np.ones(Ns) net.layer[1].b = 0.20 * np.ones(Ns) net.layer[1].c = -65 + 15*(r**2) net.layer[1].d = 8 - 6*(r**2) # Layer 2 (Left motor neurons) r = rn.rand(Nm) net.layer[2].N = Nm net.layer[2].a = 0.02 * np.ones(Nm) net.layer[2].b = 0.20 * np.ones(Nm) net.layer[2].c = -65 + 15*(r**2) net.layer[2].d = 8 - 6*(r**2) # Layer 3 (Right motor neurons) r = rn.rand(Nm) net.layer[3].N = Nm net.layer[3].a = 0.02 * np.ones(Nm) net.layer[3].b = 0.20 * np.ones(Nm) net.layer[3].c = -65 + 15*(r**2) net.layer[3].d = 8 - 6*(r**2) # Layer 4 (Left inhibitory neurons) r = rn.rand(Ni) net.layer[4].N = Ni net.layer[4].a = 0.02 * np.ones(Nm) net.layer[4].b = 0.20 * np.ones(Nm) net.layer[4].c = -65 + 15*(r**2) net.layer[4].d = 8 - 6*(r**2) # Layer 5 (Right inhibitory neurons) r = rn.rand(Ni) net.layer[5].N = Ni net.layer[5].a = 0.02 * np.ones(Nm) net.layer[5].b = 0.20 * np.ones(Nm) net.layer[5].c = -65 + 15*(r**2) net.layer[5].d = 8 - 6*(r**2) # Connectivity matrix (synaptic weights) # layer[i].S[j] is the connectivity matrix from layer j to layer i # s[i,j] is the streght of the connection from neuron j to neuron i # Connect 0 to 3 and 1 to 2 for seeking behaviour net.layer[3].S[0] = np.ones([Nm, Ns]) net.layer[3].factor[0] = F net.layer[3].delay[0] = D * np.ones([Nm, Ns], dtype=int) net.layer[2].S[1] = np.ones([Nm, Ns]) net.layer[2].factor[1] = F net.layer[2].delay[1] = D * np.ones([Nm, Ns], dtype=int) # Connect 2 to 4 and 3 to 5 net.layer[4].S[2] = np.ones([Ni, Nm]) net.layer[4].factor[2] = F net.layer[4].delay[2] = D * np.ones([Ni, Nm], dtype=int) net.layer[5].S[3] = np.ones([Ni, Nm]) net.layer[5].factor[3] = F net.layer[5].delay[3] = D * np.ones([Ni, Nm], dtype=int) # Connect 2 to 5 and 3 to 4 net.layer[3].S[4] = (-1)*np.ones([Ni, Nm]) net.layer[3].factor[4] = F net.layer[3].delay[4] = D * np.ones([Ni, Nm], dtype=int) net.layer[2].S[5] = (-1)*np.ones([Ni, Nm]) net.layer[2].factor[5] = F net.layer[2].delay[5] = D * np.ones([Ni, Nm], dtype=int) # Connect 4 and 5 (both ways) net.layer[4].S[5] = (-1)*np.ones([Ni, Ni]) net.layer[4].factor[5] = F net.layer[4].delay[5] = D * np.ones([Ni, Ni], dtype=int) net.layer[5].S[4] = (-1)*np.ones([Ni, Ni]) net.layer[5].factor[4] = F net.layer[5].delay[4] = D * np.ones([Ni, Ni], dtype=int) return net