I have put N=16 and gmax as 3
nest.ResetKernel()
# Simulation parameters
dt = 0.01 # Simulation time step in ms
nest.SetKernelStatus({"resolution": dt})
N = 16 # Number of neurons
gmax = 3
neuron_params = {
"tau_m": 140.0, # Membrane time constant in ms
"E_L": -70.6, # Resting potential (in mV)
"V_th": -40.4, # Threshold potential (in mV)
"V_reset": -70.6, # Reset potential (in mV)
"V_m":0.0,
}
nest.CopyModel("stdp_synapse", "stdp_synapse_exc",
{"weight":gmax,"alpha":1,"Wmax":gmax, "tau_plus":
20.0,"lambda": -0.0005, "mu_minus": 0, "mu_plus": 0})
nest.CopyModel("stdp_synapse", "stdp_synapse_inh",
{"weight":-gmax/(N-1),"alpha":1,"Wmax":-gmax,
"tau_plus": 20.0,"lambda": 0.005, "mu_minus": 0,
"mu_plus": 0})
G_spike_gen = nest.Create("spike_generator", N)
G_input = nest.Create("parrot_neuron", N)
G_hidden = nest.Create("iaf_psc_delta", N,params=neuron_params)
G_output = nest.Create("iaf_psc_delta", 1,params=neuron_params)
S_in = nest.Connect(G_spike_gen, G_input, "one_to_one")
# Connect input to hidden layer with excitatory STDP synapses
S_exc = nest.Connect(G_input, G_hidden,"one_to_one",syn_spec =
"stdp_synapse_exc")
# Retrieve the neuron IDs for G_input and G_hidden
input_ids = G_input.tolist()
hidden_ids = G_hidden.tolist()
# Get the existing excitatory connections and extract their source-target ID pairs
exc_connections = nest.GetConnections(G_input, G_hidden)
exc_connection_pairs = set(zip(exc_connections.get("source"),
exc_connections.get("target")))
for i in input_ids:
for h in hidden_ids:
if (i, h) not in exc_connection_pairs:
nc1 = nest.NodeCollection([i])
nc2 = nest.NodeCollection([h])
nest.Connect(nc1, nc2, syn_spec= "stdp_synapse_inh")
S_out = nest.Connect(G_hidden, G_output,"all_to_all",syn_spec =
{"weight": 40.4/N})
This is the code architecture