Thanks, that's what I needed. Even in this case I find interesting how the
expressions just depend on the tensor rank and not on the specific
dimension sizes.

Best Regards,
-E

2016-11-25 21:38 GMT+01:00 Pascal Lamblin <[email protected]>:

> 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 a topic in the
> Google Groups "theano-users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/theano-users/RSFpNhKDtIs/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> For more options, visit https://groups.google.com/d/optout.
>



-- 
--------
Emanuele Ruffaldi, Ph.D. - Assistant Professor
PERCRO, TeCIP Institute - Scuola Superiore Sant'Anna
via Luigi Alamanni 13D, San Giuliano Terme 56010 (PI), Italy
mob.: +39 340 46 72 468 - tel.: +39 050 882 508
fax.: +39 050 882 564 - skype: pititaly
http://www.percro.org - http://www.teslacore.it
--------

-- 

--- 
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