Skip to content
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

cannot take derivative of a scalar function #106

Open
denizyuret opened this issue Dec 20, 2018 · 6 comments
Open

cannot take derivative of a scalar function #106

denizyuret opened this issue Dec 20, 2018 · 6 comments
Labels

Comments

@denizyuret
Copy link
Owner

See denizyuret/Knet.jl#410

@denizyuret denizyuret added the bug label Dec 20, 2018
denizyuret added a commit that referenced this issue Dec 25, 2018
@denizyuret
Copy link
Owner Author

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?

@ekinakyurek
Copy link
Collaborator

ekinakyurek commented Jan 5, 2019 via email

@hiiroo
Copy link

hiiroo commented Mar 1, 2019

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)

@fatihtalu
Copy link

fatihtalu commented Jun 23, 2020

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))

@ozanarkancan
Copy link
Contributor

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))

@fatihtalu
Copy link

Thank you very much Ozan.
The answer is true.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants