Matlab forecasting model - gray forecasting model

Forecasting Model - Gray Forecasting Model

insert image description here

  1. Gray prediction is to predict the system that contains both known information and uncertain information , that is, to predict the gray process that changes within a certain range and is related to time.
  2. Gray prediction generates and processes the original data to find the law of system changes, and generates a data sequence with strong regularity, and then establishes a corresponding differential equation model to predict the future development of things beyond the potential situation.

gray forecasting model

  1. Gray Forecast Model (Gray Forecast Model) is a forecasting method to establish a mathematical model and make a forecast through a small amount of incomplete information. When we apply the thinking method of operations research to solve practical problems, formulate development strategies and policies, When making decisions on major issues, it is necessary to make scientific predictions about the future. Prediction is based on the past and present development laws of objective things, with the help of scientific methods to describe and analyze their future development trends and conditions, and form a scientific assumptions and judgments.

  2. Gray system theory is a theory that studies and solves gray system analysis, modeling, prediction, decision-making and control. Gray prediction is the prediction made on gray system.
    Some commonly used forecasting methods (such as regression analysis, etc.) at present require larger samples. If the samples are small, they often cause large errors and make the prediction target invalid. The gray forecasting model requires less modeling information, is convenient to operate, and has high modeling accuracy . It is widely used in various forecasting fields and is an effective tool for dealing with small sample forecasting problems.

  3. Gray system theory was proposed and developed by Professor Deng Julong of Huazhong University of Science and Technology in 1982. Over the past 20 years, it has attracted the attention of many scholars at home and abroad, and has achieved considerable development. At present, in our country, it has become one of the important methods for forecasting, decision-making, evaluation, planning control, system analysis and modeling in many fields such as society, economy, science and technology. In particular, it has a unique effect on the analysis and modeling of short time series, less statistical data, and incomplete information, so it has been widely used.

gray system

  1. The message of the white system
    system is completely clear.
  2. Is part of the information of the gray system
    known, and part of the information is unknown.
  3. The internal information of the black system
    system is unknown.
  4. Gray system features:
    (1) Use gray mathematics to deal with uncertainties and make them quantified.
     (2) Make full use of known information to seek the law of motion of the system.
     (3) Gray system theory can deal with poor information systems.

GM(1,1) model overview

insert image description here

insert image description here

modeling process

insert image description here
insert image description here

insert image description here
insert image description here

model checking

insert image description here
insert image description here

Analysis of model results

insert image description here

Key Points of Using Gray Forecasting Model

insert image description here
insert image description here

the case

insert image description here

GM(1,1) code

function gm11 = GM11_model(X,td)

%GM11_model用于灰色模型c(1,1)的建立和预测
%输入参数x为原始数据,td为未来预测期数
%输出参数gm11为一个结构体,包括。
%Coeff_a为发展系数,Coeff_u为灰作用量,
%Predict_Value为预测值,包括当前值和未来td期预测值
%AbsoluteBrror为绝对误差,RelativeErrorMean为相对误差均值
%C为方差比,P误差为小概率,R为关联度

%% 输入参数的控制与默认值

 if nargin < 2
    warning('输入参数为2个,td将默认使用默认值5')
    td = 5;
 elseif td < 0
    warning('未来预测期数td不能为负值,td将默认使用默认值0')
    td = 0;
 end
  
 %%数据预处理:累加,平均
 n  = length(X);    %%获取原始数据个数
 Ago = cumsum(X);    %% 原始数据一次累加 获取新1-AGO序列xi(1)
 % Z(i) 为xi(1)的紧邻均值生成序列
 % Z = (Ago(1:n-1)+Ago(2:end))/2;
 Z = (Ago(1:end-1) + Ago(2:end) ) / 2;  % 计算紧邻均值生成数列(长度为n-1)

 %%构造B和Ynz矩阵
 Yn = X(2:end)'; %Yn是常数项向量 X(2),x(3)
 B= [-Z;ones(1,n-1)]'; %% 累加生成数据作均值

 %% 最小二乘法求解发展系数a和灰色作用量u

 LS_solution = (B'*B)\(B'*Yn); %% 利用公式求解a,u
 a = LS_solution(1);   %%发展系数a
 u = LS_solution(2);  %%灰色作用量u


 %%建立灰度GM(1,1)模型,白化一元一阶微分方程
 F = [X(1),(X(1)-u/a)./exp(a*(1:n+td-1))+u/a];

 %% 还原序列,得到预测数据
 PreData = [F(1),F(2:end)-F(1:end-1)];


 %% 数据可视化
 t = 1:n;
 plot(t,X,'ko-','MarkerFaceColor','k')  %%原数据图像
 hold on;
 grid on

 %%预测当前数据图像
 plot(t,PreData(1:n),'b*-','LineWidth',1.5)  

 %% 未来td期数据图像
 plot(n:n+td,PreData(n:n+td),'r*-','LineWidth',1.5)
 title('GM(1,1) model --- Original VS Current And Future Predict');
 legend('OriginalData','ForecastData','ForecastFutureData','Location','best')
 legend('boxoff')
 set(get(gca, 'XLabel'), 'String', 'Time');
 set(get(gca, 'YLabel'), 'String', 'Value');



 %% 模型校验

 Err = abs(X-PreData(1:n));  %真实值与预测值误差
 q = mean(Err./X);%真实值与预测值误差
 XVar = std(X,1);%原数据的标准方差,前置因子1/n
 ErrVar = std(Err(2:end):1);%残差(2:end)的标准方差,前置因子1/n
 C = ErrVar/XVar;  %后验方差比
 %小误差率
 P = sum(abs(Err-mean(Err))<0.6745*XVar)/n;  
 R_k = (min(Err)+0.5*max(Err))./(Err+0.5*max(Err)); %rho=0.5
 R = sum(R_k)/length(R_k); %关联度

%%计算变量组合,生成输出结构体变量
 gm11.Coeff_a = a;
 gm11.Coeff_u = u;
 gm11.Predict_Value = PreData;
 gm11.AbsoluteError = Err;
 gm11.RelativeErrorMean = q;
 gm11.R = R;
 gm11.C = C;
 gm11.P = P;
 
    
end
X = [174,179,183,189,207,234,220.5,256,270,285,300,320,344,365];
gm11 = GM11_model(X,5)
%%未来预测值
prd  = gm11.Predict_Value(end-5+1:end)


%{
    
    
gm11 = 

  包含以下字段的 struct:

              Coeff_a: -0.0621
              Coeff_u: 156.7876
        Predict_Value: [1×19 double]
        AbsoluteError: [0 6.1049 0.9646 6.7429 1.2753 12.3899 15.2986 5.1045 3.0410 0.9490 2.2373 1.5880 1.8225 0.9147]
    RelativeErrorMean: 0.0185
                    R: 0.7182
                    C: NaN
                    P: 1


        根据模型评价标准
        p=1,C=0.0724,预测等级为:好;
        相对误差均值0.085,合格
        关联度0.7182,勉强合格
        由于-a系数小于0.3,适合中长期预测。
        从运行结果看,对于线性的数据使用GM(11)预测,其拟合效果还是不错。


%%未来预测值        
prd =
  387.3958  412.1987  438.5896  466.6702  496.5486
%}

Guess you like

Origin blog.csdn.net/weixin_43599390/article/details/131358339