How do I implement the sigmoid function in Octave?



so given that the sigmoid function is defined as hθ(x) = g(θ^(T)x), how can I implement this funcion in Octave given that g = zeros(size(z)) ?

Shuryu Kisuke

Posted 2017-12-19T16:43:35.087

Reputation: 203

Question was closed 2017-12-24T12:27:16.310



This will compute the sigmoid of a scalar, vector or matrix.

function g = sigmoid(z)
%   SIGMOID Compute sigmoid function
%   g = SIGMOID(z) computes the sigmoid of z.

% Compute the sigmoid of each value of z (z can be a matrix,
% vector or scalar).

SIGMOID = @(z) 1./(1 + exp(-z));

g = SIGMOID(z);



Posted 2017-12-19T16:43:35.087

Reputation: 523

Was using '/' in place of './'. My very very bad. – Yogesh Sanchihar – 2018-06-17T07:26:40.420

5You could just use g = 1 ./ (1 + exp(-z)); instead of creating this SIGMOID inside the sigmoid function. – Alisson – 2018-10-11T03:01:58.643