Beispiel #1
0
def time_cells(order):
    seed = 0
    n_neurons = 300
    theta = 4.784
    tau = 0.1
    radius = 0.3
    realizer = Balanced


    # The following was patched from nengolib commit
    # 7e204e0c305e34a4f63d0a6fbba7197862bbcf22, prior to
    # aee92b8fc45749f07f663fe696745cf0a33bfa17, so that
    # the generated PDF is consistent with the version that the
    # overlay was added to.
    def PadeDelay(c, q):
        j = np.arange(1, q+1, dtype=np.float64)
        u = (q + j - 1) * (q - j + 1) / (c * j)

        A = np.zeros((q, q))
        B = np.zeros((q, 1))
        C = np.zeros((1, q))
        D = np.zeros((1,))

        A[0, :] = B[0, 0] = -u[0]
        A[1:, :-1][np.diag_indices(q-1)] = u[1:]
        C[0, :] = - j / float(q) * (-1) ** (q - j)
        return LinearSystem((A, B, C, D), analog=True)

    F = PadeDelay(theta, order)
    synapse = Alpha(tau)

    pulse_s = 0
    pulse_w = 1.0
    pulse_h = 1.5

    T = 6.0
    dt = 0.001
    pulse = np.zeros(int(T/dt))
    pulse[int(pulse_s/dt):int((pulse_s + pulse_w)/dt)] = pulse_h

    with Network(seed=seed) as model:
        u = Node(output=PresentInput(pulse, dt))

        delay = LinearNetwork(
            F, n_neurons_per_ensemble=n_neurons / len(F), synapse=synapse,
            input_synapse=None, radii=radius, dt=dt, realizer=realizer())
        Connection(u, delay.input, synapse=None)

        p_x = Probe(delay.state.input, synapse=None)
        p_a = Probe(delay.state.add_neuron_output(), synapse=None)

    with Simulator(model, dt=dt) as sim:
        sim.run(T)

    return sim.trange(), sim.data[p_x], sim.data[p_a]
Beispiel #2
0
def test_processes():
    assert (
        repr(WhiteSignal(0.2, 10, rms=0.3))
        == "WhiteSignal(period=0.2, high=10, rms=0.3)"
    )

    check_init_args(WhiteNoise, ["dist", "scale"])
    check_repr(WhiteNoise(scale=False))
    assert repr(WhiteNoise()) == "WhiteNoise()"
    assert repr(WhiteNoise(scale=False)) == "WhiteNoise(scale=False)"

    check_init_args(FilteredNoise, ["synapse", "dist", "scale"])
    check_repr(FilteredNoise(scale=False))
    assert repr(FilteredNoise()) == "FilteredNoise()"
    assert repr(FilteredNoise(scale=False)) == "FilteredNoise(scale=False)"

    check_init_args(BrownNoise, ["dist"])
    check_repr(BrownNoise())
    assert repr(BrownNoise()) == "BrownNoise()"

    check_init_args(PresentInput, ["inputs", "presentation_time"])
    check_repr(PresentInput(inputs=np.array([1.2, 3.4]), presentation_time=5))
    assert (
        repr(PresentInput((1.2, 3.4), 5))
        == "PresentInput(inputs=array([1.2, 3.4]), presentation_time=5)"
    )

    check_init_args(WhiteSignal, ["period", "high", "rms", "y0"])
    check_repr(WhiteSignal(period=1.2, high=3.4, rms=5.6, y0=7.8))
    assert repr(WhiteSignal(1, 2)) == "WhiteSignal(period=1, high=2)"
    assert (
        repr(WhiteSignal(1.2, 3.4, 5.6, 7.8))
        == "WhiteSignal(period=1.2, high=3.4, rms=5.6, y0=7.8)"
    )

    check_init_args(Piecewise, ["data", "interpolation"])
    check_repr(Piecewise(data={1: 0.1, 2: 0.2, 3: 0.3}))
    assert (
        repr(Piecewise({1: 0.1, 2: 0.2, 3: 0.3}))
        == "Piecewise(data={1: array([0.1]), 2: array([0.2]), 3: array([0.3])})"
    )
