def R_op(self, inputs, eval_points):
outs = self(*inputs, **dict(return_list=True))
rval = [None for x in outs]
# For each output
for idx, out in enumerate(outs):
# make such that _bgrads computes only the gradients of the
# current output on the inputs ( and not all outputs)
ograds = [x.zeros_like() for x in outs]
ograds[idx] = theano.tensor.ones_like(out)
bgrads = self._bgrad(inputs, ograds)
rop_out = None
for jdx, (inp, eval_point) in enumerate(izip(inputs,
eval_points)):
# if None, then we can just ignore this branch ..
# what we do is to assume that for any non-differentiable
# branch, the gradient is actually 0, which I think is not
# the right thing to do .. have to talk to Ian and James
# about it
if bgrads[jdx] is None or \
isinstance(bgrads[jdx].type, DisconnectedType):
pass
elif eval_point is not None:
if rop_out is None:
rop_out = bgrads[jdx] * eval_point
else:
rop_out = rop_out + bgrads[jdx] * eval_point
rval[idx] = rop_out
return rval
评论列表
文章目录