1 简介 基于自编LSTM神经网络实现空调能耗数据预测。 2 部分代码 %% 程序说明 % 1、数据为7天,四个时间点的空调功耗,用前三个推测第四个训练,依次类推。第七天作为检验
1 简介
基于自编LSTM神经网络实现空调能耗数据预测。
2 部分代码
%% 程序说明% 1、数据为7天,四个时间点的空调功耗,用前三个推测第四个训练,依次类推。第七天作为检验
% 2、LSTM网络输入结点为12,输出结点为4个,隐藏结点18个
clear all;
clc;
%% 数据加载,并归一化处理
[train_data,test_data]=LSTM_data_process();
data_length=size(train_data,1);
data_num=size(train_data,2);
%% 网络参数初始化
% 结点数设置
input_num=12;
cell_num=18;
output_num=4;
% 网络中门的偏置
bias_input_gate=rand(1,cell_num);
bias_forget_gate=rand(1,cell_num);
bias_output_gate=rand(1,cell_num);
% ab=1.2;
% bias_input_gate=ones(1,cell_num)/ab;
end
if(Error_Cost(1,iter)<cost_gate)
break;
end
end
%% 绘制Error-Cost曲线图
% for n=1:1:iter
% text(n,Error_Cost(1,n),'*');
% axis([0,iter,0,1]);
% title('Error-Cost曲线图');
% end
for n=1:1:iter
semilogy(n,Error_Cost(1,n),'*');
hold on;
title('Error-Cost曲线图');
end
%% 使用第七天数据检验
%数据加载
test_final=[0.4557 0.4790 0.7019 0.8211 0.4601 0.4811 0.7101 0.8298 0.4612 0.4845 0.7188 0.8312]';
test_final=test_final/sqrt(sum(test_final.^2));
test_output=test_data(:,4);
%前馈
m=4;
gate=tanh(test_final'*weight_input_x+h_state(:,m-1)'*weight_input_h);
input_gate_input=test_final'*weight_inputgate_x+cell_state(:,m-1)'*weight_inputgate_c+bias_input_gate;
forget_gate_input=test_final'*weight_forgetgate_x+cell_state(:,m-1)'*weight_forgetgate_c+bias_forget_gate;
output_gate_input=test_final'*weight_outputgate_x+cell_state(:,m-1)'*weight_outputgate_c+bias_output_gate;
for n=1:cell_num
input_gate(1,n)=1/(1+exp(-input_gate_input(1,n)));
forget_gate(1,n)=1/(1+exp(-forget_gate_input(1,n)));
output_gate(1,n)=1/(1+exp(-output_gate_input(1,n)));
end
cell_state_test=(input_gate.*gate+cell_state(:,m-1)'.*forget_gate)';
pre_h_state=tanh(cell_state_test').*output_gate;
h_state_test=(pre_h_state*weight_preh_h)'
test_output
3 仿真结果
4 参考文献
[1]徐凌峰, 高洪. 基于LSTM神经网络的乘用车能耗预测[J]. 井冈山大学学报:自然科学版, 2021, 42(5):7.
博主简介:擅长智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机等多种领域的Matlab仿真,相关matlab代码问题可私信交流。
部分理论引用网络文献,若有侵权联系博主删除。