All problems
Yule-Walker AR(2) Solve
Problem
Solve the Yule-Walker equations for an AR(2) model given lag-1 and lag-2 autocorrelations: the system [1 r1; r1 1] * [phi1; phi2] = [r1; r2].
Return [phi1, phi2] using phi1 = r1 * (1 - r2) / (1 - r1^2) and phi2 = (r2 - r1^2) / (1 - r1^2). If 1 - r1^2 is 0, return [0.0, 0.0].
Hint
This is a 2x2 linear system; Cramer's rule gives the closed form.
Test cases
case 1
in: [0.5,0.25]
expected: [0.5,0]
case 2
in: [0.6,0.3]
expected: [0.65625,-0.09375]
case 3
in: [0.4,-0.2]
expected: [0.5714285714285715,-0.42857142857142866]
case 4
in: [0,0]
expected: [0,0]
Starter codePython
def yule_walker_ar2(r1, r2):
# Your code here
pass4 test cases · run your code against them in the editor