Part 1: Core Concepts & Mathematical Breakdown
1. Fully Connected Neural Networks & Forward Propagation
A Fully Connected (Dense) Neural Network connects every node in layer to every node in layer .
Mathematical Formulation
For any layer :
- Pre-activation (Affine transformation):
- Post-activation: where (the network input).
Dissecting the Architecture from Your Slide
Looking at the computational graph in your image:
- Inputs: with bias input .
- Hidden Layer 1:
- Hidden Layer 2:
- Output Layer: Linear combination into (here, , or with weights ):
2. Activation Functions and Their Derivatives
Activation functions introduce non-linearities, allowing networks to approximate complex, non-linear functions (Universal Approximation Theorem).
1. Sigmoid ()
- Derivative derivation:
- Vanishing Gradient Problem: When is large, or , so . Multiplying many derivatives near across layers causes gradients to vanish.
2. ReLU (Rectified Linear Unit)
- Advantage: Constant gradient of for avoids vanishing gradients; computationally trivial.
3. Tanh (Hyperbolic Tangent)
- Advantage: Zero-centered output.
3. Cost Functions ()
1. Mean Squared Error (MSE) (Regression)
2. Binary Cross-Entropy (BCE) (Binary Classification)
4. Backpropagation & The Multivariate Chain Rule
To compute , we trace every forward path from parameter to the final loss .
Step-by-Step Breakdown of (From Your Slide)
In the slide, weight directly affects pre-activation , which produces . Then branches along two distinct paths to reach the loss:
- Path A:
- Path B:
By the chain rule for multivariate functions:
Expanding across both diverging paths:
Evaluating each factor directly:
- ,
Factoring out common terms :
5. Gradient Descent vs. Momentum
1. Standard Gradient Descent (GD)
- Weakness: In ravines (areas where the surface curves much more steeply in one direction than another), GD oscillates wildly perpendicular to the valley while making very slow progress toward the minimum.
2. Gradient Descent with Momentum
Alternative (Velocity) Formulation:
Let the velocity vector be . Then:
Mathematical Mechanics & Intuition:
- (typically ): Momentum parameter (friction coefficient).
- : The previous step taken.
- Why it works:
- Cancels Oscillations: In directions where gradients alternate signs (), the history terms add up and cancel out.
- Accelerates Along Plateaus: In directions where gradients persistently point the same way, velocities accumulate: For , progress along a flat gradient is up to faster than standard GD!
- Escaping Shallow Local Minima: Kinetic energy carries the weights over small local bumps/ridges.
Part 2: Practice Exam Problems & Solutions
Exam Problem 1: Manual Forward and Backward Pass with Sigmoid
Problem
Consider a simplified 2-layer network with one input , one hidden neuron , activation , and output . The cost function is MSE: Given:
- Input , Target
- Current parameters:
- Learning rate
- Compute the forward pass values for , and . (Use ).
- Compute the exact gradients and .
- Perform one step of Gradient Descent update for and .
Solution
1. Forward Pass
- Cost:
2. Backward Pass (Chain Rule)
- Output error signal:
- Gradient for :
- Gradient for :
3. Parameter Updates
Exam Problem 2: Numerical Calculation with Momentum
Problem
Consider the scalar objective function: We optimize using the momentum update rule: Given:
- Learning rate
- Momentum factor
- Starting positions: , and before the start assume (initial momentum is zero).
- State the gradient function .
- Calculate the value of at iteration .
- Calculate the value of at iteration .
- Show how the momentum term altered compared to standard Gradient Descent without momentum.
Solution
1. Gradient Function
2. Iteration (computing )
- Gradient at :
- Previous step difference:
- Update:
3. Iteration (computing )
- Gradient at :
- Previous step difference:
- Momentum term contribution:
- Update:
4. Comparison with Standard GD
- Without momentum ():
- Optimal point:
- Analysis:
- Without momentum, standard GD moved from (still above the minimum ).
- With momentum, the accumulated velocity carried the search from , taking a much larger stride downhill and temporarily overshooting past , demonstrating how momentum preserves kinetic energy.