HIPS / autograd

Efficiently computes derivatives of numpy code.
MIT License
6.88k stars 907 forks source link

Add to_array function to Arraybox #362

Open alexanderwhatley opened 6 years ago

alexanderwhatley commented 6 years ago

I'm using autograd together with scipy's odeint in a function of the form


C = lambda x: (x - f) @ (x - f)
def cost(coeffs):
    func_vals = odeint(func, [f_0, f_prime_0], t, args=(coeffs._value,))[0]
    return C(func_vals)

Right now, I have to access coeffs._value to get the numpy array to pass in, or else scipy throws an error message, as coeffs is turned into an Arraybox object. I think it would make sense to add a to_numpy or to_array function to Arraybox so I would not have to access a private property.

terhorst commented 6 years ago

Accessing _value fails unexpectedly for me sometimes. This seems like a really common operation (comes up all the time in reinforcement learning, EM-style algorithms, etc.) where you do not want gradients to propagate for certain operations. Is there a correct way to do this?