theano中的Rop和Lop的详细解释
#------------------------------------------序-------------------------------------------------------
這篇博文是對[1]中的Rop以及Lop代碼進行詳細解釋.
因為[1]中代碼變量名稱和數學表達式名稱不對應,所以記錄下,方便以后一看就懂
[1]的代碼來自[2],[2]里面是有錯誤的,所以在這篇博客里面進行更正
代碼運行環境:
python3.6.7
ubuntu18.10-amd64
#-----------------------------------Rop例子如下----------------------------------------------------------
result= [12.5 5.2]
運行結果如下:
理論分析:
f=w?xf=w·xf=w?x
這個代碼求解的是:
?f?W?V\frac{\partial f}{\partial W}·V?W?f??V
#----------------------------------------------------------Lop例子如下------------------------------------------------------------------
import theano import numpy as np import theano.tensor as T from IPython.display import Image from IPython.display import display W = T.dmatrix('W') V = T.dmatrix('V') x = T.dvector('x')#-------------------------------------------------------------------------------------------- f = T.dot(x,W) VJ = T.Lop(f,W,V) result= theano.function([V,x], VJ) V,x=[[3.2, 2], [5.4, 2]],[0.7,1.9] result2=result([[3.2, 2], [5.4, 2]], #V[0.7,1.9])#x print("V=",V) print("x=",x) print("result=",result2) display(Image(theano.printing.pydotprint(result,return_image=True, var_with_name_simple=True)))#--------------------------------------------------------------------------------------------運行結果是:
V= [[3.2, 2], [5.4, 2]]
x= [0.7, 1.9]
result= [[ 2.24 1.4 3.78 1.4 ]
[ 6.08 3.8 10.26 3.8 ]]
這個代碼求解的是:
(VT?x)T(V^T·x)^T(VT?x)T
=xT?V=x^T·V=xT?V
=[0.71.9][3.2,2,5.4,2]=\left[ \begin{matrix} 0.7\\ 1.9 \\ \end{matrix} \right]\left[ \begin{matrix} 3.2,2,5.4,2 \end{matrix} \right] =[0.71.9?][3.2,2,5.4,2?]
這里的V是打散后的V
所以根本就不是我們想象中的"左乘"
Reference:
[1]https://www.cnblogs.com/fireae/p/3772670.html
總結
以上是生活随笔為你收集整理的theano中的Rop和Lop的详细解释的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: the computational gr
- 下一篇: 奇异值的几何意义