Problem building a custom transfer function for feedforward neural network

1 view (last 30 days)
Hello,
I am trying to build a custom transfer function for my feedforward neural network in Matlab R2019a. But, I face attached error. I defined my new sigmoid function as 'mytanhfunction' as following and I save it in my working directory. Then I try to go to main directory which (matlab installation directory) and I added 'mytanhfunction' just like other functions (like tansig and purelin ...). Still it gives me the same error. I appreciate any help on this.
function a = mytanhfunction(n,varargin)
if nargin > 0
n = convertStringsToChars(n);
end
if ischar(n)
a = nnet7.transfer_fcn(mfilename,n,varargin{:});
return
end
% Apply
a = 1 ./ (exp(-26*(n - .3)) + 1);
I used following two forms of commands in order to design my network. Both gave me the same error I attached to this.
nsk1 = 3; % number of first hidden layer neuron
nsk2 = 2; % number of second hidden layer neuron
% X=inputs
% T= target
nsk1=2;
nsk2=2;
net = newff(X,T,[nsk1,nsk2],{'mytanhfunction','mytanhfunction','purelin'});
net.trainParam.epochs = 50;
net = train(net,X,T);
______________________________________________
net = fitnet;
net.layers{1}.transferFcn = 'mytanhfunction';

Answers (2)

Alireza Bagheri
Alireza Bagheri on 20 Aug 2019
I appreciate a quick response!

Alireza Bagheri
Alireza Bagheri on 28 Aug 2019
I am still waiting for an asnswer!

Categories

Find more on Deep Learning Toolbox in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!