譜范數求解方法-奇異值分解&冪迭代法



//

一、譜范數

矩陣的譜范數指的也就是矩陣的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方法計算量大,因此使用冪迭代法可以減小計算成本。



免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM