8000 Issue with hypot in reverse mode · Issue #243 · autodiff/autodiff · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Sk 8000 ip to content
Issue with hypot in reverse mode #243
Closed
@HongyiSun

Description

@HongyiSun

Hello, Thank you for open sourced this great project!
I'm trying to play with the reverse mode with some simple code on getting the Hessian of hypot function. The result was not reasonable. Is there anything wrong on my code or how I should use the interface? Any help would be much appreciated.

Here are my sample code,

#include <autodiff/reverse/var.hpp>
#include <iostream>

using namespace autodiff;

int main() {
  var x = 1.0;
  var y = 1.0;
  var u = hypot(x, y);
  // var u = sqrt(x * x + y * y);

  auto [ux, uy] = derivativesx(u, wrt(x, y));
  auto [uxx, uxy] = derivativesx(ux, wrt(x, y));
  auto [uyx, uyy] = derivativesx(uy, wrt(x, y));
  std::cout << "u = " << u << std::endl;
  std::cout << "ux = " << ux << "\nuy = " << uy << std::endl;
  std::cout << "[uxx, uxy] = [" << uxx << ", " << uxy << "]\n"
            << "[uyx, uyy] = [" << uyx << ", " << uyy << "]" << std::endl;
}

And my result is,

u = 1.41421
ux = 0.707107
uy = 0.707107
[uxx, uxy] = [0.707107, 0]
[uyx, uyy] = [0, 0.707107]

While when I'm using var u = sqrt(x * x + y * y) instead of var u = hypot(x, y), the result looks good as,

u = 1.41421
ux = 0.707107
uy = 0.707107
[uxx, uxy] = [0.353553, -0.353553]
[uyx, uyy] = [-0.353553, 0.353553]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0