“This is the 11th day of my participation in the First Challenge 2022. For details: First Challenge 2022”

preface

This piece blog is just a note blog, slightly improper place must be corrected! Hope every big guy not stingy give advice!

Grey prediction

There is no more history of what grey forecasting is. We’re more interested in what this thing can do, what kinds of predictions it fits into, and what are the principles involved? What problems can the corresponding grey prediction solve? · Grey prediction is to predict the system containing both known information and uncertain information, which is to predict the time-related grey process that changes within a certain range.

Comparison of grey correlation degree

This was actually a bit similar to our analytic hierarchy process (ahp), they all can carry on the appraisal of a certain event, the comparison, but the difference is that the weight of use of the analytic hierarchy process (ahp) that we need to develop related, the need for consistency check, in other words, in this respect, if we use the analytic hierarchy process (ahp), then will have certain subjectivity, objectivity and the lack of the corresponding, Although we may be able to pass the consistency test, there seems to be a lack of conviction overall. So in the gray comparison, it’s more like we’ve provided a perfect sample, how similar is the sample that we have here? The closer it is, the closer the current sample is to perfection, so we can use this to realize the comparison between samples. For example, we evaluate the best employees and teachers through this method. If we use hierarchical analysis, we need to consider the weight of each skill, which will inevitably lead to different opinions and even find that the consistency test fails in the modeling process. So let’s take a look at a concrete example of how to use it. Now we need to evaluate the performance of a group of teachers.

Grey correlation degree case

Now we need to evaluate which teacher is the best.1. So the first step is to find a set of reference vectors, which are equivalent to model samples. Let’s say {9, 9, 9, 9, 9, 9, 9, 9}, because this is 9 at the top, and no one is satisfied with writing 10. Let’s remember that this set of vectors is X0={9, 9, 9, 9, 9, 9} 2. We subtract each group from the standard group and take the absolute value. 3. We find the smallest and the largest. 4. We use the formula to calculate the correlation. It doesn’t matter how it comes from, we don’t care at the moment, we just care how to use it Where P is the number between 0 and 1 and we can do that when we do the first group.And then we have a sequence that looks like this.And then we can average each teacher’s ratingSo at this point we have the order of each person, and then we can compare. Compared with analytic hierarchy process, this method is more clear and simple.

Grey forecasting model

First of all, gray prediction is more suitable for small sample prediction, that is, when the data given is not very much. In addition, gray prediction is actually a positive prediction along the time line, such as the prediction of rainfall in previous years, the most typical example is next year’s rainfall. And the old one about SARS. Then the main core of gray prediction is to process the data. The seemingly irregular data is processed through the process of accumulation and subtraction, weighted accumulation, and then the predicted data is obtained through integration. Usually, several data are predicted, and fitting may be used no matter how complicated it is.

cumulative

You just add up the first N numbers to get a new sequence. For example, after processing 1, 2, 3, 4, 5:1, 3, 6, 10, 15 Let’s write the initial sequence as:

After treatment:Let’s call it r timesSo it looks like this on the graph

b-b

So that’s even easier, that’s the latter term minus the former term. For example, 1 2 3 4 5 after processing: 0 1 1 1 1 1

Weighted neighborhood generation

That’s adding two adjacent pieces of data to scale. Original sequence:After processing, that alpha is between 0 and 1

Grey model GM(1,1)

This is what we use to wear the front thing for prediction.

Model is derived

Again, this is based on the previous example. Let’s assume the original sequence is:It’s going to be the sumAnd what we’re going to do is we’re going to get something in the original sequence, which is:D of k, we call it the grey derivative, because this is discontinuous, so all we’re going to do is actually make it differentiable. And then neighborhood weightsFinally, we introduce the model GM(1,1)or

