예제 #1
0
파일: test_svd.py 프로젝트: jrs65/scalapy
def test_svd_D():
    ## Test SVD computation of a real double precision distributed matrix
    ms, ns = 235, 326

    gA = np.random.standard_normal((ms, ns)).astype(np.float64)
    gA = np.asfortranarray(gA)

    dA = core.DistributedMatrix.from_global_array(gA, rank=0)

    U, s, VT = rt.svd(dA)
    gU = U.to_global_array(rank=0)
    gVT = VT.to_global_array(rank=0)

    if rank == 0:
        S = np.diag(s)
        assert allclose(gA, np.dot(gU, np.dot(S, gVT)))

        # compare with numpy results
        nU, ns, nVT = np.linalg.svd(gA, full_matrices=False)
        assert allclose(s, ns)
        # this should be careful as there is a freedom in determining the left/right singular vector: for A = U1 * S * V1^H = U2 * S * V2^H, one can proof that U2^H * U1 = (V1^H * V2)^H = D, where D is and diagonal matrix
        assert allclose(np.dot(nU.T.conj(), gU), np.dot(gVT, nVT.T.conj()).T.conj())
예제 #2
0
파일: test_svd.py 프로젝트: jrs65/scalapy
def test_svd_Z():
    ## Test SVD computation of a complex double precision distributed matrix
    ms, ns = 457, 26

    gA = np.random.standard_normal((ms, ns)).astype(np.float64)
    gA = gA + 1.0J * np.random.standard_normal((ms, ns)).astype(np.float64)
    gA = np.asfortranarray(gA)

    dA = core.DistributedMatrix.from_global_array(gA, rank=0)

    U, s, VT = rt.svd(dA)
    gU = U.to_global_array(rank=0)
    gVT = VT.to_global_array(rank=0)

    if rank == 0:
        S = np.diag(s)
        assert allclose(gA, np.dot(gU, np.dot(S, gVT)))

        # compare with numpy results
        nU, ns, nVT = np.linalg.svd(gA, full_matrices=False)
        assert allclose(s, ns)
        assert allclose(np.dot(nU.T.conj(), gU), np.dot(gVT, nVT.T.conj()).T.conj())
예제 #3
0
def test_svd_Z():
    ## Test SVD computation of a complex double precision distributed matrix
    ms, ns = 457, 26

    gA = np.random.standard_normal((ms, ns)).astype(np.float64)
    gA = gA + 1.0J * np.random.standard_normal((ms, ns)).astype(np.float64)
    gA = np.asfortranarray(gA)

    dA = core.DistributedMatrix.from_global_array(gA, rank=0)

    U, s, VT = rt.svd(dA)
    gU = U.to_global_array(rank=0)
    gVT = VT.to_global_array(rank=0)

    if rank == 0:
        S = np.diag(s)
        assert allclose(gA, np.dot(gU, np.dot(S, gVT)))

        # compare with numpy results
        nU, ns, nVT = np.linalg.svd(gA, full_matrices=False)
        assert allclose(s, ns)
        assert allclose(np.dot(nU.T.conj(), gU),
                        np.dot(gVT, nVT.T.conj()).T.conj())
예제 #4
0
def test_svd_D():
    ## Test SVD computation of a real double precision distributed matrix
    ms, ns = 235, 326

    gA = np.random.standard_normal((ms, ns)).astype(np.float64)
    gA = np.asfortranarray(gA)

    dA = core.DistributedMatrix.from_global_array(gA, rank=0)

    U, s, VT = rt.svd(dA)
    gU = U.to_global_array(rank=0)
    gVT = VT.to_global_array(rank=0)

    if rank == 0:
        S = np.diag(s)
        assert allclose(gA, np.dot(gU, np.dot(S, gVT)))

        # compare with numpy results
        nU, ns, nVT = np.linalg.svd(gA, full_matrices=False)
        assert allclose(s, ns)
        # this should be careful as there is a freedom in determining the left/right singular vector: for A = U1 * S * V1^H = U2 * S * V2^H, one can proof that U2^H * U1 = (V1^H * V2)^H = D, where D is and diagonal matrix
        assert allclose(np.dot(nU.T.conj(), gU),
                        np.dot(gVT, nVT.T.conj()).T.conj())
예제 #5
0
# R = tt_tt_corr
# Ri = la.inv(R)
# STRiS = np.dot(S.T, np.dot(Ri, S))
# W = np.dot(np.dot(np.dot(S, la.inv(STRiS)), S.T), Ri)
# rec_cm = np.dot(W, tt_map)
# fig = plt.figure(1, figsize=(13, 5))
# healpy.mollview(rec_cm[0], fig=1, title='')
# healpy.graticule()
# # fig.savefig('rec_cm.png')
# fig.savefig('rec_cm3.png')
# plt.close()

# svd of the total signal
gtt = np.asfortranarray(tt_map)
dtt = core.DistributedMatrix.from_global_array(gtt, rank=0)
U, s_tt, VT = rt.svd(dtt)
if rank == 0:
    print s_tt
# gU = U.to_global_array(rank=0)
# gVT = VT.to_global_array(rank=0)

# VT = np.dot(1.0/s_tt*U1.T, tt_map) # the actual V^T
VT = np.dot(np.dot(np.diag(1.0 / s_tt), U1.T), tt_map)  # the actual V^T

if rank == 0:
    rec_cm = np.dot(U1 * s2**0.5, VT)
    print rec_cm.shape

    fig = plt.figure(1, figsize=(13, 5))
    healpy.mollview(rec_cm[0], fig=1, title='')
    healpy.graticule()