本文整理汇总了Python中pycast.common.matrix.Matrix.svd方法的典型用法代码示例。如果您正苦于以下问题:Python Matrix.svd方法的具体用法?Python Matrix.svd怎么用?Python Matrix.svd使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pycast.common.matrix.Matrix
的用法示例。
在下文中一共展示了Matrix.svd方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: svd_unitary_test
# 需要导入模块: from pycast.common.matrix import Matrix [as 别名]
# 或者: from pycast.common.matrix.Matrix import svd [as 别名]
def svd_unitary_test(self):
"""Test if matrices u and v are unitary."""
a = [[22., 10., 2., 3., 7.],
[14., 7., 10., 0., 8.],
[-1., 13., - 1., -11., 3.],
[-3., -2., 13., -2., 4.],
[ 9., 8., 1., -2., 4.],
[ 9., 1., -7., 5., -1.],
[ 2., -6., 6., 5., 1.],
[ 4., 5., 0., -2., 2.]]
matrix = Matrix(5, 8)
matrix.initialize(a, rowBased=True)
u, diag, v = matrix.svd()
# u and v should be unitary matrices. Matrixmultiplication withs its
# transformation should be the identity Matrix.
res = u.transform() * u
res1 = v * v.transform()
for row in range(res.get_height()):
for col in range(res.get_width()):
if row == col:
# value should be 1 at diagonal
self.assertAlmostEqual(res.get_value(col, row), 1, PRECISION)
self.assertAlmostEqual(res1.get_value(col, row), 1, PRECISION)
else:
# value should be 0 otherwise.
self.assertAlmostEqual(res.get_value(col, row), 0, PRECISION)
self.assertAlmostEqual(res1.get_value(col, row), 0, PRECISION)
示例2: svd_test
# 需要导入模块: from pycast.common.matrix import Matrix [as 别名]
# 或者: from pycast.common.matrix.Matrix import svd [as 别名]
def svd_test(self):
"""Test the Singular Value Decomposition."""
a = [[22., 10., 2., 3., 7.],
[14., 7., 10., 0., 8.],
[-1., 13., - 1., -11., 3.],
[-3., -2., 13., -2., 4.],
[ 9., 8., 1., -2., 4.],
[ 9., 1., -7., 5., -1.],
[ 2., -6., 6., 5., 1.],
[ 4., 5., 0., -2., 2.]]
matrix = Matrix(5, 8)
matrix.initialize(a, rowBased=True)
u, diag, v = matrix.svd()
# multiply result matrices should get the original matrix
res = u * diag * v.transform()
for row in range(res.get_height()):
for col in range(res.get_width()):
self.assertAlmostEqual(res.get_value(col, row), a[row][col], PRECISION)
示例3: svd_diagional_test
# 需要导入模块: from pycast.common.matrix import Matrix [as 别名]
# 或者: from pycast.common.matrix.Matrix import svd [as 别名]
def svd_diagional_test(self):
"""Test if the one Matrix of svd() is in diagonal form."""
a = [[22., 10., 2., 3., 7.],
[14., 7., 10., 0., 8.],
[-1., 13., -1., -11., 3.],
[-3., -2., 13., -2., 4.],
[ 9., 8., 1., -2., 4.],
[ 9., 1., -7., 5., -1.],
[ 2., -6., 6., 5., 1.],
[ 4., 5., 0., -2., 2.]]
matrix = Matrix(5, 8)
matrix.initialize(a, rowBased=True)
u, diag, v = matrix.svd()
# test if Matrix is in diagonal form
for row in range(diag.get_height()):
for col in range(diag.get_width()):
if row != col:
self.assertEqual(diag.get_value(col, row), 0.0)