⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mfe_loadf_errtables.m

📁 Modeling and Forecasting Electricity Loads and Prices: A Statistical Approach" by Rafa&#322 Weron, p
💻 M
字号:
function mfe_loadf_errtables(D,L,F,LF,for_beg_i,for_end_i)
%MFE_LOADF_ERRTABLES Auxiliary routine for MFE_LOADF.
%	MFE_LOADF_ERRTABLES(...) computes forecasting errors and displays 
%   results in the command window. 
%
%   Input data:
%       D - date vector,
%       L - actual load vector,
%       F - CAISO load forecast vector,
%       LF - Model (A or B) load forecast vector,
%       FOR_BEG_I - index of the first value of the forecast period,
%       FOR_END_I - index of the last value of the forecast period,
%
%   Reference(s):
%   [1] R.Weron (2007) "Modeling and Forecasting Electricity Loads and 
%   Prices: A Statistical Approach", Wiley, Chichester.

%   Written by Adam Misiorek and Rafal Weron (2006.09.22)
%   Copyright (c) 2006 by Rafal Weron

% Define holidays and special neighboring days in 2001 and 2002
holidays = [
    20010101 % 
    20010102
    %20010115 % US holiday   % removed because of small forecast errors
    20010219 % US holiday
    20010528 % US holiday
    20010529
    20010704 % US holiday
    20010705
    20010903 % US holiday
    20010904
    %20011008 % US holiday   % removed because of small forecast errors
    %20011112 % US holiday   % removed because of small forecast errors
    20011122 % US holiday
    20011224
    20011225 % US holiday
    20011231
    20020101 % US holiday
    20020102
    %20020121 % US holiday   % removed because of small forecast errors
    20020218 % US holiday
    20020527 % US holiday
    20020528
    20020704 % US holiday
    20020705
    20020901
    20020902 % US holiday
    20020903
    %20021014 % US holiday   % removed because of small forecast errors
    %20021111 % US holiday   % removed because of small forecast errors
    20021128 % US holiday
    %20021223                 % Monday
    20021224
    20021225 % US holiday
    20021226
    %20021227
    %20021228                 % Saturday
    %20021229
    %20021230                 % Monday
    20021231
];

% define time vector
tt = for_beg_i:for_end_i;  

% date vector without holidays
DwH = find(ismember(D(tt),holidays)==0);

% date vector holidays only
DH = find(ismember(D(tt),holidays)==1);

% compute forecast errors for 2001-2002
TT = tt;
DWH = DwH;
[MSE_F,MAE_F,MAPE_F] = errors(24*L(tt)/1000,24*F(tt)/1000);
[MSE_Fwh,MAE_Fwh,MAPE_Fwh] = errors(24*L(tt(DwH))/1000,24*F(tt(DwH))/1000);
[MSE_y,MAE_y,MAPE_y] = errors(24*L(tt)/1000,24*LF/1000);
[MSE_ywh,MAE_ywh,MAPE_ywh] = errors(24*L(tt(DwH))/1000,24*LF(DwH)/1000);
disp('MSE           MAE           MAPE')
disp([num2str([MSE_F,MAE_F,MAPE_F]) '        CAISO forecast (with holidays)'])
disp([num2str([MSE_Fwh,MAE_Fwh,MAPE_Fwh]) '        CAISO forecast (w/o holidays)'])
disp([num2str([MSE_y,MAE_y,MAPE_y]) '        ARMAX forecast (with holidays)'])
disp([num2str([MSE_ywh,MAE_ywh,MAPE_ywh]) '        ARMAX forecast (w/o holidays)'])

% compute forecast errors for 2001
tt = TT(1:365);
DwH = DWH(DWH<366);
[MSE_F,MAE_F,MAPE_F] = errors(24*L(tt)/1000,24*F(tt)/1000);
[MSE_Fwh,MAE_Fwh,MAPE_Fwh] = errors(24*L(tt(DwH))/1000,24*F(tt(DwH))/1000);
[MSE_y,MAE_y,MAPE_y] = errors(24*L(tt)/1000,24*LF(1:365)/1000);
[MSE_ywh,MAE_ywh,MAPE_ywh] = errors(24*L(tt(DwH))/1000,24*LF(DwH)/1000);
disp('MSE           MAE           MAPE 2001')
disp([num2str([MSE_F,MAE_F,MAPE_F]) '        CAISO forecast (with holidays)'])
disp([num2str([MSE_Fwh,MAE_Fwh,MAPE_Fwh]) '        CAISO forecast (w/o holidays)'])
disp([num2str([MSE_y,MAE_y,MAPE_y]) '        ARMAX forecast (with holidays)'])
disp([num2str([MSE_ywh,MAE_ywh,MAPE_ywh]) '        ARMAX forecast (w/o holidays)'])

% compute forecast errors for 2002 
tt = TT(366:730);
DwH = DWH(DWH>365)-365;
[MSE_F,MAE_F,MAPE_F] = errors(24*L(tt)/1000,24*F(tt)/1000);
[MSE_Fwh,MAE_Fwh,MAPE_Fwh] = errors(24*L(tt(DwH))/1000,24*F(tt(DwH))/1000);
[MSE_y,MAE_y,MAPE_y] = errors(24*L(tt)/1000,24*LF(366:730)/1000);
[MSE_ywh,MAE_ywh,MAPE_ywh] = errors(24*L(tt(DwH))/1000,24*LF(DwH+365)/1000);
disp('MSE           MAE           MAPE 2002')
disp([num2str([MSE_F,MAE_F,MAPE_F]) '        CAISO forecast (with holidays)'])
disp([num2str([MSE_Fwh,MAE_Fwh,MAPE_Fwh]) '        CAISO forecast (w/o holidays)'])
disp([num2str([MSE_y,MAE_y,MAPE_y]) '        ARMAX forecast (with holidays)'])
disp([num2str([MSE_ywh,MAE_ywh,MAPE_ywh]) '        ARMAX forecast (w/o holidays)'])

%=========================================================================
% Internally used routine(s)
%=========================================================================

function [MSE,MAE,MAPE]=errors(X,Y)
%ERRORS Returns MSE, MAE and MAPE.
%   [MSE,MAE,MAPE]=ERRORS(X,Y) returns the Mean Square Error (MSE), 
%   Mean Absolute Error (MAE) and Mean Absolute Percentage Error (MAPE)
%   of vectors X and Y.

MSE = mean( (X(:)-Y(:)).^2 );
MAE = mean( abs(X(:)-Y(:)) );
MAPE = mean( abs( (X(:)-Y(:))./X(:) ) ) * 100;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -