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

Subtraction in Algodiff #532

Closed
priamfive opened this issue Jun 17, 2020 · 2 comments
Closed

Subtraction in Algodiff #532

priamfive opened this issue Jun 17, 2020 · 2 comments
Assignees
Labels

Comments

@priamfive
Copy link

Hi, I have been experimenting with Algodiff and have had some odd behavior with subtraction.
I'm not sure if I am doing something wrong. If I want to differentiate f(x)=1-x, I seem to get an odd result if I do it in the obvious way:
`# #require "owl-top";;

module AD = Owl.Algodiff.D;;

module AD = Owl.Algodiff.D

let f x = AD.Maths.((F 1.0) - x);;

val f : AD.t -> AD.t =

let f1 = AD.diff f;;

val f1 : AD.t -> AD.t =

f1 (F 0.0);;

  • : AD.t = [F(1)]

let g x = AD.Maths.((F 1.0) + (neg x));;

val g : AD.t -> AD.t =

let g1 = AD.diff g;;

val g1 : AD.t -> AD.t =

g1 (F 0.0);;

  • : AD.t = [F(-1)]
    `
    The second way (using g) works but the first (using f) has the wrong sign.

Perhaps the second way is what is supposed to be used but this wasn't clear from the excellent draft Owl book.

@tachukao
Copy link
Member

@priamfive thanks for raising this issue. The culprit was this line

let df_db _cp _ap _bp bt = bt

Instead of bt it should have been neg bt. This is now fixed in the PR #533

@priamfive
Copy link
Author

Great - thanks for all the good work on Owl.

@priamfive priamfive added this to Done (2020) in owl development via automation Jun 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
owl development
  
Done (2020)
Development

No branches or pull requests

3 participants