예제 #1
0
    def test_utpm_logdet_trace_expm(self):
        D, P, N = 3, 5, 4

        x = 0.1 * UTPM(numpy.random.randn(D, P, N, N))
        x = UTPM.dot(x.T, x)
        observed_logdet = UTPM.logdet(expm(x))
        desired_logdet = UTPM.trace(x)
        assert_allclose(observed_logdet.data, desired_logdet.data)
예제 #2
0
    def test_utpm_logdet_trace_expm(self):
        D, P, N = 3, 5, 4

        x = 0.1 * UTPM(numpy.random.randn(D, P, N, N))
        x = UTPM.dot(x.T, x)
        observed_logdet = UTPM.logdet(expm(x))
        desired_logdet = UTPM.trace(x)
        assert_allclose(observed_logdet.data, desired_logdet.data)
예제 #3
0
def dot(a, b):
    """
    Same as NumPy dot but in UTP arithmetic
    """
    if isinstance(a, Function) or isinstance(b, Function):
        return Function.dot(a, b)

    elif isinstance(a, UTPM) or isinstance(b, UTPM):
        return UTPM.dot(a, b)

    else:
        return numpy.dot(a, b)
예제 #4
0
def dot(a,b):
    """
    Same as NumPy dot but in UTP arithmetic
    """
    if isinstance(a,Function) or isinstance(b,Function):
        return Function.dot(a,b)

    elif isinstance(a,UTPM) or isinstance(b,UTPM):
        return UTPM.dot(a,b)

    else:
        return numpy.dot(a,b)
예제 #5
0
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)
예제 #6
0
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)
예제 #7
0
파일: example1_qr.py 프로젝트: eteq/algopy
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
예제 #8
0
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)