<s> """<STR_LIT>""" <EOL> import sys <EOL> import os <EOL> import unittest <EOL> import numpy as np <EOL> from scipy . linalg import LinAlgError <EOL> from numpy . testing import assert_allclose <EOL> from quantecon . lqcontrol import LQ <EOL> from quantecon . robustlq import RBLQ <EOL> class TestRBLQControl ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> a_0 = <NUM_LIT:100> <EOL> a_1 = <NUM_LIT:0.5> <EOL> rho = <NUM_LIT> <EOL> sigma_d = <NUM_LIT> <EOL> beta = <NUM_LIT> <EOL> c = <NUM_LIT:2> <EOL> gamma = <NUM_LIT> <EOL> theta = <NUM_LIT> <EOL> ac = ( a_0 - c ) / <NUM_LIT> <EOL> R = np . array ( [ [ <NUM_LIT:0> , ac , <NUM_LIT:0> ] , <EOL> [ ac , - a_1 , <NUM_LIT:0.5> ] , <EOL> [ <NUM_LIT:0.> , <NUM_LIT:0.5> , <NUM_LIT:0> ] ] ) <EOL> R = - R <EOL> Q = gamma / <NUM_LIT:2> <EOL> A = np . array ( [ [ <NUM_LIT:1.> , <NUM_LIT:0.> , <NUM_LIT:0.> ] , <EOL> [ <NUM_LIT:0.> , <NUM_LIT:1.> , <NUM_LIT:0.> ] , <EOL> [ <NUM_LIT:0.> , <NUM_LIT:0.> , rho ] ] ) <EOL> B = np . array ( [ [ <NUM_LIT:0.> ] , <EOL> [ <NUM_LIT:1.> ] , <EOL> [ <NUM_LIT:0.> ] ] ) <EOL> C = np . array ( [ [ <NUM_LIT:0.> ] , <EOL> [ <NUM_LIT:0.> ] , <EOL> [ sigma_d ] ] ) <EOL> self . rblq_test = RBLQ ( Q , R , A , B , C , beta , theta ) <EOL> self . lq_test = LQ ( Q , R , A , B , C , beta ) <EOL> self . Fr , self . Kr , self . Pr = self . rblq_test . robust_rule ( ) <EOL> def tearDown ( self ) : <EOL> del self . rblq_test <EOL> def test_robust_rule_vs_simple ( self ) : <EOL> rblq = self . rblq_test <EOL> Fr , Kr , Pr = self . Fr , self . Kr , self . Pr <EOL> Fs , Ks , Ps = rblq . robust_rule_simple ( P_init = Pr , tol = <NUM_LIT> ) <EOL> assert_allclose ( Fr , Fs , rtol = <NUM_LIT> ) <EOL> assert_allclose ( Kr , Ks , rtol = <NUM_LIT> ) <EOL> assert_allclose ( Pr , Ps , rtol = <NUM_LIT> ) <EOL> def test_f2k_and_k2f ( self ) : <EOL> rblq = self . rblq_test <EOL> Fr , Kr , Pr = self . Fr , self . Kr , self . Pr <EOL> K_f2k , P_f2k = rblq . F_to_K ( Fr ) <EOL> F_k2f , P_k2f = rblq . K_to_F ( Kr ) <EOL> assert_allclose ( K_f2k , Kr , rtol = <NUM_LIT> ) <EOL> assert_allclose ( F_k2f , Fr , rtol = <NUM_LIT> ) <EOL> assert_allclose ( P_f2k , P_k2f , rtol = <NUM_LIT> ) <EOL> def test_evaluate_F ( self ) : <EOL> rblq = self . rblq_test <EOL> Fr , Kr , Pr = self . Fr , self . Kr , self . Pr <EOL> Kf , Pf , df , Of , of = rblq . evaluate_F ( Fr ) <EOL> assert_allclose ( Pf , Pr ) <EOL> assert_allclose ( Kf , Kr ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> suite = unittest . TestLoader ( ) . loadTestsFromTestCase ( TestRBLQControl ) <EOL> unittest . TextTestRunner ( verbosity = <NUM_LIT:2> , stream = sys . stderr ) . run ( suite ) </s>
