tansig.m

来自「神经网络设计书籍配套源码(matlab平台)」· M 代码 · 共 32 行

M
32
字号
function a = tansig(n,b)
%TANSIG Hyperbolic tangent sigmoid transfer function.
%	
%	TANSIG(N)
%	  N - SxQ Matrix of net input (column) vectors.
%	Returns the values of N squashed between -1 an 1.
%	
%	EXAMPLE: n = -10:0.1:10;
%	         a = tansig(n);
%	         plot(n,a)
%	
%	TANSIG(Z,B) ...Used when Batching.
%	  Z - SxQ Matrix of weighted input (column) vectors.
%	  B - Sx1 Bias (column) vector.
%	Returns the squashed net input values found by adding
%	  B to each column of Z.

% Mark Beale, 1-31-92
% Revised 12-15-93, MB
% Copyright (c) 1992-94 by The MathWorks, Inc.
% $Revision: 1.1 $  $Date: 1994/01/11 16:29:26 $

if nargin < 1, error('Not enough arguments.'); end

if nargin==2
  [nr,nc] = size(n);
  n = n + b*ones(1,nc);
end
a = 2 ./ (1 + exp(-2*n)) - 1;
i = find(~finite(a));
a(i) = sign(n(i));

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?