hotteling transformation does not give desired result

43 views Asked by At

i wanted to apply HOTELLING TRANSFORMATION to the give vectors and to make practice my self, that why i have wrote following code in 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);

then i have tested it to the given matrix

A

A =

     4     6    10
     3    10    13
    -2    -6    -8

and after running code

[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

definitely this is not diagonal matrix, so what is wrong? thanks in advance

1

There are 1 answers

1
flawr On BEST ANSWER

As you're dealing with row vectors instead of column vectors you need to adjust for it in the eigenvalue/eigenvector-decomposiiton. Instead of Y=A1*centered you need Y=centered*V. Then you'll get

covariance_matrix =

    0.0000   -0.0000    0.0000
   -0.0000    1.5644   -0.0000
    0.0000   -0.0000  207.1022

So you'll get two nonzero components which is what you could expect from only three points in the 3D-space. (They can only form a plane, but not a volume.)