function [out, aux] = mreduce( type, data )

aux=[];
supptypenames={
    'PCA'
    'CMS'
    'NCMS'
    'FA'
    'LLE'
    'LEM'
    'tSNE'
};

switch (type)
    case 'PCA'
        [aux, out] = princomp(data);
    case 'CMS'
        D=pdist(data,'euclidean');
        out=cmdscale(D);
    case 'NCMS'
        D=pdist(zscore(data),'seuclidean');
%        out=mdscale(D,8,'criterion','stress', 'Replicates',10, 'Start','random'); 
        out=mdscale(D,6,'criterion','stress'); 
    case 'FA'
        %[lambda,psi,T,stats,F] = factoran(data,3,'rotate','varimax');
        %out = (F * T') * T';
        %out = F * T';
        
        [lambda,psi,T,stats,F] = factoran(data,2,'rotate','promax');
        out = F;
        aux = lambda;
    case 'LLE'
        out = llex(data',7,2)';
    case 'LEM'
        out = compute_mapping(data, 'Laplacian', 2, 12);
    case 'tSNE'
        out = compute_mapping(data, 'tSNE', 2, 8);
    otherwise
        disp ('mreduce: supported types are:');
        disp (supptypes);
        error(['type ''' type ''' not supported']);
end;

out = out(:,1:2);

end



