I'm just learning theano and I'm having some basic issues.

I've create a simple p-norm function which works, but I want to also create an L2norm function but I'm getting an error.

import theano
x = theano.tensor.dvector('x')
y = theano.tensor.dvector('y')
p = theano.tensor.dscalar('p')
pnorm = theano.function([x, y, p], pow(theano.tensor.sum((x - y) ** 2), p))

print pnorm([0, 0], [1, 1], 2)

L2norm = theano.function([x, y], pnorm(x, y, 2))

print L2norm([0, 0], [1, 1])

Also, is there a library of theano functions already implemented to do simple things like p-norm?

Thanks

asked Apr 16 '14 at 20:29

Chet%20Corcos's gravatar image

Chet Corcos
1223

What's the error message?

(Apr 17 '14 at 01:55) Justin Bayer

One Answer:

pnorm is a Theano function. You can't call a Theano function with symbolic variable. You need to call it with real value.

I think you want to define pnorm like this:

def pnorm(x, y, p): return pow(theano.tensor.sum((x - y) ** 2), p)

You will be able to call it with symbolic variable and your example should work.

answered Jun 27 '14 at 10:42

Nouiz's gravatar image

Nouiz
612

Your answer
toggle preview

powered by OSQA

User submitted content is under Creative Commons: Attribution - Share Alike; Other things copyright (C) 2010, MetaOptimize LLC.