How to compute softmax and its gradient?
    3 ビュー (過去 30 日間)
  
       古いコメントを表示
    
I am creating a simple two layer neural network where the activation function of the output layer will be softmax.
I have this for creating softmax in a numerically stable way
function g = softmax(z)
    dim = 1;
    s = ones(1, ndims(z));
    s(dim) = size(z, dim);
    maxz = max(z, [], dim);
    expz = exp(z-repmat(maxz, s));
    g = expz ./ repmat(sum(expz, dim), s);
z is a matrix that contains all of the data calculated by the previous layer one row at a time.
In order to compute the derivative of this though I will need to use the Kronecker delta but I am not sure how to do it.
Can someone provide me with a vectorized implementation for computing it in Matlab?
1 件のコメント
  usama pervaiz
 2017 年 11 月 22 日
				You can find here how to compute softmax of a matrix and its gradient http://peterroelants.github.io/posts/neural_network_implementation_intermezzo02/
回答 (0 件)
参考
カテゴリ
				Help Center および File Exchange で Deep Learning Toolbox についてさらに検索
			
	製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

