Hello everyone,

I am going through Theano Tutorials 
(http://deeplearning.net/software/theano/tutorial/gradients.html). I have a 
basic doubt:
why the foloowing return an error :
In [28]: x = T.dmatrix('x')
    ...: y = x**2
    ...: gy = T.grad(y, x)
    ...: dy = theano.function([x], gy)
    ...: 
    ...: 
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-28-74c00692575f> in <module>()
      1 x = T.dmatrix('x')
      2 y = x**2
----> 3 gy = T.grad(y, x)
      4 dy = theano.function([x], gy)
      5 

py27_venvs/venv/local/lib/python2.7/site-packages/theano/gradient.pyc in 
grad(cost, wrt, consider_constant, disconnected_inputs, add_names, known_grads, 
return_disconnected, null_gradients)
    485 
    486     if cost is not None and cost.ndim != 0:
--> 487         raise TypeError("cost must be a scalar.")
    488 
    489     if isinstance(wrt, set):

while writing y = T.sum(x**2) gives me elementwise grad succesfully.
In [29]: x = T.dmatrix('x')
    ...: y = T.sum(x**2)
    ...: gy = T.grad(y, x)
    ...: dy = theano.function([x], gy)
    ...: 

In [30]: dy([[0, 1], [-1, -2]])
Out[30]: 
array([[ 0.,  2.],
       [-2., -4.]])

with regards,
Satti

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"theano-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/theano-users/056bddee-4db4-4324-9706-64e5bbbb2783%40googlegroups.com.

Reply via email to