Skip to content
DeepForgeby svx
All problems
MediumCalculusca-246

Natural Gradient Direction

Problem

The natural gradient precondition a Euclidean gradient by the Fisher information: d = F^{-1} g.

Given the gradient components g1, g2 and the symmetric Fisher matrix [[f11, f12], [f12, f22]], return the natural gradient as [d1, d2]. Return None when the Fisher matrix is singular.

Hint

The natural gradient is the inverse Fisher matrix applied to the ordinary gradient.

Test cases

case 1
in: [1,1,1,0,1]
expected: [1,1]
case 2
in: [2,4,2,0,1]
expected: [1,4]
case 3
in: [1,0,2,1,2]
expected: [0.6666666666666666,-0.3333333333333333]
case 4
in: [0,0,1,0,1]
expected: [0,0]
Starter codePython
def natural_gradient(g1, g2, f11, f12, f22):
    # Return [d1, d2]
    # Your code here
    pass

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