我想将hotelling转换应用于给予矢量并使自己练习自我,这就是为什么我在matlab中写下了遵循代码
function [Y covariance_matrix]=hotteling_trasform(X)
% this function take X1,X2,X3,,Xn as a matrix and apply hottleing
%transformation to get new set of vectors y1, y2,..ym so that covariance
%matrix of matrix consiist by yi vectors are almost diagonal
%% determine size of given matrix
[m n]=size(X);
%% compute mean of columns of given matrix
means=mean(X);
%% substract mean from given matrix
centered=X-repmat(means,m,1);
%% calculate covariance matrix
covariance=(centered'*centered)/(m-1);
%% Apply eigenvector decomposition
[V,D]=eig(covariance);
%% determine dimension of V
[m1 n1]=size(V);
%% arrange matrix so that eigenvectors are as rows,create matrix with size n1 m1
A1=zeros(n1,m1);
for ii=1:n1
A1(ii,:)=V(:,ii);
end
%% applying hoteling transformation
Y=A1*centered; %% because centered matrix is original -means
%% calculate covariance matrix
covariance_matrix=cov(Y);
然后我对给定的矩阵进行了测试
A
A =
4 6 10
3 10 13
-2 -6 -8
运行代码
之后[Y covariance_matrix]=hotteling_trasform(A);
covariance_matrix
covariance_matrix =
8.9281 22.6780 31.6061
22.6780 66.5189 89.1969
31.6061 89.1969 120.8030
肯定这不是对角线矩阵,那怎么了?预先感谢
当您处理行矢量而不是 column 向量时,您需要在eigenvalue/eigenvalue/eigenvector-decomposiiton中对其进行调整。而不是Y=A1*centered
,您需要Y=centered*V
。那你会得到
covariance_matrix =
0.0000 -0.0000 0.0000
-0.0000 1.5644 -0.0000
0.0000 -0.0000 207.1022
因此,您将获得两个非零组件,这就是3D空间中仅三个点所能期望的。(它们只能形成平面,但不能形成音量。)