Mathematical Modeling: Predictive Model Learning - Gray Predictive Model (GM(1,1) Model)

Table of contents

foreword

1. Model realization

1. Process introduction

2. Gray generation

1. Accumulation generation operator

 2. Mean generating operator

3. Feasibility analysis (gradation test)

4. Establish GM(1,1) model

1. Data preprocessing:

 2. Build a model:

3. Construct data matrix B and data vector Y:

5. Accuracy inspection

2. Case Analysis

Summarize


foreword

Briefly introduce the gray forecasting model, and use matlab to analyze specific cases, and will continue to add later


1. Model realization

1. Process introduction

  • Gray generates new operators
  • Feasibility Analysis
  • Build a GM(1,1) model
  • precision test

2. Gray generation

To put it simply, the purpose of the gray generation new operator is to weaken the randomness of the disordered sequence and transform it into an ordered sequence to show the rules and analyze it. The common generation operators are as follows:

  • 1. Accumulative Generation Operator (AGO)
  • 2. Inverse accumulative generation operator (IAGO)
  • 3. Mean generation operator (MEAN)
  • 4. Scale generation operator

1. Accumulation generation operator

The line graph of the new sequence and the old sequence is as follows. It can be seen that the new sequence converts the original irregular sequence into a clearly regular and increasing sequence:

 

 2. Mean generating operator

That is, calculate the average value of the adjacent two items of the cumulative generating operator , taking the above example as an example:

X^{(1)} =\left \{ 6,9,17,27,34 \right \}

Z^{(1)}(k)=1/2\left [ X^{(1)}(k-1)+X^{(1)}(k) \right ] \, \, \, \, \, \, k=2,3...

Z^{(1)}=\left \{ 7.5,13,22,30.5 \right \}

3. Feasibility analysis (gradation test)

First calculate the ratio of each item of the original sequence , that is, the ratio, taking the above example as an example:

X^{(0)} =\left \{ 6,3,8,10,7 \right \}

Calculated X^{(0)}grade ratio:     \sigma (k)=X^{(0)}(k-1)/X^{(0)}(k)\, \,\: \: \, k=2,3...

If the grade ratio is satisfied:

 Then the new operatorX^{(1)} may Z^{(1)}establish a GM(1,1) model

ps: There is a condition that X^{(0)}it must be non- negative. If there is a negative number item, X^{(0)}add a positive number a after it so that X^{(0)} theX^{(1)} and or Z^{(1)}are both non-negative before performing subsequent operations.       

4. Establish GM(1,1) model

1. Data preprocessing:

Assume first that the original sequence X^{(0)}=\left \{ X^{(0)}(1),X^{(0)}(2),X^{(0)}(3),...,X^{(0)}(n) \right \}passes the grade test,

Take the mean generating operator as an example:Z^{(1)}(k)=1/2\left [ X^{(1)}(k-1)+X^{(1)}(k) \right ] \, \, \, \, \, \, k=2,3...

New order: Z^{(1)}=\left \{ Z^{(1)}(1),Z^{(1)}(2),Z^{(1)}(3),...,Z^{(1)}(n) \right \}

ps: Similarly, if the grade ratio test fails, a positive number aX^{(0)} can also be added after it , so that all grade ratios are within the allowable range.

 2. Build a model:

1. Original form: X^{(0)}(k)+aZ^{(1)}(k)=b    , purpose: find out a, b

2. Estimate a, b by regression analysis, the corresponding whitening differential equation and its solution are:

 From this we get the predicted value:

 Original sequence prediction value:

3. Construct data matrix B and data vector Y:

B = \begin{bmatrix} -Z^{(1)}(2)& 1\\ -Z^{(1)}(3)& 1\\ .& .\\ .& .\\ -Z^{(1)}(n)& 1 \end{bmatrix}=\begin{bmatrix} -\frac{1}{2}(X^{(1)}(1)+X^{(1)}(2)) & 1\\ -\frac{1}{2}(X^{(1)}(2)+X^{(1)}(3)) & 1\\ .& .\\ . & .\\ -\frac{1}{2}(X^{(1)}(n-1)+X^{(1)}(n)) &1 \end{bmatrix}                    Y = \begin{bmatrix} X^{(0)}(2)\\ X^{(0)}(3)\\ .\\ .\\ X^{(0)}(n) \end{bmatrix}

So  u = \begin{bmatrix} a\\ b \end{bmatrix}  , solving the above differential equation, we get u = (B^{T}\cdot B)^{-1}B^{T}Y

Calculate a, b and substitute the above predicted value to fit a predicted value function

5. Accuracy inspection

