tanh Function

来源:互联网 发布:萧山网络问政关注 编辑:程序博客网 时间:2024/06/06 17:18

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)=ezezez+ez=1(f(z))2

where as the sigmoid function is pretty close
f(z)f(z)=sigmoid(z)=11+ez=1f(z)

See the figure of tanh and sigmoid below.
tanh

tanh Function

sigmoid

sigmoid Function

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
tanh

tanh Function

Relative

Sigmoid Function

原创粉丝点击