采用多层人工神经网络的能源消耗的时间序列预测(Matlab代码实现)

简介: 采用多层人工神经网络的能源消耗的时间序列预测(Matlab代码实现)

💥1 概述

该项目为能源消耗的时间序列预测,在Matlab中实现。该预测采用多层人工神经网络,基于Kaggle训练集预测未来能源消耗。

📚2 运行结果

 

🎉3 参考文献

[1]程静,郑定成,吴继权.基于时间序列ARMA模型的广东省能源需求预测[J].能源工程,2010(01):1-5.DOI:10.16189/j.cnki.nygc.2010.01.012.

👨‍💻4 Matlab代码

seed = 52
    rng(seed);                                                                  % Seeds the random number generator using the nonnegative integer seed     
    % Load the data
    load lasertrain.dat 
    load laserpred.dat
    clear net
    close all
    p = 18;                                                                     % Lag    
    n = 4;                                                                      % Difference between the inputs and the number of neurons    
    [TrainData, TrainTarget] = getTimeSeriesTrainData(lasertrain, p);           % This creates TrainData and TrainTarget, such as divided in time  intervales of 5. TrainData(:,1) -> TrainTarget(1). R5 --> R1
    % Create the ANN
    numN = p - n;                                                               % Number of neurons in the hidden layer
    numE = 200;                                                                 % Number of epochs
    trainAlg = 'trainlm';                                                       % Training Algorithm 
    transFun = 'tansig';                                                        % Transfer Function   
    net = feedforwardnet(numN, trainAlg);                                       % Create general feedforward netowrk
    net.trainParam.epochs = numE;                                               % Set the number of epochs for the training 
    net.layers{1}.transferFcn = transFun;                                       % Set the Transfer Function
%     net.divideParam.trainRatio = 0.8;
%     net.divideParam.valRatio = 0.2;
%     net.divideParam.testRatio = 0;
    P = TrainData;       
    T = TrainTarget;     
    net = train(net,P,T);
    TotMat = [lasertrain ; zeros(size(laserpred))];
    for j = 1:length(laserpred) 
        r = length(lasertrain) - p + j;
        P = TotMat(r:r+p-1);
        a = sim(net,P);
        TotMat(length(lasertrain) + j) = a;
%         TotMat(length(lasertrain) + j) = (abs(round(a))+round(a))/2;
    end
    err = immse(TotMat(length(lasertrain)+1:end),laserpred);
    x = linspace(1,length(TotMat),length(TotMat));
