使用matlab进行降维

clc;
for i=1:168
    X(i,1:20)=totalPDSdat(i,5:24);
    
    labels(i,1)=0;
end

for i=169:386
    X(i,1:20)=totalNPdata(i-168,5:24);
    labels(i,1)=1;
end

item=10;  %迭代次数
sigma=1; %高斯函数方差

filename = ['-sigma-' num2str(sigma) '--' num2str(item) '.gif']; %必须预先建立gif文件  
 
% 估计本质维数,即最终降到的维数
no_dims = round(intrinsic_dim(X, 'MLE'));
disp(['MLE estimate of intrinsic dimensionality: ' num2str(no_dims)]);


for i = 1:item 
    [mappedX, mapping] = compute_mapping(X, 'Laplacian', no_dims,12,i);
    tname  = ['-sigma-' num2str(sigma) 'Result of Laplacian Eigenmaps'];  
    figure(i),
    scatter3(mappedX(:,1), mappedX(:,2), mappedX(:,3),5, labels(mapping.conn_comp),'filled');
    if isequal(labels(mapping.conn_comp),labels)
           sprintf('%s','sucess')
    else sprintf('%s','error')
   end

    title(tname);
    sigma=sigma+1;
    
    % 自动保存为gif图像  
    frame = getframe(i);  
    im = frame2im(frame);  
    [I,map] = rgb2ind(im,256);  
    if i==1  
        imwrite(I,map,filename,'gif','Loopcount',inf, 'DelayTime',0.8);  
    else  
        imwrite(I,map,filename,'gif','WriteMode','append','DelayTime',0.8);  
    end  
    
end

% Isomap降维
[mappedX, mapping] = compute_mapping(X, 'Isomap', no_dims);
if isequal(labels(mapping.conn_comp),labels)
        sprintf('%s','sucess')
else sprintf('%s','error')
end

figure
scatter3(mappedX(:,1), mappedX(:,2), mappedX(:,3),5, labels(mapping.conn_comp),'filled')
title('Result of Isomap')
drawnow

使用matlab进行降维_第1张图片

你可能感兴趣的:(matlab,降维,Matlab)