def single_neuron_time(time,
                       dt,
                       scale,
                       step_size,
                       I_function,
                       shape,
                       spike_trace,
                       additive_spike_trace,
                       tau_s,
                       trace_scale,
                       is_inhibitory,
                       learning,
                       R,
                       C,
                       threshold=-55):

    I = I_function(time, step_size, scale)
    neuron = LIFPopulation(shape, spike_trace, additive_spike_trace, tau_s,
                           trace_scale, is_inhibitory, learning, R, C,
                           threshold)
    neuron.dt = dt
    monitor = Monitor(neuron, state_variables=["s", "u"])
    monitor.set_time_steps(time, dt)
    monitor.reset_state_variables()
    for i in range(len(I)):
        neuron.forward(I[i][0])
        monitor.record()
    return neuron, I, torch.transpose(monitor.get("s") * 1, 0,
                                      1), monitor.get("u")
# encoder = Time2FirstSpikeEncoder(time = time)
encoder = PoissonEncoder(time = time, r = 10)
I = encoder(s)

# kernel = DoG_kernel(k=7, sigma1=0.1, sigma2=1)
kernel = gabor_kernel(k = 7, sigma = .4, teta = 0, gamma = .7, lambdal = .8)


n1 = InputPopulation(
        shape = shape1, spike_trace = True, additive_spike_trace = True, tau_s = 4, trace_scale = 1.,
        is_inhibitory = False, learning = False, R = 1, C = 20, threshold = -40
    )
n1.dt = dt

n2 = LIFPopulation(
        shape = shape2, spike_trace = True, additive_spike_trace = True, tau_s = 4, trace_scale = 1.,
        is_inhibitory = False, learning = False, R = 1, C = 20, threshold = -40
    )
n2.dt = dt

con1 = ConvolutionalConnection(
        pre = n1, post = n2, kernel = kernel, J = 1000, padding = 0, stride = 1
    )

monitor1 = Monitor(n1, state_variables=["s"])
monitor1.set_time_steps(time, dt)
monitor1.reset_state_variables()

monitor2 = Monitor(n2, state_variables=["s"])
monitor2.set_time_steps(time, dt)
monitor2.reset_state_variables()
Exemple #3
0
neuron_size = 100
shape1 = (int(neuron_size * 0.8), )
shape2 = (int(neuron_size * 0.2), )

# I1 = noise_function(time = time)
# I2 = I1

I1 = noise_function(time, shape1[0])
I2 = noise_function(time, shape2[0])

pn1 = LIFPopulation(shape=shape1,
                    spike_trace=True,
                    additive_spike_trace=True,
                    tau_s=10,
                    trace_scale=1.,
                    is_inhibitory=False,
                    learning=False,
                    R=1,
                    C=20,
                    threshold=-40,
                    dt=dt)

pn2 = LIFPopulation(shape=shape2,
                    spike_trace=True,
                    additive_spike_trace=True,
                    tau_s=10,
                    trace_scale=1.,
                    is_inhibitory=True,
                    learning=False,
                    R=1,
                    C=20,
Exemple #4
0
from cnsproject.plotting.plotting import time_potential
from cnsproject.plotting.plotting import current_frequency

from cnsproject.utils import compute_current_frequency

## First set of parameters
## LIF Parameters
dt = 0.01
rest_potential = np.array([-70,-80,-60,-70,-70,-70,-70],)
threshold_potential = np.array([-55,-55,-55,-55,-55,-55,-55])
tau_m = np.array([1,1,1,0.1,10,1,1])
R = np.array([1,1,1,1,1,0.1,10])

## Create LIF based on parameters
lif_neuron = LIFPopulation(
    spike_trace=False, additive_spike_trace=False, dt=dt, rest_potential=rest_potential,
    threshold_potential=threshold_potential, tau_m=tau_m, R=R
).to(device=device,dtype=dtype)

## Compute frequency
plt.figure(figsize=(18,20))
current = torch.arange(1,31,device=device,dtype=dtype)
np_current = np.arange(1,31)

for i in range(len(R)):
    model =  LIFPopulation(
        spike_trace=False, additive_spike_trace=False, dt=dt, rest_potential=rest_potential[i],
        threshold_potential=threshold_potential[i], tau_m=tau_m[i], R=R[i]
    ).to(device=device,dtype=dtype)
    frequencies = compute_current_frequency(current,model,dt)
    
    plt.subplot(4,2,i+1)
shape_ep2 = (int(neuron_size), )
shape_ip1 = (int(neuron_size), )

# I_ep1 = incremental_step_noise_function(time = time, I_value = 100, scale = scale, neuron_size = shape_ep1[0], gap = 5)
# I_ep2 = incremental_step_noise_function(time = time, I_value = 100, scale = scale, neuron_size = shape_ep2[0], gap = 3)
# I_ip1 = step_noise_function(time = time, I_value = 100, scale = scale, neuron_size = shape_ip1[0])
I_ep1 = noise_function(time, shape_ep1[0])
I_ep2 = noise_function(time, shape_ep2[0])
I_ip1 = noise_function(time, shape_ip1[0]) * 0

ep1 = LIFPopulation(shape=shape_ep1,
                    spike_trace=True,
                    additive_spike_trace=True,
                    tau_s=10,
                    trace_scale=1.,
                    is_inhibitory=False,
                    learning=False,
                    R=1,
                    C=20,
                    threshold=-40,
                    dt=dt)
ep2 = LIFPopulation(shape=shape_ep2,
                    spike_trace=True,
                    additive_spike_trace=True,
                    tau_s=10,
                    trace_scale=1.,
                    is_inhibitory=False,
                    learning=False,
                    R=1,
                    C=20,
                    threshold=-40,