Skip to content
DeepForgeby svx
All problems
EasyOptimizationop-238

Centralized Gradient Norm

Problem

Compute the Euclidean norm of a gradient vector after gradient centralization.

Subtract the mean of the components from each component, then return the norm of the centered vector. An empty input returns 0.0, and a constant vector centers to the zero vector.

Hint

Centralization removes the projection onto the all-ones direction.

Test cases

case 1
in: [[1,2,3]]
expected: 1.4142135623730951
case 2
in: [[-1,0,1,2]]
expected: 2.23606797749979
case 3
in: [[4,4,4]]
expected: 0
case 4
in: [[]]
expected: 0
case 5
in: [[5]]
expected: 0
Starter codePython
def centralized_grad_norm(g):
    # Your code here
    pass

5 test cases · run your code against them in the editor