How can i control the initial state of the neuron membrane?

Hi !!!

I am trying to implement a CPG in nengo, my inputs are vectors formed with 0 and 1. I need to control the initial value of the neuron membrane so that different neurons are activated at a given time.

Hi @Ricardo, and welcome to the Nengo forums! :smiley:

You are able to set the initial state for most of the neuron types in Nengo (some neuron types don’t have initial states, so they can’t be set). The neuron construction contains an initial_state parameter which accepts a dictionary mapping a key value (state property) to a distribution (or array) specifying what the values of said state property should be.

The state properties vary between neuron types and you can see what each neuron type’s states are by looking at the Nengo source code (e.g., here it is for the default LIF neuron type)

You can then use these custom neuron types in the nengo.Ensemble constructor to create Nengo ensembles containing neurons with the custom initial states. As an example, the following code will create an ensemble with 10 neurons where the membrane voltages are initialized to 0:

ens = nengo.Ensemble(10, 1
    neuron_type=nengo.LIF(initial_state={"voltage": nengo.dists.Choice([0])}))

I should note that by default, the LIF neuron type initializes neurons with a random membrane voltage from the Uniform distribution from 0 to 1 (see the source code). That means that the default LIF neurons already have unique starting states.

Here’s some code where I compare two “identical” ensembles, both seeded with the same value (so the gain and biases are the same), but one having the default initial states, and the other having all of the initial membrane voltage values starting at 0.
test_ens_initial_state.py (784 Bytes)

And here’s the graph you should get when you run the code. You can see that the top plot (the default ensemble) has membrane voltages starting between 0 and 1, while the bottom plot has membrane voltages all starting at 0. Note that due to the way the Nengo simulator works with probes, probe data for the t=0 is not recorded (it’s a limitation).

1 Like

Hello, if I define the initial state of the LIF neuron with a value of 1, I would expect the neuron to fire when simulating. However, it does not do it; I only get it if I inject an external input with the Node function. I would like to know what parameter I should modify so that a neuron fires without stimulus if the membrane potential exceeds the threshold.

import numpy as np            
import nengo
import matplotlib.pyplot as plt
from nengo.utils.matplotlib import rasterplot

model = nengo.Network()
with model:
    inicial = nengo.Ensemble(                  
        1,                    
        dimensions = 1,          
        intercepts = [0],      
        max_rates = [400],        

        neuron_type=nengo.LIF(initial_state={"voltage": np.ones(1)}),
        encoders = [[1]],        
        seed=0,
    )

with model:

    #  without external input (the array has 0 as input)
    # i need that this neuron firing when the external input = 0
    start =     np.array([0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]) # Change the first value to 1 to neuron firing
    
    Start_N = nengo.Node(nengo.processes.PresentInput(start, 0.002))

with model:
    nengo.Connection(Start_N, inicial, synapse = 0.0)  

with model:
    Input_Start     = nengo.Probe( Start_N)                    
    filtered_Start  = nengo.Probe(inicial, synapse=0.0001)    
    spikes_Start   = nengo.Probe(inicial.neurons)  
    voltage_Start   = nengo.Probe(inicial.neurons,"voltage")            

   

with nengo.Simulator(model) as sim:
    sim.run(0.049)

    plt.figure(1)
    plt.subplot(411)
    plt.plot(sim.trange(), sim.data[Input_Start],label='Input data')
    plt.plot(sim.trange(), sim.data[filtered_Start],label='Spikes filtered')  
    plt.xlabel("Time"), plt.title(" Start Injection")  
    plt.legend()
    plt.xlim(-0.01,0.1)

    plt.subplot(412)
    plt.plot(sim.trange(), sim.data[voltage_Start])
    plt.title("LIF neuron with 1 initial voltage")
    plt.grid()
    plt.xlim(-0.01,0.05)

    plt.subplot(413)
    rasterplot(sim.trange(), sim.data[spikes_Start])  
    plt.xlabel("Spike time"), plt.title("Fist Spike Volt_LIF = 1")
    plt.tight_layout()
    plt.xlim(-0.01,0.05)
    plt.grid()
    plt.show()