You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm having trouble getting anything to work the way I'm defining my functions, it's probably user error, but my example is terse.
I'm just trying to define a simple neural network and keep running into issues using np.tanh() or np.exp() and the only similar errors I could find are from having nested data structures, which I don't have.
Here's my full code snippet:
import autograd.numpy as np
from autograd import grad
action_dim = 2
feature_dim = 6
layer_dim = 4
w1 = np.random.rand(feature_dim, layer_dim)
b1 = np.random.rand(layer_dim)
w2 = np.random.rand(layer_dim, action_dim)
b2 = np.random.rand(action_dim)
def continuous_policy_function(w1, b1, w2, b2):
x = observation.dot(w1) + b1
x = 1.0 / (1.0 + np.exp(-x)) # sigmoid "squashing" function to interval [0,1]
out = x.dot(w2) + b2
return out
grad_function = grad(continuous_policy_function)
observation = np.random.rand(feature_dim)
action = continuous_policy_function(w1, b1, w2, b2)
print(grad_function(w1, b1, w2, b2))
and the full trace:
Traceback (most recent call last):
File "annoying_autograd.py", line 55, in <module>
print(grad_function(w1, b1, w2, b2))
File "/usr/local/Cellar/python3/3.6.4/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/autograd/wrap_util.py", line 20, in nary_f
return unary_operator(unary_f, x, *nary_op_args, **nary_op_kwargs)
File "/usr/local/Cellar/python3/3.6.4/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/autograd/differential_operators.py", line 24, in grad
vjp, ans = _make_vjp(fun, x)
File "/usr/local/Cellar/python3/3.6.4/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/autograd/core.py", line 10, in make_vjp
end_value, end_node = trace(start_node, fun, x)
File "/usr/local/Cellar/python3/3.6.4/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/autograd/tracer.py", line 10, in trace
end_box = fun(start_box)
File "/usr/local/Cellar/python3/3.6.4/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/autograd/wrap_util.py", line 15, in unary_f
return fun(*subargs, **kwargs)
File "annoying_autograd.py", line 29, in continuous_policy_function
x = 1.0 / (1.0 + np.exp(-x)) # sigmoid "squashing" function to interval [0,1]
File "/usr/local/Cellar/python3/3.6.4/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/autograd/tracer.py", line 48, in f_wrapped
return f_raw(*args, **kwargs)
AttributeError: 'ArrayBox' object has no attribute 'exp'
I'm using Python 3.6.4 and and autograd 1.2 which I pulled from pip this morning.
Please let me know what I'm doing wrong here! :)
The text was updated successfully, but these errors were encountered:
So I managed to fix this on my end but with little explanation of what I was doing wrong.
One thing that is clear is that I was using the wrong grad function, but I also had to replace all uses of dot with the @ operator. note: (this also works if you replace calls like observation.dot(w1) with np.dot(observation, w1 )
... ¯_(ツ)_/¯ I'd love to know if there is something deeper going on here!
import autograd.numpy as np
from autograd import elementwise_grad as egrad # for functions that vectorize over inputs
action_dim = 2
feature_dim = 6
layer_dim = 4
w1 = np.random.rand(feature_dim, layer_dim)
b1 = np.random.rand(layer_dim)
w2 = np.random.rand(layer_dim, action_dim)
b2 = np.random.rand(action_dim)
def continuous_policy_function(w1, b1, w2, b2):
x = observation @ w1 + b1
x = 1.0 / (1.0 + np.exp(-x)) # sigmoid "squashing" function to interval [0,1]
out = x @ w2 + b2
return out
grad_function = egrad(continuous_policy_function)
observation = np.random.rand(feature_dim)
action = continuous_policy_function(w1, b1, w2, b2)
print(grad_function(w1, b1, w2, b2))
I'm having trouble getting anything to work the way I'm defining my functions, it's probably user error, but my example is terse.
I'm just trying to define a simple neural network and keep running into issues using
np.tanh()
ornp.exp()
and the only similar errors I could find are from having nested data structures, which I don't have.Here's my full code snippet:
and the full trace:
I'm using Python 3.6.4 and and autograd 1.2 which I pulled from pip this morning.
Please let me know what I'm doing wrong here! :)
The text was updated successfully, but these errors were encountered: