极限学习机ELM
特点:收敛速度快;泛化性能好;训练过程无需调整权值和阈值,只需调整隐含层节点数可获得最优解等
ELM训练函数
[IW,B,LW,TF,TYPE]=elmtrain(P,T,N,TF,TYPE)
注: P(输入向量:(M x N)) T(输出向量:(1 x N)) N(隐含层节点数:默认为训练样本数)
TF(隐含层激活函数:'sig','sin','hardlim') TYPE(应用类型:0-回归 1-分类)
IW(隐含层与输入层连接权值矩阵) B(隐含层阈值) LW(隐含层与输出层链接权值矩阵)
ELM预测函数
Y = elmpredict(P,IW,B,LW,TF,TYPE)
data = csvread('D:\article\demo\seasonal\stl.csv');
sample = size(data,1);
timespan = 6;
imfindex = 1;
for i = 1:(sample-timespan)
x(i,:) = data(i:i+timespan-1,imfindex)';
end
y = data(timespan+1:end,imfindex);
predictspan = 7;
dividindex = size(x,1) - predictspan + 1;
x_train = x(1:dividindex-1,:);
y_train = y(1:dividindex-1,:);
x_test = x(dividindex:end,:);
y_test = y(dividindex:end,:);
[train_input,inputps] = mapminmax(x_train');
[train_output,outputps] = mapminmax(y_train');
%elmtrain(输入矩阵,输出矩阵,隐含层节点数,激活函数,应用类型[0-回归|1-分类])
%IW-输入层与隐含层连接权值 B-隐含层阈值 LW-隐含层与输出层连接权值
for hiddennum = 10:153
[IW,B,LW,TF,TYPE] = elmtrain(train_input,train_output,hiddennum,'sig',0);
ptrain = elmpredict(train_input,IW,B,LW,TF,TYPE);
predict_train = mapminmax('reverse',ptrain,outputps);
train_RMSE = sum((predict_train'-y_train).^2)/153;
MS(:,hiddennum-4) = train_RMSE;
test_input = mapminmax('apply',x_test',inputps);
ptest = elmpredict(test_input,IW,B,LW,TF,TYPE);
predict_test = mapminmax('reverse',ptest,outputps);
test_RMSE = sqrt(sum((predict_test'-y_test).^2)/7);
mse(:,hiddennum-4) = test_RMSE;
end
[IW,B,LW,TF,TYPE] = elmtrain(train_input,train_output,15,'sig',0);
ptrain = elmpredict(train_input,IW,B,LW,TF,TYPE);
predict_train = mapminmax('reverse',ptrain,outputps);
train_RMSE = sum((predict_train'-y_train).^2)/153;
disp(['train RMSE = ',num2str(train_RMSE)])
test_input = mapminmax('apply',x_test',inputps);
ptest = elmpredict(test_input,IW,B,LW,TF,TYPE);
predict_test = mapminmax('reverse',ptest,outputps);
test_RMSE = sqrt(sum((predict_test'-y_test).^2)/7);
disp(['test RMSE = ',num2str(test_RMSE)])
figure(1)
plot(predict_test,'-r')
hold on
plot(y_test,'--b')