예제 #1
0
 def test_tensor(self):
     true_shape = (3, 3)
     for shape in ((3, 9,), (2, 9, 1), (4, 1, 9), (1, 2, 3, 3)):
         arr = np.empty(shape)
         orthogonal(arr, shape=true_shape)
         arr = arr.reshape([-1] + list(true_shape))
         for a in arr:
             self.assertTrue(self.isOrthogonal(a))
예제 #2
0
def ortho_initialize(arr):
    if arr.shape[-1] > arr.shape[0]:
        q, _ = np.linalg.qr(arr.T)
        q = q.T
    else:
        q, _ = np.linalg.qr(arr)

    return q


n, m = 2, 3


A = random.randn(n, m)
print A
B = ortho_initialize(A)
print B

C = A.copy().reshape(-1)
orthogonal(C, n)

U, S, V = np.linalg.svd(B)
print S
print A.shape
print B.shape

print np.linalg.cond(B)

print C

print np.linalg.cond(C.reshape(n, m))
예제 #3
0
def ortho_initialize(arr):
    if arr.shape[-1] > arr.shape[0]:
        q, _ = np.linalg.qr(arr.T)
        q = q.T
    else:
        q, _ = np.linalg.qr(arr)

    return q


n, m = 2, 3

A = random.randn(n, m)
print A
B = ortho_initialize(A)
print B

C = A.copy().reshape(-1)
orthogonal(C, n)

U, S, V = np.linalg.svd(B)
print S
print A.shape
print B.shape

print np.linalg.cond(B)

print C

print np.linalg.cond(C.reshape(n, m))
예제 #4
0
 def test_shape(self):
     true_shape = (3, 3)
     for shape in ((9,), (9, 1), (1, 9)):
         arr = np.empty(shape)
         orthogonal(arr, shape=true_shape)
         self.assertTrue(self.isOrthogonal(arr.reshape(true_shape)))
예제 #5
0
 def test_orthonormal(self):
     arr = np.empty((3, 3))
     orthogonal(arr)
     self.assertTrue(self.isOrthogonal(arr))
     self.assertAlmostEqual(abs(np.linalg.det(arr)), 1)