A Signal-Flow-Graph Approach to On-line Gradient Calculation