Turn: Covariance Matrix

Source: Internet
Author: User

Source: http://blog.csdn.net/ybdesire/article/details/6270328

Definition of Covariance

 

For a general distribution, it can be calculated by directly inserting it into E (X) and so on. However, to calculate a specific value distribution, we need to calculate the covariance matrix based on this formula, it is not easy to respond. There are not many useful materials on the Internet. Here is an example to illustrate how the covariance matrix is calculated.

Remember, X and Y are column vectors that represent the number of possible occurrences of each sample in each case. For example

Then, X indicates the number that may appear on the X axis, and y indicates that the Y axis may appear. Note that this is the key. Given four samples, each of which is two-dimensional, there may be only two dimensions, X and Y. So

 

 

It is described in Chinese as follows:

Covariance (I, j) = (all elements in column I-mean of column I) * (all elements in column J-mean of column J)

Here there are only two columns of X and Y, so the covariance matrix obtained is a 2x2 matrix, and each element is obtained below:

Therefore, according to the definition, the covariance matrix of the given four two-dimensional samples is:

 

Use MATLAB to calculate this example

Z = [1, 2; 3, 6; 4, 2; 5, 2]

Cov (z)

Ans =

2.9167-0.3333

-0.3333 4.0000

It can be seen that the elements are reduced by three times in the covariance calculation process of Matlab. Therefore, the covariance MATLABCalculation FormulaIs:

Covariance (I, j) = (all elements in column I-mean of column I) * (all elements in column J-mean of column J)/(number of samples-1)

The following is an example of a 4-dimensional and 3-dimensional sample. Note that the 4-dimensional sample has nothing to do with the symbol X and Y. x and y represent two-dimensional samples, the 4-dimensional formula is applied directly without the confusing expression of X and Y.

 

 

 

(3) Verification with MATLAB

Z = [1 2 3 4; 3 4 1 2; 2 3 1 4]

Cov (z)

Ans =

1.0000 1.0000-1.0000-1.0000

1.0000 1.0000-1.0000-1.0000

-1.0000-1.0000 1.3333 0.6667

-1.0000-1.0000 0.6667 1.3333

The calculation method is correct. We can also see that the covariance matrix is a matrix, and its dimensions are related to the sample dimension (equal ). The source code for calculating the covariance matrix is also provided in Reference 2, which is very concise and easy to understand. Thank you!

 

Refer:

[1] http://en.wikipedia.org/wiki/Covariance_matrix

[2] http://www.cnblogs.com/cvlabs/archive/2010/05/08/1730319.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.