Residual test:

If the absolute value of all residuals is less than 0.1, it is considered to meet the higher requirements; if it is less than 0.2, it meets the general requirements;

Scale deviation test:

 If the absolute value of all grade ratio deviations is less than 0.1, it is considered to meet the higher requirements; if it is less than 0.2, it meets the general requirements;

2. Case Analysis

Predict the number of permanent residents in the next n years based on the number of permanent residents in Fujian Province in the past ten years

2010--2020 data: [3693,3784,3841,3885,3945,3984,4016,4065,4104,4137,4161] million people

1. Grade ratio test: 

        Meet the grade ratio test interval: (0.8574, 1.1663)

The grade ratio calculated by matlab is:

Passed the grade test

code:

%级比检验通过
check = [];
for k = 2:n
    lambda(k) = data(k-1)/data(k);
    if (exp(-2/(n+1))<lambda(k))&&(lambda(k)<exp(2/(n+1)))
        check(end+1) = 1;  %通过则输出1
    else check(end+1) = 0;  %不通过则输出0
    end
end 

2. Generate operator:

 Cumulative generation operator:

Mean generating operator:

code:

%累加生成算子
X1 = cumsum(data);
for i=2:n
    z(i) = 0.5*(X1(i-1)+X1(i));
end

3. Find the data matrix B and data vector Y

B:                                                                                               Y:

                                                      

code:

%数据矩阵B及数据向量Y
Y = data(2:n)';
B = [-z(2:n)',ones(n-1,1)];
u = (B'*B)\B'*Y;
a = u(1,1);
b = u(2,1);

4. Generate predictions \hat{X}^{(1)}and\hat{X}^{(0)}

\hat{X}^{(1)}: 

 \hat{X}^{(0)}

code:

%预测值
f_X1 = [];
f_X0 = [];
for k=1:n-1
    f_X1(1)=data(1);
    f_X1(k+1) = (data(1)-b/a)*exp(-a*k) + b/a;
end
for k=2:n
    f_X0(1)=data(1);
    f_X0(k)=f_X1(k)-f_X1(k-1);
end

5. Residual error test and scale deviation test:

Residual test:

  Scale deviation test: 

Both are less than 0.1, which proves that the model has high accuracy and can be used for prediction

 code:

%残差检验&级比偏差值检验
for k=1:n-1
    sigma(k)=abs((data(k)-f_f_X0(k))/data(k));
    rho(k+1)=abs(1-((1-0.5*a)*lambda(k+1))/(1+0.5*a));
end

 6. The complete code is as follows, you need to predict how much you can input by yourself:

%10至20年数据,21年数据为4219
data = [3693,3784,3841,3885,3945,3984,4016,4065,4104,4137,4161];
n = length(data);

%级比检验通过
check = [];
for k = 2:n
    lambda(k) = data(k-1)/data(k);
    if (exp(-2/(n+1))<lambda(k))&&(lambda(k)<exp(2/(n+1)))
        check(end+1) = 1;
    else check(end+1) = 0;
    end
end 

%累加生成算子
X1 = cumsum(data);
for i=2:n
    z(i) = 0.5*(X1(i-1)+X1(i));
end

%数据矩阵B及数据向量Y
Y = data(2:n)';
B = [-z(2:n)',ones(n-1,1)];
u = (B'*B)\B'*Y;
a = u(1,1);
b = u(2,1);

%预测值
f_X1 = [];
f_X0 = [];
for k=1:n-1
    f_X1(1)=data(1);
    f_X1(k+1) = (data(1)-b/a)*exp(-a*k) + b/a;
end
for k=2:n
    f_X0(1)=data(1);
    f_X0(k)=f_X1(k)-f_X1(k-1);
end

%残差检验&级比偏差值检验
for k=1:n-1
    sigma(k)=abs((data(k)-f_f_X0(k))/data(k));
    rho(k+1)=abs(1-((1-0.5*a)*lambda(k+1))/(1+0.5*a));
end

%预测下n个值
test = input('nums:');
n=n+test;
f_f_X1 = [];
f_f_X0 = [];
for k=1:n-1
    f_f_X1(1)=data(1);
    f_f_X1(k+1) = (data(1)-b/a)*exp(-a*k) + b/a;
end
for k=2:n
    f_f_X0(1)=data(1);
    f_f_X0(k)=f_f_X1(k)-f_f_X1(k-1);
end

 As a result, the 21-year resident population is 42.28 million, which is close to the real data of 4219.

3. Analysis and summary

 

Guess you like

Origin blog.csdn.net/weixin_67565775/article/details/126761016