And we can see that this is similar to least squares, but we can also do it with matrices.Introducing linear algebraWe can solve for a and b and then we plug into the equationAnd then we take the derivativeAnd then we end up with this thingThis is the solution that we constructed, and we’re going to go back to the original sequence.At this point our data is done. But we still need to check it, and we can’t trust it if it doesn’t pass.Calculated relative difference Absolute value less than 0.1 or 0.2 is betterStage difference test It’s also 0.1 or 0.2 and this green part is the grade ratioThe ratio of the latter term to the former term is also conditional. Must be inBetween otherwise can not gray prediction. If it’s predictable then the next oneStage difference test Calculated relative differenceOne of the two can be satisfied.

Grey prediction example

The title

Noise prediction, data are as follows:

year Noise rating
1986 71.4
1987 72.4
1988 72.4
1989 72.1
1990 71.4
1991 72.0
1992 71.6

The problem solving

Level than detection

Let’s construct the original sequence

Inspection by

Incremental processing

Is to get

Plug it in to solve for a, b

getgetGo back toThe predicted value of the calculation

Error operation

So let’s do that getSatisfy one of them can be used

code

The front BB so much the most important or code, hand is impossible this life is impossible.

Associated with the code


x1=[
    
    8 9 8 7 5 2 9;
    7 8 7 5 7 3 8;
    9 7 9 6 6 4 7;
    6 8 8 8 4 3 6;
    8 6 6 9 8 3 8;
    8 9 5 7 6 4 8;
]   % The sequence to compare
x=x1;
[r,c]=size(x1);

biaozhun = [9 9 9 9 9 9 9] % Standard sequence
for i=1:r
    for j=1:c
  x(i.j) =abs(biaozhun(j)-x(i.j))
 end
end
max=x(1.1)
min=x(1.1)
for i=1:r
    for j=1:c
 if x(i.j) > =max
     max=x(i.j)
 end
  end
end
for i=1:r
    for j=1:c
 if x(i.j) < =min
     min=x(i.j)
  end
  end
end
k=0.5 % Resolution coefficient value
l=(min+k*max)./(x+k*max)Find the correlation coefficient matrix
guanliandu=sum(l')/c
[rs,rind]=sort(guanliandu,'descend') % to sort the correlation degree
Copy the code

Compare the table above, the data is correct. Just change it when you need it.

Prediction code

y=input('Please enter data');
n=length(y);

jibi1=exp(1) ^ (2 -/(n+1));
jibi2=exp(1) ^ (2/(n+1));
for i=2:n
    jibi = y(n)/y(n- 1);
    if jibi>jibi1 && jibi<jibi2
        disp("Grade ratio passed")
       
    else
        disp("Grade ratio failed.")

    end
end  

yy=ones(n,1);
yy(1)=y(1);
for i=2:n
    yy(i)=yy(i- 1)+y(i)
end
B=ones(n- 1.2);
for i=1:(n- 1)
    B(i.1)=-(yy(i)+yy(i+1)) /2;
    B(i.2) =1;
end
BT=B';
for j=1:(n- 1)
    YN(j)=y(j+1);
end
YN=YN';
A=inv(BT*B)*BT*YN;
a=A(1);
u=A(2);
t=u/a;
t_test=input('Enter the number of predictions');
i=1:t_test+n;
yys(i+1)=(y(1)-t).*exp(-a.*i)+t;
yys(1)=y(1);
for j=n+t_test:- 1:2
    ys(j)=yys(j)-yys(j- 1);
end
x=1:n;
xs=2:n+t_test;
yn=ys(2:n+t_test);
plot(x,y,'-r',xs,yn,'*b');
det=0;
yuce = [];
yunce(1)=y(1);
yunce(2:n+t_test)=yn;
yunce
for i=2:n
    det=det+abs(yn(i)-y(i));
end
det=det/(n- 1);
disp([The absolute error is:,num2str(det),The '%']);
disp(['Predicted value is:',num2str(ys(n+1:n+t_test))]);

    
Copy the code

Here the main input is [](I have a problem with the Chinese code)

conclusion

By understanding this, we can know that grey prediction can be compared in relevance, that is to say, it can solve the work of analytic hierarchy process to some extent. In terms of data prediction, it is suitable for small-scale prediction, such as air water quality prediction, national population prediction, novel Coronavirus infection prediction. Of course, if the data is accurate and other factors are ignored.