Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab 如何利用遗传算法优化神经网络结构_Matlab_Neural Network_Genetic Algorithm - Fatal编程技术网

Matlab 如何利用遗传算法优化神经网络结构

Matlab 如何利用遗传算法优化神经网络结构,matlab,neural-network,genetic-algorithm,Matlab,Neural Network,Genetic Algorithm,我通过编辑ANN工具箱中的代码创建了NN模型。在我的工作中,我需要研究改变各种ANN拓扑结构对其性能的影响。该模型的目的是利用汽轮机的运行数据对网络进行训练。将数据标准化,然后根据标记为“1”的实际故障发生和正常运行期间的“0”设置目标。在下一步工作中,我将尝试使用遗传算法优化ANN拓扑 % load data load data.mat; x = data; t = target; % Choose a Training Function % For a list of all trai

我通过编辑ANN工具箱中的代码创建了NN模型。在我的工作中,我需要研究改变各种ANN拓扑结构对其性能的影响。该模型的目的是利用汽轮机的运行数据对网络进行训练。将数据标准化,然后根据标记为“1”的实际故障发生和正常运行期间的“0”设置目标。在下一步工作中,我将尝试使用遗传算法优化ANN拓扑

% load data
load data.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 = 'trainscg';  % Bayesian Regularization

% Create a Feedforward Network
hiddenLayerSize = 6;
net = feedforwardnet (hiddenLayerSize,trainFcn);

% Setup Division of Data for Training, Validation, Testing
RandStream.setGlobalStream(RandStream('mt19937ar','seed',1)); % to make the weight constant
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

% Setup of activation/transfer function
net.layers{1}.transferFcn = 'tansig';
net.layers{2}.transferFcn = 'tansig';

% 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)

plot(1:length(t), t, 1:length(y), y);
如何使用遗传算法优化三种训练算法中的哪一种给出了最好的RMSE。对于我的工作,我还需要考虑神经元的数量、隐藏层的数量和激活函数。我计划使用二进制编码来实现这一点,例如:

% Preliminary function decoding:
            function [algo, archit, activf1, activf2] = decoding(X)
            %
            % function that decodes a binary string into information
            % about the NN structure and training tralgorithm
            %
            %   [algo, archit, activf1 activf2] = decoding(X)
            %
            % "X" is a population of binary strings of size 10 (excluding 32param)
            % eg:[00,0000,00 00]
            %
            % algo  = for training algorithm trainscg, trainlm, trainbr
            %       
            % archit = hidden layer neurons from 0000 to 1001 
            %
            % activf1 = type of activation functions of hidden nodes
            % activf2 = type of activation functions of output nodes
            %           = 00 for logsig
            %           = 01 for tansig
            %           = 10 for purelin
            %M=Pz (population size)
            M = size(X,1);
            %initializations:
            a = zeros(M,2); %size for algo (training algorithm)
            b = zeros(M,4); %size for archit (hidden layer neuron)
            c = zeros(M,4); %size for activf and activf2
            %d = zeros(Pz,32);
            for i=1:M
            a = X(i,1:2);
            b = X(i,3:8);
            c = X(i,9:10);
            % for algo (training algorithm)
            if (a == [0 0])
            algo(i) = ['trainscg'];
            elseif (a == [0 1])
            algo(i) = ['trainlm'];
            elseif (a == [1 0])
            algo(i) = ['trainbr'];
            end
            % for archit (hidden layer neuron)
            if (b == [0 0 0 0])
            archit(i,1) = 1;
            elseif (b == [0 0 0 1])
            archit(i,1) = 2;
            elseif (b == [0 0 1 0])
            archit(i,1) = 3;
            elseif (b == [0 0 1 1])
            archit(i,1) = 4;
            elseif (b == [0 1 0 0])
            archit(i,1) = 5;
            elseif (b == [0 1 0 1])
            archit(i,1) = 6;
            elseif (b == [0 1 1 0])
            archit(i,1) = 7;
            elseif (b == [0 1 1 1])
            archit(i,1) = 8;
            elseif (b == [1 0 0 0])
            archit(i,1) = 9;
            elseif (b == [1 0 0 1])
            archit(i,1) = 10;
            end
            % for activf and activf2
            if (c == [0 0 0 0])
            activf1(i,:) = ['logsig'];
            activf2(i,:) = ['logsig'];
            elseif (c == [0 0 0 1])
            activf1(i,:) = ['logsig'];
            activf2(i,:) = ['tansig'];
            elseif (c == [0 0 1 0])
            activf1(i,:) = ['logsig'];
            activf2(i,:) = ['purelin'];
            elseif (c == [0 0 1 1])
            activf1(i,:) = ['tansig'];
            activf2(i,:) = ['logsig'];
            elseif (c == [0 1 0 0])
            activf1(i,:) = ['tansig'];
            activf2(i,:) = ['tansig'];
            elseif (c == [0 1 0 1])
            activf1(i,:) = ['tansig'];
            activf2(i,:) = ['purelin'];
            elseif (c == [0 1 1 0])
            activf1(i,:) = ['purelin'];
            activf2(i,:) = ['logsig'];
            elseif (c == [0 1 1 1])
            activf1(i,:) = ['purelin'];
            activf2(i,:) = ['tansig'];
            elseif (c == [1 0 0 0])
            activf1(i,:) = ['purelin'];
            activf2(i,:) = ['purelin'];
            end
            end %for
            'Population was decoded!' 

基于我有限的遗传算法知识,我需要创建一个适应度函数和函数句柄。该网络的性能指标是RMSE,因此RMSE应该是GA的适应度。如何从现在开始创建适应度函数?请注意:)

您可以用图邻域矩阵表示ANN中的所有连接。如果ANN中总共有N个神经元,那么就有NxN邻域矩阵。该矩阵可以作为GA优化的目标

n(i)=1/(1-exp(-sum(a(i,j)*w(i,j)*n(j)))