tanh Function
1. Introduction
To limit all data within the range of -1 to 1. Comparing to Sigmoid Function which output range is [0,1]
2. Formula
The formula and derivative of tanh is:
f(z)f′(z)=tanh(z)=ez−e−zez+e−z=1−(f(z))2
where as the sigmoid function is pretty close
f(z)f′(z)=sigmoid(z)=11+e−z=1−f(z)
See the figure of tanh and sigmoid below.
3. Implementation
3.1 Octave
x = linspace(-10, 10 ,10000);
y = zeros( size(x, 1), size(x, 2));
for i = 1:length(x)
y(i) = 1/(1+e^(-x(i)));
endfor
figure();
plot( x,y);
grid on;
xlabel("x");
ylabel("y=1/(1+e^-x)");
title("Sigmoid Function");
Output figure
Relative
Sigmoid Function