計算一個或多個矩陣的奇異值分解。
用法
tf.linalg.svd(
tensor, full_matrices=False, compute_uv=True, name=None
)參數
-
tensorTensor形狀[..., M, N]。讓P是M和N的最小值。 -
full_matrices如果為真,則計算全尺寸u和v。如果為 false(默認值),則僅計算前導P奇異向量。如果compute_uv是False則忽略。 -
compute_uv如果True則將計算左奇異向量和右奇異向量,並分別在u和v中返回。否則,將隻計算奇異值,這會明顯更快。 -
name字符串,操作的可選名稱。
返回
-
s奇異值。形狀是[..., P]。這些值按數量級倒序排列,因此 s[..., 0] 是最大值,s[..., 1] 是第二大值,以此類推。 -
u左奇異向量。如果full_matrices是False(默認),那麽形狀是[..., M, P];如果full_matrices是True那麽形狀是[..., M, M]。如果compute_uv是False則不返回。 -
v右奇異向量。如果full_matrices是False(默認),那麽形狀是[..., N, P]。如果full_matrices是True那麽形狀是[..., N, N]。如果compute_uv是False則不返回。
計算 tensor 中每個內部矩陣的 SVD,使得 tensor[..., :, :] = u[..., :, :] * diag(s[..., :, :]) *
transpose(conj(v[..., :, :]))
# a is a tensor.
# s is a tensor of singular values.
# u is a tensor of left singular vectors.
# v is a tensor of right singular vectors.
s, u, v = svd(a)
s = svd(a, compute_uv=False)
numpy 兼容性
大部分等同於 numpy.linalg.svd,除了
- 當
compute_uv為True時,此處輸出參數的順序為s、u、v,而不是 numpy.linalg.svd 的u、s、v。 - full_matrices 默認為
False,而不是 numpy.linalg.svd 的True。 - tf.linalg.svd 使用 SVD 的標準定義,使得
a的左奇異向量是u的列。而a的右奇異向量是v的列。另一方麵,numpy.linalg.svd 返回伴隨的 作為第三個輸出參數。
import tensorflow as tf
import numpy as np
s, u, v = tf.linalg.svd(a)
tf_a_approx = tf.matmul(u, tf.matmul(tf.linalg.diag(s), v, adjoint_b=True))
u, s, v_adj = np.linalg.svd(a, full_matrices=False)
np_a_approx = np.dot(u, np.dot(np.diag(s), v_adj))
# tf_a_approx and np_a_approx should be numerically close.
相關用法
- Python tf.linalg.set_diag用法及代碼示例
- Python tf.linalg.LinearOperatorFullMatrix.matvec用法及代碼示例
- Python tf.linalg.LinearOperatorToeplitz.solve用法及代碼示例
- Python tf.linalg.LinearOperatorIdentity.solvevec用法及代碼示例
- Python tf.linalg.LinearOperatorPermutation.solve用法及代碼示例
- Python tf.linalg.band_part用法及代碼示例
- Python tf.linalg.LinearOperatorKronecker.diag_part用法及代碼示例
- Python tf.linalg.lu_matrix_inverse用法及代碼示例
- Python tf.linalg.LinearOperatorToeplitz.matvec用法及代碼示例
- Python tf.linalg.LinearOperatorBlockLowerTriangular.solvevec用法及代碼示例
- Python tf.linalg.LinearOperatorLowerTriangular.matvec用法及代碼示例
- Python tf.linalg.LinearOperatorCirculant2D.solve用法及代碼示例
- Python tf.linalg.LinearOperatorCirculant3D.diag_part用法及代碼示例
- Python tf.linalg.LinearOperatorCirculant2D.assert_non_singular用法及代碼示例
- Python tf.linalg.LinearOperatorPermutation.diag_part用法及代碼示例
- Python tf.linalg.LinearOperatorToeplitz用法及代碼示例
- Python tf.linalg.LinearOperatorCirculant2D.matvec用法及代碼示例
- Python tf.linalg.LinearOperatorTridiag.solvevec用法及代碼示例
- Python tf.linalg.LinearOperatorTridiag.solve用法及代碼示例
- Python tf.linalg.LinearOperatorZeros.matmul用法及代碼示例
- Python tf.linalg.LinearOperatorFullMatrix.solvevec用法及代碼示例
- Python tf.linalg.LinearOperatorBlockLowerTriangular.matmul用法及代碼示例
- Python tf.linalg.LinearOperatorCirculant.matvec用法及代碼示例
- Python tf.linalg.LinearOperatorKronecker.matvec用法及代碼示例
- Python tf.linalg.LinearOperatorCirculant3D.solvevec用法及代碼示例
注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.linalg.svd。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
