Goal: Evaluate a tape with forward AD mode.
Prerequisite: Tutorial 2 - Reverse mode AD
Function:
Full code:
#include <codi.hpp>
#include <iostream>
return x * x * x;
}
int main(int nargs, char** args) {
tape.setActive();
tape.registerInput(x);
tape.registerOutput(y);
tape.setPassive();
tape.evaluateForward();
std::cout << "f(4.0) = " << y << std::endl;
std::cout <<
"df/dx(4.0) = " << y.
getGradient() << std::endl;
tape.reset();
return 0;
}
Forward mode tape evaluation works the same as a reverse mode tape evaluation. Only the inputs need to be seeded and the derivatives are obtained from the outputs.