figure
subplot(3,1,2)
plot(x(1:length(lasertrain)), TotMat(1:length(lasertrain)),'r', x(length(lasertrain)+1:end), TotMat(length(lasertrain)+1:end),'g', x(length(lasertrain)+1:end), laserpred','b');
xlim([1 1100])
title('Real set and forecast set');
legend('Training Data','Forecasted Data', 'Test data');
subplot(3,1,1)
plot(x(1:length(lasertrain)), TotMat(1:length(lasertrain)),'r', x(length(lasertrain):end), TotMat(length(lasertrain):end),'g');
xlim([1 1100])
title('Forecasted set');
legend('Training Data','Forecasted Data');
subplot(3,1,3)
plot(x(length(lasertrain)+1:end), TotMat(length(lasertrain)+1:end),'g', x(length(lasertrain)+1:end), laserpred','b');
xlim([1000 1100])
title('Detailed forcast data vs Test data');
legend('Forecasted Data', 'Test data');
formatSpec = 'The mean squared error is %4.2f \n';
fprintf(formatSpec, err)

主函数部分代码:

%% Exercise 2 - Recurrent Neural Networks
%% Initial stuff
clc
clearvars
close all
%% 1 - Hopfield Network
% Note: for this exercise, it will be interesting to check what happens if
% you add more neurons, i.e. modify T such as N is bigger.
T = [1 1; -1 -1; 1 -1]';                                                    % N x Q matrix containing Q vectors with components equal to +- 1.
                                                                            % 2-neuron network with 3 atactors
net = newhop(T);                                                            % Create a recurrent HOpfield network with stable points being the vectors from T
A1 = [0.3 0.6; -0.1 0.8; -1 0.5]';                                          % Example inputs
A2 = [-1 0.5 ; -0.5 0.1 ; -1 -1 ]';
A3 = [1 0.5  ; -0.3 -0.4 ; 0.8 -0.6]';
A4 = [0 -0.1 ; 0.1 0 ; -0.5 0.1]';
A5 = [0 0 ; 0 0.1  ; -0.1 0 ]';
A0 = [1 1; -1 -1; 1 -1]';
% Simulate a Hopfield network
% Y_1 = net([],[],Ai);                                                      % Single step iteration    
num_step = 20;                                                              % Number of steps                
Y_1 = net({num_step},{},A1);                                                % Multiple step iteration
Y_2 = net({num_step},{},A2);  
Y_3 = net({num_step},{},A3);  
Y_4 = net({num_step},{},A4);  
Y_5 = net({num_step},{},A5);
%% Now we try with 4 Neurons
T_ = [1 1 1 1; -1 -1 1 -1; 1 -1 1 1]';                                      % N x Q matrix containing Q vectors with components equal to +- 1.
                                                                            % 4-neuron network with 3 atactors
net_ = newhop(T_);                                                          % Create a recurrent HOpfield network with stable points being the vectors from T
A1_ = [0.3 0.6 0.3 0.6; -0.1 0.8 -0.1 0.8; -1 0.5 -1 0.5]';                 % Example inputs
A2_ = [-1 0.2 -1 0.2 ; -0.5 0.1  -0.5 0.1 ; -1 -1 -1 -1 ]';
A3_ = [1 0.5 1 0.5 ; -0.3 -0.4 -0.3 -0.4 ; 0.8 -0.6 0.8 -0.6]';
A4_ = [-0.5 -0.3 -0.5 -0.3 ; 0.1 0.8 0.1 0.8 ; -0.7 0.6 -0.7 0.6]';
% Simulate a Hopfield network
% Y_1 = net([],[],Ai);                                                      % Single step iteration    
num_step_ = 40;                                                             % Number of steps                
Y_1_ = net_({num_step_},{},A1_);                                            % Multiple step iteration
Y_2_ = net_({num_step_},{},A2_);  
Y_3_ = net_({num_step_},{},A3_);  
Y_4_ = net_({num_step_},{},A4_); 
%% Execute rep2.m || A script which generates n random initial points and visualises results of simulation of a 2d Hopfield network 'net'
% Note: The idea is to understand what is the relation between symmetry and
% attractors. It does not make sense that appears a fourth attractor when
% only 3 are in the Target T
close all 


相关文章
|
4天前
|
机器学习/深度学习 算法 数据安全/隐私保护
基于GRU网络的MQAM调制信号检测算法matlab仿真,对比LSTM
本研究基于MATLAB 2022a,使用GRU网络对QAM调制信号进行检测。QAM是一种高效调制技术,广泛应用于现代通信系统。传统方法在复杂环境下性能下降,而GRU通过门控机制有效提取时间序列特征,实现16QAM、32QAM、64QAM、128QAM的准确检测。仿真结果显示,GRU在低SNR下表现优异,且训练速度快,参数少。核心程序包括模型预测、误检率和漏检率计算,并绘制准确率图。
79 65
基于GRU网络的MQAM调制信号检测算法matlab仿真,对比LSTM
|
9天前
|
机器学习/深度学习 数据采集 算法
基于WOA鲸鱼优化的CNN-GRU-SAM网络时间序列回归预测算法matlab仿真
本项目基于MATLAB 2022a实现时间序列预测,采用CNN-GRU-SAM网络结构,结合鲸鱼优化算法(WOA)优化网络参数。核心代码含操作视频,运行效果无水印。算法通过卷积层提取局部特征,GRU层处理长期依赖,自注意力机制捕捉全局特征,全连接层整合输出。数据预处理后,使用WOA迭代优化,最终输出最优预测结果。
|
3天前
|
机器学习/深度学习 算法 数据安全/隐私保护
基于机器学习的人脸识别算法matlab仿真,对比GRNN,PNN,DNN以及BP四种网络
本项目展示了人脸识别算法的运行效果(无水印),基于MATLAB2022A开发。核心程序包含详细中文注释及操作视频。理论部分介绍了广义回归神经网络(GRNN)、概率神经网络(PNN)、深度神经网络(DNN)和反向传播(BP)神经网络在人脸识别中的应用,涵盖各算法的结构特点与性能比较。
|
1天前
|
机器学习/深度学习 数据采集 算法
基于GA遗传优化的CNN-LSTM-SAM网络时间序列回归预测算法matlab仿真
本项目使用MATLAB 2022a实现时间序列预测算法,完整程序无水印。核心代码包含详细中文注释和操作视频。算法基于CNN-LSTM-SAM网络,融合卷积层、LSTM层与自注意力机制,适用于金融市场、气象预报等领域。通过数据归一化、种群初始化、适应度计算及参数优化等步骤,有效处理非线性时间序列,输出精准预测结果。
|
14天前
|
传感器 算法 物联网
基于粒子群算法的网络最优节点部署优化matlab仿真
本项目基于粒子群优化(PSO)算法,实现WSN网络节点的最优部署,以最大化节点覆盖范围。使用MATLAB2022A进行开发与测试,展示了优化后的节点分布及其覆盖范围。核心代码通过定义目标函数和约束条件,利用PSO算法迭代搜索最佳节点位置,并绘制优化结果图。PSO算法灵感源于鸟群觅食行为,适用于连续和离散空间的优化问题,在通信网络、物联网等领域有广泛应用。该算法通过模拟粒子群体智慧,高效逼近最优解,提升网络性能。
|
14天前
|
机器学习/深度学习 数据采集 算法
基于GWO灰狼优化的CNN-GRU-SAM网络时间序列回归预测算法matlab仿真
本项目基于MATLAB2022a,展示了时间序列预测算法的运行效果(无水印)。核心程序包含详细中文注释和操作视频。算法采用CNN-GRU-SAM网络,结合灰狼优化(GWO),通过卷积层提取局部特征、GRU处理长期依赖、自注意力机制捕捉全局特征,最终实现复杂非线性时间序列的高效预测。
|
1月前
|
机器学习/深度学习 监控 算法
基于yolov4深度学习网络的排队人数统计系统matlab仿真,带GUI界面
本项目基于YOLOv4深度学习网络,利用MATLAB 2022a实现排队人数统计的算法仿真。通过先进的计算机视觉技术,系统能自动、准确地检测和统计监控画面中的人数,适用于银行、车站等场景,优化资源分配和服务管理。核心程序包含多个回调函数,用于处理用户输入及界面交互,确保系统的高效运行。仿真结果无水印,操作步骤详见配套视频。
59 18
|
2月前
|
SQL 安全 网络安全
网络安全与信息安全:知识分享####
【10月更文挑战第21天】 随着数字化时代的快速发展,网络安全和信息安全已成为个人和企业不可忽视的关键问题。本文将探讨网络安全漏洞、加密技术以及安全意识的重要性,并提供一些实用的建议,帮助读者提高自身的网络安全防护能力。 ####
90 17
|
2月前
|
存储 SQL 安全
网络安全与信息安全:关于网络安全漏洞、加密技术、安全意识等方面的知识分享
随着互联网的普及,网络安全问题日益突出。本文将介绍网络安全的重要性,分析常见的网络安全漏洞及其危害,探讨加密技术在保障网络安全中的作用,并强调提高安全意识的必要性。通过本文的学习,读者将了解网络安全的基本概念和应对策略,提升个人和组织的网络安全防护能力。
|
2月前
|
SQL 安全 网络安全
网络安全与信息安全:关于网络安全漏洞、加密技术、安全意识等方面的知识分享
随着互联网的普及,网络安全问题日益突出。本文将从网络安全漏洞、加密技术和安全意识三个方面进行探讨,旨在提高读者对网络安全的认识和防范能力。通过分析常见的网络安全漏洞,介绍加密技术的基本原理和应用,以及强调安全意识的重要性,帮助读者更好地保护自己的网络信息安全。
64 10

热门文章

最新文章