matrix_utils.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:Echobase 作者: akhambhati 项目源码 文件源码
def norm_fro_err(X, W, H, norm_X):
    """ Compute the approximation error in Frobeinus norm

    norm(X - W.dot(H.T)) is efficiently computed based on trace() expansion 
    when W and H are thin.

    Parameters
    ----------
    X : numpy.array or scipy.sparse matrix, shape (m,n)
    W : numpy.array, shape (m,k)
    H : numpy.array, shape (n,k)
    norm_X : precomputed norm of X

    Returns
    -------
    float
    """
    sum_squared = norm_X * norm_X - 2 * np.trace(H.T.dot(X.T.dot(W))) \
        + np.trace((W.T.dot(W)).dot(H.T.dot(H)))
    return math.sqrt(np.maximum(sum_squared, 0))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号