Skip to content
DeepForgeby svx
All problems

TRPO CG One Step

Problem

Take one conjugate-gradient step of the TRPO trust-region subproblem, starting from x = 0.

With r = b - A x = b and p = r, compute Ap, then alpha = (r . r) / (p . Ap) and return x + alpha * p. If p . Ap is zero, return the zero vector.

Hint

One CG iteration is exact when b is an eigenvector of A.

Test cases

case 1
in: [[[1,0],[0,1]],[2,3]]
expected: [2,3]
case 2
in: [[[2,0],[0,4]],[2,4]]
expected: [0.5555555555555556,1.1111111111111112]
case 3
in: [[[2,1],[1,2]],[1,0]]
expected: [0.5,0]
case 4
in: [[[1,0],[0,1]],[0,0]]
expected: [0,0]
Starter codePython
def trpo_cg_step(A, b):
    # Your code here
    pass

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