def create_prototypes(vth=255, logicalCoreId=-1, noisy=0, synscale=1): prototypes = {} prototypes['vth'] = vth #setup compartment prototypes c_prototypes = {} n_prototypes = {} s_prototypes = {} #Q Neuron c_prototypes['somaProto'] = nx.CompartmentPrototype( vThMant=vth, compartmentCurrentDecay=4095, compartmentVoltageDecay=0, logicalCoreId=logicalCoreId, enableNoise=0, **noise_kwargs) c_prototypes['spkProto'] = nx.CompartmentPrototype( vThMant=vth, biasMant=int(vth / 2), biasExp=6, compartmentCurrentDecay=4095, compartmentVoltageDecay=0, thresholdBehavior=2, logicalCoreId=logicalCoreId, enableNoise=noisy, **noise_kwargs) c_prototypes['ememProto'] = nx.CompartmentPrototype( vThMant=vth, #vMaxExp=15, compartmentCurrentDecay=4095, compartmentVoltageDecay=0, thresholdBehavior=3, logicalCoreId=logicalCoreId, enableNoise=0, **noise_kwargs) c_prototypes['somaProto'].addDendrite([c_prototypes['spkProto']], nx.COMPARTMENT_JOIN_OPERATION.OR) c_prototypes['spkProto'].addDendrite([c_prototypes['ememProto']], nx.COMPARTMENT_JOIN_OPERATION.ADD) n_prototypes['qProto'] = nx.NeuronPrototype(c_prototypes['somaProto']) #Soft Reset Neuron c_prototypes['srSomaProto'] = nx.CompartmentPrototype( vThMant=vth, compartmentCurrentDecay=4095, compartmentVoltageDecay=0, logicalCoreId=logicalCoreId, enableNoise=0, **noise_kwargs) c_prototypes['srSpkProto'] = nx.CompartmentPrototype( vThMant=vth, biasMant=0, biasExp=6, compartmentCurrentDecay=4095, compartmentVoltageDecay=0, thresholdBehavior=2, logicalCoreId=logicalCoreId, enableNoise=noisy, **noise_kwargs) c_prototypes['intProto'] = nx.CompartmentPrototype( vThMant=vth, #vMaxExp=15, compartmentCurrentDecay=4095, compartmentVoltageDecay=4095, thresholdBehavior=0, logicalCoreId=logicalCoreId, enableNoise=0, **noise_kwargs) c_prototypes['srSomaProto'].addDendrite([c_prototypes['srSpkProto']], nx.COMPARTMENT_JOIN_OPERATION.OR) c_prototypes['srSpkProto'].addDendrite([c_prototypes['intProto']], nx.COMPARTMENT_JOIN_OPERATION.ADD) n_prototypes['srProto'] = nx.NeuronPrototype(c_prototypes['srSomaProto']) #FF Neuron c_prototypes['ffSomaProto'] = nx.CompartmentPrototype( vThMant=1, compartmentCurrentDecay=4095, compartmentVoltageDecay=0, logicalCoreId=logicalCoreId, enableNoise=0, **noise_kwargs) c_prototypes['ffSomaProto'].addDendrite([c_prototypes['ememProto']], nx.COMPARTMENT_JOIN_OPERATION.ADD) n_prototypes['ffProto'] = nx.NeuronPrototype(c_prototypes['ffSomaProto']) #Inverter compartment c_prototypes['invProto'] = nx.CompartmentPrototype( vThMant=1, biasMant=2, biasExp=6, compartmentVoltageDecay=0, functionalState=2, logicalCoreId=logicalCoreId, enableNoise=0, **noise_kwargs) #buffer / OR c_prototypes['bufferProto'] = nx.CompartmentPrototype( vThMant=1, compartmentVoltageDecay=4095, compartmentCurrentDecay=4095, logicalCoreId=logicalCoreId, enableNoise=0, **noise_kwargs) #AND c_prototypes['andProto'] = nx.CompartmentPrototype( vThMant=vth, compartmentCurrentDecay=4095, compartmentVoltageDecay=4095, logicalCoreId=logicalCoreId, enableNoise=0, **noise_kwargs) #Counter v_th_max = 2**17 - 1 c_prototypes['counterProto'] = nx.CompartmentPrototype( vThMant=v_th_max, compartmentCurrentDecay=4095, compartmentVoltageDecay=0, logicalCoreId=logicalCoreId, enableNoise=0, **noise_kwargs) #Connections #scaled vth used when synscale is being used to increase dynamic range vth = vth / synscale s_prototypes['econn'] = nx.ConnectionPrototype(weight=2) s_prototypes['iconn'] = nx.ConnectionPrototype(weight=-2) s_prototypes['invconn'] = nx.ConnectionPrototype(weight=-1) s_prototypes['vthconn'] = nx.ConnectionPrototype(weight=-vth) s_prototypes['spkconn'] = nx.ConnectionPrototype(weight=vth) s_prototypes['halfconn'] = nx.ConnectionPrototype(weight=int(vth / 2) + 1) s_prototypes['thirdconn'] = nx.ConnectionPrototype(weight=int(vth / 3) + 1) s_prototypes['single'] = nx.ConnectionPrototype(weight=2) prototypes['c_prototypes'] = c_prototypes prototypes['n_prototypes'] = n_prototypes prototypes['s_prototypes'] = s_prototypes return prototypes
def _create_prototypes(self): #setup compartment prototypes c_prototypes = {} n_prototypes = {} s_prototypes = {} #Q Neuron c_prototypes['somaProto'] = nx.CompartmentPrototype( vThMant=self.vth, compartmentCurrentDecay=4095, compartmentVoltageDecay=0) c_prototypes['spkProto'] = nx.CompartmentPrototype( vThMant=self.vth, compartmentCurrentDecay=4095, compartmentVoltageDecay=0, thresholdBehavior=2) c_prototypes['ememProto'] = nx.CompartmentPrototype( vThMant=self.vth, #vMaxExp=15, compartmentCurrentDecay=4095, compartmentVoltageDecay=0, thresholdBehavior=3) c_prototypes['somaProto'].addDendrite([c_prototypes['spkProto']], nx.COMPARTMENT_JOIN_OPERATION.OR) c_prototypes['spkProto'].addDendrite([c_prototypes['ememProto']], nx.COMPARTMENT_JOIN_OPERATION.ADD) n_prototypes['qProto'] = nx.NeuronPrototype(c_prototypes['somaProto']) #S Inverter c_prototypes['invProto'] = nx.CompartmentPrototype( vThMant=self.vth - 1, compartmentCurrentDecay=4095, compartmentVoltageDecay=0, thresholdBehavior=0, functionalState=2) c_prototypes['spkProto'] = nx.CompartmentPrototype( vThMant=self.vth - 1, biasMant=self.vth, biasExp=6, thresholdBehavior=0, compartmentCurrentDecay=4095, compartmentVoltageDecay=0, functionalState=2) c_prototypes['receiverProto'] = nx.CompartmentPrototype( vThMant=self.vth - 1, compartmentCurrentDecay=4095, compartmentVoltageDecay=0, thresholdBehavior=0) c_prototypes['invProto'].addDendrite( [c_prototypes['receiverProto']], nx.COMPARTMENT_JOIN_OPERATION.BLOCK) n_prototypes['invNeuron'] = nx.NeuronPrototype( c_prototypes['invProto']) #AND c_prototypes['andProto'] = nx.CompartmentPrototype( vThMant=self.vth, compartmentCurrentDecay=4095, compartmentVoltageDecay=4095) #Counter (debug) v_th_max = 2**17 - 1 c_prototypes['counterProto'] = nx.CompartmentPrototype( vThMant=v_th_max, compartmentCurrentDecay=4095, compartmentVoltageDecay=0) #Connections s_prototypes['econn'] = nx.ConnectionPrototype(weight=2) s_prototypes['iconn'] = nx.ConnectionPrototype(weight=-2) s_prototypes['vthconn'] = nx.ConnectionPrototype(weight=-self.vth) s_prototypes['spkconn'] = nx.ConnectionPrototype(weight=self.vth) s_prototypes['halfconn'] = nx.ConnectionPrototype( weight=int(self.vth / 2) + 1) s_prototypes['single'] = nx.ConnectionPrototype(weight=2) self.c_prototypes = c_prototypes self.n_prototypes = n_prototypes self.s_prototypes = s_prototypes
def __init__(self, params, net=None, name=None): """ The STDE_group contains the sTDE neurons. One neuron consists of 4 compartments that are connected as follows: D (main/soma) | C (current) / \\ (trigger) A B (facilitator) A is the gate and lets B's current pass whenever it spikes. C receives B's current on its voltage variable and decays D receives C's voltage and integrates it, so C is basically a second current input to D The two inputs are called trigger and facilitator following Milde (2018) params are 'tau_fac': current tau of facilitator input 'tau_trigg': current tau of trigger input 'tau_v': voltage tau of TDE Neuron 'tau_c': current tau of TDE Neuron 'weight_fac': amplitude of the facilitator spike 'do_probes' : can be 'all', 'spikes' or None 'num_neurons' : number of sTDE neurons that are created """ if net is None: net = nx.NxNet() self.net = net self.num_neurons = params['num_neurons'] self.neurongroups = {} self.probes = {} self.spikegens = {} weight_fac, exponent_fac = calculate_mant_exp( params['weight_fac'] / params['tau_fac'], 7) # Create auxiliary compartments cpA = nx.CompartmentPrototype( vThMant=1, compartmentCurrentDecay=int(1 / 1 * 2**12), compartmentVoltageDecay=4095, # thresholdBehavior=nx.COMPARTMENT_THRESHOLD_MODE.NO_SPIKE_AND_PASS_V_LG_VTH_TO_PARENT ) cpB = nx.CompartmentPrototype(vThMant=100, compartmentCurrentDecay=int( 1 / params['tau_fac'] * 2**12), compartmentVoltageDecay=4095) cpC = nx.CompartmentPrototype( vThMant=1000, compartmentCurrentDecay=int(1 / 1 * 2**12), compartmentVoltageDecay=int(1 / params['tau_trigg'] * 2**12), thresholdBehavior=nx.COMPARTMENT_THRESHOLD_MODE. NO_SPIKE_AND_PASS_V_LG_VTH_TO_PARENT) # Create main compartment cpD = nx.CompartmentPrototype( vThMant=100, compartmentCurrentDecay=int(1 / params['tau_v'] * 2**12), compartmentVoltageDecay=int(1 / params['tau_c'] * 2**12), ) # build compartment tree cpC.addDendrites(prototypeA=cpA, prototypeB=cpB, joinOp=nx.COMPARTMENT_JOIN_OPERATION.PASS) cpD.addDendrite(prototype=[cpC], joinOp=nx.COMPARTMENT_JOIN_OPERATION.ADD) num_neurons = params['num_neurons'] neuronPrototype = nx.NeuronPrototype(cpD) neurongroup = net.createNeuronGroup(prototype=neuronPrototype, size=num_neurons) sgpA = net.createSpikeGenProcess(numPorts=num_neurons) sgpB = net.createSpikeGenProcess(numPorts=num_neurons) # sgpC = net.createSpikeGenProcess(numPorts=1) connProto = nx.ConnectionPrototype(weight=weight_fac, weightExponent=exponent_fac) sgpA.connect(neurongroup.dendrites[0].dendrites[1], prototype=connProto, connectionMask=sp.sparse.identity(num_neurons)) sgpB.connect(neurongroup.dendrites[0].dendrites[0], prototype=connProto, connectionMask=sp.sparse.identity(num_neurons)) spikegens = [sgpA, sgpB] if params['do_probes'] == 'all': (uA, vA, sA) = neurongroup.dendrites[0].dendrites[1].probe([ nx.ProbeParameter.COMPARTMENT_CURRENT, nx.ProbeParameter.COMPARTMENT_VOLTAGE, nx.ProbeParameter.SPIKE ]) (uB, vB, sB) = neurongroup.dendrites[0].dendrites[0].probe([ nx.ProbeParameter.COMPARTMENT_CURRENT, nx.ProbeParameter.COMPARTMENT_VOLTAGE, nx.ProbeParameter.SPIKE ]) (uC, vC, sC) = neurongroup.dendrites[0].probe([ nx.ProbeParameter.COMPARTMENT_CURRENT, nx.ProbeParameter.COMPARTMENT_VOLTAGE, nx.ProbeParameter.SPIKE ]) (uD, vD, sD) = neurongroup.soma.probe([ nx.ProbeParameter.COMPARTMENT_CURRENT, nx.ProbeParameter.COMPARTMENT_VOLTAGE, nx.ProbeParameter.SPIKE ]) probes = { 'A_current': uA, 'A_voltage': vA, 'A_spikes': sA, 'B_current': uB, 'B_voltage': vB, 'B_spikes': sB, 'C_current': uC, 'C_voltage': vC, 'C_spikes': sC, 'D_current': uD, 'D_voltage': vD, 'D_spikes': sD, } elif params['do_probes'] == 'spikes': sA = neurongroup.dendrites[0].dendrites[1].probe( [nx.ProbeParameter.SPIKE]) sB = neurongroup.dendrites[0].dendrites[0].probe( [nx.ProbeParameter.SPIKE]) sC = neurongroup.dendrites[0].probe([nx.ProbeParameter.SPIKE]) sD = neurongroup.soma.probe([nx.ProbeParameter.SPIKE]) probes = { 'A_spikes': sA, 'B_spikes': sB, 'C_spikes': sC, 'D_spikes': sD, } else: probes = None self.neurongroup = neurongroup self.probes = probes self.spikegens = spikegens self.input0 = neurongroup.dendrites[0].dendrites[0] self.input1 = neurongroup.dendrites[0].dendrites[1]
def create_prototypes(self, vth=255, logicalCoreId=-1): prototypes = {} prototypes['vth'] = vth #setup compartment prototypes c_prototypes = {} n_prototypes = {} s_prototypes = {} #Q Neuron c_prototypes['somaProto'] = nx.CompartmentPrototype( vThMant=vth, compartmentCurrentDecay=4095, compartmentVoltageDecay=0, logicalCoreId=logicalCoreId) c_prototypes['spkProto'] = nx.CompartmentPrototype( vThMant=vth, compartmentCurrentDecay=4095, compartmentVoltageDecay=0, thresholdBehavior=2, logicalCoreId=logicalCoreId) c_prototypes['ememProto'] = nx.CompartmentPrototype( vThMant=vth, #vMaxExp=15, compartmentCurrentDecay=4095, compartmentVoltageDecay=0, thresholdBehavior=3, logicalCoreId=logicalCoreId) c_prototypes['somaProto'].addDendrite([c_prototypes['spkProto']], nx.COMPARTMENT_JOIN_OPERATION.OR) c_prototypes['spkProto'].addDendrite([c_prototypes['ememProto']], nx.COMPARTMENT_JOIN_OPERATION.ADD) n_prototypes['qProto'] = nx.NeuronPrototype(c_prototypes['somaProto']) #S Inverter c_prototypes['invProto'] = nx.CompartmentPrototype( vThMant=vth - 1, compartmentCurrentDecay=4095, compartmentVoltageDecay=0, thresholdBehavior=0, functionalState=2, logicalCoreId=logicalCoreId) c_prototypes['spkProto'] = nx.CompartmentPrototype( vThMant=vth - 1, biasMant=vth, biasExp=6, thresholdBehavior=0, compartmentCurrentDecay=4095, compartmentVoltageDecay=0, functionalState=2, logicalCoreId=logicalCoreId) c_prototypes['receiverProto'] = nx.CompartmentPrototype( vThMant=vth - 1, compartmentCurrentDecay=4095, compartmentVoltageDecay=0, thresholdBehavior=0, logicalCoreId=logicalCoreId) c_prototypes['invProto'].addDendrite([c_prototypes['receiverProto']], nx.COMPARTMENT_JOIN_OPERATION.BLOCK) n_prototypes['invNeuron'] = nx.NeuronPrototype(c_prototypes['invProto']) c_prototypes['bufferProto'] = nx.CompartmentPrototype( vThMant=1, compartmentCurrentDecay=4095, compartmentVoltageDecay=4095, logicalCoreId=logicalCoreId) #AND c_prototypes['andProto'] = nx.CompartmentPrototype( vThMant=vth, compartmentCurrentDecay=4095, compartmentVoltageDecay=4095, logicalCoreId=logicalCoreId) #Counter (debug) v_th_max = 2**17 - 1 c_prototypes['counterProto'] = nx.CompartmentPrototype( vThMant=v_th_max, compartmentCurrentDecay=4095, compartmentVoltageDecay=0, logicalCoreId=logicalCoreId) #Connections s_prototypes['econn'] = nx.ConnectionPrototype(weight=2) s_prototypes['iconn'] = nx.ConnectionPrototype(weight=-2) s_prototypes['vthconn'] = nx.ConnectionPrototype(weight=-vth) s_prototypes['spkconn'] = nx.ConnectionPrototype(weight=vth) s_prototypes['halfconn'] = nx.ConnectionPrototype(weight=int(vth / 2) + 1) s_prototypes['thirdconn'] = nx.ConnectionPrototype(weight=int(vth / 3) + 1) s_prototypes['single'] = nx.ConnectionPrototype(weight=2) prototypes['c_prototypes'] = c_prototypes prototypes['n_prototypes'] = n_prototypes prototypes['s_prototypes'] = s_prototypes return prototypes