我正在从coursera学习机器学习。我正在尝试计算sigmoid函数,我有以下代码:
function g = sigmoid(z)
%SIGMOID Compute sigmoid functoon
% J = SIGMOID(z) computes the sigmoid of z.
% You need to return the following variables correctly
g = zeros(size(z));
% ====================== YOUR CODE HERE ======================
% Instructions: Compute the sigmoid of each value of z (z can be a matrix,
% vector or scalar).
g = (1 + exp(-1 * z)) .^ -1;
g = 1/(1+ (1/exp(z)))
% my question is why the first g calculation works for matrix(say 100*2) however the second only works for (100*1) as both are trying to do the same this.
% =============================================================
end发布于 2018-06-27 18:19:25
Sigmoid函数g(z)=1/(1+e^(-z))
在八度音阶中,它看起来像
g = 1./(1 + exp(-z));发布于 2017-05-14 01:40:12
正确答案
rt=-z; %changing sign of z
rt=rt'; %transposing matrix
g=1./(1+e.^(rt)); %you need to use dot(.) while dividing and also while finding power to apply those operation for every element in the matrix.回答你的问题
1.g = (1 + exp(-1 * z)) .^ -1;
2.g = 1/(1+ (1/exp(z))) 您漏掉了点运算符(.)第二个函数用于除法,第一个函数用于exp()。
发布于 2016-07-31 11:24:52
.^适用于矩阵中的每个元素。/不会。./可能(尽管您可能需要制作一些1的矩阵)
https://stackoverflow.com/questions/38680066
复制相似问题