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

Autograd usage problem #66

Closed
fatihtalu opened this issue Mar 20, 2018 · 3 comments
Closed

Autograd usage problem #66

fatihtalu opened this issue Mar 20, 2018 · 3 comments

Comments

@fatihtalu
Copy link

I want to generate the gradient value at [1,2]. I wrote the following code to do this, but it gives an error. Thanks in advance for your help.

using Knet
J(w) = w[1]^2 .+ w[2]^2;
dJ = grad(J);
w = [1,2];
println(J(w))
println(dJ(w))

Output:
5
MethodError: ^(::AutoGrad.Rec{Int64}, ::Int64) is ambiguous. Candidates:
^(x, p::Integer) in Base at intfuncs.jl:199
^(x1::AutoGrad.Rec{##1045}, x2::##1046) where {##1045<:Number, ##1046<:Number} in AutoGrad
Possible fix, define
^(::AutoGrad.Rec{##1045<:Number}, ::Integer)

@fatihtalu
Copy link
Author

Trying with broadcast, it gives the following error:
println(dJ.(w))
Output:
BoundsError

@CarloLucibello
Copy link
Collaborator

This has been fixed recently in master (Ref. #48) . Try after

Pkg.checkout("AutoGrad")
Pkg.checkout("Knet")

As an alternative, you could consider evaluating in [1.0, 2.0]

@fatihtalu
Copy link
Author

Thanks CarloLucibello.
After tried [1.0, 2.0], the problem is solved.
Output:

5.0
[2.0, 4.0]

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

No branches or pull requests

2 participants