[nengo-user] Converting digit.py from nengo 1.4 to nengo 2.0.
Eric Hunsberger
erichuns at gmail.com
Wed Oct 14 09:42:05 EDT 2015
Hi Shyh-Kang,
I've already converted this model to Nengo 2.0, so you might want to check
out the repository here: https://github.com/hunse/mnist-rbm.
As for your error, it's because we do ensemble arrays differently now.
They're made to look just like ensembles from the outside, so when you do
`Connection(layer1.output, layer2.input, function=transform, transform=w2)`
it uses the `transform` function as a multidimensional one applied to the
entire output of `layer1`. What you actually want to do is
`layer1.add_output('transform', function=transform)` and then do
`Connection(layer1.transform, layer2.input, transform=w2)` (I've left out a
few of the non-pertinent details for simplicity). Does that make sense?
Also, I'm very unhappy with how things were named in `digit.py`, since
`transform` is actually the sigmoid function that the neurons are
computing, not really a transform. I revised this when I reworked the model
for 2.0, so I think it's a lot clearer now.
Cheers,
Eric
On 13 October 2015 at 22:05, 鄭士康 <skjeng at ntu.edu.tw> wrote:
> Hi,
>
>
>
> I am trying to convert digit.py from nengo 1.4 to nengo 2.0.
>
> I got digit.py from the model
>
> “RBM Deep Belief Network for Visual Digit Recognition”
>
> provided in Model Archive.
>
> Could anyone help to solve the following problem?
>
>
>
> When I converted a piece of code:
>
>
>
> w2=read('mat_2_w.csv') # weights for layer 2 (computed using standard
> Matlab learning model)
>
> b2=read('mat_2_b.csv') # bias for layer 2 (computed using standard
> Matlab learning model)
>
>
>
>
> layer2=net.make_array('layer2',N,len(w2[0]),encoders=[[1]],intercept=(0,0.8),seed=seed)
>
> bias2=net.make_input('bias2',b2[0])
>
> net.connect(bias2,layer2)
>
>
> net.connect(layer1,layer2,func=transform,transform=numeric.array(w2).T,pstc=pstc)
>
>
>
> to
>
>
>
> with net:
>
> w2=read('mat_2_w.csv') # weights for layer 2 (computed using standard
> Matlab learning model)
>
> b2=read('mat_2_b.csv') # bias for layer 2 (computed using standard
> Matlab learning model)
>
> bias2=nengo.Node(output=b2[0])
>
> layer2=nengo.networks.EnsembleArray(N,n_ensembles=len(w2[0]))
>
> nengo.Connection(bias2, layer2.input)
>
> nengo.Connection(layer1.output, layer2.input,
> transform=np.array(w2).T, function=transform,
>
> synapse=pstc)
>
>
>
> I got an error message:
>
>
>
> Traceback (most recent call last):
>
> File "D:/KnowThyself/CCN2015/nengoProjects/rbm-vision/digit.py", line
> 80, in <module>
>
> nengo.Connection(layer1.output, layer2.input,
> transform=np.array(w2).T, function=transform, synapse=pstc)
>
> File "C:\Users\User\Anaconda\lib\site-packages\nengo\base.py", line 24,
> in __call__
>
> inst.__init__(*args, **kwargs)
>
> File "C:\Users\User\Anaconda\lib\site-packages\nengo\connection.py",
> line 249, in __init__
>
> self.function_info = function # Must be set after transform
>
> File "C:\Users\User\Anaconda\lib\site-packages\nengo\base.py", line 63,
> in __setattr__
>
> super(NengoObject, self).__setattr__(name, val)
>
> File "C:\Users\User\Anaconda\lib\site-packages\nengo\params.py", line
> 239, in __set__
>
> super(FunctionParam, self).__set__(instance, function_info)
>
> File "C:\Users\User\Anaconda\lib\site-packages\nengo\params.py", line
> 69, in __set__
>
> self.validate(instance, value)
>
> File "C:\Users\User\Anaconda\lib\site-packages\nengo\connection.py",
> line 90, in validate
>
> "(%d)" % (type_pre, size_mid, transform.shape[1]))
>
> ValueError: Validation error when setting 'Connection.function_info': Node
> output size (1) not equal to transform input size (1000)
>
>
>
> I believe this error is due to the setting of a parameter,
> function=transform; however,
>
> I tried many ways and cannot get it work, and
>
> I cannot find the answer in the documents and the code in Github.
>
> Thank you for answering my question in advance.
>
>
>
> Sincerely,
>
>
>
> Shyh-Kang Jeng
>
> _______________________________________________
> nengo-user mailing list
> nengo-user at ctnsrv.uwaterloo.ca
> http://ctnsrv.uwaterloo.ca/mailman/listinfo/nengo-user
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://artsservices.uwaterloo.ca/pipermail/nengo-user/attachments/20151014/8cdfba45/attachment-0002.html>
More information about the nengo-user
mailing list