# define a poisson spike-train rate = 10 # events per time unit length = 1.0 # one time unit isi = numpy.random.exponential(1.0 / rate, size=(rate * length * 2,)) # spike times t = numpy.add.accumulate(isi) spike_times = t[t < length] regimes = [] events = [] for i, t_spike in enumerate(spike_times): events += [nineml.On("t>%f" % t_spike, do=nineml.SpikeOutputEvent)] spiker = nineml.Regime(transitions=events) c1 = nineml.Component("Spike Generator", regimes=[spiker]) # write to file object f if defined try: # This case is used in the test suite for examples. c1.write(f) except NameError: import os base = "spike_generator" c1.write(base + ".xml") c2 = nineml.parse(base + ".xml") assert c1 == c2 c1.to_dot(base + ".dot") os.system("dot -Tpng %s -o %s" % (base + ".dot", base + ".png"))
regimes = [ nineml.Regime("dv/dt = Isyn", transitions=nineml.On( "V>Vth", do=["tspike = t", "V = Vrest", nineml.SpikeOutputEvent], to=refractory - regime), name="sub-threshold-regime"), nineml.Regime(transitions=nineml.On("t >= tspike + trefractory", to="sub-threshold-regime"), name="refractory-regime") ] ports = [nineml.ReducePort("Isyn", op="+")] leaky_iaf = nineml.Component("deltaLIFid5", regimes=regimes, ports=ports) # delta jump synapses regimes = [ nineml.Regime( "dv/dt = -g*v", transitions=nineml.On(nineml.SpikeInputEvent, do="g+=W"), ) ] ports = [nineml.RecvPort("W"), nineml.SendPort("Isyn = dv/dt")] # can i even send dv/dt as a variable? delta_syn = nineml.Component("delta_jump_id5", regimes=regimes, ports=ports)
"W -= o1*(A2_minus + A3_minus*r2)", "r1 += 1.0", "r2 += 1.0", nineml.EventPort("PreEventRelay", mode="send") ]), nineml.On(nineml.PostEvent, do=[ "W += r1*(A2_plus + A3_plus*o2)", "o1 += 1.0", "o2 += 1.0" ]) ]) ] ports = [nineml.SendPort("W")] c1 = nineml.Component("PfisterTripletSTDP", regimes=regimes, ports=ports) # write to file object f if defined try: # This case is used in the test suite for examples. c1.write(f) except NameError: import os base = "pfister_triplet_stdp" c1.write(base + ".xml") c2 = nineml.parse(base + ".xml") assert c1 == c2 c1.to_dot(base + ".dot") os.system("dot -Tpng %s -o %s" % (base + ".dot", base + ".png"))
"deps_o/dt = (1-eps_o)/tau_eo", transitions=[nineml.On(nineml.PreEvent, do=["W -= R * A_minus * eps_r * o * (W - Wmin) / (Wmax - Wmin), "W = max(W,W_min)", "r += eps_r", "eps_r = 0.0", nineml.PreEventRelay]), nineml.On(nineml.PostEvent, do=["W += R*A_plus*eps_o*r*(Wmax-W)/(Wmax-Wmin)", "W = max(W,W_max)", "o += eps_o", "eps_o = 0.0"])] )] ports = [nineml.RecvPort("R"), nineml.SendPort("W")] c1 = nineml.Component("RmulSTDPid7", regimes=regimes, ports=ports) # write to file object f if defined try: # This case is used in the test suite for examples. c1.write(f) except NameError: import os base = "RmulSTDPid7" c1.write(base + ".xml") c2 = nineml.parse(base + ".xml") assert c1 == c2 c1.to_dot(base + ".dot") os.system("dot -Tpng %s -o %s" % (base + ".dot", base + ".png"))
Author: Abigail Morrison, 1/2011. """ import nineml.abstraction_layer as nineml regimes = [ nineml.Regime("dV/dt = (Vrest - V)/(Rm*Cm) + Isyn/Cm", transitions=nineml.On( "V>Vth", do=["tspike = t", "V = Vrest", nineml.SpikeOutputEvent]), name="sub-threshold-regime") ] ports = [nineml.SendPort("V"), nineml.ReducePort("Isyn", op="+")] leaky_iaf = nineml.Component("gLIFid8", regimes=regimes, ports=ports) # alpha conductances regimes = [ nineml.Regime( "dg_a/dt = -g_a/tau_a", "dg/dt = g_a - g/tau_a", transitions=nineml.On(nineml.SpikeInputEvent, do="g+=W"), ) ] ports = [ nineml.RecvPort("V"), nineml.RecvPort("W"), nineml.SendPort("Isyn = g(E-V)")
transitions=[ nineml.On(nineml.PreEvent, do=[ "W -= lambda*alpha*W*o", "r += 1.0", nineml.EventPort("PreEventRelay", mode="send") ]), nineml.On( nineml.PostEvent, do=["W += (lambda*w0*(weight/w0)^mu*r", "o += 1.0"]) ]) ] ports = [nineml.SendPort("W")] c1 = nineml.Component("MorrisonPowerlawSTDP", regimes=regimes, ports=ports) # write to file object f if defined try: # This case is used in the test suite for examples. c1.write(f) except NameError: import os base = "morrison_powerlaw_stdp" c1.write(base + ".xml") c2 = nineml.parse(base + ".xml") assert c1 == c2 c1.to_dot(base + ".dot") os.system("dot -Tpng %s -o %s" % (base + ".dot", base + ".png"))
import nineml.abstraction_layer as nineml # note: this assumes that Pre/PostEvent are the arrival times of the event # at the synapse, i.e. after application of axonal or back-propagation delays regimes = [ nineml.Regime("dr/dt = -r/tau_plus", "do/dt = -o/tau_minus", transitions=[ nineml.On(nineml.PreEvent, do=[ "W = W - o*learning_rate*alpha*W", "r = r + 1.0", nineml.PreEventRelay ]), nineml.On( nineml.PostEvent, do=["W = W + r*learning_rate*(1-W)", "o = o + 1.0"]) ], name="basic regime") ] # should there be an additional parameter to scale the weight? ports = [nineml.SendPort("W")] STDPid8 = nineml.Component("STDP_id8", regimes=regimes, ports=ports) #"W = W - o*learning_rate*alpha*W**mu", #"W = max(W,0.0)", #W = W + r*learning_rate*(1-W)**mu", #"W = min(W,1.0)",
nineml.Regime( "dr/dt = -r/tau_plus", "do/dt = -o/tau_minus", transitions=[nineml.On(nineml.PreEvent, do=["W -= W_max * A_minus * o, "W = max(W,0.0)", "r += 1.0", nineml.PreEventRelay]), nineml.On(nineml.PostEvent, do=["W += W_max*A_plus*r", "W = min(W,W_max)", "o += 1.0"])] )] ports = [nineml.SendPort("W")] c1 = nineml.Component("STDPid1", regimes=regimes, ports=ports) # write to file object f if defined try: # This case is used in the test suite for examples. c1.write(f) except NameError: import os base = "STDPid1" c1.write(base + ".xml") c2 = nineml.parse(base + ".xml") assert c1 == c2 c1.to_dot(base + ".dot") os.system("dot -Tpng %s -o %s" % (base + ".dot", base + ".png"))
Hebbian Plasticity, J. Neuroscience, 23(9) 3697--3714 Author: Abigail Morrison, 1/2011. """ import nineml.abstraction_layer as nineml regimes = [ nineml.Regime(transitions=nineml.On(nineml.SpikeInputEvent, do=nineml.SpikeOutputEvent), name="ongoing-regime") ] linear_poiss = nineml.Component("LPNid8", regimes=regimes, ports=[]) inter_event_regime = nineml.Regime(transitions=nineml.On( nineml.SpikeInputEvent, do=["pfire = W/N", "p = rand()"], to="probabilistic_regime"), name="inter_event_regime") probabilistic_regime = nineml.Regime(transitions=[ nineml.On("pfire >= p", do=nineml.SpikeInputEventRelay, to=inter_event_regime), nineml.On("pfire < p", to=inter_event_regime) ], name="probabilistic_regime")
name="hh_regime", transitions=al.On("V > theta", do=[al.SpikeOutputEvent])) parameters = [ 'el', 'C', 'ek', 'ena', 'gkbar', 'gnabar', 'theta', 'gl', 'celsius' ] ports = [ al.SendPort("V"), al.ReducePort("Isyn", op="+"), al.ReducePort("I", op="+"), # "op" keyword argument determines how multiple inputs to this port are handled ? ] c1 = al.Component("Hodgkin-Huxley-id14", parameters=parameters, regimes=(hh_regime, ), aliases=aliases, ports=ports) # write to file object f if defined try: # This case is used in the test suite for examples. c1.write(f) except NameError: base = "HHid14" c1.write(base + ".xml") c2 = al.parse(base + ".xml") assert c1 == c2 c1.to_dot(base + ".dot")
transitions=[nineml.On("V>Vth", "set_tspike")], events=[nineml.SpikeOutputPort("V>Vth")], name="sub-threshold-regime"), nineml.Union("tspike = t", "V = Vreset", transitions=[nineml.On("true", "refractory-regime")], name="set_tspike"), nineml.Union(transitions=[ nineml.On("t >= tspike + trefractory", "sub-threshold-regime") ], name="refractory-regime") ] ports = [nineml.Port("V"), nineml.ReducePort("Isyn", op="+")] c1 = nineml.Component("LeakyIAF", regimes=regimes, ports=ports) # this is a hack until 9ml defines units, # which defines the unit of time in Brian ODE __time_factor__ = 1. * units.ms model = brian9ml.NineMLStateUpdater(c1, solver=NonlinearStateUpdater, base_regime=regimes[0]) # Initial conditions init = {'V': 0.0, 'U': 0.0, 'Isyn': 1.0} t_init = [init.get(x, 0.0) for x in model.state_vars] # Threshold is 0.5 to detect a spike event on the spikeout var, # which is 0.0 if no spike, 1.0 if spike on that clock tick.