How to change the activation function in ANN model created using toolbox
Ältere Kommentare anzeigen
I've created this model by editing the codes from the toolbox. The purpose of this model is to train the network with operating data from a turbine. the data is normalized and then the target will be set according to the actual fault occurrence which tagged as "1" and during normal operation "0". I will be comparing the result of several training function, the number of neuron, the number of layers, and activation function.
% This script assumes these variables are defined:
% data - input data.
% target - target data.
% load data
load data.mat;
load target.mat;
x = data;
t = target;
% Choose a Training Function
% For a list of all training functions type: help nntrain
% 'trainlm' is usually fastest.
% 'trainbr' takes longer but may be better for challenging problems.
% 'trainscg' uses less memory. NFTOOL falls back to this in low memory situations.
trainFcn = 'trainbr'; % Bayesian Regularization
% Create a Feedforward Network
hiddenLayerSize = 18;
net = feedforwardnet (hiddenLayerSize,trainFcn);
% Setup Division of Data for Training, Validation, Testing
RandStream.setGlobalStream(RandStream('mt19937ar','seed',1)); % to get constant result
net.divideFcn = 'divideblock'; % Divide targets into three sets using blocks of indices
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;
%TRAINING PARAMETERS
net.trainParam.show=50; %# of ephocs in display
net.trainParam.lr=0.05; %learning rate
net.trainParam.epochs=10000; %max epochs
net.trainParam.goal=0.05^2; %training goal
net.performFcn='mse'; %Name of a network performance function %type help nnperformance
% Train the Network
[net,tr] = train(net,x,t);
% Test the Network
y = net(x);
e = gsubtract(t,y);
performance = perform(net,t,y)
% View the Network
view(net)
The questions are: Is it correct to use this code below and will it affect the function of my model?
RandStream.setGlobalStream(RandStream('mt19937ar','seed',1)); % to get constant result
How to add another hidden layer? How to change the activation function for each layer? What is the best plot to show the capability of the ANN model to detect the fault of the turbine earlier than existing control system. Please advise me if there are anything that can be corrected/improved.
2 Kommentare
scadaprog
am 15 Mai 2015
Hi Rahmat,
Yes by forcing the pseudo random generator to use the same seed everytime the script runs will result the same weights in your network. You can add a layer manually and set all the parameters including the activation function like this:
net.numLayers = 3;
net.layerConnect(3,2) = 1;
net.outputConnect = [0 0 1];
net.layers{2}.size = 8;
net.layers{2}.transferFcn = 'tansig';
net.outputs{3}.range = [1 20];
or you can just create a new network: net = feedforwardnet ([18 8],trainFcn);
The best plot is of course dependent on your data and what characteristics of that data your network should learn. But for a start you can just plot your target on top of your network’s output:
plot(1:length(t), t, 1:length(y), y);
Also you can check the built in performance plots on the GUI.
Rahmat Izaizi Ismail
am 16 Mai 2015
Bearbeitet: Rahmat Izaizi Ismail
am 17 Mai 2015
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Pattern Recognition finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!