Action module in ActionSelection() of nengo_spa


I use nengo-spa (ver. 0.6.0). I have a question about ActionSelection module.

import nengo
import nengo_spa as spa

def random_pointer_input(t):
    if t < 0.1:
        return "RANDOM1"
        return "0"

def vision_input(t):
    # input sentence SP or PERIOD

d = 64
random_pt_num = 5
random_pt = ["RANDOM" + str(i) for i in range(random_pt_num)]

vocal = spa.Vocabulary(d)

model = spa.Network(vocabs=[vocab])

with model:
    switch = spa.State(d)
    random_pointer = spa.Transcode(random_pointer_input, output_vocab=d)
    vision = spa.Transcode(vision_input, output_vocab=d)

with spa.ActionSelection() as action_sel:
    spa.ifmax(, spa.sym.SWITCH) *, RANDOM1),
            spa.sym.RANDOM1 >> random_pointer
    spa.ifmax(, spa.sym.SWITCH) *, RANDOM2),
            spa.sym.RANDOM2 >> random_pointer
    spa.ifmax(, spa.sym.SWITCH) *, RANDOM3),
            spa.sym.RANDOM3 >> random_pointer
    spa.ifmax(, spa.sym.SWITCH) *, RANDOM4),
            spa.sym.RANDOM4 >> random_pointer
    spa.ifmax(, spa.sym.SWITCH) *, RANDOM5),
            spa.sym.RANDOM5 >> random_pointer
            random_pointer >> random_pointer

I want to enter multiple sentences with random SP(RANDOM1, RANDOM2, …etc). The sentences are from vision_input and the random SPs are from random_pointer_input.

My question is about the part of Action(THEN part) after the part of utility (IF-part) in spa.ActionSelection.
To write the source code smartly, I want to write as follows:

with spa.ActionSelection() as action_sel:
    for random_p in range(1, random_pt_num+1):
        if random_p != random_pt_num:
            spa.ifmax(, spa.sym.SWITCH) *, vocab[random_pt[random_p]]),
                    vocab[random_pt[random_p+1]].v >> random_pointer
            spa.ifmax(, spa.sym.SWITCH) *, vocab[random_pt[random_p]]),
                vocab[random_pt[-random_p]] >> random_pointer
                random_pointer >> random_pointer)

However, the error occurs when writing
vocab[random_pt[random_p+1]].v >> random_pointer
vocab[random_pt[random_p+1]].v >> random_pointer
as follows:

nengo_spa.exceptions.SpaTypeError: <Connector<Node> (unlabeled) at 0x7f5743fa6240> was not registered as a SPA input

So please tell me how to enter a SP into spa.State().
Thank you.

How is random_pointer declared?

1 Like

Ah, I was wrong.:sweat_drops:
I was bound to spa.Transcode().

I realized I had to connect to spa.State. Thank you @jgosmann.