我想将HOTELLING TRANSFORMATION应用于给定向量并使我的自我练习,这就是为什么我在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
绝对不是对角矩阵,所以有什么不对?提前谢谢
答案 0 :(得分:1)
当您处理行向量而不是列向量时,您需要在特征值/特征向量分解中对其进行调整。而不是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空间中仅有三个点所期望的。 (它们只能形成一个平面,但不能形成一个体积。)