Esempio n. 1
0
n_cconv_neurons = 50  #10

#ssp_cleanup_path = '/home/bjkomer/metric-representation/metric_representation/pytorch/ssp_cleanup_cosine_15_items/May07_15-21-15/model.pt'
ssp_cleanup_path = '/home/ctnuser/metric-representation/metric_representation/pytorch/ssp_cleanup_cosine_15_items/May07_15-21-15/model.pt'


def angle_to_ssp(x):

    return encode_point(np.cos(x), np.sin(x), x_axis_sp, y_axis_sp).v


heatmap_vectors = get_heatmap_vectors(xs, ys, x_axis_sp, y_axis_sp)

spatial_heatmap = SpatialHeatmap(heatmap_vectors,
                                 xs,
                                 ys,
                                 cmap='plasma',
                                 vmin=None,
                                 vmax=None)

with model:

    # Initial kick to get the starting location SSP to represent 0,0
    initial_stim = nengo.Node(lambda t: 1 if t < 0.01 else 0)

    direction_heatmap_node = nengo.Node(
        SpatialHeatmap(heatmap_vectors,
                       xs,
                       ys,
                       cmap='plasma',
                       vmin=None,
                       vmax=None),
        nengo.Connection(cconv_view.output, exp_node[args.dim:])

    nengo.Connection(exp_node[args.dim:2 * args.dim], model.queried_item.input)
    # drive the memory to the next start when the current task is finished
    nengo.Connection(exp_node[2 * args.dim:], model.current_loc.input)

    nengo.Connection(model.current_loc.output, exp_node[:args.dim])

    initial_kick = nengo.Node(lambda t: 1 if t < 0.01 else 0)
    nengo.Connection(initial_kick, model.current_loc.input[0])

    if __name__ != '__main__':
        # plots for debugging
        heatmap = SpatialHeatmap(heatmap_vectors=hmv,
                                 xs=xs,
                                 ys=xs,
                                 cmap='plasma',
                                 vmin=-1,
                                 vmax=1)
        heatmap_node = nengo.Node(heatmap, size_in=args.dim, size_out=0)
        nengo.Connection(model.current_loc.output, heatmap_node)

        dir_heatmap = SpatialHeatmap(heatmap_vectors=hmv,
                                     xs=xs,
                                     ys=xs,
                                     cmap='plasma',
                                     vmin=-1,
                                     vmax=1)
        dir_heatmap_node = nengo.Node(heatmap, size_in=args.dim, size_out=0)
        nengo.Connection(model.direction.output, dir_heatmap_node)

if __name__ == '__main__':
    if __name__ == '__main__':
        # probes
        spikes_p = nengo.Probe(ssp_loc.neurons, synapse=0.01)
        bound_spikes_p = nengo.Probe(memory.neurons, synapse=0.01)
        pos_2d_p = nengo.Probe(pos_2d)
    else:
        res = 128
        xs = np.linspace(limit_low, limit_high, res)
        ys = np.linspace(limit_low, limit_high, res)
        heatmap_vectors = get_heatmap_vectors(xs, ys, X, Y)
        # create a visualization of the heatmap
        heatmap_node = nengo.Node(
            SpatialHeatmap(
                heatmap_vectors,
                xs,
                ys,
                cmap='plasma',
                vmin=-1,  # None,
                vmax=1,  # None,
            ),
            size_in=dim,
            size_out=0,
        )

        memory_heatmap_node = nengo.Node(
            SpatialHeatmap(
                heatmap_vectors,
                xs,
                ys,
                cmap='plasma',
                vmin=-1,  # None,
                vmax=1,  # None,
Esempio n. 4
0
    for n in range(n_neurons):
        encoders_place_cell_dir[n, :] = to_ssp(preferred_locations_dir[n, :])

    model = nengo.Network(seed=seed)
    model.config[nengo.Ensemble].neuron_type = nengo.LIF()
    # model.config[nengo.Ensemble].neuron_type=nengo.Direct()
    with model:

        # Initial kick to get the starting location SSP to represent 0,0
        # initial_stim = nengo.Node(lambda t: 1 if t < 0.01 else 0)
        initial_stim = nengo.Node(lambda t: 1 if t < 0.1 else 0)

        direction_heatmap_node = nengo.Node(
            SpatialHeatmap(heatmap_vectors_dir,
                           xs_dir,
                           ys_dir,
                           cmap='plasma',
                           vmin=None,
                           vmax=None),
            size_in=dim,
            size_out=0,
        )
        location_heatmap_node = nengo.Node(
            SpatialHeatmap(heatmap_vectors,
                           xs,
                           ys,
                           cmap='plasma',
                           vmin=None,
                           vmax=None),
            size_in=dim,
            size_out=0,
        )
Esempio n. 5
0
    # )

    nengo.Connection(
        policy_out_node,
        env,
        synapse=None,
    )

    # SSP visualization
    if __name__ != "__main__":
        vmin = 0
        vmax = 1
        spatial_cleanup_input_heatmap_node = nengo.Node(
            SpatialHeatmap(heatmap_vectors,
                           xs,
                           ys,
                           cmap='plasma',
                           vmin=vmin,
                           vmax=vmax),
            size_in=args.dim,
            size_out=0,
        )
        if args.use_cleanup_gt:
            nengo.Connection(spatial_cleanup,
                             spatial_cleanup_input_heatmap_node)
        else:
            # nengo.Connection(policy_inp_node[2 * args.dim:3 * args.dim], spatial_cleanup_heatmap_node)
            # input to the cleanup
            nengo.Connection(env[args.maze_id_dim:args.maze_id_dim + args.dim],
                             spatial_cleanup_input_heatmap_node)

        localization_heatmap_node = nengo.Node(
Esempio n. 6
0
    # model.cconv_location = nengo.networks.CircularConvolution(
    #     n_neurons=neurons_per_dim * 2, dimensions=dim, invert_b=True
    # )
    model.cconv_location = spa.networks.CircularConvolution(
        n_neurons=neurons_per_dim * 2, dimensions=dim, invert_b=True)

    nengo.Connection(model.noisy_level_filler_id_cleanup.output,
                     model.cconv_location.input_a)
    nengo.Connection(item_id_input_node, model.cconv_location.input_b)

    out_node = nengo.Node(size_in=dim, size_out=0)

    nengo.Connection(model.cconv_location.output, out_node)

    heatmap_node = nengo.Node(
        SpatialHeatmap(hmv, xs, ys, cmap='plasma', vmin=None, vmax=None),
        size_in=dim,
        size_out=0,
    )

    nengo.Connection(model.cconv_location.output, heatmap_node)

    with direct_config:

        model.item_id_reader = spa.State(vocab,
                                         # neuron_type=nengo.Direct()
                                         )
        nengo.Connection(item_id_input_node, model.item_id_reader.input)

        model.item_reader = spa.State(vocab, )
        nengo.Connection(item_input_node, model.item_reader.input)
Esempio n. 7
0
        vocab=dim,
        phis=phis,
        angles=angles,
        feedback=1.01,
        limit_low=-limit,
        limit_high=limit,
    )

    # x, y, and on/off
    ssp_input = nengo.Node([0, 0, 0])

    nengo.Connection(ssp_input, model.current_loc.input, function=input_ssp)

    heatmap = SpatialHeatmap(heatmap_vectors=hmv,
                             xs=xs,
                             ys=xs,
                             cmap='plasma',
                             vmin=-1,
                             vmax=1)
    heatmap_node = nengo.Node(heatmap, size_in=dim, size_out=0)
    nengo.Connection(model.current_loc.output, heatmap_node)

    heatmap_true = SpatialHeatmap(heatmap_vectors=hmv,
                                  xs=xs,
                                  ys=xs,
                                  cmap='plasma',
                                  vmin=None,
                                  vmax=None)
    heatmap_true_node = nengo.Node(heatmap_true, size_in=dim, size_out=0)
    # nengo.Connection(model.current_loc.input, heatmap_true_node)
    nengo.Connection(ssp_input, heatmap_true_node, function=input_ssp)