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

pow applied to mixed variables #2993

Closed
jeanchristopheruel opened this issue Dec 29, 2023 · 5 comments
Closed

pow applied to mixed variables #2993

jeanchristopheruel opened this issue Dec 29, 2023 · 5 comments

Comments

@jeanchristopheruel
Copy link

jeanchristopheruel commented Dec 29, 2023

AD of pow<fvar<var>>(0, 0) causes NAN adjoint. pow<fvar<var>>(0, 0) and pow<var>(0, 0) both behave as expected.

Update
pow<var>(0, 0) should return NAN adjoint since the partials are undefined.

Steps to reproduce

stan::math::nested_rev_autodiff nested{};
stan::math::var t{0.0};
auto foo = stan::math::pow(t,0);
foo.grad();
assert(not std::isfinite(t.adj()));  // fails

Current Version:

v4.7.0

@andrjohns
Copy link
Collaborator

I think this is correct, as the second derivative of pow(x, y) w.r.t. x:

$$ \frac{d^2}{dx^2}(x^y) = x^{(-2 + y)} \cdot (-1 + y) \cdot y $$

Is not defined when both x & y are 0

@andrjohns
Copy link
Collaborator

Ah I see, we handle this in the rev header by skipping the partials update. Thanks for catching this!

@jeanchristopheruel
Copy link
Author

jeanchristopheruel commented Dec 29, 2023

Yes exacly! It is handled for rev here. You are also right, the partials are undefined.

@jeanchristopheruel
Copy link
Author

jeanchristopheruel commented Dec 29, 2023

Actually, I think pow<var> is the issue. Check out my suggestion!

@andrjohns
Copy link
Collaborator

Covered as part of #3031

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