1

I am executing the following on theano:

>>> import theano
>>> import theano.tensor as T
>>> x = T.dvector('x')
>>> y = T.dvector('y')
>>> f = T.dot(x,y)
>>> Jy= T.Rop(f,x,y)
>>> fun = theano.function([x,y],Jy)
>>> fun([1000,2000,3000],[2,4,8])
array(84.0)

However, if I calculate a simple example by hand I have:

x = [x1,x2,x3]
y = [y1,y2,y3]
f = [x1y1,x2y2,x3y3]
df/dx = |y1, 0, 0|
        |0, y2, 0|
        |0,  0,y3|
(df/dx)*y = [y1^2, y2^2, y3^2]

Thus I would expect a result of [4, 16, 64], but instead I get the sum of these. What is the Rop calculating differently?

Cantfindname
  • 2,008
  • 1
  • 17
  • 30

1 Answers1

1

The difference is caused by a misunderstanding of what theano.dot is doing in your sample code.

theano.dot(x, y) is equal to the scalar 34000 given your example inputs because it is computing the vector inner product not the element-wise product, as your hand example suggests you expect.

One can get the result you expect by changing

f = T.dot(x,y)

to

f = x * y
Daniel Renshaw
  • 33,729
  • 8
  • 75
  • 94