matlab矩阵的低秩分解,低秩分解的matlab代码看不懂,分解的两个矩阵在哪呀??...

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

有四个文件:demo.m

function [] = demo()

%This routine demonstrates an example of using LRR to do subspace segmentation. We cosntruct 5 independent subspaces, each of which has a rank of 10,

%sample 200 points of dimension 100 from each subspae, and randomly choose some points to corrupt.

[X,cids] = generate_data();

ls = [0.0001 0.0005 0.001 0.002 0.004 0.008 0.01 0.02 0.04 0.08 0.1]; %parameter lambda

rs = [];

accs=[];

for i=1:length(ls)

Z = solve_lrr(X,X,ls(i));

L = abs(Z)+abs(Z');

disp('Perfoming NCut ...');

idx = clu_ncut(L,5);

acc = compacc(idx,cids);

disp(['lambda=' num2str(ls(i)) ',seg acc=' num2str(acc)]);

rs = [rs,rank(Z,1e-3*norm(Z,2))];

accs = [accs,acc];

end

close all;

figure;

subplot(1,2,1);

plot(ls,accs);

xlabel('parameter \lambda');

ylabel('segmentation accuracy');

subplot(1,2,2);

plot(ls,rs);

xlabel('parameter \lambda');

ylabel('rank(Z)');

function [X,cids] = generate_data()

n = 200;

d = 10;

D = 100;

[U,S,V] = svd(rand(D));

cids = [];

U1 = U(:,1:d);

X = U1*rand(d,n);

cids = [cids,ones(1,n)];

for i=2:5

R = orth(rand(D));

U1 = R*U1;

X = [X,U1*rand(d,n)];

cids = [cids,i*ones(1,n)];

end

nX = size(X,2);

norm_x = sqrt(sum(X.^2,1));

norm_x = repmat(norm_x,D,1);

gn = norm_x.*randn(D,nX);

inds = rand(1,nX)<=0.3;

X(:,inds) = X(:,inds) + 0.3*gn(:,inds);

function [idx] = clu_ncut(L,K)

L = (L + L')/2;

D = diag(1./sqrt(sum(L,2)));

L = D*L*D;

[U,S,V] = svd(L);

V = U(:,1:K);

V = D*V;

idx = kmeans(V,K,'emptyaction','singleton','replicates',10,'display','off');

idx = idx';

function [acc] = compacc(Segmentation,RefSegmentation)

ngroups = length(unique(RefSegmentation));

if(size(RefSegmentation,2)==1)

RefSegmentation=RefSegmentation';

end

if(size(Segmentation,2)==1)

Segmentation=Segmentation';

end

Permutations = perms(1:ngroups);

miss = zeros(size(Permutations,1),size(Segmentation,1));

for k=1:size(Segmentation,1)

for j=1:size(Permutations,1)

miss(j,k) = sum(abs(Segmentation(k,:)-Permutations(j,RefSegmentation))>0.1);

end

end

[miss,temp] = min(miss,[],1);

acc = 1 - miss/length(Segmentation);

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值