当前位置:网站首页>[untitled] forwarding least square method
[untitled] forwarding least square method
2022-07-04 08:47:00 【Ruoshui】
Recently, a project of the company needs to be calculated TVDI(Temperature Vegetation Dryness Index , Temperature Vegetation Drought Index ) ,TVDI The calculation formula of is as follows ( The specific principle is self-contained ):
among , Is the surface temperature of any pixel ;
For a NDVI Corresponding minimum surface temperature , Corresponding to wet edge
;
For a NDVI Corresponding maximum surface temperature , Corresponding to the dry side
;a,b Wet edged fitting Equation coefficient ,c,d Is the fitting equation coefficient of the dry edge .
In the process of fitting dry and wet edges , It is necessary to use the least square method to effectively NDVI and Lst Data for linear fitting . therefore , This paper is used in work C++ The least square fitting line realized , The key is to understand the basic principle of least square fitting line , It's easy to implement . The specific least square principle will not be elaborated too much , There are a lot of introduction materials on the Internet , Here we only give the shape as Linear regression calculation of a,b Coefficient and r^2 The final calculation formula of , The relevant code is as follows :
[cpp] view plain copy
- /*************************************************************************
- The least square method is used to fit the straight line ,y = a*x + b; n Group data ; r- The correlation coefficient [-1,1],fabs(r)->1, explain x,y The linear relationship between them is good ,fabs(r)->0,x,y There is no linear relationship between , Fitting is meaningless
- a = (n*C - B*D) / (n*A - B*B)
- b = (A*D - B*C) / (n*A - B*B)
- r = E / F
- among :
- A = sum(Xi * Xi)
- B = sum(Xi)
- C = sum(Xi * Yi)
- D = sum(Yi)
- E = sum((Xi - Xmean)*(Yi - Ymean))
- F = sqrt(sum((Xi - Xmean)*(Xi - Xmean))) * sqrt(sum((Yi - Ymean)*(Yi - Ymean)))
- **************************************************************************/
- void LineFitLeastSquares(float *data_x, float *data_y, int data_n, vector<float> &vResult)
- {
- float A = 0.0;
- float B = 0.0;
- float C = 0.0;
- float D = 0.0;
- float E = 0.0;
- float F = 0.0;
- for (int i=0; i<data_n; i++)
- {
- A += data_x[i] * data_x[i];
- B += data_x[i];
- C += data_x[i] * data_y[i];
- D += data_y[i];
- }
- // Calculate slope a And intercept b
- float a, b, temp = 0;
- if( temp = (data_n*A - B*B) )// Judge whether the denominator is 0
- {
- a = (data_n*C - B*D) / temp;
- b = (A*D - B*C) / temp;
- }
- else
- {
- a = 1;
- b = 0;
- }
- // Calculate the correlation coefficient r
- float Xmean, Ymean;
- Xmean = B / data_n;
- Ymean = D / data_n;
- float tempSumXX = 0.0, tempSumYY = 0.0;
- for (int i=0; i<data_n; i++)
- {
- tempSumXX += (data_x[i] - Xmean) * (data_x[i] - Xmean);
- tempSumYY += (data_y[i] - Ymean) * (data_y[i] - Ymean);
- E += (data_x[i] - Xmean) * (data_y[i] - Ymean);
- }
- F = sqrt(tempSumXX) * sqrt(tempSumYY);
- float r;
- r = E / F;
- vResult.push_back(a);
- vResult.push_back(b);
- vResult.push_back(r*r);
- }
In order to verify the effectiveness of the algorithm , Give the following test data , The data source is the experimental data of a paper :
[cpp] view plain copy
- float pY[25] = { 10.98, 11.13, 12.51, 8.40, 9.27,
- 8.73, 6.36, 8.50, 7.82, 9.14,
- 8.24, 12.19, 11.88, 9.57, 10.94,
- 9.58, 10.09, 8.11, 6.83, 8.88,
- 7.68, 8.47, 8.86, 10.38, 11.08 };
- float pX[25] = { 35.3, 29.7, 30.8, 58.8, 61.4,
- 71.3, 74.4, 76.6, 70.7, 57.5,
- 46.4, 28.9, 28.1, 39.1, 46.8,
- 48.5, 59.3, 70.0, 70.0, 74.5,
- 72.1, 58.1, 44.6, 33.4, 28.6 };
The data is in Excel The fitting result of is , among
.
Reprinted address http://blog.csdn.net/pl20140910/article/details/51926886
In engineering practice , We often encounter similar problems :
We did n Experiments , Got a set of data
then , We want to know x and y The functional relationship between . So we describe it in XOY In rectangular coordinates , Get the following point cloud :

