-
Notifications
You must be signed in to change notification settings - Fork 912
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
grad is working, jacobian is not #64
Comments
As to your question, you need the cost function (and anything it calls that uses numpy code) to use autograd's wrapped numpy. The easiest fix would be to change the numpy import statement in my_module.py to use As a hack, your code could munge the numpy module before importing import autograd.numpy as np
from autograd import grad
import numpy as unwrapped_numpy
unwrapped_numpy.log = np.log
from my_module import cost The import of This hack is not a good long-term recipe, and it might even depend on CPython module loading details. (I didn't test it, but something along these lines should work.) |
Actually, I wasn't able to test this fix (the error doesn't happen on my Python 2.7.10 setup), so I'm reopening the issue until I can test it later today. If you notice it's still broken, please paste the full error traceback. |
Thank you for the swift response! I tested the fix but I don't think it works.. (Note that I manually hacked fix #64 in my code, as I am using pip. But from the error output you can see that the change is there). Here is the full error traceback:
As regarding my question, I will look into your proposed hack solution, thanks! |
Oh, the traceback shows the problem! The call to I'll revert the change I made; it wasn't necessary because the fix is already in master. We'll have to update the pip version. I'm going to close the issue because the bug doesn't exist on master, and we'll update the pip version at some point soon. |
Perfect, it works and sorry for the confusion. For other who might be interested, I used pip to install the latest master as follows: |
I'm not sure whether this is the right place for this follow up (as the original issue has been closed) but I put some more thought into my question regarding switching between the stripped down autograd.numpy and the original numpy. This is what I came up with. My import config
if not config.AUTOGRAD:
import numpy as np
from scipy import special
else:
import autograd.numpy as np
from autograd.scipy import special
# rest of my_module remains unchanged. The # Set autograd to active or not
AUTOGRAD = True If is True, the autograd.numpy is loaded, else the normal numpy is loaded. For my use case, this means I no longer have to copy paste functions from The price I pay is that if AUTOGRAD is set to True, then functions in Another option could be to move all the functions in |
That seems like a reasonable enough solution. Of course, if there are specific things in 'regular numpy' that are not in autograd.numpy, you can let us know by opening an issue! |
First of all, autograd is an amazing tool! The grad function works great, but I am not able to make the
jacobian
function work. I am on Python 3.4.3, numpy 1.10.1 and autograd 1.1.1 (pip).The call to the
jacobian
function works, but the function it returns does not accept my argument and throws aTypeError: The first input argument needs to be a sequence
The error seems to occur in the concatenate function, defined at
line 44 in autograd/core.py
(although I do believe this error is actually an error raised by numpy).A minimum example to reproduce this:
Another unrelated question (I am not sure if this is the correct place for this): If I wrote the above cost function in a separate module that imports numpy by itself (so not the autograd.numpy). Is it possible to somehow import this function from the module directly, instead of copy-pasting the code? Right now I get the following
AttributeError: 'FloatNode' object has no attribute 'log'
The import is as follows:
If I remove the
np.log
call from my cost function the error disappears. So I guess I somehow need to override the 'regular' numpy import with the autograd numpy import, if possible.The text was updated successfully, but these errors were encountered: