If there is no influence from p[i] to e[j] when i != j (as it seems to
be the case here), you can simply call T.grad(e.sum(), p).
On Fri, Nov 25, 2016, Emanuele Ruffaldi wrote:
>
> A question about broadcasting a general expression graph. The specific use
> is in the gradient of the distance to a sphere:
>
> c = T.vector('c') # center
> r2 = T.scalar(); # radius
> p = T.matrix('g') # points N x 3
> e = (r2-(c-p).norm(2,axis=1)) # distances N
>
>
> G1 = T.grad(e,p) # error - because e is vectorial
> GJ = T.jacobian(e,p) # generates a N x N x 3 jacobian,and I don't want the
> intermediates
>
> The workaround for the above is to express the equation over a vector:
>
> pv = T.vector('g') # single point
> ev = (r2-(c-pv).norm(2)) # 1
> Gv = T.grad(ev,pv) # 1 x 3
>
> But then if I want to evaluate a function obtained from Gv over a matrix of
> points x sized N x 3 I need to iterate, and that's inefficient:
>
> f = function([r2,c,pv],Gv)
>
> for i in range(0,x.shape[0]):
> rg[i,:] = f(3.0,...,x[i,:])
>
> Instead of this loop I would like to create a single symbolic expression
> that takes N point and produces all the gradients giving as output N x 3.
>
> Is there anyway to perform this operation? It seems like a broadcasting
> operation of a subexpression (ev) by replacing one of the terms (pv) with a
> row from the input (x). The replace method of the expression graph does not
> work because it is not possible to transform a vector term to a matrix term.
>
> Any suggestion will be appreciated
>
> Best Regards,
> Emanuele
>
>
>
> --
>
> ---
> 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.
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.