Implement one update step of the AdaGrad optimizer. Given current parameters, gradients, and accumulated squared gradients, return updated parameters and accumulator.
Step 1: Accumulate Squared Gradients
Gt=Gt−1+gt2Step 2: Parameter Update
wt=wt−1−Gt+εη⋅gtWhere: w = parameters, g = gradients, G = accumulated squared gradients, η = learning rate, ε = stability constant
w: np.ndarray - Current parameters (any shape)g: np.ndarray - Current gradients (same shape as w)G: np.ndarray - Accumulated squared gradients (same shape as w)lr: float = 0.01 - Learning rateeps: float = 1e-8 - Small constant for numerical stabilityInput: w=[1.0, 2.0], g=[0.1, -0.2], G=[0.0, 0.0], lr=0.1
Output: ([0.9, 2.1], [0.01, 0.04])
First step: G becomes [0.01, 0.04], then w updated with adaptive learning rates
Input: w=[1.0, 2.0], g=[0.0, 0.0], G=[0.1, 0.2], lr=0.1
Output: ([1.0, 2.0], [0.1, 0.2])
Zero gradient means no parameter update and G stays unchanged
Input: w=[0.0], g=[1.0], G=[100.0], lr=0.1
Output: ([-0.00995], [101.0])
Large accumulated G leads to very small effective learning rate (0.1/√101 ≈ 0.00995)
Convert inputs to NumPy arrays first. Update G by adding the squared gradients.
Use element-wise operations: np.sqrt() for the denominator and standard arithmetic for the parameter update.
(new_w, new_G) with same shapes as inputsSign in to take notes on this problem
Accepts: array
Accepts: array
Accepts: array
Accepts: number
Accepts: number
Implement one update step of the AdaGrad optimizer. Given current parameters, gradients, and accumulated squared gradients, return updated parameters and accumulator.
Step 1: Accumulate Squared Gradients
Gt=Gt−1+gt2Step 2: Parameter Update
wt=wt−1−Gt+εη⋅gtWhere: w = parameters, g = gradients, G = accumulated squared gradients, η = learning rate, ε = stability constant
w: np.ndarray - Current parameters (any shape)g: np.ndarray - Current gradients (same shape as w)G: np.ndarray - Accumulated squared gradients (same shape as w)lr: float = 0.01 - Learning rateeps: float = 1e-8 - Small constant for numerical stabilityInput: w=[1.0, 2.0], g=[0.1, -0.2], G=[0.0, 0.0], lr=0.1
Output: ([0.9, 2.1], [0.01, 0.04])
First step: G becomes [0.01, 0.04], then w updated with adaptive learning rates
Input: w=[1.0, 2.0], g=[0.0, 0.0], G=[0.1, 0.2], lr=0.1
Output: ([1.0, 2.0], [0.1, 0.2])
Zero gradient means no parameter update and G stays unchanged
Input: w=[0.0], g=[1.0], G=[100.0], lr=0.1
Output: ([-0.00995], [101.0])
Large accumulated G leads to very small effective learning rate (0.1/√101 ≈ 0.00995)
Convert inputs to NumPy arrays first. Update G by adding the squared gradients.
Use element-wise operations: np.sqrt() for the denominator and standard arithmetic for the parameter update.
(new_w, new_G) with same shapes as inputsSign in to take notes on this problem
Accepts: array
Accepts: array
Accepts: array
Accepts: number
Accepts: number