ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

谱范数求解方法-奇异值分解-幂迭代法

2022-01-04 16:34:38  阅读:1589  来源: 互联网

标签:特征值 求解 矩阵 np 迭代法 范数 norm


一、谱范数

矩阵的谱范数指的也就是矩阵的2范数,即矩阵A的最大奇异值。
image

通过上式可知,A的谱范数 = A的最大奇异值 = A^T·A的最大特征值的平方根

二、谱范数求解方法

2.1 奇异值分解法 (Singular Value Decomposition)

既然谱范数是矩阵A的最大奇异值,那么便可以通过奇异值分解[举例参考]来求解谱范数。

import numpy as np

A = np.array([2,4],[1,3],[0,0],[0,0])
U, s, V = np.linalg.svd(A)

2.2 幂迭代法 (Power Iteration Method)

幂迭代法[举例参考]核心思想是通过迭代的方法来逼近真实的特征向量。


STEP 1 我们首先来看如何使用幂迭代法求解矩阵A的最大特征值及其对应的特征向量。
image

import numpy as np

def power_iteration(A, num_simulations: int):
    # Ref:https://blog.csdn.net/weixin_42973678/article/details/107801749      thanks :D
    # Ideally choose a random vector
    # To decrease the chance that our vector
    # Is orthogonal to the eigenvector
    b_k = np.random.rand(A.shape[1])

    for _ in range(num_simulations):
        # calculate the matrix-by-vector product Ab
        b_k1 = np.dot(A, b_k)

        # calculate the norm
        b_k1_norm = np.linalg.norm(b_k1)

        # re normalize the vector
        b_k = b_k1 / b_k1_norm

    return b_k

举例:
image

验证:

A = np.array([[2,1],[1,2]])
V = power_iteration(A, 100).reshape(1,-1)
print(V)   # array([[0.70710678, 0.70710678]])

求得最大特征值对应的特征向量后,可以通过
image
求解对应的最大特征值。

max_lambda = np.dot(V,np.dot(A,V.T))
print(max_lambda)  # array([[3.]])

STEP 2 通过谱范数计算公式来计算谱范数

即通过STEP 1 的方法计算矩阵A^T·A的最大特征值和对应的特征向量,然后对最大特征值取根号,就是矩阵A的最大奇异值。

三、总结


As we mentioned above, the spectral norm σ(W) that we use to regularize each layer of the discriminator is the largest singular value of W. If we naively apply singular value decomposition to compute the σ(W) at each round of the algorithm, the algorithm can become computationally heavy. Instead, we can use the power iteration method to estimate σ(W). With power iteration method, we can estimate the spectral norm with very small additional computational time relative to the full computational cost of the vanilla GANs.
------------------------------------------------------from 《SPECTRAL NORMALIZATION FOR GENERATIVE ADVERSARIAL NETWORKS》


在计算谱范数时,SVD方法计算量大,因此使用幂迭代法可以减小计算成本。

标签:特征值,求解,矩阵,np,迭代法,范数,norm
来源: https://www.cnblogs.com/wonderlust/p/15762986.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有