If-then loops in nodes


#1

Hi -

I am trying to model the Wisconsin Card Sort test (I am surprised no one has done this already). I need to count model correct responses. I am trying to get nodes to do this (simulating the external tester) and I can’t figure out how to use if-then loops within nodes. e.g. I am trying to input 2 for the first second, and then 1 thereafter. I want the 2nd node to reverse them. I get the following error: “reverse() takes 1 positional argument but 2 were given” ; I suspect the answer is trivial. Thanks

import nengo

import nengo.spa as spa

D = 64
model = spa.SPA()
with model:
   	def two_one(t):
    		if 0 < t < 1:
      			 return 2
    		else:
       			return 1
           
   node = nengo.Node(output = two_one)
   
   
   def reverse():
       if node.output == 2:
           return 1
       else: 
           return 2
           
   node2 = nengo.Node(size_in = 1, size_out = 1, output = reverse)
   nengo.Connection(node,node2)

#2

Try this:

import nengo

import nengo.spa as spa

D = 64
model = spa.SPA()
with model:
    def two_one(t):
        if 0 < t < 1:
      	    return 2
        else:
       	    return 1
           
    node = nengo.Node(output = two_one)
   
   
    def reverse(t, x):
        if x == 2:
           return 1
        else: 
           return 2
           
    node2 = nengo.Node(size_in = 1, size_out = 1, output = reverse)
    nengo.Connection(node, node2, synapse=None)

#3

I tried it three years ago as my course project for Chris’ course, but was unsuccessful. However, this was before:

  1. I understood how to make large-scale models using SPA
  2. The Nengo API had stabilized to it’s current version.

#4

Thanks Jan