"V": -60.0, # membrane potential "m": 0.0529324, # prob. for Na channel activation "h": 0.3176767, # prob. for not Na channel blocking "n": 0.5961207 } # prob. for K channel activation s_ini = {"g": -0.2} ps_p = { "tau": 1.0, # Decay time constant [ms] "E": -80.0 } # Reversal potential [mV] stim_ini = {"startSpike": [0], "endSpike": [1]} pop1 = model.add_neuron_population("Pop1", 10, "TraubMiles", p, ini) stim = model.add_neuron_population("Stim", 1, "SpikeSourceArray", {}, stim_ini) model.add_synapse_population("Pop1self", "SPARSE_GLOBALG", 10, pop1, pop1, "StaticPulse", {}, s_ini, {}, {}, "ExpCond", ps_p, {}, init_connectivity(ring_model, {})) model.add_synapse_population("StimPop1", "SPARSE_GLOBALG", NO_DELAY, stim, pop1, "StaticPulse", {}, s_ini, {}, {}, "ExpCond", ps_p, {}, init_connectivity("OneToOne", {})) stim.set_extra_global_param("spikeTimes", [0.0]) model.build() model.load() v = np.empty((2000, 10))
while True: filename = "weights_%u_%u.npy" % (len(weights), len(weights) + 1) if path.exists(filename): weights.append(np.load(filename)) else: break # weights[1] = np.random.uniform(G_MAX/2, G_MAX, (128,10)) # Initial values to initialise all neurons to if_init = {"V": 0.0, "SpikeCount": 0} rm_init = {"V": 50.0, "preV": 50.0} # Create first neuron layer neuron_layers = [ model.add_neuron_population("neuron0", weights[0].shape[0], if_model, if_params, if_init) ] # Create current source to deliver input to first layers of neurons current_input = model.add_current_source("current_input", cs_model, "neuron0", {}, {"magnitude": 0.0}) # Create subsequent neuron layer for i, w in enumerate(weights): neuron_layers.append( model.add_neuron_population("neuron%u" % (i + 1), w.shape[1], "RulkovMap", rm_params, rm_init)) # Create synaptic connections between layers model.add_synapse_population("synapse%u" % 0, "DENSE_INDIVIDUALG", NO_DELAY, neuron_layers[0], neuron_layers[1], "StaticPulse",
NUM_INPUT = X.shape[1] NUM_CLASSES = 10 OUTPUT_NEURON_NUM = 15 neurons_count = { "inp": NUM_INPUT, "inh": NUM_INPUT / 4, "out": NUM_CLASSES * OUTPUT_NEURON_NUM } neuron_layers = {} for k in neurons_count.keys(): if k == "out": neuron_layers[k] = model.add_neuron_population(k, neurons_count[k], if_model, IF_PARAMS, if_init) else: neuron_layers[k] = model.add_neuron_population(k, neurons_count[k], poisson_model, {}, poisson_init) inp2out_w = np.load("fusi_new6.npy") inp2out = model.add_synapse_population("inp2out", "DENSE_INDIVIDUALG", NO_DELAY, neuron_layers['inp'], neuron_layers['out'], "StaticPulse", {}, {"g": inp2out_w.flatten()}, {}, {}, "DeltaCurr", {}, {}) inh2out = model.add_synapse_population("inh2out", "DENSE_INDIVIDUALG",
const scalar dt = $(t) - $(sT_pre); const scalar timing = exp(-dt / $(tau)); const scalar newWeight = $(g) + ($(eta) * timing); $(g) = fmin($(wMax), fmax($(wMin), newWeight)); """, is_pre_spike_time_required=True, is_post_spike_time_required=True) # Create model model = GeNNModel("float", "mnist_mb") model.dT = DT model._model.set_seed(1337) # Create neuron populations lif_init = {"V": -60.0, "RefracTime": 0.0} pn = model.add_neuron_population("pn", NUM_PN, "LIF", PN_PARAMS, lif_init) kc = model.add_neuron_population("kc", NUM_KC, "LIF", KC_PARAMS, lif_init) ggn = model.add_neuron_population("ggn", 1, "LIF", GGN_PARAMS, lif_init) mbon = model.add_neuron_population("mbon", NUM_MBON, "LIF", MBON_PARAMS, lif_init) # Create current source to deliver input to network pn_input = model.add_current_source("pn_input", cs_model, "pn", {}, {"magnitude": 0.0}) # Create synapse populations model.add_synapse_population( "pn_kc", "SPARSE_GLOBALG", NO_DELAY, pn, kc, "StaticPulse", {}, {"g": PN_KC_WEIGHT}, {}, {}, "ExpCurr", {"tau": PN_KC_TAU_SYN}, {}, init_connectivity("FixedProbabilityNoAutapse", {"prob": PN_KC_SPARSITY}))
fusi_params = {"tauC": 60.0, "a": 0.1, "b": 0.1, "thetaV": 0.8, "thetaLUp": 3.0, "thetaLDown": 3.0, "thetaHUp": 13.0, "thetaHDown": 4.0, "thetaX": 0.5, "alpha": 0.0035, "beta": 0.0035, "Xmax": 1.0, "Xmin": 0.0, "JC": 1.0, "Jplus": 1.0, "Jminus": 0.0} fusi_init = {"X": 0.0} fusi_post_init = {"C": 2.0} presyn_params = {"rate" : 50.0} extra_poisson_params = {"rate" : 100.0} poisson_init = {"timeStepToSpike" : 0.0} model = GeNNModel("float", "fusi") model.dT = TIMESTEP presyn = model.add_neuron_population("presyn", 1, "PoissonNew", presyn_params, poisson_init) postsyn = model.add_neuron_population("postsyn", 1, if_model, if_params, if_init) extra_poisson = model.add_neuron_population("extra_poisson", 10, "PoissonNew", extra_poisson_params, poisson_init) pre2post = model.add_synapse_population( "pre2post", "DENSE_INDIVIDUALG", NO_DELAY, presyn, postsyn, fusi_model, fusi_params, fusi_init, {}, fusi_post_init, "DeltaCurr", {}, {}) extra_poisson2post = model.add_synapse_population( "extra_poisson2post", "DENSE_GLOBALG", NO_DELAY, extra_poisson, postsyn,
# Load weights weights = [] while True: filename = "weights_%u_%u.npy" % (len(weights), len(weights) + 1) if path.exists(filename): weights.append(np.load(filename)) else: break # Initial values to initialise all neurons to if_init = {"V": 0.0, "SpikeCount": 0} # Create first neuron layer neuron_layers = [ model.add_neuron_population("neuron0", weights[0].shape[0], if_model, IF_PARAMS, if_init) ] # Create subsequent neuron layer for i, w in enumerate(weights): neuron_layers.append( model.add_neuron_population("neuron%u" % (i + 1), w.shape[1], if_model, IF_PARAMS, if_init)) # Create synaptic connections between layers for i, (pre, post, w) in enumerate(zip(neuron_layers[:-1], neuron_layers[1:], weights)): model.add_synapse_population("synapse%u" % i, "DENSE_INDIVIDUALG", NO_DELAY, pre, post, "StaticPulse", {}, {"g": w.flatten()}, {}, {}, "DeltaCurr", {}, {})
model = GeNNModel("float", "pygenn") model.dT = 0.1 # Initialise IzhikevichVariable parameters - arrays will be automatically uploaded izk_init = { "V": -65.0, "U": -20.0, "a": [0.02, 0.1, 0.02, 0.02], "b": [0.2, 0.2, 0.2, 0.2], "c": [-65.0, -65.0, -50.0, -55.0], "d": [8.0, 2.0, 2.0, 4.0] } # Add neuron populations and current source to model pop = model.add_neuron_population("Neurons", 4, "IzhikevichVariable", {}, izk_init) model.add_current_source("CurrentSource", "DC", "Neurons", {"amp": 10.0}, {}) # Build and load model model.build() model.load() # Create a numpy view to efficiently access the membrane voltage from Python voltage_view = pop.vars["V"].view # Simulate v = None while model.t < 200.0: model.step_time() model.pull_state_from_device("Neurons") v = np.copy(voltage_view) if v is None else np.vstack((v, voltage_view))
if_init = {"V": 0.0, "SpikeCount": 0} stdp_init = { "g": init_var("Uniform", { "min": STDP_PARAMS["gmin"], "max": STDP_PARAMS["gmax"] }) } neurons_count = [784, 128, NUM_CLASSES] neuron_layers = [] # Create neuron layers for i in range(len(neurons_count)): neuron_layers.append( model.add_neuron_population("neuron%u" % (i), neurons_count[i], if_model, IF_PARAMS, if_init)) weights_0_1 = np.load("weights_0_1.npy") synapses = [] # Create synaptic connections between layers # for i, (pre, post) in enumerate(zip(neuron_layers[:-1], neuron_layers[1:])): # if i == 0: # synapses.append(model.add_synapse_population( # "synapse%u" % i, "DENSE_INDIVIDUALG", NO_DELAY, # pre, post, # "StaticPulse", {}, {"g": weights_0_1.flatten()}, {}, {}, # "DeltaCurr", {}, {})) # else: # synapses.append(model.add_synapse_population( # "synapse%u" % i, "DENSE_INDIVIDUALG", NO_DELAY,
var_name_types=[("rate", "scalar"), ("spikeCount", "scalar")], sim_code=""" """, reset_code=""" $(spikeCount) += 1; """, threshold_condition_code="$(gennrand_uniform) >= exp(-$(rate) * 0.001 * DT)" ) TIMESTEP = 1.0 PRESENT_TIMESTEPS = 1000 model = GeNNModel("float", "tutorial_1") model.dT = TIMESTEP poisson_init = {"rate": 30.0, "spikeCount": 0.0} p = model.add_neuron_population("p", 1, poisson_model, {}, poisson_init) model.build() model.load() while model.timestep < PRESENT_TIMESTEPS: model.step_time() model.pull_var_from_device("p", "spikeCount") spikeNum = p.vars["spikeCount"].view print("Spike Rate: ") print(spikeNum)
parameters = BenchmarkParameters(*parameter_list) model = GeNNModel("float", "pygenn") model.dT = parameters.dt np.random.seed(0) layers = [] for i in range(parameters.batch_size): ones = np.ones(parameters.features) # Note: weights, parameters and poisson rate are magic numbers that seem to generate reasonable spike activity weights = np.random.rand(parameters.features, parameters.features).flatten() * 8 model.add_neuron_population( f"PoissonNew{i}", parameters.features, "PoissonNew", {"rate": 100}, {"timeStepToSpike": 1}, ) # From https://neuralensemble.org/docs/PyNN/reference/neuronmodels.html#pyNN.standardmodels.cells.IF_curr_exp lif_params = { "C": 1.0, "TauM": 20.0, "Vrest": 0.0, "Vreset": 0.0, "Vthresh": 1.0, "Ioffset": 0.0, "TauRefrac": 0.1, } lif_vars = {"V": 0.0 * ones, "RefracTime": 0.0 * ones} layer = model.add_neuron_population(f"LIF{i}", parameters.features,
model.dT = 0.1 p = {"gNa": 7.15, # Na conductance in [muS] "ENa": 50.0, # Na equi potential [mV] "gK": 1.43, # K conductance in [muS] "EK": -95.0, # K equi potential [mV] "gl": 0.02672, # leak conductance [muS] "El": -63.563, # El: leak equi potential in mV, "C": 0.143} # membr. capacity density in nF ini = {"V": -60.0, # membrane potential "m": 0.0529324, # prob. for Na channel activation "h": 0.3176767, # prob. for not Na channel blocking "n": 0.5961207} # prob. for K channel activation pop1 = model.add_neuron_population("Pop1", 10, "TraubMiles", p, ini) model.build() model.load() v = np.empty((10000, 10)) v_view = pop1.vars["V"].view while model.t < 1000.0: model.step_time() pop1.pull_var_from_device("V") v[model.timestep - 1,:]=v_view[:] fig, axis = plt.subplots() axis.plot(v)