本文整理汇总了Python中MatrixUtil.assert_square方法的典型用法代码示例。如果您正苦于以下问题:Python MatrixUtil.assert_square方法的具体用法?Python MatrixUtil.assert_square怎么用?Python MatrixUtil.assert_square使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MatrixUtil
的用法示例。
在下文中一共展示了MatrixUtil.assert_square方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: dccov_to_edm
# 需要导入模块: import MatrixUtil [as 别名]
# 或者: from MatrixUtil import assert_square [as 别名]
def dccov_to_edm(HSH):
"""
@param HSH: a double centered covariance matrix
@return: a Euclidean distance matrix
"""
MatrixUtil.assert_square(HSH)
return cov_to_edm(HSH)
示例2: adjacency_to_laplacian
# 需要导入模块: import MatrixUtil [as 别名]
# 或者: from MatrixUtil import assert_square [as 别名]
def adjacency_to_laplacian(A):
"""
@param A: an adjacency matrix
@return: a laplacian matrix
"""
MatrixUtil.assert_square(A)
return np.diag(np.sum(A, 0)) - A
示例3: laplacian_to_edm
# 需要导入模块: import MatrixUtil [as 别名]
# 或者: from MatrixUtil import assert_square [as 别名]
def laplacian_to_edm(L):
"""
@param L: a laplacian matrix
@return: a Euclidean distance matrix
"""
MatrixUtil.assert_square(L)
return dccov_to_edm(laplacian_to_dccov(L))
示例4: laplacian_to_adjacency
# 需要导入模块: import MatrixUtil [as 别名]
# 或者: from MatrixUtil import assert_square [as 别名]
def laplacian_to_adjacency(L):
"""
@param L: a laplacian matrix
@return: an adjacency matrix
"""
MatrixUtil.assert_square(L)
return np.diag(np.diag(L)) - L
示例5: edm_to_dccov
# 需要导入模块: import MatrixUtil [as 别名]
# 或者: from MatrixUtil import assert_square [as 别名]
def edm_to_dccov(D):
"""
@param D: a Euclidean distance matrix
@return: a double centered covariance matrix
"""
MatrixUtil.assert_square(D)
return -(0.5)*MatrixUtil.double_centered(D)
示例6: q_to_cov
# 需要导入模块: import MatrixUtil [as 别名]
# 或者: from MatrixUtil import assert_square [as 别名]
def q_to_cov(Q):
"""
@param Q: a neighbor joining Q matrix
@return: something like a covariance matrix
"""
MatrixUtil.assert_square(Q)
n = len(Q)
S = -Q/(2*(n-2))
return S
示例7: bott_duffin_const
# 需要导入模块: import MatrixUtil [as 别名]
# 或者: from MatrixUtil import assert_square [as 别名]
def bott_duffin_const(M):
"""
Compute a constrained generalized inverse.
Specifically, this is the Bott-Duffin inverse of M
constrained to the orthogonal complement of the constant vector.
"""
MatrixUtil.assert_square(M)
n = len(M)
e = np.ones(n)
return bott_duffin(M, e)
示例8: laplacian_to_dccov
# 需要导入模块: import MatrixUtil [as 别名]
# 或者: from MatrixUtil import assert_square [as 别名]
def laplacian_to_dccov(L):
"""
@param L: a laplacian matrix
@return: a double centered covariance matrix
"""
MatrixUtil.assert_square(L)
M = np.ones_like(L) / float(len(L))
# This should be the same but perhaps not as numerically stable:
# HSH = np.linalg.pinv(L)
HSH = np.linalg.pinv(L - M) + M
return HSH
示例9: cov_to_edm
# 需要导入模块: import MatrixUtil [as 别名]
# 或者: from MatrixUtil import assert_square [as 别名]
def cov_to_edm(S):
"""
@param S: a covariance matrix
@return: a Euclidean distance matrix
"""
MatrixUtil.assert_square(S)
n = len(S)
d = np.diag(S)
e = np.ones_like(d)
D = np.outer(d, e) + np.outer(e, d) - 2*S
return D
示例10: edm_to_q
# 需要导入模块: import MatrixUtil [as 别名]
# 或者: from MatrixUtil import assert_square [as 别名]
def edm_to_q(D):
"""
@param D: a treelike distance matrix
@return: the neighbor joining Q matrix
"""
MatrixUtil.assert_square(D)
n = len(D)
r = np.sum(D, 0)
e = np.ones_like(r)
Q = (n-2)*D - np.outer(e, r) - np.outer(r, e)
return Q
示例11: dccov_to_laplacian
# 需要导入模块: import MatrixUtil [as 别名]
# 或者: from MatrixUtil import assert_square [as 别名]
def dccov_to_laplacian(HSH):
"""
This function stably pseudoinverts a double centered matrix.
@param HSH: a double centered covariance matrix
@return: a laplacian matrix
"""
MatrixUtil.assert_square(HSH)
M = np.ones_like(HSH) / float(len(HSH))
# This should be the same but perhaps not as numerically stable:
# L = np.linalg.pinv(HSH)
L = np.linalg.pinv(HSH - M) + M
return L
示例12: edm_to_laplacian
# 需要导入模块: import MatrixUtil [as 别名]
# 或者: from MatrixUtil import assert_square [as 别名]
def edm_to_laplacian(D):
"""
@param D: a Euclidean distance matrix
@return: a laplacian matrix
"""
MatrixUtil.assert_square(D)
D_pinv = np.linalg.pinv(D)
a = np.sum(D_pinv, 0)
denom = np.sum(D_pinv)
if not denom:
raise ValueError('the EDM is not spherical')
L = -2.0*(D_pinv - np.outer(a,a)/denom)
return L
示例13: dccov_to_q
# 需要导入模块: import MatrixUtil [as 别名]
# 或者: from MatrixUtil import assert_square [as 别名]
def dccov_to_q(HSH):
"""
Is there a shortcut here?
@param HSH: a doubly centered covariance matrix
@return: a neighbor joining Q matrix
"""
MatrixUtil.assert_square(HSH)
n = len(HSH)
d = np.diag(HSH)
e = np.ones_like(d)
D = np.outer(d, e) + np.outer(e, d) - 2*HSH
r = np.sum(D, 0)
e = np.ones_like(r)
Q = (n-2)*D - np.outer(e, r) - np.outer(r, e)
return Q