clear all;
close all;
clc;
%% 导入数据
P_train = xlsread('data','training set','B2:G191')';
T_train= xlsread('data','training set','H2:H191')';
% 测试集——44个样本
P_test=xlsread('data','test set','B2:G45')';
T_test=xlsread('data','test set','H2:H45')';
%% 优化参数设置
SearchAgents = 10; % 种群数量 50
Function_name='LSTM_MIN';
Max_iterations = 6; % 迭代次数 10
lowerbound = [10 0.001 10 ];%三个参数的下限
upperbound = [200 0.02 200 ];%三个参数的上限
dimension = 3;%数量,即要优化的LSTM参数个数
fitness = @(x)LSTM_MIN(x,P_train,P_test,T_train,T_test);
%% 优化LSTM
[Best_score,Best_pos,Convergence_curve]=POA(SearchAgents,Max_iterations,lowerbound,upperbound,dimension,fitness)
save file2
%% 寻优得到的参数进行赋值
clear all;clc;close all;warning off;
load file2
Tuna1(1,1)=floor(Best_pos(1,1));
Tuna1(1,3)=floor(Best_pos(1,3));
numHiddenUnits=round(Tuna1(1,1));
MaxEpochs=abs(Tuna1(1,3));
InitialLearnRate=abs(Best_pos(1,2));
%% 导入数据
P_train = xlsread('data','training set','B2:G191')';
T_train= xlsread('data','training set','H2:H191')';
% 测试集——44个样本
P_test=xlsread('data','test set','B2:G45')';
T_test=xlsread('data','test set','H2:H45')';
train_x=P_train;
train_y=T_train;
test_x=P_test;
test_y=T_test;
method=@mapminmax;
%% 数据归一化
[train_x,train_ps]=method(train_x);
test_x=method('apply',test_x,train_ps);
[train_y,output_ps]=method(train_y);
test_y=method('apply',test_y,output_ps);
%% 数据转换为双精度格式
XTrain = double(train_x) ;
XTest = double(test_x) ;
YTrain = double(train_y);
YTest = double(test_y);
%% 确定训练集和预测集维度
numFeatures = size(XTrain,1); %输入特征维数
numResponses = size(YTrain,1);%输出特征维数
智能算法及其模型预测