then , We found that ,x and y「 Probably 」 It's a linear relationship , Because we can roughly connect all the sample points with a straight line , Here's the picture :

therefore , We can 「 guess 」. The next question , Is to find out a and b Value .
This seems to be a very simple problem ,a and b Are two unknowns , We just need to find two sample points randomly , List the equations :
Two unknowns , Two equations , I can solve for that a and b Value .
However , It's wrong here , Or inaccurate . Why? ? because This functional relationship , It is our 「 guess 」 Of , It is not necessarily objective and correct ( Although it may be right ). So we can't solve such a simple and rough set of equations .
Then what shall I do? ? Since it is 「 guess 」 Of , Then there is an error . Then we will slightly revise this functional relationship to :
here , They are the first i The dependent variable of the experiment 、 The independent variables 、 error .
Since it is 「 guess 」, Then of course we hope to guess more accurately . How to measure accurately ? Nature and e It matters .
After the above formula is modified, you can get :
ad locum ,a and b Is the independent variable ,e Is the function value .
This is the easiest place to get confused , Why? a,b It's an independent variable , instead of x,y?
This is to mention 「 Curve fitting 」 The concept of . So-called 「 fitting 」 That is, we need to find a function , Come on 「 matching 」 The sample value we obtained in the experiment . Put it in the example above , We need to adjust a and b Value , To make this function and the data obtained in the experiment more 「 matching 」. therefore ,a and b It's just 「 Curve fitting 」 Arguments in the process .
Next , Continue the problem of how to make the error smaller .
「 Least square method 」 The ideological core of , Is to define a loss function :
obviously , If we adjust a and b, bring Q To achieve the minimum , that 「 Curve fitting 」 The error will also be minimal .
here ,Q yes a,b Function of . According to higher mathematics, only ,Q The minimum point of its derivative must be 0 The point of .
therefore , We make :
After solving the above equations, we get about a,b A system of binary quadratic equations , Therefore, we can solve a and b Value . This is the whole process of the least square method .
The last show :
(1) English name of least square method Least Squares, Actually translated into 「 The least square method 」, It's easier to understand . Its core is to define the loss function ;
(2) There is more than one method to evaluate errors , And things like etc. ( Of course, this is not the least square method );
(3) The least square method can not only be used for fitting primary functions , It can also be used for fitting higher-order functions ;
(4) The least square method is both a method of curve fitting , It can also be used for optimization .
边栏推荐
- awk从入土到入门(10)awk内置函数
- Developers really review CSDN question and answer function, and there are many improvements~
- snipaste 方便的截图软件,可以复制在屏幕上
- Mouse over to change the transparency of web page image
- SSRF vulnerability exploitation - attack redis
- Show server status on Web page (on or off) - PHP
- A method for detecting outliers of data
- 转:优秀的管理者,关注的不是错误,而是优势
- PHP converts seconds to timestamps - PHP
- 没有Kubernetes怎么玩Dapr?
猜你喜欢

ctfshow web255 web 256 web257

MySQL relearn 1-centos install mysql5.7

Sequence model

AcWing 244. Enigmatic cow (tree array + binary search)

The basic syntax of mermaid in typera

Four essential material websites for we media people to help you easily create popular models
![Private collection project practice sharing [Yugong series] February 2022 U3D full stack class 007 - production and setting skybox resources](/img/f9/6c97697896cd1bd0f1d62542959f29.jpg)
Private collection project practice sharing [Yugong series] February 2022 U3D full stack class 007 - production and setting skybox resources

Ehrlich sieve + Euler sieve + interval sieve

Codeforces Round #750 (Div. 2)(A,B,C,D,F1)

ctfshow web255 web 256 web257
随机推荐
Webapi interview question summary 01
How to play dapr without kubernetes?
How to play dapr without kubernetes?
地平线 旭日X3 PI (一)首次开机细节
What should I do if there is a problem with the graphics card screen on the computer
How can we make a monthly income of more than 10000? We media people with low income come and have a look
How college students choose suitable computers
Industry depression has the advantages of industry depression
Flutter integrated amap_ flutter_ location
Educational Codeforces Round 119 (Rated for Div. 2)
[attack and defense world | WP] cat
go-zero微服务实战系列(九、极致优化秒杀性能)
awk从入门到入土(12)awk也可以写脚本,替代shell
User login function: simple but difficult
Comprendre la méthode de détection des valeurs aberrantes des données
awk从入门到入土(4)用户自定义变量
[CV] Wu Enda machine learning course notes | Chapter 9
Leetcode topic [array] -136- numbers that appear only once
[untitled] 2022 polymerization process analysis and polymerization process simulation examination
根据数字显示中文汉字