計算Entropic Regularization[Wilson]時總是出現Warning: numerical errors at iteration 0的可能原因

在使用下面的文章和第三方庫

Marco Cuturi, Sinkhorn Distances: Lightspeed Computation of Optimal Transport, NIPS 2013

https://pythonot.github.io/

計算Entropic Regularization的Wassertein loss時,總是出現如下問題:

Warning: numerical errors at iteration 0

導致計算出的Wassertein distance爲0,從而影響網絡的訓練。

 

經過分析發現,Warning: numerical errors at iteration 0出現當且僅當矩陣K的轉置中含有0元素,而根據文章:

 

K= e^{-M_{XY}/\gamma}

理論上是不會有0元素的。因此原因其實很簡單,就是γ太小了!例如當γ=0.001時

(Pdb) M
array([[0.26596661, 0.23665913, 0.25129144, ..., 0.25782531, 0.25837383,
        0.24954239],
       [0.24605081, 0.24002687, 0.23672875, ..., 0.24692256, 0.24100467,
        0.23279034],
       [0.25954123, 0.24295745, 0.23761645, ..., 0.25519669, 0.24264093,
        0.24277576],
       ...,
       [0.26867422, 0.26456161, 0.28494031, ..., 0.27320845, 0.28464691,
        0.27690985],
       [0.31739641, 0.29082387, 0.28749557, ..., 0.30555643, 0.28721051,
        0.30280537],
       [0.27102495, 0.24505942, 0.25931435, ..., 0.26164062, 0.26206772,
        0.24817103]])
(Pdb) M.min()
0.21602636026751282
(Pdb) (M/reg).min()
216.0263602675128
(Pdb) (-M/reg).min()
-1000.0
(Pdb) np.exp((-M/reg)).min()
0.0

將γ適度調大至0.1,即可解決Warning: numerical errors at iteration 0從而出現計算錯誤的問題。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章