def run_stdp(NE,NI,v_init,C_e,C_ii,C_ie,mon_bin,dt): from brian.neurongroup import NeuronGroup from brian.monitor import PopulationRateMonitor from brian.stdunits import mV, ms, nS, pF, pA, Hz from brian.units import second from brian.equations import Equations from brian.network import Network from brian.connections import Connection from brian.stdp import STDP from brian.clock import Clock runtime = 10*second eta = 1e-2 # Learning rate tau_stdp = 20*ms # STDP time constant alpha = 3*Hz*tau_stdp*2 # Target rate parameter gmax = 100 # Maximum inhibitory weight eqs_neurons=''' dv/dt=(-gl*(v-el)-(g_ampa*w*v+g_gaba*(v-er)*w)+bgcurrent)/memc : volt dg_ampa/dt = -g_ampa/tau_ampa : 1 dg_gaba/dt = -g_gaba/tau_gaba : 1 ''' namespace = {'tau_ampa':5.0*ms,'tau_gaba':10.0*ms, 'bgcurrent':200*pA,'memc':200.0*pF, 'el':-60*mV,'w':1.*nS,'gl':10.0*nS,'er':-80*mV} eqs_neurons = Equations(eqs_neurons, ** namespace) clock = Clock(dt) neurons=NeuronGroup(NE+NI,model=eqs_neurons,clock=clock, threshold=-50.*mV,reset=-60*mV,refractory=5*ms) neurons.v = v_init Pe=neurons.subgroup(NE) Pi=neurons.subgroup(NI) rme = PopulationRateMonitor(Pe,mon_bin) rmi = PopulationRateMonitor(Pi,mon_bin) con_e = Connection(Pe,neurons,'g_ampa') con_ie = Connection(Pi,Pe,'g_gaba') con_ii = Connection(Pi,Pi,'g_gaba') con_e.connect_from_sparse(C_e, column_access=True) con_ie.connect_from_sparse(C_ie, column_access=True) con_ii.connect_from_sparse(C_ii, column_access=True) eqs_istdp = ''' dA_pre/dt=-A_pre/tau_stdp : 1 dA_post/dt=-A_post/tau_stdp : 1 ''' stdp_params = {'tau_stdp':tau_stdp, 'eta':eta, 'alpha':alpha} eqs_istdp = Equations(eqs_istdp, **stdp_params) stdp_ie = STDP(con_ie, eqs=eqs_istdp, pre='''A_pre+=1. w+=(A_post-alpha)*eta''', post='''A_post+=1. w+=A_pre*eta''', wmax=gmax) net = Network(neurons, con_e, con_ie, con_ii, stdp_ie, rme, rmi) net.run(runtime,report='text') return (rme.times,rme.rate), (rmi.times,rmi.rate)
def __init__(self, expr='', level=0, **kwds): self._eventdriven={} # dictionary event driven variables (RHS) # might be set to True in the Synapses __init__ function if the model # equations refer to variables in the pre- or postsynaptic group. # In this case, the model is never linear self.refers_others = False Equations.__init__(self, expr, level=level+1, **kwds)
def __init__(self, expr='', level=0, **kwds): self._eventdriven = {} # dictionary event driven variables (RHS) # might be set to True in the Synapses __init__ function if the model # equations refer to variables in the pre- or postsynaptic group. # In this case, the model is never linear self.refers_others = False Equations.__init__(self, expr, level=level + 1, **kwds)
def add_diffeq(self, name, eq, unit, global_namespace={}, local_namespace={}, nonzero=True): ''' unit may contain "(event-driven)" ''' pattern = re.compile("(\w+)\s*\(event\-driven\)\s*") result = pattern.match(unit) # event-driven if result: unit, = result.groups() # We treat as a diff eq to get the correct namespaces Equations.add_diffeq(self, name, eq, unit, global_namespace, local_namespace, nonzero=False) if isinstance(unit, Quantity): unit = scalar_representation(unit) self._string[name] = '0*' + unit + '/second' self._namespace[name]['second'] = second # then add it to the list of event-driven variables self._eventdriven[name] = eq else: Equations.add_diffeq(self, name, eq, unit, global_namespace, local_namespace, nonzero)
def current_clamp(vm='vm', i_inj='i_inj', v_rec='v_rec', i_cmd='i_cmd', Re=80 * Mohm, Ce=4 * pF, bridge=0 * ohm, capa_comp=0 * farad, v_uncomp=None): ''' Continuous current-clamp amplifier + electrode. vm = membrane potential (or electrode) variable i_inj = injected current (into the neuron) v_rec = recorded potential i_cmd = command current bridge = bridge resistance compensation capa_comp = capacitance neutralization Re = electrode resistance Ce = electrode capacitance (input capacitance) v_uncomp = uncompensated potential (raw measured potential) ''' if capa_comp != Ce: return Equations(''' Vr=U-R*Ic : volt I=(U-V)/Re : amp dU/dt=(Ic-I)/(Ce-CC) : volt ''', Vr=v_rec, V=vm, I=i_inj, Ic=i_cmd, R=bridge, Ce=Ce, CC=capa_comp, U=v_uncomp, Re=Re) else: return Equations(''' Vr=V+(Re-R)*I : volt I=Ic : amp # not exactly an alias because the units of Ic is unknown ''', Vr=v_rec, V=vm, I=i_inj, Ic=i_cmd, R=bridge, Re=Re)
def voltage_clamp(vm='vm', v_cmd='v_cmd', i_rec='i_rec', i_inj='i_inj', Re=20 * Mohm, Rs=0 * Mohm, tau_u=1 * ms): ''' Continuous voltage-clamp amplifier + ideal electrode (= input capacitance is already neutralized). vm = membrane potential (or electrode) variable v_cmd = command potential i_inj = injected current (into the neuron) i_rec = recorded current (= -i_inj) Re = electrode resistance Rs = series resistance compensation tau_u = delay of series compensation (for stability) ''' return Equations(''' Irec=-I : amp I=(Vc+U-Vr)/Re : amp dU/dt=(Rs*I-U)/tau : volt ''', Vr=vm, Vc=v_cmd, I=i_inj, Rs=Rs, tau=tau_u, Irec=i_rec, Re=Re)
def __init__(self, N, clock, params=default_params): # x=input # r=firing rate # a=adaptation signal # e=efficacy # tau_r1 = firing rate rise time constant # tau_r2 = firing rate decay rate # tau_ar = adaptation rate # tau_a = adaptation recovery rate # eta = rate - adaptation gain eqs=Equations(''' dr/dt=x/tau_r1-r/tau_r2 : 1 da/dt=(eta*r)/tau_ar-a/tau_a : 1 e=1.0-a : 1 tau_a : second tau_r1 : second tau_r2 : second tau_ar : second eta : 1 x : 1 ''') NeuronGroup.__init__(self, N, model=eqs, compile=True, freeze=True, clock=clock) self.N=N self.params=params self.tau_a=self.params.tau_a self.tau_r1=self.params.tau_r1 self.tau_r2=self.params.tau_r2 self.tau_ar=self.params.tau_ar self.eta=self.params.eta
def add_diffeq(self, name, eq, unit, global_namespace={}, local_namespace={}, nonzero=True): ''' unit may contain "(event-driven)" ''' pattern=re.compile("(\w+)\s*\(event\-driven\)\s*") result=pattern.match(unit) # event-driven if result: unit, = result.groups() # We treat as a diff eq to get the correct namespaces Equations.add_diffeq(self,name, eq, unit, global_namespace, local_namespace, nonzero=False) if isinstance(unit, Quantity): unit = scalar_representation(unit) self._string[name]='0*' + unit + '/second' self._namespace[name]['second']=second # then add it to the list of event-driven variables self._eventdriven[name]=eq else: Equations.add_diffeq(self,name, eq, unit, global_namespace, local_namespace, nonzero)
def separate_equations(eqs, additional_dependencies=[]): eqs.prepare() all_vars = eqs._string.keys() # Construct a list of dependency sets, where each variable in each # dependency set induces a dependency on each other variable in each # dependency set depsets = [] for var in all_vars: ids = set(get_identifiers(eqs._string[var])) ids = ids.intersection(all_vars) ids.add(var) depsets.append(ids) for expr in additional_dependencies: ids = set(get_identifiers(expr)) ids = ids.intersection(all_vars) depsets.append(ids) # Construct a graph deps which indicates what variable depends on which # other variables (or is depended on by other variables). deps = defaultdict(set) for ids in depsets: for id1 in ids: for id2 in ids: deps[id1].add(id2) # Extract all the independent subgraphs ind_graphs = [] while len(deps): ind_graphs.append(set(next_independent_subgraph(deps).keys())) if len(ind_graphs) == 1: return [eqs] # Finally, we construct an Equations object for each of the subgraphs ind_eqs = [] for G in ind_graphs: neweqs = Equations() for var in G: if var in eqs._eq_names: neweqs.add_eq(var, eqs._string[var], eqs._units[var], local_namespace=eqs._namespace[var]) elif var in eqs._diffeq_names: nonzero = var in eqs._diffeq_names_nonzero neweqs.add_diffeq(var, eqs._string[var], eqs._units[var], local_namespace=eqs._namespace[var], nonzero=nonzero) elif var in eqs._alias.keys(): neweqs.add_alias(var, eqs._string[var].strip()) else: assert False ind_eqs.append(neweqs) return ind_eqs
def OrnsteinUhlenbeck(x, mu, sigma, tau): ''' An Ornstein-Uhlenbeck process. mu = mean sigma = standard deviation tau = time constant x = name of the variable Returns an Equations() object ''' return Equations('dx/dt=(mu-x)*invtau+sigma*((2.*invtau)**.5)*xi : unit', \ x=x, mu=mu, sigma=sigma, invtau=1. / tau, unit=get_unit(mu))
def __init__(self, P, V, I, clock=None): eqs = Equations(''' record : units_record command : units_command ''', units_record=P.unit(V), units_command=P.unit(I)) NeuronGroup.__init__(self, len(P), model=eqs, clock=clock) self._P = P self._V = V self._I = I
def test_equations_examples(self): from brian.equations import Equations from brian import stdunits # parameter __time_factor__ = 1. * stdunits.ms # eqns e = Equations(""" dV/dt = (-V/(c*tau))/__time_factor__ : 1. c = V**2 : 1. """) assert e._diffeq_names == ['V'] assert e._eq_names == ['c'] e = Equations(""" c = c+u : 1. """) assert e._diffeq_names == ['V'] assert e._eq_names == ['c']
def electrode(Re, Ce, v_el='v_el', vm='vm', i_inj='i_inj', i_cmd='i_cmd'): ''' An intracellular electrode modeled as an RC circuit, or multiple RC circuits in series (if Re, Ce are lists). v_el = electrode (=recording) potential vm = membrane potential i_inj = current entering the membrane i_cmd = electrode command current (None = no injection) Returns an Equations() object. ''' if isSequenceType(Re): if len(Re) != len(Ce) or len(Re) < 2: raise TypeError, "Re and Ce must have the same length" v_mid, i_mid = [], [] for i in range(len(Re) - 1): v_mid.append('v_mid_' + str(i) + unique_id()) i_mid.append('i_mid_' + str(i) + unique_id()) eqs = electrode(Re[0], Ce[0], v_mid[0], vm, i_inj, i_mid[0]) for i in range(1, len(Re) - 1): eqs + electrode(Re[i], Ce[i], v_mid[i], v_mid[i - 1], i_mid[i - 1], i_mid[i]) eqs += electrode(Re[-1], Ce[-1], v_el, v_mid[-1], i_mid[-1], i_cmd) return eqs else: if Ce > 0 * farad: return Equations(''' dvr/dt = ((vm-vr)/Re+ic)/Ce : mV ie = (vr-vm)/Re : nA''', vr=v_el, vm=vm, ic=i_cmd, ie=i_inj, \ Re=Re, Ce=Ce) else: # ideal electrode - pb here return Equations(''' vr = vm+Re*ic : volt ie = ic : amp''', vr=v_el, vm=vm, ic=i_cmd, ie=i_inj)
def __init__(self, morphology=None, model=None, threshold=None, reset=NoReset(), refractory=0 * ms, level=0, clock=None, unit_checking=True, compile=False, freeze=False, implicit=True, Cm=0.9 * uF / cm**2, Ri=150 * ohm * cm, bc_type=2, diffeq_nonzero=True): clock = guess_clock(clock) N = len(morphology) # number of compartments if isinstance(model, str): model = Equations(model, level=level + 1) model += Equations(''' v:volt # membrane potential ''') # Process model equations (Im) to extract total conductance and the remaining current if use_sympy: try: membrane_eq = model._string['Im'] # the membrane equation except: raise TypeError, "The transmembrane current Im must be defined" # Check conditional linearity ids = get_identifiers(membrane_eq) _namespace = dict.fromkeys( ids, 1. ) # there is a possibility of problems here (division by zero) _namespace['v'] = AffineFunction() eval(membrane_eq, model._namespace['v'], _namespace) try: eval(membrane_eq, model._namespace['v'], _namespace) except: # not linear raise TypeError, "The membrane current must be linear with respect to v" # Extracts the total conductance from Im, and the remaining current z = symbolic_eval(membrane_eq) symbol_v = sympy.Symbol('v') b = z.subs(symbol_v, 0) a = -sympy.simplify(z.subs(symbol_v, 1) - b) gtot_str = "_gtot=" + str(a) + ": siemens/cm**2" I0_str = "_I0=" + str(b) + ": amp/cm**2" model += Equations( gtot_str + "\n" + I0_str, level=level + 1) # better: explicit insertion with namespace of v else: raise TypeError, "The Sympy package must be installed for SpatialNeuron" # Equations for morphology (isn't it a duplicate??) eqs_morphology = Equations(""" diameter : um length : um x : um y : um z : um area : um**2 """) full_model = model + eqs_morphology NeuronGroup.__init__(self, N, model=full_model, threshold=threshold, reset=reset, refractory=refractory, level=level + 1, clock=clock, unit_checking=unit_checking, implicit=implicit) self.model_with_diffeq_nonzero = diffeq_nonzero self._state_updater = SpatialStateUpdater(self, clock) self.Cm = ones(len(self)) * Cm self.Ri = Ri self.bc_type = bc_type #default boundary condition on leaves self.bc = ones(len(self)) # boundary conditions on branch points self.changed = True # Insert morphology self.morphology = morphology self.morphology.compress(diameter=self.diameter, length=self.length, x=self.x, y=self.y, z=self.z, area=self.area)
def create_netobjs(stim, params): C = params['Cap'] KappaN = params['Kappan'] KappaP = params['Kappap'] I0N = params['I0n'] I0P = params['I0p'] Ut = params['Ut'] Delta_t = (Ut / KappaP) #Feed-Forward parameters i_inj = params['i_inj'] i_injinh1 = params['i_injinh1'] i_injinh2 = params['i_injinh2'] i_injinh3 = params['i_injinh3'] i_injinh4 = params['i_injinh4'] i_leak = params['i_leak'] tau_syn_E = params['tau_syn_E'] tau_syn_I = params['tau_syn_I'] tau_synloc_E = params['tau_synloc_E'] tau_synloc_IE = params['tau_synloc_IE'] v_thresh = params['v_thresh'] w_syn_E1 = params['w_syn_E1'] w_syn_E2 = params['w_syn_E2'] w_syn_I = params['w_syn_I'] w_synloc_E = params['w_synloc_E'] w_synloc_EE = params['w_synloc_EE'] w_synloc_EI = params['w_synloc_EI'] w_synloc_IE = params['w_synloc_IE'] w_synloc_S = params['w_synloc_S'] ##Feed-Back parameters #w =dict() #w['e'] =1e-11 #w['i'] =5e-11/N_IP1 #w['ei'] =2e-11/N_EP1 eqs = Equations(''' dV/dt=(-I_lk + I_fb + I_in + Ia + Iloce - Iloci - Ii)/C: volt I_fb = I0P*exp((V-v_thresh)/Delta_t) : amp I_in : amp I_lk = i_leak : amp dIa/dt=-Ia/tau_syn_E: amp dIloce/dt=-Iloce/tau_synloc_E: amp dIloci/dt=-Iloci/tau_synloc_IE: amp dIi/dt=-Ii/tau_syn_I: amp ''') EIP = NeuronGroup(N, model=eqs, reset=0, threshold=1.5, refractory=.001) EP1 = EIP[:N_EP1] IP1 = EIP[N_EP1:] EP1.I_in = np.random.normal(1, sigma_mismatch, N_EP1) * i_inj IP1.I_in = np.random.normal(1,sigma_mismatch,N_IP1)*\ np.array([i_injinh1, i_injinh2, i_injinh3, i_injinh4]) #Create connections between population v_loclat = np.zeros([N_EP1]) v_loclat[N_EP1 / 2] = w_synloc_S v_loclat[[N_EP1 / 2 - 1, N_EP1 / 2 + 1]] = w_synloc_E v_loclat[[N_EP1 / 2 - 2, N_EP1 / 2 + 2]] = w_synloc_EE v_loclat[[N_EP1 / 2 - 3, N_EP1 / 2 + 3]] = w_synloc_EE / 2 v_loclat = np.roll(v_loclat, -N_EP1 / 2) W = np.array([np.roll(v_loclat, i) for i in range(N_EP1)]) W *= np.random.normal(1, sigma_mismatch, W.shape) ConnE = Connection(EP1, EP1, 'Iloce') ConnE.connect(EP1, EP1, W) ConnEI = Connection(EP1, IP1, 'Iloce') ConnEI.connect( EP1, IP1, W=w_synloc_EI * np.random.normal(1, sigma_mismatch, [len(EP1), len(IP1)])) ConnIE = Connection(IP1, EP1, 'Iloci') ConnIE.connect( IP1, EP1, W=w_synloc_IE * np.random.normal(1, sigma_mismatch, [len(IP1), len(EP1)])) M_EIP = SpikeMonitor(EIP) MV_EIP = StateMonitor(EIP, 'V', record=range(0, N), timestep=int(1 * ms / defaultclock.dt)) @network_operation def update_mpot(): EIP.V[EIP.V < 0.] = 0. # ME_EP1= StateMonitor(EP1,'Ie',record=range(0,N_EP1),timestep=int(1*ms/defaultclock.dt)) # MI_EP1= StateMonitor(EP1,'Ii',record=range(0,N_EP1),timestep=int(1*ms/defaultclock.dt)) # MW_EP1= StateMonitor(EP1,'Ia',record=range(0,N_EP1),timestep=int(1*ms/defaultclock.dt)) netobjs = { 'EIP': EIP, 'update_mpot': update_mpot, 'ConnE': ConnE, 'ConnEI': ConnEI, 'ConnIE': ConnIE, #'M_In1': M_In1, 'M_EIP': M_EIP, 'MV_EIP': MV_EIP } return netobjs, M_EIP, MV_EIP
def __init__(self, params=default_params, pyr_params=pyr_params(), inh_params=inh_params(), plasticity_params=plasticity_params(), background_input=None, task_inputs=None, clock=defaultclock): self.params = params self.pyr_params = pyr_params self.inh_params = inh_params self.plasticity_params = plasticity_params self.background_input = background_input self.task_inputs = task_inputs ## Set up equations # Exponential integrate-and-fire neuron eqs = exp_IF(params.C, params.gL, params.EL, params.VT, params.DeltaT) eqs += Equations('g_muscimol : nS') # AMPA conductance - recurrent input current eqs += exp_synapse('g_ampa_r', params.tau_ampa, siemens) eqs += Current('I_ampa_r=g_ampa_r*(E-vm): amp', E=params.E_ampa) # AMPA conductance - background input current eqs += exp_synapse('g_ampa_b', params.tau_ampa, siemens) eqs += Current('I_ampa_b=g_ampa_b*(E-vm): amp', E=params.E_ampa) # AMPA conductance - task input current eqs += exp_synapse('g_ampa_x', params.tau_ampa, siemens) eqs += Current('I_ampa_x=g_ampa_x*(E-vm): amp', E=params.E_ampa) # Voltage-dependent NMDA conductance eqs += biexp_synapse('g_nmda', params.tau1_nmda, params.tau2_nmda, siemens) eqs += Equations('g_V = 1/(1+(Mg/3.57)*exp(-0.062 *vm/mV)) : 1 ', Mg=params.Mg) eqs += Current('I_nmda=g_V*g_nmda*(E-vm): amp', E=params.E_nmda) # GABA-A conductance eqs += exp_synapse('g_gaba_a', params.tau_gaba_a, siemens) eqs += Current('I_gaba_a=(g_gaba_a+g_muscimol)*(E-vm): amp', E=params.E_gaba_a) eqs += InjectedCurrent('I_dcs: amp') # Total synaptic conductance eqs += Equations( 'g_syn=g_ampa_r+g_ampa_x+g_ampa_b+g_V*g_nmda+g_gaba_a : siemens') eqs += Equations( 'g_syn_exc=g_ampa_r+g_ampa_x+g_ampa_b+g_V*g_nmda : siemens') # Total synaptic current eqs += Equations( 'I_abs=(I_ampa_r**2)**.5+(I_ampa_b**2)**.5+(I_ampa_x**2)**.5+(I_nmda**2)**.5+(I_gaba_a**2)**.5 : amp' ) NeuronGroup.__init__(self, params.network_group_size, model=eqs, threshold=-20 * mV, refractory=1 * ms, reset=params.Vr, compile=True, freeze=True, clock=clock) self.init_subpopulations() self.init_connectivity(clock)
def __init__(self, morphology=None, model=None, threshold=None, reset=NoReset(), refractory=0 * ms, level=0, clock=None, unit_checking=True, compile=False, freeze=False, Cm=0.9 * uF / cm**2, Ri=150 * ohm * cm): clock = guess_clock(clock) N = len(morphology) # number of compartments if isinstance(model, str): model = Equations(model, level=level + 1) model += Equations(''' v:volt # membrane potential ''') # Process model equations (Im) to extract total conductance and the remaining current if use_sympy: try: membrane_eq = model._string['Im'] # the membrane equation except: raise TypeError, "The transmembrane current Im must be defined" # Check conditional linearity ids = get_identifiers(membrane_eq) _namespace = dict.fromkeys( ids, 1. ) # there is a possibility of problems here (division by zero) _namespace['v'] = AffineFunction() eval(membrane_eq, model._namespace['v'], _namespace) try: eval(membrane_eq, model._namespace['v'], _namespace) except: # not linear raise TypeError, "The membrane current must be linear with respect to v" # Extracts the total conductance from Im, and the remaining current z = symbolic_eval(membrane_eq) symbol_v = sympy.Symbol('v') b = z.subs(symbol_v, 0) a = -sympy.simplify(z.subs(symbol_v, 1) - b) gtot_str = "_gtot=" + str(a) + ": siemens/cm**2" I0_str = "_I0=" + str(b) + ": amp/cm**2" model += Equations( gtot_str + "\n" + I0_str, level=level + 1) # better: explicit insertion with namespace of v else: raise TypeError, "The Sympy package must be installed for SpatialNeuron" # Equations for morphology (isn't it a duplicate??) eqs_morphology = Equations(""" diameter : um length : um x : um y : um z : um area : um**2 """) full_model = model + eqs_morphology # Create the state updater NeuronGroup.__init__(self, N, model=full_model, threshold=threshold, reset=reset, refractory=refractory, level=level + 1, clock=clock, unit_checking=unit_checking, implicit=True) #Group.__init__(self, full_model, N, unit_checking=unit_checking, level=level+1) #self._eqs = model #var_names = full_model._diffeq_names self.Cm = Cm # could be a vector? self.Ri = Ri self._state_updater = SpatialStateUpdater(self, clock) #S0 = {} # Fill missing units #for key, value in full_model._units.iteritems(): # if not key in S0: # S0[key] = 0 * value #self._S0 = [0] * len(var_names) #for var, i in zip(var_names, count()): # self._S0[i] = S0[var] # Insert morphology self.morphology = morphology self.morphology.compress(diameter=self.diameter, length=self.length, x=self.x, y=self.y, z=self.z, area=self.area)
def is_linear(self): if self.refers_others: return False return Equations.is_linear(self)
print("Preparing simulation ...") defaultclock.dt = dt = 0.1*msecond duration = 0.2*second w = 2*msecond # coincidence window for npss Vrest = -60*mvolt Vth = -50*mvolt tau = 20*msecond n_ext = 1000 p_ext = 0.5 p_int = 0.05 w_ext = 0.1*mvolt r_ext = 10*hertz w_int = 0.09*mvolt lif_eq = Equations("dV/dt = (Vrest-V)/tau : volt") lif_eq.prepare() lif_group = NeuronGroup(1000, lif_eq, threshold="V>Vth", reset=Vrest, refractory=2*msecond) inp_group = PoissonGroup(n_ext, rates=r_ext) # external input only applied to a part of the network n_ext_rec = 100 inp_conn = Connection(inp_group, lif_group[:n_ext_rec], weight=w_ext, sparseness=p_ext, fixed=True, delay=5*msecond) asympt_inp = n_ext*p_ext*w_ext*r_ext*tau voltage_range = Vth-Vrest if asympt_inp <= voltage_range: print("Network spikes unlikely to occur: %f <= %f" % ( asympt_inp, voltage_range)) # print("Aborting!")
self._P.state(self._I)[:] = -self.record # Inject if self._estimation: I = 2. * (rand() - .5) * self._amp + self._DC self.record = -I # Record self._Vrec.append(V[0]) self._Irec.append(I) if self._compensation: # Compensate self._lastI[self._posI] = -self.record[0] self._posI = (self._posI - 1) % self._ktail V[0] = V[0] - sum( self.Ke * self._lastI[range(self._posI, self._ktail) + range(0, self._posI)]) self._J += self.clock._dt * self._gain2 * (self.command - V) self.record = -(self._gain * (self.command - V) + self._J) if __name__ == '__main__': from brian import * taum = 20 * ms gl = 20 * nS Cm = taum * gl eqs = Equations('dv/dt=(-gl*v+i_inj)/Cm : volt') + electrode( 50 * Mohm, 10 * pF, vm='v', i_cmd=.5 * nA) neuron = NeuronGroup(1, model=eqs) M = StateMonitor(neuron, 'v_el', record=True) run(100 * ms) plot(M.times / ms, M[0] / mV) show()
else: assert False ind_eqs.append(neweqs) return ind_eqs if __name__ == '__main__': from brian import * # T = second # eqs = Equations(''' # da/dt = y/T : 1 # db/dt = x/T : 1 # c : 1 # x = c # y = x*x : 1 # dd/dt = e/T : 1 # de/dt = d/T : 1 # df/dt = e/T : 1 # ''') tau_pre = tau_post = 10 * ms eqs = Equations(""" dA_pre/dt = -A_pre/tau_pre : 1 dA_post/dt = -A_post/tau_post : 1 """) eqs_sep = separate_equations(eqs) for e in eqs_sep: print '******************' print e