Ejemplo n.º 1
0
def verify_LUUL_vs_R2(n, print_option = False):

    redh_m = redh_mat(n)
    L = L_matri(n)
    U = U_matri(n)

    LU = np.dot(L, U)
    LUU = np.dot(LU, U.T)
    LUUL = np.dot(LUU, L.T)
    UU = np.dot(U, U.T)

    R2 = np.dot(redh_m, redh_m.T)

    if(print_option == True):
        print "n = ", n, ", L, UU, R'R"
        print L
        print UU
        print R2

        if(np.allclose(R2, LUUL, rtol=1e-03, atol=1e-05)):
            print 'LUUL_vs_R2: two methods give same results, n = ', n

    UU_tr = np.trace(UU)
    R2_tr = np.trace(R2)
    print "LUUL, n = ", n, ", UU_tr = ", UU_tr, ", R2_tr = ", R2_tr, "\n"

    return L, UU, UU_tr, R2_tr
Ejemplo n.º 2
0
def verify_ULLU_vs_R2(n, print_option = False):

    redh_m = redh_mat(n)
    L = L_matri(n)
    U = U_matri(n)

    UL = np.dot(U.T, L.T)
    ULL = np.dot(UL, L)
    ULLU = np.dot(ULL, U)
    LL = np.dot(L.T, L)

    R2 = np.dot(redh_m.T, redh_m)

    if(print_option == True):
        print "n = ", n, ", U, LL, R'R"
        print U
        print LL
        print R2

        if(np.allclose(R2, ULLU, rtol=1e-03, atol=1e-05)):
            print 'ULLU_vs_R2: two methods give same results, n = ', n

    LL_tr = np.trace(LL)
    R2_tr = np.trace(R2)
    print "ULLU, n = ", n, ", LL_tr = ", LL_tr, ", R2_tr = ", R2_tr, "\n"

    return U, LL, LL_tr, R2_tr
Ejemplo n.º 3
0
def check_redh1000_mt2_1_positive(n, print_option):

    redh_m = redh_mat(n)
    # R*R'
    redh_mt2 = np.dot(redh_m, redh_m.T)

    # 10000*R*R' - I, substract an identity matrix I
    redh10000_mt2_1 = 10000*redh_mt2 - np.eye(n, dtype = int)
    redh10000_mt2_1_pos = check_mat_semipos(n, redh10000_mt2_1 , 'redh10000_mt2_1', print_option)

    return redh10000_mt2_1_pos
Ejemplo n.º 4
0
def get_H_from_redh_mat(n):

    rhm = redh_mat(n)
    n_eye = np.eye(n)

    A = rhm - n_eye

    # At this moment, we do not know how to do matrix decomposition such as: redh_mat R = I + HQH'
    # Let's just do a SVD decomposition to see what we can get: R = I + USV
    U, s, V = np.linalg.svd(A, full_matrices=True)

    print 'U:', U
    print 's:', s
    print 'V:', V
    print 'V_transpo', V.transpose()
Ejemplo n.º 5
0
def verify_LU_of_Redh(n, print_option = False):

    redh_m = redh_mat(n)
    L = L_matri(n)
    U = U_matri(n)

    LU = np.dot(L, U)

    if(print_option == True):
        print "L, U, R"
        print L
        print U
        print redh_m, "\n"

        if(np.allclose(redh_m, LU, rtol=1e-03, atol=1e-05)):
            print 'n = ', n, ', LU = R, two methods give same results'
Ejemplo n.º 6
0
def use_sqrtm_approx_of_H_K(n, print_option = True):

    redh_m = redh_mat(n)
    redh_mt2 = np.dot(redh_m, redh_m.T)

    # Use mp to calculate sqrtm, somehow, we can find sqrtm in np.
    H_approx = mp.sqrtm(redh_mt2)
    K_approx = mp.sqrtm(redh_mt2)

    # convert from mp matrix format to np matrix format
    H_approx_mat  = np.matrix(H_approx.tolist(), dtype=float)
    K_approx_mat  = np.matrix(K_approx.tolist(), dtype=float)

    if(print_option):
        print 'H_approx_mat  = ', H_approx_mat

    dataRate_compare_HKH_vs_MM_watef(H_approx_mat, K_approx_mat, n)
Ejemplo n.º 7
0
def check_redh2_semipos(n, print_option = True):

    redh_m = redh_mat(n)

    # R*R
    redh_m2 = np.dot(redh_m, redh_m)

    # R*R'
    redh_mt2 = np.dot(redh_m, redh_m.T)

    # check det of R*R and R*R' are same
    redh_m2_det = np.linalg.det(redh_m2)
    redh_mt2_det = np.linalg.det(redh_mt2)
    assert(np.allclose(redh_m2_det, redh_mt2_det))

    prod_r = 2
    redh_m2_pos, redh_m2_1_pos,  redh_mt2_pos, redh_mt2_1_pos = check_redh_semipos(n, redh_m2, redh_mt2, prod_r, print_option)

    return  redh_m2_pos, redh_m2_1_pos,  redh_mt2_pos, redh_mt2_1_pos
Ejemplo n.º 8
0
def check_redh4_semipos(n, print_option = True):

    redh_m = redh_mat(n)
    redh_m2 = np.dot(redh_m, redh_m)
    redh_m3 = np.dot(redh_m2, redh_m)

    # R*R*R*R
    redh_m4 = np.dot(redh_m3, redh_m)

    redh_mt2 = np.dot(redh_m, redh_m.T)

    # R*R'*R*R'
    redh_mt4 = np.dot(redh_mt2, redh_mt2)

    # check det of R*R and R*R' are same
    redh_m4_det = np.linalg.det(redh_m4)
    redh_mt4_det = np.linalg.det(redh_mt4)
    assert(np.allclose(redh_m4_det, redh_mt4_det))

    prod_r = 4
    redh_m4_pos, redh_m4_1_pos,  redh_mt4_pos, redh_mt4_1_pos = check_redh_semipos(n, redh_m4, redh_mt4, prod_r, print_option)

    return  redh_m4_pos, redh_m4_1_pos,  redh_mt4_pos, redh_mt4_1_pos