Preface
This section is mainly to practice the use of PCA,PCA whitening and Zca whitening on 2D data, 2D data set is 45 data points, each data point is 2 dimensions.
Some MATLAB functions
Color Scatter point graph function: Scatter (x,y,c,s) x, y is two vectors for locating data points, S is the size of the plot point, C is the color used for the drawing, S and C can be given as vectors or expressions, s and C are marked as vectors of the same length as x or Y. Inch and color will change according to the linear law. You can also add the fifth parameter ' filled ' after the first 4 parameters of the scatter function, which means filling the drawing point. The biggest difference between scatter and plot is that scatter can draw a point graph with variable size and color.
Example: Given data t=0:pi/10:2*pi, Y=sin (t), observe the drawing results of the function at different input parameters.
T=0:pi/10:2*pi; Y=sin (t)
Subplot (3,2,1); Scatter (t,y)
Subplot (3,2,2); Scatter (t,y, ' V ')
Subplot (3,2,3); Scatter (T,y, (ABS (y) +2). ^4, ' filled ')
Subplot (3,2,4); Scatter (t,y,30,[0:2: +], ' V ', ' filled ')
Subplot (3,2,5); Scatter (T,y, (t+1). ^3,y, ' filled ')
diag function : extracting and creating diagonal matrices of diagonal elements
Set the following x as the square and V as the vector
1, X = Diag (v,k) when V is a vector containing n elements, the return of a n+abs (k) square matrix X, vector v in Matrix X on the K-Diagonal, k=0 represents the main diagonal, k>0 is represented above the main diagonal,k< 0 means below the main diagonal. Example 1:
V=[1 2 3];
Diag (V, 3)
Ans =
0 0 0 1 0 0
0 0 0 0 2 0
0 0 0 0 0 3
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
Note: Data is generated diagonally from the third position above the main diagonal matrix.
Example 2:
V=[1 2 3];
Diag (V,-1)
Ans =
0 0 0 0
1 0 0 0
0 2 0 0
0 0 3 0
Note: Data is generated diagonally from the first position below the main diagonal matrix.
2, X = Diag (v)
The vector v is on the main diagonal of the square X, similar to the Diag (v,k), k=0 case.
Example 3:
V=[1 2 3];
Diag (v)
Ans =
1 0 0
0 2 0
0 0 3
Note: Written in the form of a diagonal matrix
3. v = diag (x,k)
Returns the column vector v,v formed by the elements on the K-diagonal of the matrix X
Example 4:
V=[1 0 3;2 3 1;4 5 3];
Diag (v,1)
Ans =
0
1
Note: The first data above the main diagonal is taken as the starting data, and is sorted in diagonal order as a column vector form
4, V = diag (x) returns the element on the main diagonal of matrix X, similar to Diag (X,K), Case 5 of K=0:
V=[1 0 0;0 3 0;0 0 3];
Diag (v)
Ans =
1
3
3
or instead:
V=[1 0 3;2 3 1;4 5 3];
Diag (v)
Ans =
1
3
3
Note: The data of the main diagonal is taken out as a column vector form
5,diag (diag (X))
Take the diagonal element of the X-matrix and construct a diagonal matrix with the diagonal of the X-diagonal element.
Example 6:
X=[1 2;3 4]
Diag (Diag (X))
X =
1 2
3 4
Ans =
1 0
0 4
Deep Learning III: PCA in 2d_exercise (Stanford University UFLDL in depth learning tutorial)