Let me be more specific. As to multiplying, I know that the result of 
gradient is something like [array(), array(), ...], the number of elements 
in this list is the number of derivative parameters.
If T.grad() * 2, it would double the number of elements in the list, but 
not the value of elements.
So what need to do if I want to multiply something with every element in 
the gradient list?

Same as the problem of summing

On Tuesday, July 19, 2016 at 3:50:45 PM UTC+8, 祝士祥 wrote:
>
> Hi everybody,
>
> I am trying to calculate the product between a result of gradient and a 
> formula, like this:
> T.grad(T.log(hl_mean).sum(), self.params, disconnected_inputs='warn') * T.
> log(vn_mean).sum()
> The error is:
> theano.tensor.var.AsTensorError: ('Cannot convert [dot.0, 
> Elemwise{mul}.0, Elemwise{second,no_inplace}.0] to TensorType', <type 
> 'list'>)
>
> And to sum multiple results of gradient, like this:
> (Rls, updates) = theano.scan(
>     calculate_Rl,
>     outputs_info=None,
>     non_sequences=v_input,
>     n_steps=hidden_sample_l
> )
> Rn = Rls.sum()
> calculate_Rl returns a result of gradient:
> def calculate_Rl(v_input):
>     # Sample a h_sample according to one v_input
>     _, hl_mean, hl_sample = self.sample_h_given_v(v_input)
>     # Calculate the probability of visible output according to h_sample
>     _, vn_mean = self.propdown(hl_sample)
>     # return T.grad(T.log(hl_mean).sum(), self.params, 
> disconnected_inputs='warn') \
>     #        * T.log(vn_mean).sum() \
>     #        + T.grad((T.log(vn_mean).sum()), self.params, 
> consider_constant=[vn_mean], disconnected_inputs='warn')
>     return T.grad(T.log(hl_mean).sum(), self.params, 
> disconnected_inputs='warn') * T.log(vn_mean).sum()
> The error is:
> AttributeError: 'list' object has no attribute 'sum'
>
> So, the question is how to operate the results of gradients in Theano? 
> Such as calculating product or sum? 
>
>
>
> Any help is appreciated! Thanks!
>
>
>

-- 

--- 
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].
For more options, visit https://groups.google.com/d/optout.

Reply via email to