Right, that's a bug (https://github.com/Theano/Theano/issues/5790).

However, for some reason `seq` seems to be defined as int64, which I
doubt is what you want since you are taking a gradient wrt it, which
would be 0.

Moreover, the expression for the gradient does not look right. It
currently returns 0 for the boundaries, which is not correct.
It should be 0 for param2 (changing it by epsilon would not change
the output most of the time), and the sum of the output gradients for
param1, at least when step > 0, which is your case.

On Mon, Mar 27, 2017, Julia K wrote:
> Hi,
> 
> I'm getting an error when trying to get the gradient of a function. 
> 
> Basically, I want to use two parameters to define the lower and upper bound 
> of an iterator.
> For easier understanding I simplified my code:
> 
> from theano import theano, tensor as tt
> 
> def get_sum(param1, param2):
>     seq = tt.arange(param1, param2)
>     
>     components, _ = theano.scan(lambda index: index**2,
>                                outputs_info=None,
>                                sequences=[seq])
>     return tt.sum(components)
> 
> 
> param1 = tt.dscalar('param1')
> param1.tag.test_value = 0.0
> 
> param2 = tt.dscalar('param2')
> param2.tag.test_value = 10.0
> 
> objective = get_sum(param1, param2)
> 
> obj_function = theano.function(inputs=[param1, param2],outputs=objective)
> 
> obj_gradient = theano.gradient.jacobian(objective,[param1])
> gradient_function = theano.function(inputs=[param1, param2], 
> outputs=obj_gradient)
> 
> ---------------------------------------------------------------------------
> 
> ...
> 
> TypeError: ARange{dtype='int64'}.grad illegally  returned an integer-valued 
> variable. (Input index 0, dtype int64)
> 
> 
> The function that is called in theano.scan (which is index**2 in the 
> example) could be any function that uses the index as one of its parameters.
> 
> What do I need to change about the code to make it work?
> 
> The same error occurs when using theano version 0.8.2 or 
> 0.9.0.dev-b3d19ce8e8d7cdf87c3f84599be81647803aa1f6
> 
> -- 
> 
> --- 
> 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 theano-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.


-- 
Pascal

-- 

--- 
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 theano-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to