예제 #1
0
 def test_bidiagonal_recreate_2(self):
     mat = Matrix.from_cols([[1, 2, 3], [2, 5, 1], [-1, 3, -2]])
     b, left, right = reduce_to_bidiagonal(mat)
     for index, hh in list(enumerate(left))[::-1]:
         b = hh.multiply_left(b, index)
     for index, hh in list(enumerate(right))[::-1]:
         b = hh.multiply_right(b, index + 1)
     utils.assert_matrix_equal(mat, b)
예제 #2
0
 def check_svd(self, u, s, v, mat):
     utils.assert_orthonormal(u)
     utils.assert_orthonormal(v)
     utils.assert_lower_triangular(s)
     utils.assert_upper_triangular(s)
     diagonal = utils.extract_diagonal(s)
     for i in range(len(diagonal) - 1):
         assert diagonal[i] >= diagonal[i + 1]
     for elem in diagonal:
         assert elem >= 0
     product = u.multiply(s).multiply(v.transpose())
     product.print_full()
     mat.print_full()
     utils.assert_matrix_equal(product, mat)
예제 #3
0
 def test_householder_inverse(self):
     vec = [5, 4, 3, 2, 1]
     householder = Householder(vec)
     householder_mat = householder.to_matrix()
     product = householder_mat.multiply(householder_mat)
     utils.assert_matrix_equal(product, Matrix.identity(5))
예제 #4
0
 def test_householder_symmetric(self):
     vec = [5, 4, 3, 2, 1]
     householder = Householder(vec)
     householder_mat = householder.to_matrix()
     utils.assert_matrix_equal(householder_mat, householder_mat.transpose())
예제 #5
0
 def test_givens_inverse(self):
     givens = Givens(1, 1).to_matrix()
     product = givens.transpose().multiply(givens)
     utils.assert_matrix_equal(product, Matrix.identity(2))