function [net,RMSE,Y] = main(xapp_alli,yapp_alli)
%This main function adjusts the learning weights of an ENN structure(emotinalNets)for a fitting problem. This main function applies genetic algorithm (ga) and uses the adjusted weights in feedforward computing of ENN (simENN)
%该主函数调整ENN结构(emotinalNets)的学习权重以用于拟合问题。 这个主要功能应用遗传算法(ga)并在ENN的前馈计算中使用调整后的权重(simENN)
%Written by Ehsan Lotfi esilotf@gmail.com
%Related Paper: Lotfi, E., Khosravi, A., Akbarzadeh-T, M. R., & Nahavandi, S. (2014, October). Wind power forecasting using emotional neural networks. In Systems, Man and Cybernetics (SMC), 2014 IEEE International Conference on (pp. 311-316). IEEE.
%Authorship: Ehsan Lotfi, esilotf@gmail.com
xapp_all = xapp_alli;
yapp_all= yapp_alli;
[ns,nf] = size(xapp_alli); %ns is number of samples and nf is number of features ,size表示获取矩阵的行数和列数,分别返回ns和nf
[ns,nC] = size(yapp_alli);%ns是目标向量的数量,nC是目标向量?
net = emotionalNets(xapp_all',yapp_all');%创建脑情绪网络
net = initEnn(net,'purelin','purelin');%初始化脑情绪网络
ooTra = zeros(1,1);
ooTes = zeros(1,1);%?
for ci = 1:nC%?
options = gaoptimset(@ga);
options = gaoptimset(options,'Generations',1000,'PopulationSize',4000,'PlotFcns',{@gaplotbestf},'TolFun',0.00,'HybridFcn',@fminsearch); % you can changed these parameters
%种群大小为4000,进化代数为1000
[TraP,TraT,TesP,TesT]=my_get_TraTes(xapp_all,yapp_all); %Training and test sets extraction function: It should be rewritten, according to your application.
%训练集和测试集提取,根据不同应用场景可改写
for i=1:size(TraP,1)
TraP(i,nf+1)=max(TraP(i,1:nf));
end
for i=1:size(TesP,1)
TesP(i,nf+1)=max(TesP(i,1:nf));
end
%%%%%%%%%%%%%%%%%%%%%%%%%% To adjust the learning weights, use GA %%%%%%%%%
f=@(x) sum((myf2(x,TraP,nf)-TraT(:,ci)').^2);%f为适应度函数句柄,myf2的调用?
[x, fval] = ga(f,2*nf+2,options);%遗传算法调用格式,x为遗传算法得到的最优个体,fval为最优个体x对应的适应度函数值,2*nf+2为个体所含变量数目,options为设置好的参数
%%%%%%%%%%%%%%%%%%%%%%%% Set the adjusted learning weights to net and testing%%%%%%%
net = set_weightArray_x(net,x);
Y.train = simEnn(net,TraP');
Y.test = simEnn(net,TesP');
targetTemp = TesT';
outputTemp = Y.test;
RMSE = (sum((targetTemp - outputTemp).^2)/size(targetTemp,2))^0.5;
ooTra(ci,1:size(TraP,1)) = myf2(x,TraP(1:size(TraP,1),1:nf+1),nf);
ooTes(ci,1:1:size(TesP,1)) = myf2(x,TesP(1:size(TesP,1),1:nf+1),nf);
f = figure(2);
plotregression(TraT',Y.train,'Training',...
TesT',Y.test,'Test');
end