I have a Do While Loop error while doing a statistical calculation, how can I fix this?
Afficher commentaires plus anciens
So I'm trying to do a principle component analysis using the NIPALS algorithim. I have been writing my own version in Matlab, and I got it to run but I'm not sure it's working properly. I tested it on a small 6x6 matrix "A" but I would just get back weird values in the T score plot like 1's and 0's, but sometimes I got a 1.4? I was wondering if I did anything wrong, or if this is okay.
function[T, P]=nipals()
A = [8 8 6 7 6 5; 8 8 3 4 3 2]; %Normalize Original Matrix X=zscore(A); T=zeros(6,3); %observations P=zeros(6,3); %variables tolerance=1e-6
%Finding 3 T Scores and Principal Components for k = 1:3
%Extract First T Score, first column from X
T=X(:,1);
check = false;
i=0;
while(~check)
i=i+1;
%Calculate P Vector
P=(X'*T)/(T'*T);
%Normalizing the P Vector
P=P/norm(P);
%Calculating New T Score
Tnew=(X*P)/(P'*P);
difference=(Tnew-T)'*(Tnew-T);
T=Tnew;
if difference <= tolerance^2
check = true;
end
end
T(:,k) = Tnew;
P(:,k) = P;
end
Réponses (0)
Catégories
En savoir plus sur Gaussian Mixture Models dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!