-
-
Save rlopc/8094962 to your computer and use it in GitHub Desktop.
function g = sigmoidFunction(z) | |
% Compute sigmoid function | |
% You need to return the following variables correctly | |
g = zeros(size(z)); | |
% Instructions: z can be a matrix, vector or scalar | |
g = 1.0 ./ ( 1.0 + exp(-z)); % For Matlab | |
% g = 1.0 ./ ( 1.0 + e.^(-z)); % For Octave, it can use 'exp(1)' or 'e' | |
end |
i have done this so many times but i keep getting that my function 'z' is not defined
@jamayz since it is a function, you need to specify 'z' yourself. You can try sigmoidFunction(0) for example in the command line and you should get 0.5.
Also please note that 'z' can be a vector or matrix. so you can specify z=[1 2 3], as a vector and try the code.
Why does the expression g = 1`/ (1 + exp(-y)) does not work in Octave if v is a 100 x 1 vector ??
-=-=-=-=-=-=-=-=-=
octave:70> size(y)
ans =
100 1
octave:71> y=zeros([100,1]);
octave:72> g=1/(1+exp(-y))
g =
Columns 1 through 16:
0.0050000 0.0050000 0.0050000 0.0050000
Hey!
May you explain the use of g = zeros(size(z)); here!
I tried and ran it into octave for every scalar like:
a=2;
size(2);
it always gave out of
1 1
can you explain it!
Can you explain the use of g = zeros(size(z));
I am not able to get how to use it
It allows you to catch the number of elements whether its a matrix/vector/scalar, and apply properly the elementwize option.
to rephrase the last answer: the dot in front of operators make sit the elementwise version of that operator