回归预测 | MATLAB实现GMDH自组织网络模型多输入单输出
效果一览
基本介绍
模型构建
程序设计
- 完整程序和数据下载:GMDH自组织网络模型多输入单输出完整程序和数据
- 运行主程序MainGMDH.m即可。
%% GMDH parametes
PSD=[6 4 2];% Number max allowed neron in each layer
validateCof=.20;
%% Modeling
nSamples=length(x(:,1));
nValition=ceil(validateCof*nSamples);
nTrain=nSamples-nValition;
Perm = randperm(nSamples);
trainIndex = Perm(1:nTrain);
validationIndex=Perm(nTrain+1:end);
trainedGMDH=GMDH(PSD,x(trainIndex,:),t(trainIndex,:));
outputs=ApplyGMDH(trainedGMDH,x(validationIndex,:));
orginalVector=t(validationIndex,:);
%% Resultes
figure;
PlotResults(t(validationIndex,:), outputs, 'Validation');
figure;
PlotResults(t(trainedGMDH.suffleList_train,:), trainedGMDH.Layers{end}.value, 'Train Data');
function PlotResults(Targets, Outputs, Title)
Errors = Targets - Outputs;
MSE = mean(Errors.^2);
RMSE = sqrt(MSE);
ErrorMean = mean(Errors);
ErrorStd = std(Errors);
subplot(2,2,[1 2]);
plot(Targets);
hold on;
plot(Outputs);
legend('Targets','Outputs');
ylabel('Targets and Outputs');
grid on;
title(Title);
subplot(2,2,3);
plot(Errors);
title(['MSE = ' num2str(MSE) ', RMSE = ' num2str(RMSE)]);
ylabel('Errors');
grid on;
subplot(2,2,4);
histfit(Errors, 50);
title(['Error Mean = ' num2str(ErrorMean) ', Error StD = ' num2str(ErrorStd)]);
end
unction output1=ApplyGMDH(inputGMDH,X)
%for each layer calculate output value
output=X;
for i=1:numel(inputGMDH.Layers)
output=CalculateLayerOutput(inputGMDH.Layers{i},output);
end
output1=output;
end
function y=CalculateLayerOutput(L,X)
m = size(X,1);
N = numel(L);
y = zeros(m,N);
for i=1:numel(L)
A=VolterraSeries(X(:,L(i).path(1)),X(:,L(i).path(2)));
y(:,i) = A*L(i).Coff;
end
end
function Y = VolterraSeries(x1,x2)
y1=ones(1,numel(x1));
y2=x1(:,1)';
y3=x2(:,1)';
y4= x1(:,1).^2';
y5=x2(:,1).^2';
y6=(x1(:,1).*x2(:,1))';
Y =[y1;y2;y3;y4;y5;y6]';
end