Exemplo n.º 1
0
    def test_noninteractive(self):
        "Test case for when agents don't interact with each other"
        # Copied these values from test_lqcontrol
        a = np.array([[.95, 0.], [0, .95]])
        b1 = np.array([.95, 0.])
        b2 = np.array([0., .95])
        r1 = np.array([[-.25, 0.], [0., 0.]])
        r2 = np.array([[0., 0.], [0., -.25]])
        q1 = np.array([[-.15]])
        q2 = np.array([[-.15]])
        f1, f2, p1, p2 = nnash(a, b1, b2, r1, r2, q1, q2, 0, 0, 0, 0, 0, 0,
                               tol=1e-8, max_iter=10000)

        alq = a[:1, :1]
        blq = b1[:1].reshape((1, 1))
        rlq = r1[:1, :1]
        qlq = q1

        lq_obj = LQ(qlq, rlq, alq, blq, beta=1.)
        p, f, d = lq_obj.stationary_values()

        assert_allclose(f1, f2[:, ::-1])
        assert_allclose(f1[0, 0], f[0])
        assert_allclose(p1[0, 0], p2[1, 1])
        assert_allclose(p1[0, 0], p[0, 0])
Exemplo n.º 2
0
    def test_noninteractive(self):
        "Test case for when agents don't interact with each other"
        # Copied these values from test_lqcontrol
        a = np.array([[.95, 0.], [0, .95]])
        b1 = np.array([.95, 0.])
        b2 = np.array([0., .95])
        r1 = np.array([[-.25, 0.], [0., 0.]])
        r2 = np.array([[0., 0.], [0., -.25]])
        q1 = np.array([[-.15]])
        q2 = np.array([[-.15]])
        f1, f2, p1, p2 = nnash(a, b1, b2, r1, r2, q1, q2, 0, 0, 0, 0, 0, 0,
                               tol=1e-8, max_iter=10000)

        alq = a[:1, :1]
        blq = b1[:1].reshape((1, 1))
        rlq = r1[:1, :1]
        qlq = q1

        lq_obj = LQ(qlq, rlq, alq, blq, beta=1.)
        p, f, d = lq_obj.stationary_values()

        assert_allclose(f1, f2[:, ::-1])
        assert_allclose(f1[0, 0], f[0])
        assert_allclose(p1[0, 0], p2[1, 1])
        assert_allclose(p1[0, 0], p[0, 0])
    plt.plot(xs,density(xs))
    plt.show()

############
#  AD-HOC #
###########    
theta =2
R=-R
F, P, K = quantecon.robustlq.RBLQ(Q,R,A,B,C,beta,theta).robust_rule()

P = quantecon.solve_discrete_riccati(A, B, R, Q)
from quantecon.lqcontrol import LQ
I=np.eye(4)
lq = LQ(-beta*I*theta, R, A, C, beta=beta)

Ptest, ftest, dtest = lq.stationary_values()




theta =901

A=np.matrix([[rho1,0,0,0],
             [0,rho2,0,0],
             [0,0,rho3,0],
             [0,0,0,rho4]])

B=np.zeros((4,4))

C=np.identity(4)
Exemplo n.º 4
0
B = np.matrix([[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]])

C = np.matrix([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]])

Q = np.matrix([[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]])

R = np.matrix([[r1, 0, 0, 0], [0, r2, 0, 0], [0, 0, r3, 0], [0, 0, 0, r4]])

P = np.ones(4)
I = np.ones(4)
Z = np.zeros(4)
quantecon.robustlq.RBLQ(Q, R, A, B, C, beta, theta).robust_rule()
F, K, P = quantecon.robustlq.RBLQ.robust_rule()

lq = LQ(-beta * I * theta, R, A, C, beta=beta)
P, f, d = lq.stationary_values()

#Define M for Schur-Decomposition

M11 = A + C * np.linalg.inv(beta * theta * A) * C.T * R
M12 = C * np.linalg.inv(beta * theta * A) * C.T
M21 = np.linalg.inv(A) * R
M22 = np.linalg.inv(A)

M1 = np.hstack((M11, M12))
M2 = np.hstack((M21, M22))

M = np.vstack((M1, M2))

[T, Z, sdim] = scipy.linalg.schur(M, output='real', sort='iuc')