Auto differentiation with cpp
This is a toy example of auto differentiation in cpp. The basic idea is to build a static computation graph including all the extra nodes for calculating the gradients. Basically, what we need are:
- class Node, the nodes in the computation graph, including the input nodes, the operation type, ...
- class Operation, to perform the detailed forward and backward computation.
To build the backprop-graph, we make a reverse topological sort and use the chain rule to calculate the gradients. After the graph construction, we feed the input values and run forward on the whole computation graph.
- Addition
- Multiplication
Reference:
- CSE599W: http://dlsys.cs.washington.edu/