After discussing with Chong Wang of IIM, I have understood completely http://deeplearning.stanford.edu/wiki/index.php/Softmax_Regression. This is a good reference. The matlab code can be found in my computer by searching "Softmax". It is in "matlab\work\classifier\Softmax".
在 Logistic Regression 里就可以看到它 。具體來說,Softmax 函數 定義如下:
它在 Logistic Regression 里其到的作用是講線性預測值轉化為類別概率:假設 是第 個類別的線性預測結果,帶入 Softmax 的結果其實就是先對每一個 取 exponential 變成非負,然后除以所有項之和進行歸一化,現在每個 就可以解釋成觀察到的數據 屬于類別 的概率,或者稱作似然 (Likelihood)。
然后 Logistic Regression 的目標函數是根據最大似然原則來建立的,假設數據 所對應的類別為 ,則根據我們剛才的計算最大似然就是要最大化 的值 。后面這個操作就是 caffe 文檔里說的 Multinomial Logistic Loss,具體寫出來是這個樣子:
而 Softmax-Loss 其實就是把兩者結合到一起,只要把 的定義展開即可
沒有任何 fancy 的東西。
注意點:區別Softmax 函數和Softmax-Loss
reference:
http://freemind.pluskid.org/machine-learning/softmax-vs-softmax-loss-numerical-stability/