下面这幅图像是使用K均值聚类得到的结果,看看,是不是跟深度学习的结果有点相似?有点那么个味道?
用来训练的小图片是从一些生活照中随机剪切出来的。下面是对应的matlab代码。
clear all; close all; clc;
% load mnist_uint8.mat;
% X = double(train_x(1 : 1 : end, :)) / 255;
load naturalImgData;
X = double(naturalImgData(1 : 10 : end, :)) / 255;
% X = X - repmat(mean(X, 1), size(X, 1), 1);
X = X - repmat(mean(X, 2), 1, size(X, 2));
maxValue = max(X(:));
minValue = min(X(:));
X = (X - minValue) / (maxValue - minValue) * 2 - 1;
xRot = zeros(size(X)); % You need to compute this
[n m] = size(X);
sigma = (1.0 / m) * X * X';
[u s v] = svd(sigma);
xRot = u' * X;
covar = zeros(size(X, 1)); % You need to compute this
covar = (1 ./ m) * xRot * xRot';
figure('name','Visualisation of covariance matrix');
imagesc(covar);
k = 0; % Set k accordingly
ss = diag(s);
k = length(ss((cumsum(ss) / sum(ss)) <= 0.99));
xHat = zeros(size(X)); % You need to compute this
xHat = u * [u( : , 1 : k)' * X; zeros(n - k, m)];
% fudgefactor = 0;
% X = whiten(X, fudgefactor);
% A = X'*X;
% [V,D] = eig(A);
% X = X*V*diag(1./(diag(D)+fudgefactor).^(1/2))*V';
visualize(X(1:100, :));
visualize(xHat(1:100, :));
clusterNum = 400;
opts = statset('Display','final');
[idx,ctrs] = kmeans(X, clusterNum, 'Distance','correlation', 'Replicates',1,'Options',opts);
visualize(ctrs);