AutoGrad.jl icon indicating copy to clipboard operation
AutoGrad.jl copied to clipboard

cannot take derivative of a scalar function

Open denizyuret opened this issue 6 years ago • 6 comments

See https://github.com/denizyuret/Knet.jl/issues/410

denizyuret avatar Dec 20 '18 13:12 denizyuret

This turned out to be tough nut to crack: it has to do with broadcast multiplying a Result{Array} with an Array{Any} that has Result's in it. I am not sure this code does anything useful but it certainly proved useful as a test case. @ekinakyurek where did you find this code and what is it supposed to compute?

denizyuret avatar Jan 05 '19 02:01 denizyuret

This the forward part of my code for calculating gradients via backslash. I was just trying to benchmark it with AutoGrad, then I got this message.

On Sat, Jan 5, 2019 at 5:16 AM denizyuret [email protected] wrote:

This turned out to be tough nut to crack: it has to do with broadcast multiplying a Result{Array} with an Array{Any} that has Result's in it. I am not sure this code does anything useful but it certainly proved useful as a test case. @ekinakyurek https://github.com/ekinakyurek where did you find this code and what is it supposed to compute?

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/denizyuret/AutoGrad.jl/issues/106#issuecomment-451619783, or mute the thread https://github.com/notifications/unsubscribe-auth/AOpr8YTMIDT47N_U1RMCMVRBlaVbVbC6ks5vAAsKgaJpZM4ZcNZ_ .

ekinakyurek avatar Jan 05 '19 07:01 ekinakyurek

I am not sure if that is exactly the same problem, but gives "AssertionError: Only scalar valued functions supported." with the code below.

using CuArrays
using AutoGrad
a= Param([cu(rand(4,1)) for i=1:4])
f(x) = (maximum.(a)).^2
@show f(a)
dvals = @diff f(a)
parameters = collect(params(dvals))
map(x->grad(dvals, x),parameters)

hiiroo avatar Mar 01 '19 16:03 hiiroo

The plot of F(t) runs. But Fd(t) can not run. I see the same error (AssertionError: Only scalar valued functions supported.)

using Knet, Plots F(t) = sin.(t) Fd = grad(F)

t=0:0.1:2*3.14 plot(F(t)) plot(Fd(t))

fatihtalu avatar Jun 23 '20 13:06 fatihtalu

To take the grad of F, F should return a scalar value. Then you can apply broadcasted version of both F and Fd on t.

using Knet, Plots
F(t) = sin(t)
Fd = grad(F)

t=0:0.1:2*3.14
plot(F.(t))
plot(Fd.(t))

ozanarkancan avatar Jun 23 '20 13:06 ozanarkancan

Thank you very much Ozan. The answer is true.

fatihtalu avatar Jun 23 '20 14:06 fatihtalu