Skip to content

Instantly share code, notes, and snippets.

@ahmadyan
Created November 12, 2018 04:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahmadyan/07b24d0fd3333ce3416f98683a68bd95 to your computer and use it in GitHub Desktop.
Save ahmadyan/07b24d0fd3333ce3416f98683a68bd95 to your computer and use it in GitHub Desktop.
Rosenbrock function example for auto-differentiation
// Rosenbrock function, a = 1.0, b = 100
class Rosenbrock {
public:
template <typename T>
bool operator()(const T *const x, const T *const y, T *cost) const {
cost[0] = (T(1.0) - x[0]) * (T(1.0) - x[0]) +
T(100.0) * (y[0] - x[0] * x[0]) * (y[0] - x[0] * x[0]);
return true;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment