[nengo-user] trouble generating scripts/simpleNode question
Terry Stewart
terry.stewart at gmail.com
Fri May 30 16:08:26 EDT 2014
Hi again Brain,
Hmm, another good question. I've never tried to do that, but this
seems to work:
------------------------
from spa import *
import nef
D=16
class Rules:
def start(vision='START'):
set(state=vision)
def A(state='A'):
set(state='B')
def B(state='B'):
set(state='C')
def C(state='C'):
set(state='D')
def D(state='D'):
set(state='E')
def E(state='E'):
set(state='A')
class Routing(SPA):
dimensions = 16
state = Buffer()
vision = Buffer(feedback=0)
BG = BasalGanglia(Rules)
thal = Thalamus(BG)
model = Routing()
# grab the vocab object that maps strings into vectors
vocab = model.vocabs['vision']
# make the simplenode input
class MyInput(nef.SimpleNode):
def origin_X(self):
if self.t < 0.1:
return vocab.parse('START+A').v
else:
return [0]*D
model.net.add(MyInput('input'))
# connect it up to the vision system
model.connect_to_sink('input', 'vision', transform=None, pstc=0.01)
--------------------------------
This is really the same sort of thing the Input() class is doing, but
this way you have more explicit control.
:)
Terry
On Fri, May 30, 2014 at 3:46 PM, Brian Krainer <bkrainer731 at gmail.com> wrote:
> Thanks, that was very helpful!
>
> How would this be done in the more complex BG models such as sequencerouted.py? I see there is an Input class but I'm not really sure how to include arbitrary code with that. Any tips?
>
> Thank you,
> Brian
>
>> On May 30, 2014, at 3:31 PM, Terry Stewart <terry.stewart at gmail.com> wrote:
>>
>> Hi Brian,
>>
>> We're still working on fixing the generate script bug you pointed out,
>> but in the meantime I thought I'd take a quick look at the second
>> question. :)
>>
>> You're right it's not clear how to do this... the trick is that you
>> have to give the origin on your SimpleNode a particular name "X", and
>> then it works fine. Here's an example:
>>
>> -----------------------------
>> import nef
>> import nps
>>
>> net=nef.Network('Basal Ganglia')
>>
>> class MyNode(nef.SimpleNode):
>> def origin_X(self): # this is what the origin must be called
>> return [0.5, 0.9, 0.5, 0.5, 0.5]
>>
>> input = net.add(MyNode('input'))
>>
>> net.make('output',1,3,mode='direct')
>>
>> nps.basalganglia.make_basal_ganglia(net,'input','output', 3, same_neurons=False,
>> neurons=50)
>>
>> net.add_to_nengo()
>> net.view()
>> -------------------------
>>
>> let me know if that works for you!
>>
>> Terry
>>
>>> On Thu, May 29, 2014 at 1:37 PM, Brian Krainer <bkrainer731 at gmail.com> wrote:
>>> Hello,
>>>
>>> I've got 2 questions:
>>>
>>> 1)I'm trying to use 'generate script' with models that I've made using the
>>> GUI. Sometimes it works fine, but other times I get the error:
>>>
>>> "Could not perform action: java.lang.ClassCastException: java.lang.Integer
>>> cannot be cast to java.lang.Double"
>>>
>>> I thought maybe there was something wrong with the way I was connecting
>>> things in the network, so I loaded one of the examples from the 'demo'
>>> directory (basalganglia.py) and tried to generate the script. This gave me
>>> the same error. Why is this the case?
>>>
>>> 2) Is it possible to use a simpleNode class to define a function that is
>>> input to the Basal Ganglia network? I can't seem to figure out the correct
>>> syntax if it is possible.
>>>
>>> Thanks,
>>> Brian
>>>
>>> _______________________________________________
>>> nengo-user mailing list
>>> nengo-user at ctnsrv.uwaterloo.ca
>>> http://ctnsrv.uwaterloo.ca/mailman/listinfo/nengo-user
>>>
More information about the nengo-user
mailing list