import numpy; from algopy import UTPM # symmetric eigenvalue decomposition, forward UTPM D,P,M,N = 3,1,4,4 Q,R = UTPM.qr(UTPM(numpy.random.rand(D,P,M,N))) l = UTPM(numpy.random.rand(*(D,P,N))) l.data[0,0,:4] = [1,1,2,3] l.data[1,0,:4] = [0,0,3,4] l.data[2,0,:4] = [1,2,5,6] L = UTPM.diag(l) B = UTPM.dot(Q,UTPM.dot(L,Q.T)) print('B = \n', B) l2,Q2 = UTPM.eigh(B) print('l2 - l =\n',l2 - l)
import numpy; from algopy import UTPM # QR decomposition, UTPM forward D,P,M,N = 3,1,500,20 A = UTPM(numpy.random.rand(D,P,M,N)) Q,R = UTPM.qr(A) B = UTPM.dot(Q,R) # check that the results are correct print 'Q.T Q - 1\n',UTPM.dot(Q.T,Q) - numpy.eye(N) print 'QR - A\n',B - A print 'triu(R) - R\n', UTPM.triu(R) - R # QR decomposition, UTPM reverse Bbar = UTPM(numpy.random.rand(D,P,M,N)) Qbar,Rbar = UTPM.pb_dot(Bbar, Q, R, B) Abar = UTPM.pb_qr(Qbar, Rbar, A, Q, R) print 'Abar - Bbar\n',Abar - Bbar
import numpy from algopy import UTPM # symmetric eigenvalue decomposition, forward UTPM D, P, M, N = 3, 1, 4, 4 Q, R = UTPM.qr(UTPM(numpy.random.rand(D, P, M, N))) l = UTPM(numpy.random.rand(*(D, P, N))) l.data[0, 0, :4] = [1, 1, 2, 3] l.data[1, 0, :4] = [0, 0, 3, 4] l.data[2, 0, :4] = [1, 2, 5, 6] L = UTPM.diag(l) B = UTPM.dot(Q, UTPM.dot(L, Q.T)) print('B = \n', B) l2, Q2 = UTPM.eigh(B) print('l2 - l =\n', l2 - l)
import numpy; from algopy import UTPM # QR decomposition, UTPM forward D,P,M,N = 3,1,500,20 A = UTPM(numpy.random.rand(D,P,M,N)) Q,R = UTPM.qr(A) B = UTPM.dot(Q,R) # check that the results are correct print('Q.T Q - 1\n',UTPM.dot(Q.T,Q) - numpy.eye(N)) print('QR - A\n',B - A) print('triu(R) - R\n', UTPM.triu(R) - R) # QR decomposition, UTPM reverse Bbar = UTPM(numpy.random.rand(D,P,M,N)) Qbar,Rbar = UTPM.pb_dot(Bbar, Q, R, B) Abar = UTPM.pb_qr(Qbar, Rbar, A, Q, R) print('Abar - Bbar\n',Abar - Bbar)