Created
October 19, 2011 03:42
-
-
Save dwf/1297430 to your computer and use it in GitHub Desktop.
Demonstrates an issue with the numerical stability of the gradient of arccos.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import theano.tensor as tensor | |
| from theano import function | |
| import numpy as np | |
| value = np.array([ 0.992827313923019039165751564724, | |
| 0.118152792712208978831434080803, | |
| -0.008531793400639134036800292904, | |
| 0.016157066691618496290239193058]) | |
| aa = tensor.vector('aa') | |
| bb = tensor.vector('bb') | |
| ee = tensor.scalar() | |
| cc = tensor.arccos(tensor.clip((aa * bb).sum(), -1, 1 - ee)) | |
| dd = tensor.grad(cc, bb) | |
| g = function([aa, bb, ee], dd) | |
| print g(value, value, 1e-7) | |
| print g(value, value, 1e-8) | |
| print g(value, value, 1e-9) | |
| print g(value, value, 0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Output of the above Python code as of Theano master 11ee6cee3b: | |
| wardefar@grieg:~$ python test.py | |
| [-0. -0. 0. -0.] | |
| [-0. -0. 0. -0.] | |
| [-0. -0. 0. -0.] | |
| [-66627513.18554519 -7929099.69734382 572558.96299959 | |
| -1084282.39124676] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment