基于自组织长短期记忆神经网络的时间序列预测(MATLAB)

发布于:2024-06-30 ⋅ 阅读:(15) ⋅ 点赞:(0)

LSTM是为了解决RNN 的梯度消失问题而诞生的特殊循环神经网络。该网络开发了一种异于普通神经元的节点结构,引入了3 个控制门的概念。该节点称为LSTM 单元。LSTM 神经网络避免了梯度消失的情况,能够记忆更长久的历史信息,更能有效地拟合长期时间序列数据的变化趋势。因此,如今在语音识别,序列预测等方面,LSTM 被广泛地应用于这些领域,取得了很多丰硕的成果。在构建 LSTM 网络的过程中,结构的确定是一大挑战。大多数方法都是采用启发式的方式确定最佳的隐藏层神经元个数,效率大大降低。为了解决这一问题,自组织方法被广泛应用于此。自组织方法大致有两个方向,增加神经元个数以及减少神经元个数,通常被称为生长以及剪枝。比如如下的基于敏感度分析的一种自组织 LSTM 神经网络的预测算法:

图片

鉴于此,采用一种基于自组织长短期记忆神经网络进行时间序列预测,运行环境为MATLAB 2018。


function  [TrainTargets,TrainOutputs] = fuzzfcm(x)
x = x';
%
Delays = [1 2 3];
[Inputs, Targets] = TimeSeries(x, Delays);
Inputs = Inputs';
Targets = Targets';
nData = size(Inputs,1);

% Shuffling Data
PERM = 1:nData; % Permutation to Shuffle Data
%
pTrain=0.80;
nTrainData=round(pTrain*nData);
TrainInd=PERM(1:nTrainData);
TrainInputs=Inputs(TrainInd,:);
TrainTargets=Targets(TrainInd,:);
%
pTest=1-pTrain;
nTestData=nData-nTrainData;
TestInd=PERM(nTrainData+1:end);
TestInputs=Inputs(TestInd,:);
TestTargets=Targets(TestInd,:);

%% FCM FIS Generation Method and Parameters       
        nCluster=10;        
        Exponent=2;       
        MaxIt=100;          
        MinImprovment=1e-5;  
        DisplayInfo=1;
        FCMOptions=[Exponent MaxIt MinImprovment DisplayInfo];
        fis=genfis3(TrainInputs,TrainTargets,'sugeno',nCluster,FCMOptions);
        
% Training ANFIS Structure
MaxEpoch=100;                 
ErrorGoal=0;                
InitialStepSize=0.01;         
StepSizeDecreaseRate=0.9;     
StepSizeIncreaseRate=1.1;    
TrainOptions=[MaxEpoch ...
              ErrorGoal ...
              InitialStepSize ...
              StepSizeDecreaseRate ...
              StepSizeIncreaseRate];
DisplayInfo=true;
DisplayError=true;
DisplayStepSize=true;
DisplayFinalResult=true;
DisplayOptions=[DisplayInfo ...
                DisplayError ...
                DisplayStepSize ...
                DisplayFinalResult];
OptimizationMethod=1;
% 0: Backpropagation
% 1: Hybrid
fis=anfis([TrainInputs TrainTargets],fis,TrainOptions,DisplayOptions,[],OptimizationMethod);

% Apply ANFIS to Data
Outputs=evalfis(Inputs,fis);
TrainOutputs=Outputs(TrainInd,:);
TestOutputs=Outputs(TestInd,:);

% Error Calculation
TrainErrors=TrainTargets-TrainOutputs;
TrainMSE=mean(TrainErrors.^2);
TrainRMSE=sqrt(TrainMSE);
TrainErrorMean=mean(TrainErrors);
TrainErrorSTD=std(TrainErrors);
%
TestErrors=TestTargets-TestOutputs;
TestMSE=mean(TestErrors.^2);
TestRMSE=sqrt(TestMSE);
TestErrorMean=mean(TestErrors);
TestErrorSTD=std(TestErrors);

%Results
% figure;
% PlotResults(TrainTargets,TrainOutputs,'Train Data');
% figure;
% PlotResults(TestTargets,TestOutputs,'Test Data');
% figure;
% PlotResults(Targets,Outputs,'All Data');
% figure;
%     plotregression(TrainTargets, TrainOutputs, 'Train Data', ...
%                    TestTargets, TestOutputs, 'Test Data', ...
%                    Targets, Outputs, 'All Data');

完整代码:https://mbd.pub/o/bread/mbd-ZJ2Ykpxs


end

图片

图片

图片

图片

图片

擅长领域:现代信号处理,机器学习,深度学习,数字孪生,时间序列分析,设备缺陷检测、设备异常检测、设备智能故障诊断与健康管理PHM等。