Closed axch closed 7 years ago
In commit 09876c9f75f512b8c2887d0ba5258414f09b81d9 I replaced math.log
by np.log
in the code to compute the gradient of pow
, so that for the partial wrt the exponent it gives NaN instead of raising an exception when the base is a negative real. I have not confirmed that this change doesn't have bad consequences, but it does seem to get around the immediate problem I had with gradient methods, which now give a sensible result.
I think actually solves this.
The "correct" answer is that exponentiation with negative base and real-valued exponent is undefined, so crash. However, a relatively common use case of
**
is to spell polynomials, as withx**3
. In this case, the gradient of**
should clearly be[3x**2, 0]
, even for negativex
, as the exponent is intended to be a non-varying integer.If we had first-class integers (#436, #570) in Venture I would be comfortable defining the gradient of
**
to be generic in the argument type, and produce the latter answer if the exponent came in as an integer. That policy would also suggest doing the same thing for other type-generic numerical operations, and/or teaching integers to accept "gradient" steps but not move.