Beispiel #3
0
def test_present_input(Simulator, rng, allclose):
    n = 5
    c, ni, nj = 3, 8, 8
    images = rng.normal(size=(n, c, ni, nj))
    pres_time = 0.1

    model = nengo.Network()
    with model:
        u = nengo.Node(PresentInput(images, pres_time))
        up = nengo.Probe(u)

    with Simulator(model) as sim:
        sim.run(1.0)

    t = sim.trange()
    i = (np.floor((t - sim.dt) / pres_time + 1e-7) % n).astype(int)
    y = sim.data[up].reshape(len(t), c, ni, nj)
    for k, [ii, image] in enumerate(zip(i, y)):
        assert allclose(image, images[ii], rtol=1e-4, atol=1e-7), (k, ii)
Beispiel #4
0
                     transform=OneToOne(gain=1.0),
                     synapse=tau)
    nengo.Connection(STN_COG_out,
                     GPI_COG.input,
                     transform=OneToAll(gain=1.0),
                     synapse=tau)
    nengo.Connection(STN_MOT_out,
                     GPI_MOT.input,
                     transform=OneToAll(gain=1.0),
                     synapse=tau)

    stim_cog = nengo.Node([-1, -1])
    stim_mot = nengo.Node([-1, -1])
    stim_asc = nengo.Node([-1, -1, -1, -1])

    stim_cog.output = PresentInput(inputs=fill(cogstim), presentation_time=0.5)
    stim_mot.output = PresentInput(inputs=fill(motstim), presentation_time=0.5)
    stim_asc.output = PresentInput(inputs=np.hstack(
        [fill(cogstim), fill(motstim)]),
                                   presentation_time=0.5)

    stim_asc_r = nengo.Ensemble(pop * (inps * inps), inps * inps, radius=20)
    nengo.Connection(stim_asc, stim_asc_r, function=ascstim, synapse=None)
    nengo.Connection(stim_asc_r, CTX_ASC.input, synapse=None)
    nengo.Connection(stim_cog,
                     CTX_COG.input,
                     function=precogstim,
                     synapse=None)
    nengo.Connection(stim_mot,
                     CTX_MOT.input,
                     function=premotstim,
Beispiel #5
0
def runTrial(cogstim, motstim):
    global asctoasc
    with model:
        CTX_COG = nengo.networks.EnsembleArray(n_ensembles=inps,
                                               n_neurons=arrpop * 4,
                                               radius=radius)
        STR_COG = nengo.networks.EnsembleArray(n_ensembles=inps,
                                               n_neurons=arrpop,
                                               radius=radius)
        GPI_COG = nengo.networks.EnsembleArray(n_ensembles=inps,
                                               n_neurons=arrpop,
                                               radius=radius)
        STN_COG = nengo.networks.EnsembleArray(n_ensembles=inps,
                                               n_neurons=arrpop,
                                               radius=radius)
        THL_COG = nengo.networks.EnsembleArray(n_ensembles=inps,
                                               n_neurons=arrpop,
                                               radius=radius)

        CTX_MOT = nengo.networks.EnsembleArray(n_ensembles=inps,
                                               n_neurons=arrpop * 4,
                                               radius=radius)
        STR_MOT = nengo.networks.EnsembleArray(n_ensembles=inps,
                                               n_neurons=arrpop,
                                               radius=radius)
        GPI_MOT = nengo.networks.EnsembleArray(n_ensembles=inps,
                                               n_neurons=arrpop,
                                               radius=radius)
        STN_MOT = nengo.networks.EnsembleArray(n_ensembles=inps,
                                               n_neurons=arrpop,
                                               radius=radius)
        THL_MOT = nengo.networks.EnsembleArray(n_ensembles=inps,
                                               n_neurons=arrpop,
                                               radius=radius)

        # Assuming both are 2D arrays of [inps, inps] represented in 1D array of size inps*inps
        # Each row corresponds to a cue and each column to a position

        CTX_ASC = nengo.networks.EnsembleArray(n_ensembles=inps * inps,
                                               n_neurons=pop * inps * inps,
                                               radius=radius)
        STR_ASC = nengo.networks.EnsembleArray(n_ensembles=inps * inps,
                                               n_neurons=pop * inps,
                                               radius=radius)

        CTX_COG_out = CTX_COG.add_output('func_cog_ctx',
                                         lambda x: clamp(x + CTX_noise, 0))
        STR_COG_out = STR_COG.add_output('func_cog_str',
                                         lambda V: sigmoid(V + STR_noise, 1))
        GPI_COG_out = GPI_COG.add_output('func_cog_gpi',
                                         lambda x: clamp(x + GPI_noise, 2))
        STN_COG_out = STN_COG.add_output('func_cog_stn',
                                         lambda x: clamp(x + STN_noise, 4))
        THL_COG_out = THL_COG.add_output('func_cog_thl',
                                         lambda x: clamp(x + THL_noise, 3))

        CTX_MOT_out = CTX_MOT.add_output('func_mot_ctx',
                                         lambda x: clamp(x + CTX_noise, 0))
        STR_MOT_out = STR_MOT.add_output('func_mot_str',
                                         lambda V: sigmoid(V + STR_noise, 1))
        GPI_MOT_out = GPI_MOT.add_output('func_mot_gpi',
                                         lambda x: clamp(x + GPI_noise, 2))
        STN_MOT_out = STN_MOT.add_output('func_mot_stn',
                                         lambda x: clamp(x + STN_noise, 4))
        THL_MOT_out = THL_MOT.add_output('func_mot_thl',
                                         lambda x: clamp(x + THL_noise, 3))

        CTX_ASC_out = CTX_ASC.add_output('func_asc_ctx',
                                         lambda x: clamp(x + CTX_noise, 0))
        STR_ASC_out = STR_ASC.add_output('func_asc_str',
                                         lambda V: sigmoid(V + STR_noise, 1))

        #np.array([ 0.56135171,  0.53677366,  0.49578237,  0.49318303])

        conn = nengo.Connection(CTX_COG_out,
                                STR_COG.input,
                                transform=W,
                                synapse=tau)
        nengo.Connection(CTX_MOT_out,
                         STR_MOT.input,
                         transform=weights(inps),
                         synapse=tau)
        asctoasc[:] = 0
        np.fill_diagonal(asctoasc, weights(inps * inps))
        nengo.Connection(CTX_ASC_out,
                         STR_ASC.input,
                         transform=asctoasc,
                         synapse=tau)
        nengo.Connection(CTX_COG_out,
                         STR_ASC.input,
                         transform=CogToAsc(gain=0.2).transpose(),
                         synapse=tau)
        nengo.Connection(CTX_MOT_out,
                         STR_ASC.input,
                         transform=MotToAsc(gain=0.2).transpose(),
                         synapse=tau)
        nengo.Connection(STR_COG_out,
                         GPI_COG.input,
                         transform=OneToOne(gain=-2.0),
                         synapse=tau)
        nengo.Connection(STR_MOT_out,
                         GPI_MOT.input,
                         transform=OneToOne(gain=-2.0),
                         synapse=tau)
        nengo.Connection(STR_ASC_out,
                         GPI_COG.input,
                         transform=CogToAsc(gain=-2.0, norm=False),
                         synapse=tau)
        nengo.Connection(STR_ASC_out,
                         GPI_MOT.input,
                         transform=MotToAsc(gain=-2.0, norm=False),
                         synapse=tau)
        nengo.Connection(GPI_COG_out,
                         THL_COG.input,
                         transform=OneToOne(gain=-0.5),
                         synapse=tau)
        nengo.Connection(GPI_MOT_out,
                         THL_MOT.input,
                         transform=OneToOne(gain=-0.5),
                         synapse=tau)
        nengo.Connection(THL_COG_out,
                         CTX_COG.input,
                         transform=OneToOne(gain=1.0),
                         synapse=tau)
        nengo.Connection(THL_MOT_out,
                         CTX_MOT.input,
                         transform=OneToOne(gain=1.0),
                         synapse=tau)
        nengo.Connection(CTX_COG_out,
                         THL_COG.input,
                         transform=OneToOne(gain=0.4),
                         synapse=tau)
        nengo.Connection(CTX_MOT_out,
                         THL_MOT.input,
                         transform=OneToOne(gain=0.4),
                         synapse=tau)
        nengo.Connection(CTX_COG_out,
                         STN_COG.input,
                         transform=OneToOne(gain=1.0),
                         synapse=tau)
        nengo.Connection(CTX_MOT_out,
                         STN_MOT.input,
                         transform=OneToOne(gain=1.0),
                         synapse=tau)
        nengo.Connection(STN_COG_out,
                         GPI_COG.input,
                         transform=OneToAll(gain=1.0),
                         synapse=tau)
        nengo.Connection(STN_MOT_out,
                         GPI_MOT.input,
                         transform=OneToAll(gain=1.0),
                         synapse=tau)

        stim_cog = nengo.Node([-1, -1])
        stim_mot = nengo.Node([-1, -1])
        stim_asc = nengo.Node([-1, -1, -1, -1])

        stim_cog.output = PresentInput(inputs=fill(cogstim),
                                       presentation_time=0.5)
        stim_mot.output = PresentInput(inputs=fill(motstim),
                                       presentation_time=0.5)
        stim_asc.output = PresentInput(inputs=np.hstack(
            [fill(cogstim), fill(motstim)]),
                                       presentation_time=0.5)

        stim_asc_r = nengo.Ensemble(pop * (inps * inps),
                                    inps * inps,
                                    radius=20)
        nengo.Connection(stim_asc, stim_asc_r, function=ascstim, synapse=None)
        nengo.Connection(stim_asc_r, CTX_ASC.input, synapse=None)
        nengo.Connection(stim_cog,
                         CTX_COG.input,
                         function=precogstim,
                         synapse=None)
        nengo.Connection(stim_mot,
                         CTX_MOT.input,
                         function=premotstim,
                         synapse=None)

        weights_p = nengo.Probe(conn,
                                'weights',
                                synapse=None,
                                sample_every=3.0)
        ctxcog = nengo.Probe(CTX_COG.output, synapse=None, sample_every=2.0)
        ctxmot = nengo.Probe(CTX_MOT.output, synapse=None, sample_every=2.0)
        strcog = nengo.Probe(STR_COG.output, synapse=None, sample_every=2.0)

    with nengo.Simulator(model) as sim:
        sim.reset()
        sim.run(3.0)
    t = sim.trange()
    return sim.data[ctxcog], sim.data[ctxmot], sim.data[strcog], sim.data[
        weights_p]
Beispiel #6
0
processes = nengo.processes.WhiteSignal(10, high=10, y0=0)
neuron_type = nengo.LIF()


def function(w):
    return w.sum()


def inputfunction(t):
    return np.cos(8 * t)


pulse_s = 0
pulse_w = 1.5
pulse_h = 1.0

T = 6.0
dt = 0.001
pulse = np.zeros(int(T / dt))
pulse[int(pulse_s / dt):int((pulse_s + pulse_w) / dt)] = pulse_h

with nengolib.Network() as model:
    rw = nengolib.networks.RollingWindow(theta=2,
                                         n_neurons=600,
                                         process=processes,
                                         neuron_type=neuron_type)
    stim = nengo.Node(PresentInput(pulse, dt))

    nengo.Connection(stim, rw.input, synapse=None)
    output = rw.add_output(function=function)