├── docs ├── SubKit.pdf ├── references.bib └── SubKit.tex ├── libs ├── ncut │ ├── jpg_images │ │ ├── 1.jpg │ │ ├── 2.jpg │ │ ├── 3.jpg │ │ └── Thumbs.db │ ├── sparsifyc.mexa64 │ ├── spmtimesd.mexa64 │ ├── sparsifyc.mexmaci64 │ ├── spmtimesd.mexmaci64 │ ├── mex_w_times_x_symmetric.mexa64 │ ├── mex_w_times_x_symmetric.mexmaci64 │ ├── X2distances.m │ ├── computeW.m │ ├── discretisationEigenVectorData.m │ ├── imread_ncut.m │ ├── showmask.m │ ├── compileDir_simple.m │ ├── doog1.m │ ├── ncutW.m │ ├── fft_filt_2.m │ ├── doog2.m │ ├── compute_relation.m │ ├── gaussian.m │ ├── NcutImage.m │ ├── make_filterbank_odd2.m │ ├── make_filterbank_even2.m │ ├── compute_relation2.m │ ├── computeEdges.m │ ├── ICgraph.m │ ├── demoNcutClustering.m │ ├── discretisation.m │ ├── mex_w_times_x_symmetric.cpp │ ├── demoNcutImage.m │ ├── README.txt │ ├── ncut.m │ ├── build_scene.m │ ├── quadedgep.m │ ├── spmtimesd.cpp │ ├── cimgnbmap.cpp │ ├── affinityic.cpp │ ├── sparsifyc.cpp │ └── a_times_b_cmplx.cpp ├── RPCAKit │ ├── doc │ │ ├── RPCAKit.pdf │ │ ├── References.bib │ │ └── RPCAKit.tex │ ├── README.md │ ├── LICENSE │ ├── rpca_fro.m │ ├── rpca_l1.m │ └── rpca_l1l2.m └── rpcakit │ └── doc │ ├── RPCAKit.synctex.gz │ ├── RPCAKit.out │ ├── RPCAKit.aux │ └── RPCAKit.log ├── .gitignore ├── common ├── norm_l1.m ├── norm_l1l2.m ├── solve_l2.m ├── normalize.m ├── solve_l1.m ├── condense_clusters.m ├── solve_nn.m ├── solve_l1l2.m ├── gen_depcoeff.m ├── gen_lrr_data.m └── gen_depmultivar_data.m ├── lrr ├── lrr_noiseless.m ├── r_lrr_fro.m ├── r_lrr_l1.m ├── r_lrr_l1l2.m ├── lrr_relaxed_lin.m ├── lrr_relaxed.m ├── lrr_relaxed_lin_ext.m ├── lrr_relaxed_lin_acc.m ├── lrr_exact_l1.m ├── lrr_exact_l1l2.m └── lrr_exact_fro.m ├── lsr └── lsr_relaxed.m ├── demo_lsr.m ├── demo_ssc.m ├── demo_lrr.m ├── demo_cass.m ├── demo_osc.m ├── demo_osc_lrr.m ├── demo_spatsc.m ├── ssc ├── ssc_relaxed_lin.m ├── ssc_noisefree.m ├── ssc_relaxed.m ├── ssc_relaxed_lin_ext.m ├── ssc_relaxed_lin_acc.m ├── ssc_exact_l1.m ├── ssc_exact_l1l2.m └── ssc_exact_fro.m ├── LICENSE ├── demo_mlap.m ├── cass └── cass_relaxed.m ├── osc ├── osc_relaxed_cvpr.m ├── osc_lrr_relaxed.m ├── osc_lrr_exact.m ├── osc_relaxed.m └── osc_exact.m ├── README.md ├── spatsc ├── spatsc_relaxed_cvpr.m ├── spatsc_relaxed.m └── spatsc_exact.m └── mlap └── mlap.m /docs/SubKit.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sjtrny/SubKit/HEAD/docs/SubKit.pdf -------------------------------------------------------------------------------- /libs/ncut/jpg_images/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sjtrny/SubKit/HEAD/libs/ncut/jpg_images/1.jpg -------------------------------------------------------------------------------- /libs/ncut/jpg_images/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sjtrny/SubKit/HEAD/libs/ncut/jpg_images/2.jpg -------------------------------------------------------------------------------- /libs/ncut/jpg_images/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sjtrny/SubKit/HEAD/libs/ncut/jpg_images/3.jpg -------------------------------------------------------------------------------- /libs/ncut/sparsifyc.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sjtrny/SubKit/HEAD/libs/ncut/sparsifyc.mexa64 -------------------------------------------------------------------------------- /libs/ncut/spmtimesd.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sjtrny/SubKit/HEAD/libs/ncut/spmtimesd.mexa64 -------------------------------------------------------------------------------- /libs/RPCAKit/doc/RPCAKit.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sjtrny/SubKit/HEAD/libs/RPCAKit/doc/RPCAKit.pdf -------------------------------------------------------------------------------- /libs/ncut/sparsifyc.mexmaci64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sjtrny/SubKit/HEAD/libs/ncut/sparsifyc.mexmaci64 -------------------------------------------------------------------------------- /libs/ncut/spmtimesd.mexmaci64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sjtrny/SubKit/HEAD/libs/ncut/spmtimesd.mexmaci64 -------------------------------------------------------------------------------- /libs/ncut/jpg_images/Thumbs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sjtrny/SubKit/HEAD/libs/ncut/jpg_images/Thumbs.db -------------------------------------------------------------------------------- /libs/rpcakit/doc/RPCAKit.synctex.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sjtrny/SubKit/HEAD/libs/rpcakit/doc/RPCAKit.synctex.gz -------------------------------------------------------------------------------- /libs/ncut/mex_w_times_x_symmetric.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sjtrny/SubKit/HEAD/libs/ncut/mex_w_times_x_symmetric.mexa64 -------------------------------------------------------------------------------- /libs/ncut/mex_w_times_x_symmetric.mexmaci64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sjtrny/SubKit/HEAD/libs/ncut/mex_w_times_x_symmetric.mexmaci64 -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | docs/SubKit.aux 3 | 4 | docs/SubKit.log 5 | 6 | docs/SubKit.out 7 | 8 | docs/SubKit.synctex.gz 9 | 10 | docs/SubKit.toc 11 | -------------------------------------------------------------------------------- /libs/rpcakit/doc/RPCAKit.out: -------------------------------------------------------------------------------- 1 | \BOOKMARK [1][-]{section.1}{RPCA}{}% 1 2 | \BOOKMARK [1][-]{section.2}{Function Listing}{}% 2 3 | \BOOKMARK [1][-]{section.3}{Implementation}{}% 3 4 | -------------------------------------------------------------------------------- /common/norm_l1.m: -------------------------------------------------------------------------------- 1 | function [ val ] = norm_l1( X ) 2 | %% L1 norm of X 3 | % 4 | % Created by Stephen Tierney 5 | % stierney@csu.edu.au 6 | % 7 | 8 | val = sum(abs(X(:))); 9 | 10 | end 11 | 12 | -------------------------------------------------------------------------------- /common/norm_l1l2.m: -------------------------------------------------------------------------------- 1 | function L = norm_l1l2(x) 2 | %% L1/L2 norm of X 3 | % 4 | % Created by Stephen Tierney 5 | % stierney@csu.edu.au 6 | % 7 | 8 | L = 0; 9 | for i=1:size(x,2) 10 | L = L + norm(x(:,i)); 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /libs/ncut/X2distances.m: -------------------------------------------------------------------------------- 1 | function distances = X2distances(X,Sigma); 2 | %Timothee Cour, 2004 3 | [n,k] = size(X); 4 | if nargin >= 2 5 | X = X*inv(sqrtm(Sigma)); 6 | end 7 | temp = sum(X.*X,2); 8 | temp = repmat(temp,1,n); 9 | distances = -2*X*X' + temp + temp'; -------------------------------------------------------------------------------- /common/solve_l2.m: -------------------------------------------------------------------------------- 1 | function [ x ] = solve_l2( w, lambda ) 2 | %% Solves the following 3 | % 4 | % arg min_{x} 1/2 || x - b ||_2^2 + lambda/2 || x ||_2^2 5 | % 6 | % Created by Stephen Tierney 7 | % stierney@csu.edu.au 8 | % 9 | 10 | x = w ./ (lambda + 1); 11 | 12 | end 13 | 14 | -------------------------------------------------------------------------------- /common/normalize.m: -------------------------------------------------------------------------------- 1 | function x = normalize(y) 2 | %% Normalizes each column such that the norm of each col is 1 3 | % 4 | % Created by Stephen Tierney 5 | % stierney@csu.edu.au 6 | % 7 | 8 | for i=1:size(y,2) 9 | x(:,i) = y(:,i)/sqrt(y(:,i)'*y(:,i)); 10 | end 11 | end -------------------------------------------------------------------------------- /common/solve_l1.m: -------------------------------------------------------------------------------- 1 | function [ x ] = solve_l1( b, lambda ) 2 | %% Solves the following 3 | % 4 | % arg min_{x} || x - b ||_2^2 + lambda || x ||_1 5 | % 6 | % Created by Stephen Tierney 7 | % stierney@csu.edu.au 8 | % 9 | 10 | x = sign(b).*max(abs(b) - lambda, 0); 11 | 12 | end 13 | 14 | -------------------------------------------------------------------------------- /lrr/lrr_noiseless.m: -------------------------------------------------------------------------------- 1 | function [ Z ] = lrr_noiseless( A, num_clusters ) 2 | %% Solves the following 3 | % 4 | % min || Z ||_* 5 | % s.t. X = XZ 6 | % 7 | % Created by Stephen Tierney 8 | % stierney@csu.edu.au 9 | % 10 | 11 | [~, ~, V] = svd(A); 12 | 13 | Z = V(:,1:num_clusters) * V(:,1:num_clusters)'; 14 | 15 | end 16 | 17 | -------------------------------------------------------------------------------- /libs/RPCAKit/README.md: -------------------------------------------------------------------------------- 1 | RPCAKit 2 | ======= 3 | 4 | MATLAB library for RPCA. 5 | 6 | RPCAKit currently implements RPCA with the following noise models: 7 | - Gaussian (rpca_fro) 8 | - Sparse (rpca_l1) 9 | - Sample Specific (rpca_l1l2) 10 | 11 | See the docs, demo and functions for more details. 12 | 13 | Written by Stephen Tierney (stierney@csu.edu.au) -------------------------------------------------------------------------------- /libs/ncut/computeW.m: -------------------------------------------------------------------------------- 1 | function W = computeW(imageX,dataW,emag,ephase) 2 | % W = computeW(imageX,dataW,emag,ephase) 3 | % Timothee Cour, Stella Yu, Jianbo Shi, 2004. 4 | [p,q] = size(imageX); 5 | 6 | [w_i,w_j] = cimgnbmap([p,q],dataW.sampleRadius,dataW.sample_rate); 7 | 8 | W = affinityic(emag,ephase,w_i,w_j,max(emag(:)) * dataW.edgeVariance); 9 | W = W/max(W(:)); 10 | -------------------------------------------------------------------------------- /libs/ncut/discretisationEigenVectorData.m: -------------------------------------------------------------------------------- 1 | function Y = discretisationEigenVectorData(EigenVector) 2 | % Y = discretisationEigenVectorData(EigenVector) 3 | % 4 | % discretizes previously rotated eigenvectors in discretisation 5 | % Timothee Cour, Stella Yu, Jianbo Shi, 2004 6 | 7 | [n,k]=size(EigenVector); 8 | 9 | 10 | [Maximum,J]=max(EigenVector'); 11 | 12 | Y=sparse(1:n,J',1,n,k); 13 | -------------------------------------------------------------------------------- /libs/ncut/imread_ncut.m: -------------------------------------------------------------------------------- 1 | function I = imread_ncut(Image_file_name,nr,nc); 2 | % I = imread_ncut(Image_file_name); 3 | % 4 | % Timothee Cour, Stella Yu, Jianbo Shi, 2004. 5 | 6 | 7 | %% read image 8 | 9 | I = imread(Image_file_name); 10 | [Inr,Inc,nb] = size(I); 11 | 12 | if (nb>1), 13 | I =double(rgb2gray(I)); 14 | else 15 | I = double(I); 16 | end 17 | 18 | I = imresize(I,[nr, nc],'bicubic'); 19 | -------------------------------------------------------------------------------- /libs/ncut/showmask.m: -------------------------------------------------------------------------------- 1 | function RGB=showmask(V,M,display_flag); 2 | % showmask(V,M); 3 | % 4 | % M is a nonneg. mask 5 | % Jianbo Shi, 1997 6 | 7 | V=V-min(V(:)); 8 | V=V/max(V(:)); 9 | V=.25+0.75*V; %brighten things up a bit 10 | 11 | M=M-min(M(:)); 12 | M=M/max(M(:)); 13 | 14 | H=0.0+zeros(size(V)); 15 | S=M; 16 | RGB=hsv2rgb(H,S,V); 17 | 18 | %if nargin>2 19 | image(RGB) 20 | axis('image') 21 | %end 22 | -------------------------------------------------------------------------------- /common/condense_clusters.m: -------------------------------------------------------------------------------- 1 | function t = condense_clusters(s,width) 2 | %% Condense the clusters into a single vector 3 | % 4 | % Created by Stephen Tierney 5 | % stierney@csu.edu.au 6 | % 7 | [~, idx] = sort(sum(s,1),'descend'); 8 | s = s(:,idx); 9 | 10 | for i=1:size(s,2) 11 | s(:,i) = i*s(:,i); 12 | end; 13 | 14 | s = sum(s,2); 15 | t = repmat(s,[1,width]); 16 | end -------------------------------------------------------------------------------- /common/solve_nn.m: -------------------------------------------------------------------------------- 1 | function [ X, s ] = solve_nn( Y, tau ) 2 | %% Solves the following 3 | % 4 | % min tau * |X|_* + 1/2*|X - Y|^2 5 | % 6 | % Created by Stephen Tierney 7 | % stierney@csu.edu.au 8 | % 9 | 10 | [U, S, V] = svd(Y, 'econ'); 11 | s = diag(S); 12 | 13 | ind = find(s <= tau); 14 | s(ind) = 0; 15 | 16 | ind = find(s > tau); 17 | s(ind) = s(ind) - tau; 18 | 19 | S = diag(s); 20 | 21 | X = U*S*(V'); 22 | 23 | end 24 | 25 | -------------------------------------------------------------------------------- /lrr/r_lrr_fro.m: -------------------------------------------------------------------------------- 1 | function [ Z ] = r_lrr_fro( X, lambda, num_clusters ) 2 | %% Solves the following 3 | % 4 | % min || Z ||_* 5 | % s.t. A = AZ, X = A + N 6 | % 7 | % Where N is assumed to be Gaussian 8 | % 9 | % This problem is decomposable into RPCA then Noiseless LRR 10 | % lambda is therefore the paramter for RPCA 11 | % 12 | % Created by Stephen Tierney 13 | % stierney@csu.edu.au 14 | % 15 | 16 | A = rpca_fro(X, lambda); 17 | 18 | Z = lrr_noiseless(A, num_clusters); 19 | 20 | end 21 | 22 | -------------------------------------------------------------------------------- /lrr/r_lrr_l1.m: -------------------------------------------------------------------------------- 1 | function [ Z ] = r_lrr_l1( X, lambda, num_clusters ) 2 | %% Solves the following 3 | % 4 | % min || Z ||_* 5 | % s.t. A = AZ, X = A + N 6 | % 7 | % Where N is assumed to be sparse 8 | % 9 | % This problem is decomposable into RPCA then Noiseless LRR 10 | % lambda is therefore the paramter for RPCA 11 | % 12 | % Created by Stephen Tierney 13 | % stierney@csu.edu.au 14 | % 15 | 16 | A = rpca_l1(X, lambda); 17 | 18 | Z = lrr_noiseless(A, num_clusters); 19 | 20 | end 21 | 22 | -------------------------------------------------------------------------------- /lrr/r_lrr_l1l2.m: -------------------------------------------------------------------------------- 1 | function [ Z ] = r_lrr_l1l2( X, lambda, num_clusters ) 2 | %% Solves the following 3 | % 4 | % min || Z ||_* 5 | % s.t. A = AZ, X = A + N 6 | % 7 | % Where N is assumed to be column-wise corrupted 8 | % 9 | % This problem is decomposable into RPCA then Noiseless LRR 10 | % lambda is therefore the paramter for RPCA 11 | % 12 | % Created by Stephen Tierney 13 | % stierney@csu.edu.au 14 | % 15 | 16 | A = rpca_l1l2(X, lambda); 17 | 18 | Z = lrr_noiseless(A, num_clusters); 19 | 20 | end 21 | 22 | -------------------------------------------------------------------------------- /lsr/lsr_relaxed.m: -------------------------------------------------------------------------------- 1 | function [ Z ] = lsr_relaxed( X, lambda, diag ) 2 | %% Solves the following 3 | % 4 | % min 1/2 || X - XZ ||_F^2 + lambda/2 || Z ||_F^2 5 | % s.t. diag(Z) = 0 (when diag = 1) 6 | % 7 | % Created by Stephen Tierney 8 | % stierney@csu.edu.au 9 | % 10 | 11 | if (diag) 12 | D = (X' * X + lambda*eye(size(X,2))); 13 | Z = spdiags(diag(D), 0, size(X,2), size(X,2)) \ D; 14 | Z(logical(eye(size(Z)))) = 0; 15 | else 16 | Z = (X' * X + lambda*eye(size(X,2))) \ X'*X; 17 | end 18 | 19 | end 20 | 21 | -------------------------------------------------------------------------------- /common/solve_l1l2.m: -------------------------------------------------------------------------------- 1 | function [ E ] = solve_l1l2( W, lambda ) 2 | %% Solves the following 3 | % 4 | % arg min_{x} || X - W ||_2^2 + lambda || X ||_1/2 5 | % 6 | % Created by Stephen Tierney 7 | % stierney@csu.edu.au 8 | % 9 | 10 | [m, n] = size(W); 11 | 12 | E = W; 13 | 14 | for i = 1 : n 15 | 16 | norm_col = norm(W(:,i)); 17 | 18 | if (norm_col > lambda) 19 | E(:,i) = (norm_col - lambda) * W(:,i) / norm_col; 20 | else 21 | E(:,i) = zeros(m, 1); 22 | end 23 | 24 | end 25 | 26 | end 27 | -------------------------------------------------------------------------------- /libs/ncut/compileDir_simple.m: -------------------------------------------------------------------------------- 1 | function compileDir_simple(Cdir); 2 | if nargin<1 3 | Cdir=pwd; 4 | end 5 | 6 | files = dir(fullfile(Cdir,'*.cpp')); 7 | 8 | oldDir=pwd; 9 | cd(Cdir); 10 | for j=1:length(files) 11 | try 12 | % cm = sprintf('mex %s',files(j).name); 13 | cm = sprintf('mex -largeArrayDims %s',files(j).name); 14 | disp(cm); 15 | eval(cm); 16 | catch 17 | disp(lasterr); 18 | disp('IGNORE if the file is a C++ file which is not a mex file (ie without a mexFunction inside)'); 19 | end 20 | end 21 | 22 | cd(oldDir); -------------------------------------------------------------------------------- /libs/ncut/doog1.m: -------------------------------------------------------------------------------- 1 | function H=doog1(sig,r,th,N); 2 | % H=doog1(sig,r,th,N); 3 | % Serge Belongie 4 | 5 | no_pts=N; % no. of points in x,y grid 6 | 7 | [x,y]=meshgrid(-(N/2)+1/2:(N/2)-1/2,-(N/2)+1/2:(N/2)-1/2); 8 | 9 | phi=pi*th/180; 10 | sigy=sig; 11 | sigx=r*sig; 12 | R=[cos(phi) -sin(phi); sin(phi) cos(phi)]; 13 | C=R*diag([sigx,sigy])*R'; 14 | 15 | X=[x(:) y(:)]; 16 | 17 | Gb=gaussian(X,[0 0]',C); 18 | Gb=reshape(Gb,N,N); 19 | 20 | m=R*[0 sig]'; 21 | 22 | a=1; 23 | b=-1; 24 | 25 | % make odd-symmetric filter 26 | Ga=gaussian(X,m/2,C); 27 | Ga=reshape(Ga,N,N); 28 | Gb=rot90(Ga,2); 29 | H=a*Ga+b*Gb; 30 | 31 | -------------------------------------------------------------------------------- /demo_lsr.m: -------------------------------------------------------------------------------- 1 | paths = ['common:', genpath('libs'), 'lsr:']; 2 | addpath(paths); 3 | 4 | rng(1); 5 | 6 | dim_data = 100; 7 | dim_space = 4; 8 | n_space = 5; 9 | cluster_size = 20; 10 | m = 0.1; 11 | v = 0.001; 12 | 13 | A = gen_depmultivar_data(dim_data, dim_space, cluster_size, n_space, m, v); 14 | A = normalize(A); 15 | 16 | corruption = 0; 17 | 18 | N = randn(size(A)) * corruption; 19 | 20 | X = A + N; 21 | 22 | X = normalize(X); 23 | 24 | Z = lsr_relaxed(X, 0.01); 25 | 26 | clusters = ncutW(abs(Z) + abs(Z'), n_space); 27 | 28 | final_clusters = condense_clusters(clusters, 1); 29 | 30 | figure, imagesc(final_clusters); 31 | 32 | rmpath(paths); -------------------------------------------------------------------------------- /demo_ssc.m: -------------------------------------------------------------------------------- 1 | paths = ['common:', genpath('libs'), 'ssc:']; 2 | addpath(paths); 3 | 4 | rng(1); 5 | 6 | dim_data = 100; 7 | dim_space = 4; 8 | n_space = 5; 9 | cluster_size = 20; 10 | m = 0.1; 11 | v = 0.001; 12 | 13 | A = gen_depmultivar_data(dim_data, dim_space, cluster_size, n_space, m, v); 14 | A = normalize(A); 15 | 16 | corruption = 0; 17 | 18 | N = randn(size(A)) * corruption; 19 | 20 | X = A + N; 21 | 22 | X = normalize(X); 23 | 24 | Z = ssc_relaxed(X, 0.01); 25 | 26 | clusters = ncutW(abs(Z) + abs(Z'), n_space); 27 | 28 | final_clusters = condense_clusters(clusters, 1); 29 | 30 | figure, imagesc(final_clusters); 31 | 32 | rmpath(paths); -------------------------------------------------------------------------------- /common/gen_depcoeff.m: -------------------------------------------------------------------------------- 1 | function [ coeff ] = gen_depcoeff( m, v, dim_space, cluster_size ) 2 | %% Generate dependant coefficients 3 | % 4 | % Created by Stephen Tierney 5 | % stierney@csu.edu.au 6 | % 7 | v_nbor = v / 2; 8 | 9 | lower_sigma = v_nbor*(triu(ones(cluster_size, cluster_size),-1) - triu(ones(cluster_size, cluster_size))); 10 | 11 | sigma = tril(lower_sigma)' + tril(lower_sigma); 12 | sigma(logical(eye(size(sigma)))) = v*ones(cluster_size, 1); 13 | 14 | coeff = zeros(dim_space, cluster_size); 15 | for k = 1 : dim_space 16 | coeff(k, :) = mvnrnd( m + zeros(cluster_size, 1), sigma , 1); 17 | end 18 | 19 | 20 | end 21 | 22 | -------------------------------------------------------------------------------- /demo_lrr.m: -------------------------------------------------------------------------------- 1 | paths = ['common:', genpath('libs'), 'lrr:']; 2 | addpath(paths); 3 | 4 | rng(1); 5 | 6 | dim_data = 100; 7 | dim_space = 4; 8 | n_space = 5; 9 | cluster_size = 20; 10 | m = 0.1; 11 | v = 0.001; 12 | 13 | A = gen_depmultivar_data(dim_data, dim_space, cluster_size, n_space, m, v); 14 | A = normalize(A); 15 | 16 | corruption = 0; 17 | 18 | N = randn(size(A)) * corruption; 19 | 20 | X = A + N; 21 | 22 | X = normalize(X); 23 | 24 | Z = lrr_relaxed(X, 0.01); 25 | 26 | imagesc(Z); 27 | 28 | clusters = ncutW(abs(Z) + abs(Z'), n_space); 29 | 30 | final_clusters = condense_clusters(clusters, 1); 31 | 32 | figure, imagesc(final_clusters); 33 | 34 | rmpath(paths); -------------------------------------------------------------------------------- /libs/ncut/ncutW.m: -------------------------------------------------------------------------------- 1 | function [NcutDiscrete,NcutEigenvectors,NcutEigenvalues] = ncutW(W,nbcluster); 2 | % [NcutDiscrete,NcutEigenvectors,NcutEigenvalues] = ncutW(W,nbcluster); 3 | % 4 | % Calls ncut to compute NcutEigenvectors and NcutEigenvalues of W with nbcluster clusters 5 | % Then calls discretisation to discretize the NcutEigenvectors into NcutDiscrete 6 | % Timothee Cour, Stella Yu, Jianbo Shi, 2004 7 | 8 | % compute continuous Ncut eigenvectors 9 | [NcutEigenvectors,NcutEigenvalues] = ncut(W,nbcluster); 10 | 11 | % compute discretize Ncut vectors 12 | [NcutDiscrete,NcutEigenvectors] =discretisation(NcutEigenvectors); 13 | 14 | 15 | NcutDiscrete = full(NcutDiscrete); -------------------------------------------------------------------------------- /demo_cass.m: -------------------------------------------------------------------------------- 1 | paths = ['common:', genpath('libs'), 'cass:']; 2 | addpath(paths); 3 | 4 | rng(1); 5 | 6 | dim_data = 100; 7 | dim_space = 4; 8 | n_space = 5; 9 | cluster_size = 20; 10 | m = 0.1; 11 | v = 0.001; 12 | 13 | A = gen_depmultivar_data(dim_data, dim_space, cluster_size, n_space, m, v); 14 | A = normalize(A); 15 | 16 | corruption = 0; 17 | 18 | N = randn(size(A)) * corruption; 19 | 20 | X = A + N; 21 | 22 | X = normalize(X); 23 | 24 | Z = cass_relaxed(X, 0.01); 25 | 26 | imagesc(Z); 27 | 28 | clusters = ncutW(abs(Z) + abs(Z'), n_space); 29 | 30 | final_clusters = condense_clusters(clusters, 1); 31 | 32 | figure, imagesc(final_clusters); 33 | 34 | rmpath(paths); -------------------------------------------------------------------------------- /demo_osc.m: -------------------------------------------------------------------------------- 1 | paths = ['common:', genpath('libs'), 'osc:']; 2 | addpath(paths); 3 | 4 | rng(1); 5 | 6 | dim_data = 100; 7 | dim_space = 4; 8 | n_space = 5; 9 | cluster_size = 20; 10 | m = 0.1; 11 | v = 0.001; 12 | 13 | A = gen_depmultivar_data(dim_data, dim_space, cluster_size, n_space, m, v); 14 | A = normalize(A); 15 | 16 | corruption = 0; 17 | 18 | N = randn(size(A)) * corruption; 19 | 20 | X = A + N; 21 | 22 | X = normalize(X); 23 | 24 | lambda_1 = 0.099; 25 | lambda_2 = 0.001; 26 | Z = osc_relaxed(X, lambda_1, lambda_2); 27 | 28 | clusters = ncutW(abs(Z) + abs(Z'), n_space); 29 | 30 | final_clusters = condense_clusters(clusters, 1); 31 | 32 | figure, imagesc(final_clusters); 33 | 34 | rmpath(paths); -------------------------------------------------------------------------------- /demo_osc_lrr.m: -------------------------------------------------------------------------------- 1 | paths = ['common:', genpath('libs'), 'osc:']; 2 | addpath(paths); 3 | 4 | rng(1); 5 | 6 | dim_data = 100; 7 | dim_space = 4; 8 | n_space = 5; 9 | cluster_size = 20; 10 | m = 0.1; 11 | v = 0.001; 12 | 13 | A = gen_depmultivar_data(dim_data, dim_space, cluster_size, n_space, m, v); 14 | A = normalize(A); 15 | 16 | corruption = 0; 17 | 18 | N = randn(size(A)) * corruption; 19 | 20 | X = A + N; 21 | 22 | X = normalize(X); 23 | 24 | lambda_1 = 0.099; 25 | lambda_2 = 0.001; 26 | Z = osc_relaxed_lrr(X, lambda_1, lambda_2); 27 | 28 | clusters = ncutW(abs(Z) + abs(Z'), n_space); 29 | 30 | final_clusters = condense_clusters(clusters, 1); 31 | 32 | figure, imagesc(final_clusters); 33 | 34 | rmpath(paths); -------------------------------------------------------------------------------- /demo_spatsc.m: -------------------------------------------------------------------------------- 1 | paths = ['common:', genpath('libs'), 'spatsc:']; 2 | addpath(paths); 3 | 4 | rng(1); 5 | 6 | dim_data = 100; 7 | dim_space = 4; 8 | n_space = 5; 9 | cluster_size = 20; 10 | m = 0.1; 11 | v = 0.001; 12 | 13 | A = gen_depmultivar_data(dim_data, dim_space, cluster_size, n_space, m, v); 14 | A = normalize(A); 15 | 16 | corruption = 0; 17 | 18 | N = randn(size(A)) * corruption; 19 | 20 | X = A + N; 21 | 22 | X = normalize(X); 23 | 24 | lambda_1 = 0.099; 25 | lambda_2 = 0.001; 26 | Z = spatsc_relaxed(X, lambda_1, lambda_2); 27 | 28 | clusters = ncutW(abs(Z) + abs(Z'), n_space); 29 | 30 | final_clusters = condense_clusters(clusters, 1); 31 | 32 | figure, imagesc(final_clusters); 33 | 34 | rmpath(paths); -------------------------------------------------------------------------------- /common/gen_lrr_data.m: -------------------------------------------------------------------------------- 1 | function [ X ] = gen_lrr_data( dim_data, dim_space, cluster_size, n_space ) 2 | %% Generate synthetic data as presrcibed by 3 | % 4 | % Robust subspace segmentation by low-rank representation 5 | % Guangcan Liu, Zhouchen Lin and Yong Yu 6 | % 7 | % Created by Stephen Tierney 8 | % stierney@csu.edu.au 9 | % 10 | 11 | X = zeros(dim_data, cluster_size*n_space); 12 | 13 | [T, ~] = qr(rand(dim_data,dim_data)); 14 | if det(T) < 1 15 | T(:,1) = -T(:,1); 16 | end 17 | 18 | U = orth(rand(dim_data, dim_space)); 19 | 20 | X(:, 1:cluster_size) = U * randn(dim_space, cluster_size); 21 | for j = 1 : n_space-1 22 | U = T * U; 23 | X(:, cluster_size*j+1: cluster_size*(j+1)) = U * randn(dim_space, cluster_size); 24 | end 25 | 26 | end -------------------------------------------------------------------------------- /libs/ncut/fft_filt_2.m: -------------------------------------------------------------------------------- 1 | function FI=fft_filt_2(V,FB,sf); 2 | % FI=fft_filt_2(V,FB,sf); 3 | % fft-based filtering 4 | % requires image to be called "V" 5 | % and filters to be in FB 6 | % sf is the subsampling factor 7 | % 8 | % FI is the result 9 | % Jianbo Shi, 1997 10 | 11 | [M1,M2,N3]=size(FB); 12 | % prepare FFT of image for filtering 13 | [N1,N2]=size(V); 14 | I=zeros(size(V)+[M1-1 M2-1]); 15 | I(1:N1,1:N2)=V; 16 | N1s=length(1:sf:N1); 17 | N2s=length(1:sf:N2); 18 | IF=fft2(I); 19 | FI=zeros(N1s,N2s,N3); 20 | 21 | % apply filters 22 | for n=1:N3; 23 | f=rot90(FB(:,:,n),2); 24 | fF=fft2(f,N1+M1-1,N2+M2-1); 25 | IfF=IF.*fF; 26 | If=real(ifft2(IfF)); 27 | If=If(ceil((M1+1)/2):ceil((M1+1)/2)+N1-1,ceil((M2+1)/2):ceil((M2+1)/2)+N2-1); 28 | FI(:,:,n)=If(1:sf:N1,1:sf:N2); 29 | end 30 | 31 | -------------------------------------------------------------------------------- /common/gen_depmultivar_data.m: -------------------------------------------------------------------------------- 1 | function [ X ] = gen_depmultivar_data( dim_data, dim_space, cluster_size, n_space, m, v ) 2 | %% Generate Dependant Multivariate Data 3 | % 4 | % Created by Stephen Tierney 5 | % stierney@csu.edu.au 6 | % 7 | 8 | X = zeros(dim_data, cluster_size*n_space); 9 | 10 | [T, ~] = qr(rand(dim_data,dim_data)); 11 | if det(T) < 1 12 | T(:,1) = -T(:,1); 13 | end 14 | 15 | basis = orth(randn(dim_data, dim_space)); 16 | 17 | X(:, 1:cluster_size) = basis * gen_depcoeff(m, v, dim_space, cluster_size); 18 | 19 | for j = 1 : n_space-1 20 | 21 | basis = T * basis; 22 | 23 | X(:, cluster_size*j+1: cluster_size*(j+1)) = basis * gen_depcoeff(m, v, dim_space, cluster_size); 24 | 25 | end 26 | 27 | 28 | end 29 | 30 | -------------------------------------------------------------------------------- /libs/ncut/doog2.m: -------------------------------------------------------------------------------- 1 | function G=doog2(sig,r,th,N); 2 | % G=doog2(sig,r,th,N); 3 | % Make difference of offset gaussians kernel 4 | % theta is in degrees 5 | % (see Malik & Perona, J. Opt. Soc. Amer., 1990) 6 | % 7 | % Example: 8 | % >> imagesc(doog2(1,12,0,64,1)) 9 | % >> colormap(gray) 10 | % 11 | % Serge Belongie 12 | 13 | 14 | no_pts=N; % no. of points in x,y grid 15 | 16 | [x,y]=meshgrid(-(N/2)+1/2:(N/2)-1/2,-(N/2)+1/2:(N/2)-1/2); 17 | 18 | phi=pi*th/180; 19 | sigy=sig; 20 | sigx=r*sig; 21 | R=[cos(phi) -sin(phi); sin(phi) cos(phi)]; 22 | C=R*diag([sigx,sigy])*R'; 23 | 24 | X=[x(:) y(:)]; 25 | 26 | Gb=gaussian(X,[0 0]',C); 27 | Gb=reshape(Gb,N,N); 28 | 29 | m=R*[0 sig]'; 30 | Ga=gaussian(X,m,C); 31 | Ga=reshape(Ga,N,N); 32 | Gc=rot90(Ga,2); 33 | 34 | a=-1; 35 | b=2; 36 | c=-1; 37 | 38 | G = a*Ga + b*Gb + c*Gc; 39 | 40 | -------------------------------------------------------------------------------- /libs/ncut/compute_relation.m: -------------------------------------------------------------------------------- 1 | function [W,distances] = compute_relation(data,scale_sig,order) 2 | % 3 | % [W,distances] = compute_relation(data,scale_sig) 4 | % Input: data= Feature_dimension x Num_data 5 | % ouput: W = pair-wise data similarity matrix 6 | % Dist = pair-wise Euclidean distance 7 | % 8 | % 9 | % Jianbo Shi, 1997 10 | 11 | 12 | distances = zeros(length(data),length(data)); 13 | for j = 1:length(data), 14 | distances(j,:) = (sqrt((data(1,:)-data(1,j)).^2 +... 15 | (data(2,:)-data(2,j)).^2)); 16 | end 17 | 18 | % distances = X2distances(data'); 19 | 20 | if (~exist('scale_sig')), 21 | scale_sig = 0.05*max(distances(:)); 22 | end 23 | 24 | if (exist('order') ~= 1), 25 | order = 2; 26 | end 27 | 28 | tmp = (distances/scale_sig).^order; 29 | 30 | W = exp(-tmp); 31 | 32 | -------------------------------------------------------------------------------- /libs/ncut/gaussian.m: -------------------------------------------------------------------------------- 1 | function p=gaussian(x,m,C); 2 | % p=gaussian(x,m,C); 3 | % 4 | % Evaluate the multi-variate density with mean vector m and covariance 5 | % matrix C for the input vector x. 6 | % 7 | % p=gaussian(X,m,C); 8 | % 9 | % Vectorized version: Here X is a matrix of column vectors, and p is 10 | % a vector of probabilities for each vector. 11 | % Jianbo Shi, 1997 12 | d=length(m); 13 | 14 | if size(x,1)~=d 15 | x=x'; 16 | end 17 | N=size(x,2); 18 | 19 | detC = det(C); 20 | if rcond(C) threshold); 22 | egx1 = g(:,:,1); 23 | egy1 = g(:,:,2); 24 | eindex = find(edges2); 25 | [ey,ex,values] = find(edges2); 26 | 27 | egx = egx1(eindex); 28 | egy = egy1(eindex); 29 | 30 | edgemap.eindex = eindex; 31 | edgemap.values = values; 32 | edgemap.x = ex; 33 | edgemap.y = ey; 34 | edgemap.gx = egx; 35 | edgemap.gy = egy; 36 | edgemap.emag = emag; 37 | edgemap.ephase = ephase; 38 | edgemap.imageEdges = edges2; 39 | -------------------------------------------------------------------------------- /libs/ncut/ICgraph.m: -------------------------------------------------------------------------------- 1 | function [W,imageEdges] = ICgraph(I,dataW,dataEdgemap); 2 | % [W,imageEdges] = ICgraph(I,dataW,dataEdgemap); 3 | % Input: 4 | % I = gray-level image 5 | % optional parameters: 6 | % dataW.sampleRadius=10; 7 | % dataW.sample_rate=0.3; 8 | % dataW.edgeVariance = 0.1; 9 | % 10 | % dataEdgemap.parametres=[4,3, 21,3];%[number of filter orientations, number of scales, filter size, elongation] 11 | % dataEdgemap.threshold=0.02; 12 | % 13 | % Output: 14 | % W: npixels x npixels similarity matrix based on Intervening Contours 15 | % imageEdges: image showing edges extracted in the image 16 | % 17 | % Timothee Cour, Stella Yu, Jianbo Shi, 2004. 18 | 19 | 20 | 21 | [p,q] = size(I); 22 | 23 | if (nargin< 2) | isempty(dataW), 24 | dataW.sampleRadius=10; 25 | dataW.sample_rate=0.3; 26 | dataW.edgeVariance = 0.1; 27 | end 28 | 29 | if (nargin<3) | isempty(dataEdgemap), 30 | dataEdgemap.parametres=[4,3, 21,3];%[number of filter orientations, number of scales, filter size, elongation] 31 | dataEdgemap.threshold=0.02; 32 | end 33 | 34 | 35 | edgemap = computeEdges(I,dataEdgemap.parametres,dataEdgemap.threshold); 36 | imageEdges = edgemap.imageEdges; 37 | W = computeW(I,dataW,edgemap.emag,edgemap.ephase); 38 | -------------------------------------------------------------------------------- /libs/rpcakit/doc/RPCAKit.aux: -------------------------------------------------------------------------------- 1 | \relax 2 | \providecommand\hyper@newdestlabel[2]{} 3 | \providecommand\HyperFirstAtBeginDocument{\AtBeginDocument} 4 | \HyperFirstAtBeginDocument{\ifx\hyper@anchor\@undefined 5 | \global\let\oldcontentsline\contentsline 6 | \gdef\contentsline#1#2#3#4{\oldcontentsline{#1}{#2}{#3}} 7 | \global\let\oldnewlabel\newlabel 8 | \gdef\newlabel#1#2{\newlabelxx{#1}#2} 9 | \gdef\newlabelxx#1#2#3#4#5#6{\oldnewlabel{#1}{{#2}{#3}}} 10 | \AtEndDocument{\ifx\hyper@anchor\@undefined 11 | \let\contentsline\oldcontentsline 12 | \let\newlabel\oldnewlabel 13 | \fi} 14 | \fi} 15 | \global\let\hyper@last\relax 16 | \gdef\HyperFirstAtBeginDocument#1{#1} 17 | \providecommand\HyField@AuxAddToFields[1]{} 18 | \providecommand\HyField@AuxAddToCoFields[2]{} 19 | \citation{candes2011robust} 20 | \citation{candes2011robust} 21 | \citation{lin2011linearized} 22 | \@writefile{toc}{\contentsline {section}{\numberline {1}RPCA}{1}{section.1}} 23 | \@writefile{toc}{\contentsline {section}{\numberline {2}Function Listing}{1}{section.2}} 24 | \@writefile{toc}{\contentsline {section}{\numberline {3}Implementation}{1}{section.3}} 25 | \citation{lin2011linearized} 26 | \citation{candes2011robust} 27 | \citation{candes2011robust} 28 | \citation{liu2010robust} 29 | \bibstyle{plain} 30 | \bibdata{references} 31 | -------------------------------------------------------------------------------- /lrr/lrr_relaxed_lin_ext.m: -------------------------------------------------------------------------------- 1 | function [ Z ] = lrr_relaxed_lin_ext( X, lambda ) 2 | %% Solves the following 3 | % 4 | % min || X - XZ ||_F^2 + lambda || Z ||_* 5 | % 6 | % by extended gradient descent 7 | % 8 | % Created by Stephen Tierney 9 | % stierney@csu.edu.au 10 | % 11 | 12 | max_iterations = 100; 13 | 14 | func_vals = zeros(max_iterations, 1); 15 | previous_func_val = Inf; 16 | 17 | n = size(X, 2); 18 | 19 | Z = zeros(n); 20 | 21 | rho = 1; 22 | 23 | gamma = 1.1; 24 | 25 | for k = 1 : max_iterations 26 | 27 | Z_prev = Z; 28 | 29 | searching = true; 30 | while( searching ) 31 | partial = -X'*X + X'*X*Z_prev; 32 | 33 | V = Z_prev - 1/rho * partial; 34 | 35 | [Z, s] = solve_nn(V, lambda/rho); 36 | 37 | func_vals(k) = 0.5*norm(X - X*Z, 'fro')^2 + lambda * sum(s); 38 | 39 | approx = 0.5*norm(X - X*Z_prev, 'fro')^2 + sum(sum((Z - Z_prev).*partial)) + 0.5*rho*norm(Z - Z_prev, 'fro')^2 + lambda * sum(s); 40 | 41 | if ( func_vals(k, 1) > approx ) 42 | rho = gamma * rho; 43 | else 44 | searching = false; 45 | end 46 | end 47 | 48 | if ( abs(func_vals(k) - previous_func_val) <= 1*10^-6 ) 49 | break; 50 | else 51 | previous_func_val = func_vals(k); 52 | end 53 | 54 | end 55 | 56 | end 57 | 58 | -------------------------------------------------------------------------------- /libs/ncut/demoNcutClustering.m: -------------------------------------------------------------------------------- 1 | function demoNcutClustering; 2 | % demoNcutClustering 3 | % 4 | % demo for NcutClustering 5 | % also initialize matlab paths to subfolders 6 | % Timothee Cour, Stella Yu, Jianbo Shi, 2004. 7 | 8 | disp('Ncut Clustering demo'); 9 | 10 | %% make up a point data set 11 | caseid = 2;%3 12 | [data,size_cluster] = build_scene(caseid); 13 | figure(1);clf; 14 | plot(data(1,:),data(2,:),'ks', 'MarkerFaceColor','k','MarkerSize',5); axis image; hold on; 15 | 16 | disp('This is the input data points to be clustered, press Enter to continue...'); 17 | pause; 18 | 19 | disp('Compute clustering...'); 20 | 21 | % compute similarity matrix 22 | [W,Dist] = compute_relation(data); 23 | 24 | % clustering graph in 25 | nbCluster = 4; 26 | tic; 27 | [NcutDiscrete,NcutEigenvectors,NcutEigenvalues] = ncutW(W,nbCluster); 28 | disp(['The computation took ' num2str(toc) ' seconds']); 29 | figure(3); 30 | plot(NcutEigenvectors); 31 | 32 | % display clustering result 33 | cluster_color = ['rgbmyc']; 34 | figure(2);clf; 35 | for j=1:nbCluster, 36 | id = find(NcutDiscrete(:,j)); 37 | plot(data(1,id),data(2,id),[cluster_color(j),'s'], 'MarkerFaceColor',cluster_color(j),'MarkerSize',5); hold on; 38 | end 39 | hold off; axis image; 40 | disp('This is the clustering result'); 41 | disp('The demo is finished.'); 42 | -------------------------------------------------------------------------------- /ssc/ssc_relaxed_lin_ext.m: -------------------------------------------------------------------------------- 1 | function [ Z ] = ssc_relaxed_lin_ext( X, lambda ) 2 | %% Solves the following 3 | % 4 | % min || X - XZ ||_F^2 + lambda || Z ||_1 5 | % 6 | % by extended gradient descent 7 | % 8 | % Created by Stephen Tierney 9 | % stierney@csu.edu.au 10 | % 11 | 12 | max_iterations = 100; 13 | 14 | func_vals = zeros(max_iterations, 1); 15 | previous_func_val = Inf; 16 | 17 | n = size(X, 2); 18 | 19 | Z = zeros(n); 20 | 21 | rho = 1; 22 | 23 | gamma = 1.1; 24 | 25 | for k = 1 : max_iterations 26 | 27 | Z_prev = Z; 28 | 29 | searching = true; 30 | while( searching ) 31 | partial = -X'*X + X'*X*Z_prev; 32 | 33 | V = Z_prev - 1/rho * partial; 34 | 35 | Z = solve_l1(V, lambda/rho); 36 | 37 | Z(logical(eye(size(Z)))) = 0; 38 | 39 | func_vals(k, 1) = lambda*norm_l1(Z) + 1/2 *norm(X - X*Z, 'fro')^2; 40 | 41 | approx = 0.5*norm(X - X*Z_prev, 'fro')^2 + sum(sum((Z - Z_prev).*partial)) + 0.5*rho*norm(Z - Z_prev, 'fro')^2 + lambda*norm_l1(Z); 42 | 43 | if ( func_vals(k, 1) > approx ) 44 | rho = gamma * rho; 45 | else 46 | searching = false; 47 | end 48 | end 49 | 50 | if ( abs(func_vals(k) - previous_func_val) <= 1*10^-6 ) 51 | break; 52 | else 53 | previous_func_val = func_vals(k); 54 | end 55 | 56 | end 57 | 58 | end 59 | 60 | -------------------------------------------------------------------------------- /libs/ncut/discretisation.m: -------------------------------------------------------------------------------- 1 | function [EigenvectorsDiscrete,EigenVectors]=discretisation(EigenVectors) 2 | % 3 | % EigenvectorsDiscrete=discretisation(EigenVectors) 4 | % 5 | % Input: EigenVectors = continuous Ncut vector, size = ndata x nbEigenvectors 6 | % Output EigenvectorsDiscrete = discrete Ncut vector, size = ndata x nbEigenvectors 7 | % 8 | % Timothee Cour, Stella Yu, Jianbo Shi, 2004 9 | 10 | [n,k]=size(EigenVectors); 11 | 12 | vm = sqrt(sum(EigenVectors.*EigenVectors,2)); 13 | EigenVectors = EigenVectors./repmat(vm,1,k); 14 | 15 | R=zeros(k); 16 | R(:,1)=EigenVectors(1+round(rand(1)*(n-1)),:)'; 17 | c=zeros(n,1); 18 | for j=2:k 19 | c=c+abs(EigenVectors*R(:,j-1)); 20 | [minimum,i]=min(c); 21 | R(:,j)=EigenVectors(i,:)'; 22 | end 23 | 24 | lastObjectiveValue=0; 25 | exitLoop=0; 26 | nbIterationsDiscretisation = 0; 27 | nbIterationsDiscretisationMax = 20;%voir 28 | while exitLoop== 0 29 | nbIterationsDiscretisation = nbIterationsDiscretisation + 1 ; 30 | EigenvectorsDiscrete = discretisationEigenVectorData(EigenVectors*R); 31 | [U,S,V] = svd(EigenvectorsDiscrete'*EigenVectors,0); 32 | NcutValue=2*(n-trace(S)); 33 | 34 | if abs(NcutValue-lastObjectiveValue) < eps | nbIterationsDiscretisation > nbIterationsDiscretisationMax 35 | exitLoop=1; 36 | else 37 | lastObjectiveValue = NcutValue; 38 | R=V*U'; 39 | end 40 | end -------------------------------------------------------------------------------- /libs/RPCAKit/doc/References.bib: -------------------------------------------------------------------------------- 1 | %% This BibTeX bibliography file was created using BibDesk. 2 | %% http://bibdesk.sourceforge.net/ 3 | 4 | 5 | %% Created for Steve at 2014-08-12 11:39:52 +1000 6 | 7 | 8 | %% Saved with string encoding Unicode (UTF-8) 9 | 10 | 11 | 12 | @inproceedings{liu2010robust, 13 | Author = {Liu, Guangcan and Lin, Zhouchen and Yu, Yong}, 14 | Booktitle = {International Conference on Machine Learning}, 15 | Date-Added = {2014-08-12 01:39:42 +0000}, 16 | Date-Modified = {2014-08-12 01:39:42 +0000}, 17 | Pages = {663--670}, 18 | Title = {Robust subspace segmentation by low-rank representation}, 19 | Year = {2010}} 20 | 21 | @inproceedings{lin2011linearized, 22 | Author = {Lin, Zhouchen and Liu, Risheng and Su, Zhixun}, 23 | Booktitle = {Advances in neural information processing systems}, 24 | Date-Added = {2014-08-12 01:19:07 +0000}, 25 | Date-Modified = {2014-08-12 01:19:07 +0000}, 26 | Pages = {612--620}, 27 | Title = {Linearized alternating direction method with adaptive penalty for low-rank representation}, 28 | Year = {2011}} 29 | 30 | @article{candes2011robust, 31 | Author = {Cand{\`e}s, Emmanuel J and Li, Xiaodong and Ma, Yi and Wright, John}, 32 | Date-Added = {2014-08-12 01:18:34 +0000}, 33 | Date-Modified = {2014-08-12 01:18:34 +0000}, 34 | Journal = {Journal of the ACM (JACM)}, 35 | Number = {3}, 36 | Pages = {11}, 37 | Publisher = {ACM}, 38 | Title = {Robust principal component analysis?}, 39 | Volume = {58}, 40 | Year = {2011}} 41 | -------------------------------------------------------------------------------- /libs/RPCAKit/rpca_fro.m: -------------------------------------------------------------------------------- 1 | function [ A ] = rpca_fro( X, lambda ) 2 | %% Solves the following 3 | % 4 | % min || A ||_* + lambda/2 * || N ||_F^2 5 | % s.t. X = A + N 6 | % 7 | % Created by Stephen Tierney 8 | % stierney@csu.edu.au 9 | % 10 | 11 | max_iterations = 100; 12 | 13 | func_vals = zeros(max_iterations, 1); 14 | 15 | A = zeros(size(X)); 16 | 17 | N = zeros(size(X)); 18 | 19 | Y = zeros(size(X)); 20 | 21 | mu = 0.5; 22 | mu_max = 100; 23 | 24 | gamma_0 = 1.1; 25 | 26 | normfX = norm(X,'fro'); 27 | 28 | tol_1 = 1*10^-2; 29 | tol_2 = 1*10^-4; 30 | 31 | for k = 1 : max_iterations 32 | 33 | A_prev = A; 34 | N_prev = N; 35 | 36 | % Solve for A 37 | 38 | V = X - N + 1/mu * Y; 39 | 40 | [A, s] = solve_nn(V, 1/mu); 41 | 42 | % Solve for N 43 | 44 | V = X - A + 1/mu * Y; 45 | 46 | N = solve_l2(V, lambda/mu); 47 | 48 | % Update Y 49 | 50 | Y = Y + mu*(X - A - N); 51 | 52 | if (mu * max(norm(A - A_prev,'fro'), norm(N - N_prev))/norm(X,'fro') < 1*10^-3) 53 | gamma = gamma_0; 54 | else 55 | gamma = 1; 56 | end 57 | 58 | mu = min(mu_max, gamma * mu); 59 | 60 | % Check convergence 61 | 62 | func_vals(k) = sum(s) + lambda*0.5*norm(N, 'fro')^2; 63 | 64 | if ( norm(X - A - N, 'fro') < tol_1 ... 65 | && (mu * max([ norm(A - A_prev,'fro'), norm(N - N_prev, 'fro')]) / normfX < tol_2)) 66 | break; 67 | end 68 | 69 | 70 | end 71 | 72 | end -------------------------------------------------------------------------------- /lrr/lrr_relaxed_lin_acc.m: -------------------------------------------------------------------------------- 1 | function [ Z ] = lrr_relaxed_lin_acc( X, lambda ) 2 | %% Solves the following 3 | % 4 | % min || X - XZ ||_F^2 + lambda || Z ||_* 5 | % 6 | % by accelerated gradient descent 7 | % 8 | % Created by Stephen Tierney 9 | % stierney@csu.edu.au 10 | % 11 | 12 | max_iterations = 100; 13 | 14 | func_vals = zeros(max_iterations, 1); 15 | previous_func_val = Inf; 16 | 17 | n = size(X, 2); 18 | 19 | Z = zeros(n); 20 | J = zeros(n); 21 | 22 | rho = 1; 23 | gamma = 1.1; 24 | 25 | alpha = 1; 26 | 27 | for k = 1 : max_iterations 28 | 29 | Z_prev = Z; 30 | alpha_prev = alpha; 31 | 32 | searching = true; 33 | while( searching ) 34 | partial = -X'*X + X'*X*J; 35 | 36 | V = J - 1/rho * partial; 37 | 38 | [Z, s] = solve_nn(V, lambda/rho); 39 | 40 | func_vals(k) = 0.5*norm(X - X*Z, 'fro')^2 + lambda * sum(s); 41 | 42 | approx = 0.5*norm(X - X*J, 'fro')^2 + sum(sum((Z - J).*partial)) + 0.5*rho*norm(Z - J, 'fro')^2 + lambda * sum(s); 43 | 44 | if ( func_vals(k) > approx ) 45 | rho = gamma * rho; 46 | else 47 | searching = false; 48 | end 49 | end 50 | 51 | alpha = (1 + sqrt(1 + 4*alpha_prev^2)) / 2; 52 | 53 | J = Z + ((alpha_prev - 1)/alpha)*(Z - Z_prev); 54 | 55 | if ( abs(func_vals(k) - previous_func_val) <= 1*10^-6 ) 56 | break; 57 | else 58 | previous_func_val = func_vals(k); 59 | end 60 | 61 | end 62 | 63 | end 64 | 65 | -------------------------------------------------------------------------------- /libs/RPCAKit/rpca_l1.m: -------------------------------------------------------------------------------- 1 | function [ A ] = rpca_l1( X, lambda ) 2 | %% Solves the following 3 | % 4 | % min || A ||_* + lambda * || N ||_1 5 | % s.t. X = A + N 6 | % 7 | % Created by Stephen Tierney 8 | % stierney@csu.edu.au 9 | % 10 | 11 | max_iterations = 100; 12 | 13 | func_vals = zeros(max_iterations, 1); 14 | 15 | A = zeros(size(X)); 16 | 17 | N = zeros(size(X)); 18 | 19 | Y = zeros(size(X)); 20 | 21 | mu = 0.5; 22 | mu_max = 100; 23 | 24 | gamma_0 = 1.1; 25 | 26 | normfX = norm(X,'fro'); 27 | 28 | tol_1 = 1*10^-2; 29 | tol_2 = 1*10^-4; 30 | 31 | for k = 1 : max_iterations 32 | 33 | A_prev = A; 34 | N_prev = N; 35 | 36 | % Solve for A 37 | 38 | V = X - N + 1/mu * Y; 39 | 40 | [A, s] = solve_nn(V, 1/mu); 41 | 42 | % Solve for N 43 | 44 | V = X - A + 1/mu * Y; 45 | 46 | N = solve_l1(V, lambda/mu); 47 | 48 | % Update Y 49 | 50 | Y = Y + mu*(X - A - N); 51 | 52 | if (mu * max(norm(A - A_prev,'fro'), norm(N - N_prev))/norm(X,'fro') < 1*10^-3) 53 | gamma = gamma_0; 54 | else 55 | gamma = 1; 56 | end 57 | 58 | mu = min(mu_max, gamma * mu); 59 | 60 | % Check convergence 61 | 62 | func_vals(k) = sum(s) + lambda*norm_l1(N); 63 | 64 | % Check convergence 65 | 66 | func_vals(k) = sum(s) + lambda*0.5*norm(N, 'fro')^2; 67 | 68 | if ( norm(X - A - N, 'fro') < tol_1 ... 69 | && (mu * max([ norm(A - A_prev,'fro'), norm(N - N_prev, 'fro')]) / normfX < tol_2)) 70 | break; 71 | end 72 | 73 | end 74 | 75 | end -------------------------------------------------------------------------------- /ssc/ssc_relaxed_lin_acc.m: -------------------------------------------------------------------------------- 1 | function [ Z ] = ssc_relaxed_lin_acc( X, lambda ) 2 | %% Solves the following 3 | % 4 | % min || X - XZ ||_F^2 + lambda || Z ||_1 5 | % 6 | % by accelerated gradient descent 7 | % 8 | % Created by Stephen Tierney 9 | % stierney@csu.edu.au 10 | % 11 | 12 | max_iterations = 100; 13 | 14 | func_vals = zeros(max_iterations, 1); 15 | previous_func_val = Inf; 16 | 17 | n = size(X, 2); 18 | 19 | Z = zeros(n); 20 | J = zeros(n); 21 | 22 | rho = 1; 23 | gamma = 1.1; 24 | 25 | alpha = 1; 26 | 27 | for k = 1 : max_iterations 28 | 29 | Z_prev = Z; 30 | alpha_prev = alpha; 31 | 32 | searching = true; 33 | while( searching ) 34 | partial = -X'*X + X'*X*J; 35 | 36 | V = J - 1/rho * partial; 37 | 38 | Z = solve_l1(V, lambda/rho); 39 | 40 | Z(logical(eye(size(Z)))) = 0; 41 | 42 | func_vals(k, 1) = lambda*norm_l1(Z) + 1/2 *norm(X - X*Z, 'fro')^2; 43 | 44 | approx = 0.5*norm(X - X*J, 'fro')^2 + sum(sum((Z - J).*partial)) + 0.5*rho*norm(Z - J, 'fro')^2 + lambda*norm_l1(Z); 45 | 46 | if ( func_vals(k, 1) > approx ) 47 | rho = gamma * rho; 48 | else 49 | searching = false; 50 | end 51 | end 52 | 53 | alpha = (1 + sqrt(1 + 4*alpha_prev^2)) / 2; 54 | 55 | J = Z + ((alpha_prev - 1)/alpha)*(Z - Z_prev); 56 | 57 | 58 | if ( abs(func_vals(k) - previous_func_val) <= 1*10^-6 ) 59 | break; 60 | else 61 | previous_func_val = func_vals(k); 62 | end 63 | 64 | end 65 | 66 | end 67 | 68 | -------------------------------------------------------------------------------- /libs/RPCAKit/rpca_l1l2.m: -------------------------------------------------------------------------------- 1 | function [ A ] = rpca_l1l2( X, lambda ) 2 | %% Solves the following 3 | % 4 | % min || A ||_* + lambda * || N ||_1/2 5 | % s.t. X = A + N 6 | % 7 | % Created by Stephen Tierney 8 | % stierney@csu.edu.au 9 | % 10 | 11 | max_iterations = 100; 12 | 13 | func_vals = zeros(max_iterations, 1); 14 | 15 | A = zeros(size(X)); 16 | 17 | N = zeros(size(X)); 18 | 19 | Y = zeros(size(X)); 20 | 21 | mu = 0.5; 22 | mu_max = 100; 23 | 24 | gamma_0 = 1.1; 25 | 26 | normfX = norm(X,'fro'); 27 | 28 | tol_1 = 1*10^-2; 29 | tol_2 = 1*10^-4; 30 | 31 | for k = 1 : max_iterations 32 | 33 | A_prev = A; 34 | N_prev = N; 35 | 36 | % Solve for A 37 | 38 | V = X - N + 1/mu * Y; 39 | 40 | [A, s] = solve_nn(V, 1/mu); 41 | 42 | % Solve for N 43 | 44 | V = X - A + 1/mu * Y; 45 | 46 | N = solve_l1l2(V, lambda/mu); 47 | 48 | % Update Y 49 | 50 | Y = Y + mu*(X - A - N); 51 | 52 | if (mu * max(norm(A - A_prev,'fro'), norm(N - N_prev))/norm(X,'fro') < 1*10^-3) 53 | gamma = gamma_0; 54 | else 55 | gamma = 1; 56 | end 57 | 58 | mu = min(mu_max, gamma * mu); 59 | 60 | % Check convergence 61 | 62 | func_vals(k) = sum(s) + lambda*norm_l1l2(N); 63 | 64 | % Check convergence 65 | 66 | func_vals(k) = sum(s) + lambda*0.5*norm(N, 'fro')^2; 67 | 68 | if ( norm(X - A - N, 'fro') < tol_1 ... 69 | && (mu * max([ norm(A - A_prev,'fro'), norm(N - N_prev, 'fro')]) / normfX < tol_2)) 70 | break; 71 | end 72 | 73 | end 74 | 75 | end -------------------------------------------------------------------------------- /libs/ncut/mex_w_times_x_symmetric.cpp: -------------------------------------------------------------------------------- 1 | /*================================================================ 2 | * mex_w_times_x_symmetric.c = used by ncuthard2.m in eigensolver. 3 | * 4 | * Examples: 5 | * mex_w_times_x_c_symmetric(x,triu(A)) = A*x; 6 | * A is sparse and symmetric, but x is full 7 | * 8 | * Timothee Cour, Oct 12, 2003. 9 | 10 | % test sequence: 11 | m=100; 12 | n=50; 13 | x=rand(n,1); 14 | A=sprand(m,n,0.01); 15 | 16 | y2 = mex_w_times_x_c_symmetric(x,triu(A)); 17 | y1=A*x; 18 | max(abs(y1-y2)) 19 | *=================================================================*/ 20 | 21 | # include "math.h" 22 | # include "mex.h" 23 | # include "a_times_b_cmplx.cpp" 24 | /*# include "a_times_b.c"*/ 25 | 26 | 27 | void mexFunction( 28 | int nargout, 29 | mxArray *out[], 30 | int nargin, 31 | const mxArray *in[] 32 | ) 33 | { 34 | int np, nc; 35 | mwIndex*ir, *jc; 36 | double *x, *y, *pr; 37 | 38 | if (nargin < 2) {//voir 39 | mexErrMsgTxt("Four input arguments required !"); 40 | } 41 | if (nargout>1) { 42 | mexErrMsgTxt("Too many output arguments."); 43 | } 44 | 45 | x = mxGetPr(in[0]); 46 | pr = mxGetPr(in[1]); 47 | ir = mxGetIr(in[1]); 48 | jc = mxGetJc(in[1]); 49 | 50 | np = mxGetM(in[1]); 51 | nc = mxGetN(in[1]); 52 | 53 | out[0] = mxCreateDoubleMatrix(np,1,mxREAL); 54 | y = mxGetPr(out[0]); 55 | 56 | CSRsymm_VecMult_CAB_double(np,nc,pr,ir,jc,x,y); 57 | } 58 | -------------------------------------------------------------------------------- /lrr/lrr_exact_l1.m: -------------------------------------------------------------------------------- 1 | function [ Z ] = lrr_exact_l1( X, lambda ) 2 | %% Solves the following 3 | % 4 | % min || E ||_1 + lambda || Z ||_* 5 | % s.t. X = XZ + E 6 | % 7 | % Created by Stephen Tierney 8 | % stierney@csu.edu.au 9 | % 10 | 11 | max_iterations = 200; 12 | 13 | func_vals = zeros(max_iterations, 1); 14 | 15 | Z = zeros(size(X, 2)); 16 | 17 | E = zeros(size(X)); 18 | 19 | Y = zeros(size(X)); 20 | 21 | mu = 0.1; 22 | mu_max = 1; 23 | 24 | normfX = norm(X,'fro'); 25 | rho = (norm(X,2)^2) * 1.2; 26 | 27 | gamma_0 = 1.1; 28 | 29 | tol_1 = 1*10^-2; 30 | tol_2 = 1*10^-4; 31 | 32 | for k = 1 : max_iterations 33 | 34 | Z_prev = Z; 35 | E_prev = E; 36 | 37 | % Solve for Z 38 | 39 | partial = mu*X'*(X*Z - (X - E - 1/mu * Y)); 40 | 41 | V = Z - 1/rho * partial; 42 | 43 | [Z, s] = solve_nn(V, lambda/rho); 44 | 45 | % Solve for E 46 | 47 | V = X - X*Z - 1/mu * Y; 48 | 49 | E = solve_l1(V, 1/mu); 50 | 51 | % Update Y 52 | 53 | Y = Y + mu*(X*Z -X + E); 54 | 55 | if (mu * max(sqrt(rho) * norm(Z - Z_prev,'fro'), norm(E - E_prev))/norm(X,'fro') < tol_2) 56 | gamma = gamma_0; 57 | else 58 | gamma = 1; 59 | end 60 | 61 | mu = min(mu_max, gamma * mu); 62 | 63 | % Check convergence 64 | 65 | func_vals(k) = norm_l1(E) + lambda * sum(s); 66 | 67 | if ( norm(X*Z - X + E, 'fro')/normfX < tol_1 ... 68 | && (mu * sqrt(rho) * max([ norm(Z - Z_prev,'fro'), norm(E - E_prev, 'fro')]/normfX) < tol_2)) 69 | break; 70 | end 71 | 72 | end 73 | 74 | end 75 | 76 | -------------------------------------------------------------------------------- /lrr/lrr_exact_l1l2.m: -------------------------------------------------------------------------------- 1 | function [ Z ] = lrr_exact_l1l2( X, lambda ) 2 | %% Solves the following 3 | % 4 | % min || E ||_1/2 + lambda || Z ||_* 5 | % s.t. X = XZ + E 6 | % 7 | % Created by Stephen Tierney 8 | % stierney@csu.edu.au 9 | % 10 | 11 | max_iterations = 200; 12 | 13 | func_vals = zeros(max_iterations, 1); 14 | 15 | Z = zeros(size(X, 2)); 16 | 17 | E = zeros(size(X)); 18 | 19 | Y = zeros(size(X)); 20 | 21 | mu = 0.1; 22 | mu_max = 1; 23 | 24 | normfX = norm(X,'fro'); 25 | rho = (norm(X,2)^2) * 1.2; 26 | 27 | gamma_0 = 1.1; 28 | 29 | tol_1 = 1*10^-2; 30 | tol_2 = 1*10^-4; 31 | 32 | for k = 1 : max_iterations 33 | 34 | Z_prev = Z; 35 | E_prev = E; 36 | 37 | % Solve for Z 38 | 39 | partial = mu*X'*(X*Z - (X - E - 1/mu * Y)); 40 | 41 | V = Z - 1/rho * partial; 42 | 43 | [Z, s] = solve_nn(V, lambda/rho); 44 | 45 | % Solve for E 46 | 47 | V = X - X*Z - 1/mu * Y; 48 | 49 | E = solve_l1l2(V, 1/mu); 50 | 51 | % Update Y 52 | 53 | Y = Y + mu*(X*Z -X + E); 54 | 55 | if (mu * max(sqrt(rho) * norm(Z - Z_prev,'fro'), norm(E - E_prev))/norm(X,'fro') < tol_2) 56 | gamma = gamma_0; 57 | else 58 | gamma = 1; 59 | end 60 | 61 | mu = min(mu_max, gamma * mu); 62 | 63 | % Check convergence 64 | 65 | func_vals(k) = norm_l1l2(E) + lambda * sum(s); 66 | 67 | if ( norm(X*Z - X + E, 'fro')/normfX < tol_1 ... 68 | && (mu * sqrt(rho) * max([ norm(Z - Z_prev,'fro'), norm(E - E_prev, 'fro')]/normfX) < tol_2)) 69 | break; 70 | end 71 | 72 | end 73 | 74 | end 75 | 76 | -------------------------------------------------------------------------------- /lrr/lrr_exact_fro.m: -------------------------------------------------------------------------------- 1 | function [ Z ] = lrr_exact_fro( X, lambda ) 2 | %% Solves the following 3 | % 4 | % min || E ||_F^2 + lambda || Z ||_* 5 | % s.t. X = XZ + E 6 | % 7 | % Created by Stephen Tierney 8 | % stierney@csu.edu.au 9 | % 10 | 11 | max_iterations = 200; 12 | 13 | func_vals = zeros(max_iterations, 1); 14 | 15 | Z = zeros(size(X, 2)); 16 | 17 | E = zeros(size(X)); 18 | 19 | Y = zeros(size(X)); 20 | 21 | mu = 0.1; 22 | mu_max = 1; 23 | 24 | normfX = norm(X,'fro'); 25 | rho = (norm(X,2)^2) * 1.2; 26 | 27 | gamma_0 = 1.1; 28 | 29 | tol_1 = 1*10^-2; 30 | tol_2 = 1*10^-4; 31 | 32 | for k = 1 : max_iterations 33 | 34 | Z_prev = Z; 35 | E_prev = E; 36 | 37 | % Solve for Z 38 | 39 | partial = mu*X'*(X*Z - (X - E - 1/mu * Y)); 40 | 41 | V = Z - 1/rho * partial; 42 | 43 | [Z, s] = solve_nn(V, lambda/rho); 44 | 45 | % Solve for E 46 | 47 | V = X - X*Z - 1/mu * Y; 48 | 49 | E = solve_l2(V, 1/mu); 50 | 51 | % Update Y 52 | 53 | Y = Y + mu*(X*Z -X + E); 54 | 55 | if (mu * max(sqrt(rho) * norm(Z - Z_prev,'fro'), norm(E - E_prev))/norm(X,'fro') < tol_2) 56 | gamma = gamma_0; 57 | else 58 | gamma = 1; 59 | end 60 | 61 | mu = min(mu_max, gamma * mu); 62 | 63 | % Check convergence 64 | 65 | func_vals(k) = 0.5*norm(E, 'fro')^2 + lambda * sum(s); 66 | 67 | if ( norm(X*Z - X + E, 'fro')/normfX < tol_1 ... 68 | && (mu * sqrt(rho) * max([ norm(Z - Z_prev,'fro'), norm(E - E_prev, 'fro')]/normfX) < tol_2)) 69 | break; 70 | end 71 | 72 | end 73 | 74 | end 75 | 76 | -------------------------------------------------------------------------------- /ssc/ssc_exact_l1.m: -------------------------------------------------------------------------------- 1 | function [ Z ] = ssc_exact_l1( X, lambda ) 2 | %% Solves the following 3 | % 4 | % min || E ||_1 + lambda || Z ||_1 5 | % s.t. X = XZ + E 6 | % 7 | % Created by Stephen Tierney 8 | % stierney@csu.edu.au 9 | % 10 | 11 | max_iterations = 200; 12 | 13 | func_vals = zeros(max_iterations, 1); 14 | 15 | Z = zeros(size(X, 2)); 16 | 17 | E = zeros(size(X)); 18 | 19 | Y = zeros(size(X)); 20 | 21 | mu = 0.1; 22 | mu_max = 1; 23 | 24 | normfX = norm(X,'fro'); 25 | rho = (norm(X,2)^2) * 1.2; 26 | 27 | gamma_0 = 1.1; 28 | 29 | tol_1 = 1*10^-2; 30 | tol_2 = 1*10^-4; 31 | 32 | for k = 1 : max_iterations 33 | 34 | Z_prev = Z; 35 | E_prev = E; 36 | 37 | % Solve for Z 38 | 39 | partial = mu*X'*(X*Z - (X - E - 1/mu * Y)); 40 | 41 | V = Z - 1/rho * partial; 42 | 43 | Z = solve_l1(V, lambda/rho); 44 | 45 | Z(logical(eye(size(Z)))) = 0; 46 | 47 | % Solve for E 48 | 49 | V = X - X*Z - 1/mu * Y; 50 | 51 | E = solve_l1(V, 1/mu); 52 | 53 | % Update Y 54 | 55 | Y = Y + mu*(X*Z -X + E); 56 | 57 | if (mu * max(sqrt(rho) * norm(Z - Z_prev,'fro'), norm(E - E_prev))/norm(X,'fro') < tol_2) 58 | gamma = gamma_0; 59 | else 60 | gamma = 1; 61 | end 62 | 63 | mu = min(mu_max, gamma * mu); 64 | 65 | % Check convergence 66 | 67 | func_vals(k) = norm_l1(E) + lambda*norm_l1(Z); 68 | 69 | if ( norm(X*Z - X + E, 'fro')/normfX < tol_1 ... 70 | && (mu * sqrt(rho) * max([ norm(Z - Z_prev,'fro'), norm(E - E_prev, 'fro')]/normfX) < tol_2)) 71 | break; 72 | end 73 | 74 | end 75 | 76 | end 77 | 78 | -------------------------------------------------------------------------------- /ssc/ssc_exact_l1l2.m: -------------------------------------------------------------------------------- 1 | function [ Z ] = ssc_exact_l1l2( X, lambda ) 2 | %% Solves the following 3 | % 4 | % min || E ||_1/2 + lambda || Z ||_1 5 | % s.t. X = XZ + E 6 | % 7 | % Created by Stephen Tierney 8 | % stierney@csu.edu.au 9 | % 10 | 11 | max_iterations = 200; 12 | 13 | func_vals = zeros(max_iterations, 1); 14 | 15 | Z = zeros(size(X, 2)); 16 | 17 | E = zeros(size(X)); 18 | 19 | Y = zeros(size(X)); 20 | 21 | mu = 0.1; 22 | mu_max = 1; 23 | 24 | normfX = norm(X,'fro'); 25 | rho = (norm(X,2)^2) * 1.2; 26 | 27 | gamma_0 = 1.1; 28 | 29 | tol_1 = 1*10^-2; 30 | tol_2 = 1*10^-4; 31 | 32 | for k = 1 : max_iterations 33 | 34 | Z_prev = Z; 35 | E_prev = E; 36 | 37 | % Solve for Z 38 | 39 | partial = mu*X'*(X*Z - (X - E - 1/mu * Y)); 40 | 41 | V = Z - 1/rho * partial; 42 | 43 | Z = solve_l1(V, lambda/rho); 44 | 45 | Z(logical(eye(size(Z)))) = 0; 46 | 47 | % Solve for E 48 | 49 | V = X - X*Z - 1/mu * Y; 50 | 51 | E = solve_l1l2(V, 1/mu); 52 | 53 | % Update Y 54 | 55 | Y = Y + mu*(X*Z -X + E); 56 | 57 | if (mu * max(sqrt(rho) * norm(Z - Z_prev,'fro'), norm(E - E_prev))/norm(X,'fro') < tol_2) 58 | gamma = gamma_0; 59 | else 60 | gamma = 1; 61 | end 62 | 63 | mu = min(mu_max, gamma * mu); 64 | 65 | % Check convergence 66 | 67 | func_vals(k) = norm_l1l2(E) + lambda*norm_l1(Z); 68 | 69 | if ( norm(X*Z - X + E, 'fro')/normfX < tol_1 ... 70 | && (mu * sqrt(rho) * max([ norm(Z - Z_prev,'fro'), norm(E - E_prev, 'fro')]/normfX) < tol_2)) 71 | break; 72 | end 73 | 74 | end 75 | 76 | end 77 | 78 | -------------------------------------------------------------------------------- /ssc/ssc_exact_fro.m: -------------------------------------------------------------------------------- 1 | function [ Z ] = ssc_exact_fro( X, lambda ) 2 | %% Solves the following 3 | % 4 | % min || E ||_F^2 + lambda || Z ||_1 5 | % s.t. X = XZ + E 6 | % 7 | % Created by Stephen Tierney 8 | % stierney@csu.edu.au 9 | % 10 | 11 | max_iterations = 200; 12 | 13 | func_vals = zeros(max_iterations, 1); 14 | 15 | Z = zeros(size(X, 2)); 16 | 17 | E = zeros(size(X)); 18 | 19 | Y = zeros(size(X)); 20 | 21 | mu = 0.1; 22 | mu_max = 1; 23 | 24 | normfX = norm(X,'fro'); 25 | rho = (norm(X,2)^2) * 1.2; 26 | 27 | gamma_0 = 1.1; 28 | 29 | tol_1 = 1*10^-2; 30 | tol_2 = 1*10^-4; 31 | 32 | for k = 1 : max_iterations 33 | 34 | Z_prev = Z; 35 | E_prev = E; 36 | 37 | % Solve for Z 38 | 39 | partial = mu*X'*(X*Z - (X - E - 1/mu * Y)); 40 | 41 | V = Z - 1/rho * partial; 42 | 43 | Z = solve_l1(V, lambda/rho); 44 | 45 | Z(logical(eye(size(Z)))) = 0; 46 | 47 | % Solve for E 48 | 49 | V = X - X*Z - 1/mu * Y; 50 | 51 | E = solve_l2(V, 1/mu); 52 | 53 | % Update Y 54 | 55 | Y = Y + mu*(X*Z -X + E); 56 | 57 | if (mu * max(sqrt(rho) * norm(Z - Z_prev,'fro'), norm(E - E_prev))/norm(X,'fro') < tol_2) 58 | gamma = gamma_0; 59 | else 60 | gamma = 1; 61 | end 62 | 63 | mu = min(mu_max, gamma * mu); 64 | 65 | % Check convergence 66 | 67 | func_vals(k) = 0.5*norm(E, 'fro')^2 + lambda*norm_l1(Z); 68 | 69 | if ( norm(X*Z - X + E, 'fro')/normfX < tol_1 ... 70 | && (mu * sqrt(rho) * max([ norm(Z - Z_prev,'fro'), norm(E - E_prev, 'fro')]/normfX) < tol_2)) 71 | break; 72 | end 73 | 74 | end 75 | 76 | end 77 | 78 | -------------------------------------------------------------------------------- /libs/ncut/demoNcutImage.m: -------------------------------------------------------------------------------- 1 | function demoNcutImage; 2 | % demoNcutImage 3 | % 4 | % demo for NcutImage 5 | % also initialize matlab paths to subfolders 6 | % Timothee Cour, Stella Yu, Jianbo Shi, 2004. 7 | 8 | disp('Ncut Image Segmentation demo'); 9 | 10 | %% read image, change color image to brightness image, resize to 160x160 11 | I = imread_ncut('jpg_images/3.jpg',160,160); 12 | 13 | %% display the image 14 | figure(1);clf; imagesc(I);colormap(gray);axis off; 15 | disp('This is the input image to segment, press Enter to continue...'); 16 | pause; 17 | 18 | %% compute the edges imageEdges, the similarity matrix W based on 19 | %% Intervening Contours, the Ncut eigenvectors and discrete segmentation 20 | nbSegments = 5; 21 | disp('computing Ncut eigenvectors ...'); 22 | tic; 23 | [SegLabel,NcutDiscrete,NcutEigenvectors,NcutEigenvalues,W,imageEdges]= NcutImage(I,nbSegments); 24 | disp(['The computation took ' num2str(toc) ' seconds on the ' num2str(size(I,1)) 'x' num2str(size(I,2)) ' image']); 25 | 26 | 27 | %% display the edges 28 | figure(2);clf; imagesc(imageEdges); axis off 29 | disp('This is the edges computed, press Enter to continue...'); 30 | pause; 31 | 32 | %% display the segmentation 33 | figure(3);clf 34 | bw = edge(SegLabel,0.01); 35 | J1=showmask(I,imdilate(bw,ones(2,2))); imagesc(J1);axis off 36 | disp('This is the segmentation, press Enter to continue...'); 37 | pause; 38 | 39 | %% display Ncut eigenvectors 40 | figure(4);clf;set(gcf,'Position',[100,500,200*(nbSegments+1),200]); 41 | [nr,nc,nb] = size(I); 42 | for i=1:nbSegments 43 | subplot(1,nbSegments,i); 44 | imagesc(reshape(NcutEigenvectors(:,i) , nr,nc));axis('image');axis off; 45 | end 46 | disp('This is the Ncut eigenvectors...'); 47 | disp('The demo is finished.'); 48 | 49 | -------------------------------------------------------------------------------- /cass/cass_relaxed.m: -------------------------------------------------------------------------------- 1 | function [ Z ] = cass_relaxed( X, lambda ) 2 | %% Solves the following 3 | % 4 | % min 1/2 || X - XZ ||_F^2 + \sum_i^N lambda || X diag(Z(:,i) ||_* 5 | % 6 | % via ADMAP. Since each col of Z is independant we handle them one at a time. 7 | % 8 | % Created by Stephen Tierney 9 | % stierney@csu.edu.au 10 | % 11 | 12 | max_iterations = 200; 13 | 14 | N = size(X, 2); 15 | 16 | Z = zeros(N); 17 | 18 | mu_max = 1*10^1; 19 | 20 | gamma_0 = 1.1; 21 | 22 | tol_1 = 1*10^-2; 23 | tol_2 = 1*10^-4; 24 | 25 | for j = 1 : N 26 | 27 | func_vals = zeros(max_iterations, 1); 28 | 29 | mu = 0.1; 30 | 31 | z = zeros(N-1, 1); 32 | J = zeros(size(X,1), N-1); 33 | Y = zeros(size(X,1), N-1); 34 | 35 | sub_X = X(:, 1:end ~= j); 36 | 37 | XtX = sub_X' * sub_X; 38 | diagXtX = diag(diag(XtX)); 39 | 40 | for k = 1 : max_iterations 41 | 42 | z_prev = z; 43 | J_prev = J; 44 | 45 | % Update J 46 | [J, s] = solve_nn(sub_X * diag(z) - 1/mu * Y, lambda/mu); 47 | 48 | % Update z 49 | z = (XtX + mu * diagXtX) \ (sub_X' * X(:,j) + diag(sub_X'*(Y + mu * J)) ); 50 | 51 | % Update Y 52 | Y = Y + mu * (J - sub_X * diag(z)); 53 | 54 | if max(max(abs(z - z_prev)), max(max(abs(J - J_prev))) ) > tol_2 55 | gamma = gamma_0 ; 56 | else 57 | gamma = 1 ; 58 | end 59 | 60 | mu = min(mu_max, gamma * mu); 61 | 62 | % Check convergence 63 | 64 | func_vals(k) = 0.5*norm(X(:,j) - sub_X * z, 'fro')^2 + lambda*sum(s); 65 | 66 | if ( max(max(abs(J - sub_X * diag(z)))) < tol_1... 67 | && max(max(abs(J - J_prev))) < tol_1... 68 | && max(max(abs(z - z_prev))) < tol_1 ) 69 | break; 70 | end 71 | 72 | end 73 | 74 | Z(1:end ~= j,j) = z; 75 | end 76 | 77 | 78 | end 79 | 80 | -------------------------------------------------------------------------------- /osc/osc_relaxed_cvpr.m: -------------------------------------------------------------------------------- 1 | function [ Z ] = osc_relaxed_cvpr( X, lambda_1, lambda_2, diagconstraint) 2 | %% Solves the following 3 | % 4 | % min || X - XZ ||_F^2 + lambda_1 || Z ||_1 + lambda_2 || Z R ||_1/2 5 | % 6 | % via ADM 7 | % 8 | % Created by Stephen Tierney 9 | % stierney@csu.edu.au 10 | % 11 | 12 | if (~exist('diagconstraint','var')) 13 | diagconstraint = 0; 14 | end 15 | 16 | max_iterations = 200; 17 | 18 | func_vals = zeros(max_iterations,1); 19 | 20 | [~, xn, ~] = size(X); 21 | 22 | S = zeros(xn, xn); % S = Z 23 | R = (triu(ones(xn,xn-1),1) - triu(ones(xn, xn-1))) + (triu(ones(xn, xn-1),-1)-triu(ones(xn, xn-1))); 24 | R = sparse(R); 25 | 26 | U = zeros(xn, xn-1); 27 | 28 | G = zeros(xn, xn); 29 | F = zeros(xn, xn-1); 30 | 31 | Z = zeros(xn, xn); 32 | 33 | gamma_1 = 1; 34 | gamma_2 = 1; 35 | p = 1.1; 36 | 37 | tol = 1*10^-3; 38 | 39 | for k = 1 : max_iterations 40 | 41 | % Update Z 42 | V = S - (G/gamma_1); 43 | 44 | Z = solve_l1(V, lambda_1/gamma_1); 45 | 46 | % Set Z diag to 0 47 | if (diagconstraint) 48 | Z(logical(eye(size(Z)))) = 0; 49 | end 50 | 51 | % Update S 52 | A = X'*X + gamma_1*speye(xn,xn); 53 | B = gamma_2*(R*R'); 54 | C = -(X'*X + gamma_2*U*R' + gamma_1*Z + G + F*R'); 55 | 56 | S = lyap(A, B, C); 57 | 58 | % Update U 59 | V = S*R - (1/gamma_2)*F; 60 | 61 | U = solve_l1l2(V, lambda_2/gamma_2); 62 | 63 | % Update G, F 64 | G = G + gamma_1 * (Z - S); 65 | F = F + gamma_2 * (U - S*R); 66 | 67 | % Update gamma_1, gamma_2 68 | 69 | gamma_1 = p * gamma_1; 70 | gamma_2 = p * gamma_2; 71 | 72 | % Check convergence 73 | func_vals(k) = .5 * norm(X - X*Z,'fro')^2 + lambda_1*norm(Z,1) +lambda_2*norm_l1l2(Z*R); 74 | 75 | if k > 1 76 | if func_vals(k) < tol 77 | break 78 | end 79 | end 80 | 81 | if k > 100 82 | if func_vals(k) < tol || func_vals(k-1) == func_vals(k) ... 83 | || func_vals(k-1) - func_vals(k) < tol 84 | break 85 | end 86 | end 87 | 88 | 89 | end 90 | 91 | end -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | SubKit 2 | ====== 3 | 4 | MATLAB implementations of Subspace Clustering Algorithms. 5 | 6 | Subkit currently implements the following algorithms: 7 | 8 | - [Sparse Subspace Clustering][6] 9 | - [Low-Rank Subspace Clustering][4] 10 | - [Robust and Effcient Subspace Segmentation via Least Squares Regression][7] 11 | - [Correlation Adaptive Subspace Segmentation by Trace Lasso][9] 12 | 13 | Spatial Penalised Variants: 14 | - [Spatial Subspace Clustering] [5] 15 | - [Ordered Subspace Clustering][3] 16 | - [Low Rank Sequential Subspace Clustering][10] 17 | 18 | Multi-task and Collaborative Variants: 19 | - [Multi-task Low-rank Affinity Pursuit for Image Segmenation][8] 20 | 21 | ## Citing 22 | 23 | Cite "Segmentation of Subspaces in Sequential Data" by Stephen Tierney, Yi Guo and Junbin Gao 24 | 25 | Please lso provide a direct link to this webpage somewhere in your paper (https://github.com/sjtrny/SubKit) 26 | 27 | @article{tierney2015segmentation, 28 | title={Segmentation of Subspaces in Sequential Data}, 29 | author={Tierney, Stephen and Guo, Yi and Gao, Junbin}, 30 | journal={arXiv preprint arXiv:1504.04090}, 31 | year={2015} 32 | } 33 | 34 | ## Acknowledgement 35 | 36 | The research project is supported by the Australian Research Council (ARC) through the grant DP130100364. 37 | 38 | ## Included Libraries 39 | 40 | - [NCut][2] 41 | 42 | [1]: http://sjtrny.com/publications/ 43 | [2]: http://www.cis.upenn.edu/~jshi/software/ 44 | [3]: http://www.cv-foundation.org/openaccess/content_cvpr_2014/papers/Tierney_Subspace_Clustering_for_2014_CVPR_paper.pdf 45 | [4]: http://machinelearning.wustl.edu/mlpapers/paper_files/icml2010_LiuLY10.pdf 46 | [5]: http://sdiwc.net/digital-library/web-admin/upload-pdf/00000406.pdf 47 | [6]: http://vision.jhu.edu/assets/SSC-CVPR09-Ehsan.pdf 48 | [7]: http://arxiv.org/abs/1404.6736 49 | [8]: http://research.microsoft.com/en-us/um/people/jingdw/pubs/iccv11-segmentation.pdf 50 | [9]: http://www.cis.pku.edu.cn/faculty/vision/zlin/Publications/2013-ICCV-CASS.pdf 51 | [10]: http://ieeexplore.ieee.org/xpl/articleDetails.jsp?arnumber=7280328 52 | -------------------------------------------------------------------------------- /spatsc/spatsc_relaxed_cvpr.m: -------------------------------------------------------------------------------- 1 | function [ Z ] = spatsc_relaxed_cvpr( X, lambda_1, lambda_2, diagconstraint) 2 | %% Solves the following 3 | % 4 | % min || X - XZ ||_F^2 + lambda_1 || Z ||_1 + lambda_2 || Z R ||_1 5 | % 6 | % via ADM 7 | % 8 | % Created by Stephen Tierney 9 | % stierney@csu.edu.au 10 | % 11 | 12 | if (~exist('diagconstraint','var')) 13 | diagconstraint = 0; 14 | end 15 | 16 | max_iterations = 200; 17 | 18 | func_vals = zeros(max_iterations,1); 19 | 20 | [~, xn, ~] = size(X); 21 | 22 | S = zeros(xn, xn); % S = Z 23 | R = (triu(ones(xn,xn-1),1) - triu(ones(xn, xn-1))) + (triu(ones(xn, xn-1),-1)-triu(ones(xn, xn-1))); 24 | R = sparse(R); 25 | 26 | U = zeros(xn, xn-1); 27 | 28 | G = zeros(xn, xn); 29 | F = zeros(xn, xn-1); 30 | 31 | Z = zeros(xn, xn); 32 | 33 | gamma_1 = 1; 34 | gamma_2 = 1; 35 | p = 1.1; 36 | 37 | tol = 1*10^-3; 38 | 39 | for k = 1 : max_iterations 40 | 41 | % Update Z 42 | V = S - (G/gamma_1); 43 | 44 | Z = solve_l1(V, lambda_1/gamma_1); 45 | 46 | % Set Z diag to 0 47 | if (diagconstraint) 48 | Z(logical(eye(size(Z)))) = 0; 49 | end 50 | 51 | % Update S 52 | A = X'*X + gamma_1*speye(xn,xn); 53 | B = gamma_2*(R*R'); 54 | C = -(X'*X + gamma_2*U*R' + gamma_1*Z + G + F*R'); 55 | 56 | S = lyap(A, B, C); 57 | 58 | % Update U 59 | V = S*R - (1/gamma_2)*F; 60 | 61 | U = solve_l1(V, lambda_2/gamma_2); 62 | 63 | % Update G, F 64 | 65 | G = G + gamma_1 * (Z - S); 66 | F = F + gamma_2 * (U - S*R); 67 | 68 | % Update gamma_1, gamma_2 69 | 70 | gamma_1 = p * gamma_1; 71 | gamma_2 = p * gamma_2; 72 | 73 | % Check convergence 74 | func_vals(iteration) = .5 * norm(X - X*Z,'fro')^2 + lambda_1*norm(Z,1) +lambda_2*norm(Z*R, 1); 75 | 76 | if iteration > 1 77 | if funVal(iteration) < tol 78 | break 79 | end 80 | end 81 | 82 | if iteration > 100 83 | if func_vals(iteration) < tol || func_vals(iteration-1) == func_vals(iteration) ... 84 | || func_vals(iteration-1) - func_vals(iteration) < tol 85 | break 86 | end 87 | end 88 | 89 | 90 | end 91 | 92 | end -------------------------------------------------------------------------------- /osc/osc_lrr_relaxed.m: -------------------------------------------------------------------------------- 1 | function [ Z ] = spatsc_lrr_relaxed( X, lambda_1, lambda_2, mu, diagconstraint) 2 | 3 | if (~exist('diagconstraint','var')) 4 | diagconstraint = 0; 5 | end 6 | 7 | max_iterations = 200; 8 | 9 | func_vals = zeros(max_iterations,1); 10 | 11 | [~, xn, ~] = size(X); 12 | 13 | Z = zeros(xn, xn); 14 | Z_prev = Z; 15 | 16 | R = (triu(ones(xn,xn-1),1) - triu(ones(xn, xn-1))) + (triu(ones(xn, xn-1),-1)-triu(ones(xn, xn-1))); 17 | R = sparse(R); 18 | 19 | U = zeros(xn, xn-1); 20 | U_prev = U; 21 | 22 | Y_2 = zeros(xn, xn-1); 23 | 24 | % mu = 0.000000001; %0.1; 25 | 26 | if (~exist('mu','var')) 27 | mu = 0.1; 28 | end 29 | 30 | mu_max = 100; %1; % 0.001; 31 | gamma_0 = 1.1; 32 | 33 | normfX = norm(X,'fro'); 34 | rho = (norm(X)^2) * 1.1; %1.1; 35 | 36 | tol_1 = 1*10^0; 37 | tol_2 = 1*10^-4; 38 | 39 | covar = X'*X; 40 | lam_2_ctrl = max(lambda_2/lambda_2, 0); 41 | 42 | for k = 1 : max_iterations 43 | 44 | %Update Z 45 | partial = -covar + covar*Z_prev - lam_2_ctrl*mu*(U_prev - Z_prev*R + 1/mu *Y_2)*R' ; 46 | % partial = -X'*(X - X*Z_prev) - mu*(U_prev - Z_prev*R + 1/mu *Y_2)*R' ; 47 | 48 | V = Z_prev - 1/rho* partial; 49 | 50 | Z = solve_nn(V, lambda_1/rho); 51 | 52 | % Set Z diag to 0 53 | if (diagconstraint) 54 | Z(logical(eye(size(Z)))) = 0; 55 | end 56 | 57 | %Update J 58 | partial = mu*(U_prev - Z_prev*R + 1/mu *Y_2); 59 | V = U_prev - 1/rho * partial; 60 | 61 | U = solve_l1(V, lambda_2/rho); 62 | 63 | Y_2 = lam_2_ctrl*(Y_2 + mu * (U - Z*R)); 64 | 65 | % Update mu 66 | if (mu * max([norm(Z - Z_prev,'fro'), norm(U - U_prev,'fro')] / normfX) < tol_2) 67 | gamma_1 = gamma_0; 68 | else 69 | gamma_1 = 1; 70 | end 71 | 72 | mu = min(mu_max, gamma_1 * mu); 73 | 74 | % Check convergence 75 | func_vals(k) = .5 * norm(X - X*Z,'fro')^2 + lambda_1*norm_l1(Z) +lambda_2*norm_l1(Z*R); 76 | 77 | if ( k > 1 && norm(U - Z*R, 'fro') < tol_1 ... 78 | && mu * max([norm(Z - Z_prev,'fro'), norm(U - U_prev,'fro')] / normfX) < tol_2) 79 | break; 80 | end 81 | 82 | if ( k > 5 && abs(func_vals(k) - func_vals(k-1)) < 1*10^-4) 83 | break 84 | end 85 | 86 | % Update prev vals 87 | Z_prev = Z; 88 | % S_prev = S; 89 | U_prev = U; 90 | 91 | end 92 | 93 | end -------------------------------------------------------------------------------- /libs/ncut/README.txt: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % Normalized Cut Segmentation Code % 3 | % % 4 | % Timothee Cour (INRIA), Stella Yu (Berkeley), Jianbo Shi (UPENN) % 5 | % % 6 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 7 | 8 | License 9 | This software is made publicly for research use only. It may be modified and redistributed under the terms of the GNU General Public License. 10 | 11 | Citation 12 | Please cite the following if you plan to use the code in your own work: 13 | * Normalized Cuts and Image Segmentation, Jianbo Shi and Jitendra Malik, IEEE Transactions on Pattern Analysis and Machine Intelligence (PAMI) 2000 14 | * Normalized Cut Segmentation Code, Timothee Cour, Stella Yu, Jianbo Shi. Copyright 2004 University of Pennsylvania, Computer and Information Science Department. 15 | 16 | Tested on matlab R2009b. 17 | 18 | Installation Notes : 19 | 20 | 1) After you unzipped the files to mydir, 21 | put the Current Directory in Matlab to mydir 22 | 23 | 2) In the matlab command prompt, 24 | type compileDir_simple to compile the mex files (ignore the error on the C++ non-mex file; needs to be done once) 25 | 26 | 3) You can now try any of the functions 27 | 28 | type demoNcutImage to see a demo of image segmentation 29 | type demoNcutClustering to see a demo of point cloud clustering 30 | 31 | 32 | Other top level functions: 33 | 34 | NcutImage.m: given image "I", segment it into "nbSegments" segments 35 | [SegLabel,NcutDiscrete,NcutEigenvectors,NcutEigenvalues,W]= NcutImage(I,nbSegments); 36 | 37 | ICgraph.m: compute Intervening Contour based pixel similarity matrix W 38 | W = ICgraph(I); 39 | 40 | ncutW.m: Given a similarity graph "W", computes Ncut clustering on the graph into "nbSegments" groups; 41 | [NcutDiscrete,NcutEigenvectors,NcutEigenvalues] = ncutW(W,nbSegments); 42 | 43 | 44 | Release notes: 45 | 46 | 2010, January 22: release of all c++ source mex files compatible with matlab R2009b 47 | 2006, May 04: release version 8: fixed incompatibility issues with new matlab 48 | 2004, June 18: release version 7: initial release 49 | 50 | Maintained by Timothee Cour, timothee dot cour at gmail dot com 51 | 52 | January 22, 2010. -------------------------------------------------------------------------------- /osc/osc_lrr_exact.m: -------------------------------------------------------------------------------- 1 | function [ Z, func_vals ] = spatsc_lrr_exact( X, lambda_1, lambda_2, diagconstraint ) 2 | 3 | if (~exist('diagconstraint','var')) 4 | diagconstraint = 0; 5 | end 6 | 7 | max_iterations = 200; 8 | 9 | func_vals = zeros(max_iterations,1); 10 | 11 | [xm, xn, ~] = size(X); 12 | 13 | Z = zeros(xn, xn); 14 | Z_prev = Z; 15 | 16 | E = zeros(xm, xn); 17 | E_prev = E; 18 | 19 | R = (triu(ones(xn,xn-1),1) - triu(ones(xn, xn-1))) + (triu(ones(xn, xn-1),-1)-triu(ones(xn, xn-1))); 20 | R = sparse(R); 21 | 22 | J = zeros(xn, xn-1); 23 | J_prev = J; 24 | 25 | Y_1 = zeros(xm, xn); 26 | Y_2 = zeros(xn, xn-1); 27 | 28 | mu = 0.1; %0.1; 29 | 30 | mu_max = 10; %1; % 0.001; 31 | gamma_0 = 1.1; 32 | 33 | normfX = norm(X,'fro'); 34 | rho = (norm(X)^2) * 1.1; %1.1; 35 | 36 | tol_1 = 1*10^-2; 37 | tol_2 = 1*10^-4; 38 | 39 | XTX = X'*X; 40 | for k = 1 : max_iterations 41 | 42 | % Update Z 43 | partial = mu*(XTX * Z_prev - XTX + X'*( E_prev + 1/mu * Y_1) ) + (Z_prev*R - (J_prev + 1/mu * Y_2)) * R'; 44 | 45 | V = Z_prev - 1/rho* partial; 46 | 47 | [Z,nnZ] = solve_nn(V, lambda_1/rho); 48 | 49 | 50 | % Update E 51 | 52 | V = -X*Z_prev + X - 1/mu * Y_1; 53 | 54 | E = solve_l2(V, 1/mu); 55 | 56 | % Update J 57 | partial = mu*(J_prev - Z_prev*R + 1/mu *Y_2); 58 | V = J_prev - 1/rho * partial; 59 | 60 | J = solve_l1(V, lambda_2/rho); 61 | 62 | % Update Y_1 and Y_2 63 | Y_1 = Y_1 + mu * (X*Z - X + E); 64 | Y_2 = Y_2 + mu * (J - Z*R); 65 | 66 | % Update mu 67 | if (mu * (max([sqrt(rho)*norm(Z - Z_prev,'fro'), norm(E - E_prev, 'fro'), norm(J-J_prev,'fro')] / normfX)) < tol_2) 68 | gamma = gamma_0; 69 | else 70 | gamma = 1; 71 | end 72 | 73 | mu = min(mu_max, gamma * mu); 74 | 75 | % func_vals(k) = .5 * norm(E,'fro')^2 + lambda_1*norm_l1(Z) +lambda_2*norm_l1(Z*R); 76 | func_vals(k) = .5 * norm(E,'fro')^2 + lambda_1*nnZ +lambda_2*norm_l1(Z*R); 77 | 78 | % Check convergence 79 | if ( (norm(X*Z - X + E, 'fro')/normfX < tol_1 && norm(J - Z*R, 'fro')/normfX < tol_1) ... 80 | && (mu * max([ sqrt(rho)*norm(Z - Z_prev,'fro'), norm(E - E_prev, 'fro'), norm(J-J_prev,'fro')]) / normfX < tol_2)) 81 | break; 82 | end 83 | 84 | % Update prev vals 85 | Z_prev = Z; 86 | E_prev = E; 87 | J_prev = J; 88 | 89 | end 90 | 91 | end 92 | -------------------------------------------------------------------------------- /osc/osc_relaxed.m: -------------------------------------------------------------------------------- 1 | function [ Z ] = osc_relaxed( X, lambda_1, lambda_2, diagconstraint, mu) 2 | %% Solves the following 3 | % 4 | % min || X - XZ ||_F^2 + lambda_1 || Z ||_1 + lambda_2 || Z R ||_1/2 5 | % 6 | % via LADMPSAP 7 | % 8 | % Created by Stephen Tierney 9 | % stierney@csu.edu.au 10 | % 11 | 12 | if (~exist('diagconstraint','var')) 13 | diagconstraint = 0; 14 | end 15 | 16 | max_iterations = 200; 17 | 18 | func_vals = zeros(max_iterations,1); 19 | 20 | [~, xn, ~] = size(X); 21 | 22 | Z = zeros(xn, xn); 23 | Z_prev = Z; 24 | 25 | R = (triu(ones(xn,xn-1),1) - triu(ones(xn, xn-1))) + (triu(ones(xn, xn-1),-1)-triu(ones(xn, xn-1))); 26 | R = sparse(R); 27 | 28 | U = zeros(xn, xn-1); 29 | U_prev = U; 30 | 31 | Y_2 = zeros(xn, xn-1); 32 | 33 | if (~exist('mu','var')) 34 | mu = 0.1; 35 | end 36 | 37 | mu_max = 100; %1; % 0.001; 38 | gamma_0 = 1.1; 39 | 40 | normfX = norm(X,'fro'); 41 | rho = (norm(X)^2) * 1.1; %1.1; 42 | 43 | tol_1 = 1*10^0; 44 | tol_2 = 1*10^-4; 45 | 46 | covar = X'*X; 47 | lam_2_ctrl = max(lambda_2/lambda_2, 0); 48 | 49 | for k = 1 : max_iterations 50 | 51 | %Update Z 52 | partial = -covar + covar*Z_prev - lam_2_ctrl*mu*(U_prev - Z_prev*R + 1/mu *Y_2)*R' ; 53 | 54 | V = Z_prev - 1/rho* partial; 55 | 56 | Z = solve_l1(V, lambda_1/rho); 57 | 58 | % Set Z diag to 0 59 | if (diagconstraint) 60 | Z(logical(eye(size(Z)))) = 0; 61 | end 62 | 63 | Z(Z < 0) = 0; 64 | 65 | %Update J 66 | partial = mu*(U_prev - Z_prev*R + 1/mu *Y_2); 67 | V = U_prev - 1/rho * partial; 68 | 69 | U = solve_l1l2(V, lambda_2/rho); 70 | 71 | Y_2 = lam_2_ctrl*(Y_2 + mu * (U - Z*R)); 72 | 73 | % Update mu 74 | if (mu * max([norm(Z - Z_prev,'fro'), norm(U - U_prev,'fro')] / normfX) < tol_2) 75 | gamma_1 = gamma_0; 76 | else 77 | gamma_1 = 1; 78 | end 79 | 80 | mu = min(mu_max, gamma_1 * mu); 81 | 82 | % Check convergence 83 | func_vals(k) = .5 * norm(X - X*Z,'fro')^2 + lambda_1*norm_l1(Z) +lambda_2*norm_l1l2(Z*R); 84 | 85 | if ( k > 1 && norm(U - Z*R, 'fro') < tol_1 ... 86 | && mu * max([norm(Z - Z_prev,'fro'), norm(U - U_prev,'fro')] / normfX) < tol_2) 87 | break; 88 | end 89 | 90 | if ( k > 5 && abs(func_vals(k) - func_vals(k-1)) < 1*10^-4) 91 | break 92 | end 93 | 94 | % Update prev vals 95 | Z_prev = Z; 96 | U_prev = U; 97 | 98 | end 99 | 100 | end -------------------------------------------------------------------------------- /spatsc/spatsc_relaxed.m: -------------------------------------------------------------------------------- 1 | function [ Z ] = spatsc_relaxed( X, lambda_1, lambda_2, diagconstraint, mu) 2 | %% Solves the following 3 | % 4 | % min || X - XZ ||_F^2 + lambda_1 || Z ||_1 + lambda_2 || Z R ||_1 5 | % 6 | % via LADMPSAP 7 | % 8 | % Created by Stephen Tierney 9 | % stierney@csu.edu.au 10 | % 11 | 12 | if (~exist('diagconstraint','var')) 13 | diagconstraint = 0; 14 | end 15 | 16 | max_iterations = 200; 17 | 18 | func_vals = zeros(max_iterations,1); 19 | 20 | [~, xn, ~] = size(X); 21 | 22 | Z = zeros(xn, xn); 23 | Z_prev = Z; 24 | 25 | R = (triu(ones(xn,xn-1),1) - triu(ones(xn, xn-1))) + (triu(ones(xn, xn-1),-1)-triu(ones(xn, xn-1))); 26 | R = sparse(R); 27 | 28 | U = zeros(xn, xn-1); 29 | U_prev = U; 30 | 31 | Y_2 = zeros(xn, xn-1); 32 | 33 | if (~exist('mu','var')) 34 | mu = 0.1; 35 | end 36 | 37 | mu_max = 100; %1; % 0.001; 38 | gamma_0 = 1.1; 39 | 40 | normfX = norm(X,'fro'); 41 | rho = (norm(X)^2) * 1.1; %1.1; 42 | 43 | tol_1 = 1*10^0; 44 | tol_2 = 1*10^-4; 45 | 46 | covar = X'*X; 47 | lam_2_ctrl = max(lambda_2/lambda_2, 0); 48 | 49 | for k = 1 : max_iterations 50 | 51 | %Update Z 52 | partial = -covar + covar*Z_prev - lam_2_ctrl*mu*(U_prev - Z_prev*R + 1/mu *Y_2)*R' ; 53 | 54 | V = Z_prev - 1/rho* partial; 55 | 56 | Z = solve_l1(V, lambda_1/rho); 57 | 58 | % Set Z diag to 0 59 | if (diagconstraint) 60 | Z(logical(eye(size(Z)))) = 0; 61 | end 62 | 63 | Z(Z < 0) = 0; 64 | 65 | %Update J 66 | partial = mu*(U_prev - Z_prev*R + 1/mu *Y_2); 67 | V = U_prev - 1/rho * partial; 68 | 69 | U = solve_l1(V, lambda_2/rho); 70 | 71 | Y_2 = lam_2_ctrl*(Y_2 + mu * (U - Z*R)); 72 | 73 | % Update mu 74 | if (mu * max([norm(Z - Z_prev,'fro'), norm(U - U_prev,'fro')] / normfX) < tol_2) 75 | gamma_1 = gamma_0; 76 | else 77 | gamma_1 = 1; 78 | end 79 | 80 | mu = min(mu_max, gamma_1 * mu); 81 | 82 | % Check convergence 83 | func_vals(k) = .5 * norm(X - X*Z,'fro')^2 + lambda_1*norm_l1(Z) +lambda_2*norm_l1(Z*R); 84 | 85 | if ( k > 1 && norm(U - Z*R, 'fro') < tol_1 ... 86 | && mu * max([norm(Z - Z_prev,'fro'), norm(U - U_prev,'fro')] / normfX) < tol_2) 87 | break; 88 | end 89 | 90 | if ( k > 5 && abs(func_vals(k) - func_vals(k-1)) < 1*10^-4) 91 | break 92 | end 93 | 94 | % Update prev vals 95 | Z_prev = Z; 96 | U_prev = U; 97 | 98 | end 99 | 100 | end -------------------------------------------------------------------------------- /osc/osc_exact.m: -------------------------------------------------------------------------------- 1 | function [ Z ] = osc_exact( X, lambda_1, lambda_2, mu, diagconstraint ) 2 | %% Solves the following 3 | % 4 | % min || E ||_F^2 + lambda_1 || Z ||_1 + lambda_2 || Z R ||_1/2 5 | % s.t. X = XZ + E 6 | % 7 | % Created by Stephen Tierney 8 | % stierney@csu.edu.au 9 | % 10 | 11 | if (~exist('diagconstraint','var')) 12 | diagconstraint = 0; 13 | end 14 | 15 | max_iterations = 200; 16 | 17 | func_vals = zeros(max_iterations,1); 18 | 19 | [xm, xn, ~] = size(X); 20 | 21 | Z = zeros(xn, xn); 22 | Z_prev = Z; 23 | 24 | E = zeros(xm, xn); 25 | E_prev = E; 26 | 27 | R = (triu(ones(xn,xn-1),1) - triu(ones(xn, xn-1))) + (triu(ones(xn, xn-1),-1)-triu(ones(xn, xn-1))); 28 | R = sparse(R); 29 | 30 | J = zeros(xn, xn-1); 31 | J_prev = J; 32 | 33 | Y_1 = zeros(xm, xn); 34 | Y_2 = zeros(xn, xn-1); 35 | 36 | if (~exist('mu','var')) 37 | mu = 0.1; 38 | end 39 | 40 | mu_max = 10; %1; % 0.001; 41 | gamma_0 = 1.1; 42 | 43 | normfX = norm(X,'fro'); 44 | rho = (norm(X)^2) * 1.1; %1.1; 45 | 46 | tol_1 = 1*10^-2; 47 | tol_2 = 1*10^-4; 48 | 49 | for k = 1 : max_iterations 50 | 51 | % Update Z 52 | partial = mu*(X' * (X * Z_prev - (X - E_prev - 1/mu * Y_1)) + (Z_prev*R - (J_prev + 1/mu * Y_2)) * R'); 53 | 54 | V = Z_prev - 1/rho* partial; 55 | 56 | Z = solve_l1(V, lambda_1/(rho)); 57 | 58 | % Set Z diag to 0 59 | if (diagconstraint) 60 | Z(logical(eye(size(Z)))) = 0; 61 | end 62 | 63 | % Update E 64 | V = -X*Z_prev + X - 1/mu * Y_1; 65 | 66 | E = solve_l2(V, 1/mu); 67 | 68 | % Update J 69 | J = solve_l1l2(Z_prev*R - 1/mu *Y_2, lambda_2/mu); 70 | 71 | % Update Y_1 and Y_2 72 | Y_1 = Y_1 + mu * (X*Z - X + E); 73 | Y_2 = Y_2 + mu * (J - Z*R); 74 | 75 | % Update mu 76 | if (mu * sqrt(rho)* (max([norm(Z - Z_prev,'fro'), norm(E - E_prev, 'fro'), norm(J-J_prev,'fro')] / normfX)) < tol_2) 77 | gamma = gamma_0; 78 | else 79 | gamma = 1; 80 | end 81 | 82 | mu = min(mu_max, gamma * mu); 83 | 84 | func_vals(k) = .5 * norm(E,'fro')^2 + lambda_1*norm_l1(Z) +lambda_2*norm_l1l2(Z*R); 85 | 86 | % Check convergence 87 | if ( (norm(X*Z - X + E, 'fro')/normfX < tol_1 && norm(J - Z*R, 'fro')/normfX < tol_1) ... 88 | && (mu * sqrt(rho)* max([ norm(Z - Z_prev,'fro'), norm(E - E_prev, 'fro'), norm(J-J_prev,'fro')]) / normfX < tol_2)) 89 | break; 90 | end 91 | 92 | % Update prev vals 93 | Z_prev = Z; 94 | E_prev = E; 95 | J_prev = J; 96 | 97 | end 98 | 99 | end 100 | -------------------------------------------------------------------------------- /spatsc/spatsc_exact.m: -------------------------------------------------------------------------------- 1 | function [ Z ] = spatsc_exact( X, lambda_1, lambda_2, diagconstraint ) 2 | %% Solves the followingr 3 | % 4 | % min || E ||_F^2 + lambda_1 || Z ||_1 + lambda_2 || Z R ||_1 5 | % s.t. X = XZ + E 6 | % 7 | % Created by Stephen Tierney 8 | % stierney@csu.edu.au 9 | % 10 | 11 | if (~exist('diagconstraint','var')) 12 | diagconstraint = 0; 13 | end 14 | 15 | max_iterations = 200; 16 | 17 | func_vals = zeros(max_iterations,1); 18 | 19 | [xm, xn, ~] = size(X); 20 | 21 | Z = zeros(xn, xn); 22 | Z_prev = Z; 23 | 24 | E = zeros(xm, xn); 25 | E_prev = E; 26 | 27 | R = (triu(ones(xn,xn-1),1) - triu(ones(xn, xn-1))) + (triu(ones(xn, xn-1),-1)-triu(ones(xn, xn-1))); 28 | R = sparse(R); 29 | 30 | J = zeros(xn, xn-1); 31 | J_prev = J; 32 | 33 | Y_1 = zeros(xm, xn); 34 | Y_2 = zeros(xn, xn-1); 35 | 36 | if (~exist('mu','var')) 37 | mu = 0.1; 38 | end 39 | 40 | mu_max = 10; %1; % 0.001; 41 | gamma_0 = 1.1; 42 | 43 | normfX = norm(X,'fro'); 44 | rho = (norm(X)^2) * 1.1; %1.1; 45 | 46 | tol_1 = 1*10^-2; 47 | tol_2 = 1*10^-4; 48 | 49 | for k = 1 : max_iterations 50 | 51 | % Update Z 52 | partial = mu*(X' * (X * Z_prev - (X - E_prev - 1/mu * Y_1)) + (Z_prev*R - (J_prev + 1/mu * Y_2)) * R'); 53 | 54 | V = Z_prev - 1/rho* partial; 55 | 56 | Z = solve_l1(V, lambda_1/(rho)); 57 | 58 | % Set Z diag to 0 59 | if (diagconstraint) 60 | Z(logical(eye(size(Z)))) = 0; 61 | end 62 | 63 | % Update E 64 | 65 | V = -X*Z_prev + X - 1/mu * Y_1; 66 | 67 | E = solve_l2(V, 1/mu); 68 | 69 | % Update J 70 | partial = mu*(J_prev - Z_prev*R + 1/mu *Y_2); 71 | V = J_prev - 1/rho * partial; 72 | 73 | J = solve_l1(V, lambda_2/rho); 74 | 75 | % Update Y_1 and Y_2 76 | Y_1 = Y_1 + mu * (X*Z - X + E); 77 | Y_2 = Y_2 + mu * (J - Z*R); 78 | 79 | % Update mu 80 | if (mu * (max([sqrt(rho)*norm(Z - Z_prev,'fro'), norm(E - E_prev, 'fro'), norm(J-J_prev,'fro')] / normfX)) < tol_2) 81 | gamma = gamma_0; 82 | else 83 | gamma = 1; 84 | end 85 | 86 | mu = min(mu_max, gamma * mu); 87 | 88 | func_vals(k) = .5 * norm(E,'fro')^2 + lambda_1*norm_l1(Z) +lambda_2*norm_l1(Z*R); 89 | 90 | % Check convergence 91 | if ( (norm(X*Z - X + E, 'fro')/normfX < tol_1 && norm(J - Z*R, 'fro')/normfX < tol_1) ... 92 | && (mu * max([ sqrt(rho)*norm(Z - Z_prev,'fro'), norm(E - E_prev, 'fro'), norm(J-J_prev,'fro')]) / normfX < tol_2)) 93 | break; 94 | end 95 | 96 | % Update prev vals 97 | Z_prev = Z; 98 | E_prev = E; 99 | J_prev = J; 100 | 101 | end 102 | 103 | end 104 | -------------------------------------------------------------------------------- /libs/ncut/ncut.m: -------------------------------------------------------------------------------- 1 | function [Eigenvectors,Eigenvalues] = ncut(W,nbEigenValues,dataNcut); 2 | % function [Eigenvectors,Eigenvalues] = ncut(W,nbEigenValues,dataNcut); 3 | % 4 | % Input: 5 | % W= symmetric similarity matrix 6 | % nbEigenValues= number of Ncut eigenvectors computed 7 | % dataNcut= optional parameters 8 | % 9 | % default parameters for dataNcut: 10 | % dataNcut.offset = 5e-1; offset in the diagonal of W 11 | % dataNcut.verbose = 0; 0 for verbose off mode, 1,2,3 for verbose on modes 12 | % dataNcut.maxiterations = 100; max number of iterations in eigensolver 13 | % dataNcut.eigsErrorTolerance = 1e-6; error tolerance in eigensolver 14 | % dataNcut.valeurMin=1e-6; % truncates any values in W less than valeurMin 15 | % 16 | % Output: 17 | % Eigenvectors= continuouse Ncut eigenvectos, size = length(W) x nbEigenValues 18 | % Eigenvalues= Ncut eigenvalues, size = 1x nbEigenValues 19 | % 20 | % Timothee Cour, Stella Yu, Jianbo Shi, 2004. 21 | 22 | if nargin < 2 23 | nbEigenValues = 8; 24 | end 25 | if nargin < 3 26 | dataNcut.offset = 5e-1; 27 | dataNcut.verbose = 0; 28 | dataNcut.maxiterations = 300; 29 | dataNcut.eigsErrorTolerance = 1e-8; 30 | dataNcut.valeurMin=1e-6; 31 | end 32 | % if nargin < 3 33 | % dataNcut.offset = 5e-1; 34 | % dataNcut.verbose = 0; 35 | % dataNcut.maxiterations = 100; 36 | % dataNcut.eigsErrorTolerance = 1e-6; 37 | % dataNcut.valeurMin=1e-6; 38 | % end 39 | 40 | % make W matrix sparse 41 | W = sparsifyc(W,dataNcut.valeurMin); 42 | 43 | % check for matrix symmetry 44 | if max(max(abs(W-W'))) > 1e-10 %voir (-12) 45 | %disp(max(max(abs(W-W')))); 46 | error('W not symmetric'); 47 | end 48 | 49 | n = size(W,1); 50 | nbEigenValues = min(nbEigenValues,n); 51 | offset = dataNcut.offset; 52 | 53 | 54 | % degrees and regularization 55 | d = sum(abs(W),2); 56 | dr = 0.5 * (d - sum(W,2)); 57 | d = d + offset * 2; 58 | dr = dr + offset; 59 | W = W + spdiags(dr,0,n,n); 60 | 61 | Dinvsqrt = 1./sqrt(d+eps); 62 | P = spmtimesd(W,Dinvsqrt,Dinvsqrt); 63 | clear W; 64 | 65 | options.issym = 1; 66 | 67 | if dataNcut.verbose 68 | options.disp = 3; 69 | else 70 | options.disp = 0; 71 | end 72 | options.maxit = dataNcut.maxiterations; 73 | options.tol = dataNcut.eigsErrorTolerance; 74 | 75 | options.v0 = ones(size(P,1),1); 76 | options.p = max(35,2*nbEigenValues); %voir 77 | options.p = min(options.p,n); 78 | 79 | %warning off 80 | % [vbar,s,convergence] = eigs2(@mex_w_times_x_symmetric,size(P,1),nbEigenValues,'LA',options,tril(P)); 81 | % [vbar,s,convergence] = eigs_new(@mex_w_times_x_symmetric,size(P,1),nbEigenValues,'LA',options,tril(P)); 82 | [vbar,s,convergence] = eigs(P,nbEigenValues); 83 | %warning on 84 | 85 | s = real(diag(s)); 86 | [x,y] = sort(-s); 87 | Eigenvalues = -x; 88 | vbar = vbar(:,y); 89 | Eigenvectors = spdiags(Dinvsqrt,0,n,n) * vbar; 90 | 91 | for i=1:size(Eigenvectors,2) 92 | Eigenvectors(:,i) = (Eigenvectors(:,i) / norm(Eigenvectors(:,i)) )*norm(ones(n,1)); 93 | if Eigenvectors(1,i)~=0 94 | Eigenvectors(:,i) = - Eigenvectors(:,i) * sign(Eigenvectors(1,i)); 95 | end 96 | end 97 | -------------------------------------------------------------------------------- /mlap/mlap.m: -------------------------------------------------------------------------------- 1 | function [ Zs ] = mlap( Xs, lambda, tau ) 2 | %% Solves the following 3 | % 4 | % min alpha || A ||_1/2 + \sum_i^K (lambda || E_i ||_1/2 + || Z_i ||_*) 5 | % s.t. X_i = X_i Z_i + E_i 6 | % A = [Z_1; Z_2; ... ; Z_K] 7 | % 8 | % Created by Stephen Tierney 9 | % stierney@csu.edu.au 10 | % 11 | 12 | if (length(lambda) == 1) 13 | lambda = repmat(lambda, size(Xs, 2), 1); 14 | end 15 | 16 | max_iterations = 200; 17 | 18 | func_vals = zeros(max_iterations, 1); 19 | 20 | num_obs = length(Xs); 21 | N = size(Xs{1}, 2); 22 | 23 | 24 | Zs = zeros(N, N, num_obs); 25 | 26 | Es = cell(size(Xs)); 27 | Ys = cell(size(Xs)); 28 | 29 | for k = 1 : num_obs 30 | Es{k} = zeros(size(Xs{k})); 31 | Ys{k} = zeros(size(Xs{k})); 32 | end 33 | 34 | % A is tall, each column corresponds to a Z 35 | A = zeros(N^2, num_obs); 36 | Ws = zeros(N, N, num_obs); 37 | 38 | mu = 0.1; 39 | mu_max = 1; 40 | 41 | rho_list = zeros(num_obs, 1); 42 | for k = 1 : num_obs 43 | rho_list(k) = (norm(Xs{k},2)^2) * 1.1; 44 | end 45 | rho = max(rho_list); 46 | 47 | gamma_0 = 1.1; 48 | 49 | tol_1 = 1*10^-2; 50 | tol_2 = 1*10^-4; 51 | 52 | for t = 1 : max_iterations 53 | 54 | Zs_prev = Zs; 55 | Es_prev = Es; 56 | A_prev = A; 57 | 58 | sub_func_val = 0; 59 | 60 | for k = 1 : num_obs 61 | % Solve for Z 62 | 63 | partial = mu*Xs{k}'*(Xs{k}*Zs_prev(:,:,k) - (Xs{k} - Es_prev{k} - 1/mu * Ys{k}))... 64 | + mu*(Zs_prev(:,:,k) - reshape(A_prev(:,k), size(Zs(:,:,k))) + 1/mu * Ws(:,:,k)); 65 | 66 | V_Z = Zs_prev(:,:,k) - 1/rho * partial; 67 | 68 | [Zs(:,:,k), s_z] = solve_nn(V_Z, lambda(k)/rho); 69 | 70 | % Solve for E 71 | 72 | V_E = Xs{k} - Xs{k}*Zs_prev(:,:,k) - 1/mu * Ys{k}; 73 | Es{k} = solve_l2(V_E, 1/mu); 74 | 75 | % Update Y 76 | 77 | Ys{k} = Ys{k} + mu*(Xs{k}*Zs(:,:,k) - Xs{k} + Es{k}); 78 | sub_func_val = sub_func_val + lambda(k)*sum(s_z) + 0.5*norm(Es{k}, 'fro')^2; 79 | 80 | end 81 | 82 | % Solve for A 83 | 84 | V_A = reshape(Zs_prev + 1/mu * Ws, N^2, num_obs); 85 | 86 | [A, s_a] = solve_nn(V_A, tau/mu); 87 | 88 | % Update W 89 | 90 | Ws = Ws + reshape(mu*(reshape(Zs_prev, N^2, num_obs) - A), [N, N, num_obs]); 91 | 92 | % Update function value 93 | 94 | func_vals(t) = sub_func_val + tau*sum(s_a); 95 | 96 | % Check convergence 97 | 98 | fit_error = zeros(num_obs, 1); 99 | az_error = zeros(num_obs, 1); 100 | Z_shp = reshape(Zs, N^2, num_obs); 101 | z_diff = zeros(num_obs, 1); 102 | e_diff = zeros(num_obs, 1); 103 | for k = 1: num_obs 104 | fit_error(k) = norm(Xs{k}*Zs(:,:,k) - Xs{k} + Es{k}, 'fro')/ norm(Xs{k}, 'fro'); 105 | az_error(k) = norm(A(:,k) - Z_shp(:,k), 2); 106 | z_diff(k) = norm(Zs(:,:,k) - Zs_prev(:,:,k), 'fro')/ norm(Xs{k}, 'fro'); 107 | e_diff(k) = norm(Es{k} - Es_prev{k}, 'fro')/ norm(Xs{k}, 'fro'); 108 | end 109 | 110 | if ( ( max(fit_error) < tol_1 && max(az_error) < tol_1) ... 111 | && (mu * sqrt(rho)* max([ max(z_diff), max(e_diff), norm(A-A_prev,'fro')]) < tol_2)) 112 | break; 113 | end 114 | 115 | % Update mu 116 | if (mu *sqrt(rho)* max([ max(z_diff), max(e_diff), norm(A-A_prev,'fro')]) < tol_2) 117 | gamma = gamma_0; 118 | else 119 | gamma = 1; 120 | end 121 | 122 | mu = min(mu_max, gamma * mu); 123 | 124 | 125 | end 126 | 127 | end 128 | 129 | -------------------------------------------------------------------------------- /libs/ncut/build_scene.m: -------------------------------------------------------------------------------- 1 | function [data,size_cluster] = build_scene(caseid) 2 | % [data,size_cluster] = build_scene(case) 3 | % 4 | % case 1: random gaussian shaped blobs. 5 | % case 2: one circular plus some gaussian blob, one inside, one outside 6 | % case 3: one circular plus some gaussian blob, one inside, two outside 7 | % Jianbo Shi, 1997 8 | 9 | 10 | if caseid ==1, 11 | sigma_h = 2; 12 | sigma_v = 10; 13 | 14 | s_v = 10; 15 | s_h = 30; 16 | 17 | a = [sigma_h*randn(1,40);sigma_v*randn(1,40)]; 18 | b = [s_h;s_v]*ones(1,50) + [sigma_h*randn(1,50);... 19 | sigma_v*randn(1,50)]; 20 | 21 | data = [a,b]; 22 | size_cluster = [40,50]; 23 | 24 | elseif caseid == 2, 25 | num_cluster = 3; 26 | radius = 15; 27 | size_cluster = [80,20,20]; 28 | 29 | raw_data = randn(2,sum(size_cluster)); 30 | tmp = rand(2,size_cluster(1))-0.5; 31 | 32 | [t,idt] = sort(tmp(2,:)); 33 | r_noise = 4; 34 | raw_data2 = [tmp(1,idt)*r_noise;... 35 | tmp(2,idt)*2]; 36 | 37 | data = [(radius-raw_data2(1,1:size_cluster(1))).*... 38 | cos(pi*raw_data2(2,1:size_cluster(1)));... 39 | (radius-raw_data2(1,1:size_cluster(1))).*... 40 | sin(pi*raw_data2(2,1:size_cluster(1)))]; 41 | 42 | 43 | center = [0,0];sig = [1,2]; 44 | % size_cluster_base 45 | scb = size_cluster(1)+1; 46 | scb_next = scb+size_cluster(2)-1; 47 | data = [data,[center(1)+sig(1)*raw_data(1,scb:scb_next);... 48 | center(2)+sig(2)*raw_data(2,scb:scb_next)]]; 49 | 50 | 51 | center = [radius+10,0]; sig = [1,1]; 52 | scb = scb_next+1; 53 | scb_next = scb+size_cluster(3)-1; 54 | data = [data,[center(1)+sig(1)*raw_data(1,scb:scb_next);... 55 | center(2)+sig(2)*raw_data(2,scb:scb_next)]]; 56 | elseif caseid==3, 57 | num_cluster = 4; 58 | radius = 15; 59 | size_cluster = [80,10,20,20]; 60 | 61 | raw_data = randn(2,sum(size_cluster)); 62 | tmp = rand(2,size_cluster(1))-0.5; 63 | 64 | [t,idt] = sort(tmp(2,:)); 65 | r_noise = 4; 66 | raw_data2 = [tmp(1,idt)*r_noise;... 67 | tmp(2,idt)*2]; 68 | 69 | data = [(radius-raw_data2(1,1:size_cluster(1))).*... 70 | cos(pi*raw_data2(2,1:size_cluster(1)));... 71 | (radius-raw_data2(1,1:size_cluster(1))).*... 72 | sin(pi*raw_data2(2,1:size_cluster(1)))]; 73 | 74 | 75 | center = [0,0];sig = [1,2]; 76 | % size_cluster_base 77 | scb = size_cluster(1)+1; 78 | scb_next = scb+size_cluster(2)-1; 79 | data = [data,[center(1)+sig(1)*raw_data(1,scb:scb_next);... 80 | center(2)+sig(2)*raw_data(2,scb:scb_next)]]; 81 | 82 | 83 | center = [radius+25,8]; sig = [1,2.3]; 84 | scb = scb_next+1; 85 | scb_next = scb+size_cluster(3)-1; 86 | data = [data,[center(1)+sig(1)*raw_data(1,scb:scb_next);... 87 | center(2)+sig(2)*raw_data(2,scb:scb_next)]]; 88 | 89 | center = [radius+25,-6]; sig = [1.5,2.4]; 90 | scb = scb_next+1; 91 | scb_next = scb+size_cluster(4)-1; 92 | data = [data,[center(1)+sig(1)*raw_data(1,scb:scb_next);... 93 | center(2)+sig(2)*raw_data(2,scb:scb_next)]]; 94 | elseif caseid == 4, 95 | size_cluster = [100,10,10]; 96 | radius = 10; 97 | tmp = rand(2,size_cluster(1))-0.5; 98 | 99 | [t,idt] = sort(tmp(2,:)); 100 | r_noise = 4; 101 | raw_data2 = [tmp(1,idt)*r_noise;... 102 | tmp(2,idt)*2]; 103 | 104 | data = [(radius-raw_data2(1,1:size_cluster(1))).*... 105 | cos(pi*raw_data2(2,1:size_cluster(1)));... 106 | (radius-raw_data2(1,1:size_cluster(1))).*... 107 | sin(pi*raw_data2(2,1:size_cluster(1)))]; 108 | 109 | 110 | result = zeros(1,size_cluster(1)); 111 | 112 | % for j =1:size_cluster(1), 113 | % result(j) = sum(sum(A(1:j,1:j)))/j; 114 | % end 115 | 116 | end 117 | -------------------------------------------------------------------------------- /libs/ncut/quadedgep.m: -------------------------------------------------------------------------------- 1 | % function [x,y,gx,gy,par,threshold,mag,mage,g,FIe,FIo,mago] = quadedgep(I,par,threshold); 2 | % Input: 3 | % I = image 4 | % par = vector for 4 parameters 5 | % [number of filter orientations, number of scales, filter size, elongation] 6 | % To use default values, put 0. 7 | % threshold = threshold on edge strength 8 | % Output: 9 | % [x,y,gx,gy] = locations and gradients of an ordered list of edgels 10 | % x,y could be horizontal or vertical or 45 between pixel sites 11 | % but it is guaranteed that there [floor(y) + (floor(x)-1)*nr] 12 | % is ordered and unique. In other words, each edgel has a unique pixel id. 13 | % par = actual par used 14 | % threshold = actual threshold used 15 | % mag = edge magnitude 16 | % mage = phase map 17 | % g = gradient map at each pixel 18 | % [FIe,FIo] = odd and even filter outputs 19 | % mago = odd filter output of optimum orientation 20 | % 21 | % Stella X. Yu, 2001 22 | 23 | 24 | 25 | function [x,y,gx,gy,par,threshold,mag,mage,g,FIe,FIo,mago] = quadedgep(I,par,threshold); 26 | 27 | if nargin<3 | isempty(threshold), 28 | threshold = 0.2; 29 | end 30 | 31 | [r,c] = size(I); 32 | def_par = [8,1,20,3]; 33 | 34 | % take care of parameters, any missing value is substituted by a default value 35 | if nargin<2 | isempty(par), 36 | par = def_par; 37 | end 38 | par(end+1:4)=0; 39 | par = par(:); 40 | j = (par>0); 41 | have_value = [ j, 1-j ]; 42 | j = 1; n_filter = have_value(j,:) * [par(j); def_par(j)]; 43 | j = 2; n_scale = have_value(j,:) * [par(j); def_par(j)]; 44 | j = 3; winsz = have_value(j,:) * [par(j); def_par(j)]; 45 | j = 4; enlong = have_value(j,:) * [par(j); def_par(j)]; 46 | 47 | % always make filter size an odd number so that the results will not be skewed 48 | j = winsz/2; 49 | if not(j > fix(j) + 0.1), 50 | winsz = winsz + 1; 51 | end 52 | 53 | % filter the image with quadrature filters 54 | FBo = make_filterbank_odd2(n_filter,n_scale,winsz,enlong); 55 | FBe = make_filterbank_even2(n_filter,n_scale,winsz,enlong); 56 | n = ceil(winsz/2); 57 | f = [fliplr(I(:,2:n+1)), I, fliplr(I(:,c-n:c-1))]; 58 | f = [flipud(f(2:n+1,:)); f; flipud(f(r-n:r-1,:))]; 59 | FIo = fft_filt_2(f,FBo,1); 60 | FIo = FIo(n+[1:r],n+[1:c],:); 61 | FIe = fft_filt_2(f,FBe,1); 62 | FIe = FIe(n+[1:r],n+[1:c],:); 63 | 64 | % compute the orientation energy and recover a smooth edge map 65 | % pick up the maximum energy across scale and orientation 66 | % even filter's output: as it is the second derivative, zero cross localize the edge 67 | % odd filter's output: orientation 68 | mag = sqrt(sum(FIo.^2,3)+sum(FIe.^2,3)); 69 | mag_a = sqrt(FIo.^2+FIe.^2); 70 | [tmp,max_id] = max(mag_a,[],3); 71 | base_size = r * c; 72 | id = [1:base_size]'; 73 | mage = reshape(FIe(id+(max_id(:)-1)*base_size),[r,c]); 74 | mage = (mage>0) - (mage<0); 75 | 76 | ori_incr=pi/n_filter; % to convert jshi's coords to conventional image xy 77 | ori_offset=ori_incr/2; 78 | theta = ori_offset+([1:n_filter]-1)*ori_incr; % orientation detectors 79 | % [gx,gy] are image gradient in image xy coords, winner take all 80 | mago = reshape(FIo(id+(max_id(:)-1)*base_size),[r,c]); 81 | ori = theta(max_id); 82 | ori = ori .* (mago>0) + (ori + pi).*(mago<0); 83 | gy = mag .* cos(ori); 84 | gx = -mag .* sin(ori); 85 | g = cat(3,gx,gy); 86 | 87 | % phase map: edges are where the phase changes 88 | mag_th = max(mag(:)) * threshold; 89 | eg = (mag>mag_th); 90 | h = eg & [(mage(2:r,:) ~= mage(1:r-1,:)); zeros(1,c)]; 91 | v = eg & [(mage(:,2:c) ~= mage(:,1:c-1)), zeros(r,1)]; 92 | [y,x] = find(h | v); 93 | k = y + (x-1) * r; 94 | h = h(k); 95 | v = v(k); 96 | y = y + h * 0.5; % i 97 | x = x + v * 0.5; % j 98 | t = h + v * r; 99 | gx = g(k) + g(k+t); 100 | k = k + (r * c); 101 | gy = g(k) + g(k+t); 102 | 103 | 104 | -------------------------------------------------------------------------------- /libs/ncut/spmtimesd.cpp: -------------------------------------------------------------------------------- 1 | /*================================================================ 2 | * spmtimesd.c 3 | * This routine computes a sparse matrix times a diagonal matrix 4 | * whose diagonal entries are stored in a full vector. 5 | * 6 | * Examples: 7 | * spmtimesd(m,d,[]) = diag(d) * m, 8 | * spmtimesd(m,[],d) = m * diag(d) 9 | * spmtimesd(m,d1,d2) = diag(d1) * m * diag(d2) 10 | * m could be complex, but d is assumed real 11 | * 12 | * Stella X. Yu's first MEX function, Nov 9, 2001. 13 | 14 | % test sequence: 15 | 16 | m = 1000; 17 | n = 2000; 18 | a=sparse(rand(m,n)); 19 | d1 = rand(m,1); 20 | d2 = rand(n,1); 21 | tic; b=spmtimesd(a,d1,d2); toc 22 | tic; bb = spdiags(d1,0,m,m) * a * spdiags(d2,0,n,n); toc 23 | e = (bb-b); 24 | max(abs(e(:))) 25 | 26 | *=================================================================*/ 27 | 28 | # include "mex.h" 29 | 30 | void mexFunction( 31 | int nargout, 32 | mxArray *out[], 33 | int nargin, 34 | const mxArray *in[] 35 | ) 36 | { 37 | /* declare variables */ 38 | int i, j, k, m, n, nzmax, xm, yn; 39 | mwIndex *pir, *pjc, *qir, *qjc; 40 | double *x, *y, *pr, *pi, *qr, *qi; 41 | 42 | /* check argument */ 43 | if (nargin != 3) { 44 | mexErrMsgTxt("Three input arguments required"); 45 | } 46 | if (nargout>1) { 47 | mexErrMsgTxt("Too many output arguments."); 48 | } 49 | if (!(mxIsSparse(in[0]))) { 50 | mexErrMsgTxt("Input argument #1 must be of type sparse"); 51 | } 52 | if ( mxIsSparse(in[1]) || mxIsSparse(in[2]) ) { 53 | mexErrMsgTxt("Input argument #2 & #3 must be of type full"); 54 | } 55 | 56 | /* computation starts */ 57 | m = mxGetM(in[0]); 58 | n = mxGetN(in[0]); 59 | pr = mxGetPr(in[0]); 60 | pi = mxGetPi(in[0]); 61 | pir = mxGetIr(in[0]); 62 | pjc = mxGetJc(in[0]); 63 | 64 | i = mxGetM(in[1]); 65 | j = mxGetN(in[1]); 66 | xm = ((i>j)? i: j); 67 | 68 | i = mxGetM(in[2]); 69 | j = mxGetN(in[2]); 70 | yn = ((i>j)? i: j); 71 | 72 | if ( xm>0 && xm != m) { 73 | mexErrMsgTxt("Row multiplication dimension mismatch."); 74 | } 75 | if ( yn>0 && yn != n) { 76 | mexErrMsgTxt("Column multiplication dimension mismatch."); 77 | } 78 | 79 | 80 | nzmax = mxGetNzmax(in[0]); 81 | mxComplexity cmplx = (pi==NULL ? mxREAL : mxCOMPLEX); 82 | out[0] = mxCreateSparse(m,n,nzmax,cmplx); 83 | if (out[0]==NULL) { 84 | mexErrMsgTxt("Not enough space for the output matrix."); 85 | } 86 | 87 | qr = mxGetPr(out[0]); 88 | qi = mxGetPi(out[0]); 89 | qir = mxGetIr(out[0]); 90 | qjc = mxGetJc(out[0]); 91 | 92 | /* left multiplication */ 93 | x = mxGetPr(in[1]); 94 | if (yn==0) { 95 | for (j=0; j> \mu_0$ and $\epsilon > 0$. 108 | 109 | \item Check stopping criteria 110 | \[ 111 | \|\mathbf X - \mathbf A^{k+1} - \mathbf N^{k+1} \|_F < \epsilon_1, \; 112 | \mu_k \frac{\textrm{max} ( \| \mathbf A_{k+1} - \mathbf A_{k} \|_F , \| \mathbf N_{k+1} - \mathbf N_{k} \|_F)}{\| \mathbf X \|_F} < \epsilon_2 113 | \] 114 | 115 | 116 | \end{enumerate} 117 | 118 | \bibliographystyle{plain} 119 | \bibliography{references} 120 | 121 | \end{document} -------------------------------------------------------------------------------- /libs/ncut/cimgnbmap.cpp: -------------------------------------------------------------------------------- 1 | /*================================================================ 2 | * function [i,j] = cimgnbmap([nr,nc], nb_r, sample_rate) 3 | * computes the neighbourhood index matrix of an image, 4 | * with each neighbourhood sampled. 5 | * Input: 6 | * [nr,nc] = image size 7 | * nb_r = neighbourhood radius, could be [r_i,r_j] for i,j 8 | * sample_rate = sampling rate, default = 1 9 | * Output: 10 | * [i,j] = each is a column vector, give indices of neighbour pairs 11 | * UINT32 type 12 | * i is of total length of valid elements, 0 for first row 13 | * j is of length nr * nc + 1 14 | * 15 | * See also: imgnbmap.c, id2cind.m 16 | * 17 | * Examples: 18 | * [i,j] = imgnbmap(10, 20); % [10,10] are assumed 19 | * 20 | * Stella X. Yu, Nov 12, 2001. 21 | 22 | % test sequence: 23 | nr = 15; 24 | nc = 15; 25 | nbr = 1; 26 | [i,j] = cimgnbmap([nr,nc], nbr); 27 | mask = csparse(i,j,ones(length(i),1),nr*nc); 28 | show_dist_w(rand(nr,nc),mask) 29 | 30 | *=================================================================*/ 31 | 32 | # include "mex.h" 33 | # include "math.h" 34 | # include 35 | 36 | void mexFunction( 37 | int nargout, 38 | mxArray *out[], 39 | int nargin, 40 | const mxArray *in[] 41 | ) 42 | { 43 | /* declare variables */ 44 | int nr, nc, np, nb, total; 45 | double *dim, sample_rate; 46 | int r_i, r_j, a1, a2, b1, b2, self, neighbor; 47 | int i, j, k, s, t, nsamp, th_rand, no_sample; 48 | unsigned long *p; 49 | 50 | 51 | /* check argument */ 52 | if (nargin < 2) { 53 | mexErrMsgTxt("Two input arguments required"); 54 | } 55 | if (nargout> 2) { 56 | mexErrMsgTxt("Too many output arguments."); 57 | } 58 | 59 | /* get image size */ 60 | i = mxGetM(in[0]); 61 | j = mxGetN(in[0]); 62 | dim = (double *)mxGetData(in[0]); 63 | nr = (int)dim[0]; 64 | if (j>1 || i>1) { 65 | nc = (int)dim[1]; 66 | } else { 67 | nc = nr; 68 | } 69 | np = nr * nc; 70 | 71 | /* get neighbourhood size */ 72 | i = mxGetM(in[1]); 73 | j = mxGetN(in[1]); 74 | dim = (double*)mxGetData(in[1]); 75 | r_i = (int)dim[0]; 76 | if (j>1 || i>1) { 77 | r_j = (int)dim[1]; 78 | } else { 79 | r_j = r_i; 80 | } 81 | if (r_i<0) { r_i = 0; } 82 | if (r_j<0) { r_j = 0; } 83 | 84 | /* get sample rate */ 85 | if (nargin==3) { 86 | sample_rate = (mxGetM(in[2])==0) ? 1: mxGetScalar(in[2]); 87 | } else { 88 | sample_rate = 1; 89 | } 90 | /* prepare for random number generator */ 91 | if (sample_rate<1) { 92 | srand( (unsigned)time( NULL ) ); 93 | th_rand = (int)ceil((double)RAND_MAX * sample_rate); 94 | no_sample = 0; 95 | } else { 96 | sample_rate = 1; 97 | th_rand = RAND_MAX; 98 | no_sample = 1; 99 | } 100 | 101 | /* figure out neighbourhood size */ 102 | 103 | nb = (r_i + r_i + 1) * (r_j + r_j + 1); 104 | if (nb>np) { 105 | nb = np; 106 | } 107 | nb = (int)ceil((double)nb * sample_rate); 108 | 109 | /* intermediate data structure */ 110 | p = (unsigned long *)mxCalloc(np * (nb+1), sizeof(unsigned long)); 111 | if (p==NULL) { 112 | mexErrMsgTxt("Not enough space for my computation."); 113 | } 114 | 115 | /* computation */ 116 | total = 0; 117 | for (j=0; j=nc) { b2 = nc-1; } 130 | 131 | /* i range */ 132 | a1 = i - r_i; 133 | if (a1<0) { a1 = 0; } 134 | a2 = i + r_i; 135 | if (a2>=nr) { a2 = nr-1; } 136 | 137 | /* number of more samples needed */ 138 | nsamp = nb - p[self]; 139 | 140 | k = 0; 141 | t = b1; 142 | s = i + 1; 143 | if (s>a2) { 144 | s = a1; 145 | t = t + 1; 146 | } 147 | while (ka2) { 160 | s = a1; 161 | t = t + 1; 162 | } 163 | } /* k */ 164 | 165 | total = total + p[self]; 166 | } /* i */ 167 | } /* j */ 168 | 169 | /* i, j */ 170 | out[0] = mxCreateNumericMatrix(total, 1, mxUINT32_CLASS, mxREAL); 171 | out[1] = mxCreateNumericMatrix(np+1, 1, mxUINT32_CLASS, mxREAL); 172 | unsigned int *qi = (unsigned int *)mxGetData(out[0]); 173 | unsigned int *qj = (unsigned int *)mxGetData(out[1]); 174 | if (out[0]==NULL || out[1]==NULL) { 175 | mexErrMsgTxt("Not enough space for the output matrix."); 176 | } 177 | 178 | total = 0; 179 | for (j=0; j1) { 46 | mexErrMsgTxt("Too many output arguments"); 47 | } 48 | 49 | /* get edgel information */ 50 | nr = mxGetM(in[0]); 51 | nc = mxGetN(in[0]); 52 | if ( nr*nc ==0 || nr != mxGetM(in[1]) || nc != mxGetN(in[1]) ) { 53 | mexErrMsgTxt("Edge magnitude and phase shall be of the same image size"); 54 | } 55 | emag = mxGetPr(in[0]); 56 | ephase = mxGetPr(in[1]); 57 | np = nr * nc; 58 | 59 | /* get new index pair */ 60 | if (!mxIsUint32(in[2]) | !mxIsUint32(in[3])) { 61 | mexErrMsgTxt("Index pair shall be of type UINT32"); 62 | } 63 | if (mxGetM(in[3]) * mxGetN(in[3]) != np + 1) { 64 | mexErrMsgTxt("Wrong index representation"); 65 | } 66 | pi = (unsigned int*)mxGetData(in[2]); 67 | pj = (unsigned int*)mxGetData(in[3]); 68 | 69 | /* create output */ 70 | out[0] = mxCreateSparse(np,np,pj[np],mxREAL); 71 | if (out[0]==NULL) { 72 | mexErrMsgTxt("Not enough memory for the output matrix"); 73 | } 74 | w = mxGetPr(out[0]); 75 | ir = mxGetIr(out[0]); 76 | jc = mxGetJc(out[0]); 77 | 78 | /* find my sigma */ 79 | if (nargin<5) { 80 | sigma = 0; 81 | for (k=0; ksigma) { sigma = emag[k]; } 83 | } 84 | sigma = sigma / 6; 85 | printf("sigma = %6.5f",sigma); 86 | } else { 87 | sigma = mxGetScalar(in[4]); 88 | } 89 | a = 0.5 / (sigma * sigma); 90 | 91 | /* computation */ 92 | total = 0; 93 | for (j=0; j= abs(dj)) { 121 | slope = dj / di; 122 | step = (iy>=jy) ? 1 : -1; 123 | 124 | iip1 = jy; 125 | jjp1 = jx; 126 | 127 | 128 | for (ii=0;ii maxori){ 137 | maxori = z; 138 | } 139 | } 140 | 141 | iip1 = iip2; 142 | jjp1 = jjp2; 143 | phase1 = phase2; 144 | } 145 | 146 | /* sample in j direction */ 147 | } else { 148 | slope = di / dj; 149 | step = (ix>=jx) ? 1: -1; 150 | 151 | jjp1 = jx; 152 | iip1 = jy; 153 | 154 | 155 | for (jj=0;jj maxori){ 164 | maxori = z; 165 | } 166 | 167 | } 168 | 169 | iip1 = iip2; 170 | jjp1 = jjp2; 171 | phase1 = phase2; 172 | } 173 | } 174 | 175 | maxori = 0.5 * maxori; 176 | maxori = exp(-maxori * maxori * a); 177 | } 178 | ir[total] = i; 179 | 180 | w[total] = maxori; 181 | total = total + 1; 182 | 183 | } /* i */ 184 | } /* j */ 185 | 186 | jc[np] = total; 187 | } 188 | -------------------------------------------------------------------------------- /libs/ncut/sparsifyc.cpp: -------------------------------------------------------------------------------- 1 | /*================================================================= 2 | * syntax: SPMX = SPARSIFY(MX, THRES) 3 | * 4 | * SPARSIFY - sparsify the input matrix, i.e. ignore the values 5 | * of the matrix which are below a threshold 6 | * 7 | * Input: - MX: m-by-n matrix (sparse or full) 8 | * - THRES: threshold value (double) 9 | * 10 | * Output: - SPMX: m-by-n sparse matrix only with values 11 | * whose absolut value is above the given threshold 12 | * 13 | * Written by Mirko Visontai (10/24/2003) 14 | *=================================================================*/ 15 | 16 | 17 | #include 18 | #include "mex.h" 19 | 20 | void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) 21 | { 22 | /* Declare variable */ 23 | int i,m,n,nzmax,newnnz,col,processed,passed; 24 | int starting_row_index, current_row_index, stopping_row_index; 25 | double *in_pr,*in_pi,*out_pr,*out_pi; 26 | mwIndex *in_ir,*in_jc,*out_ir,*out_jc; 27 | double thres; 28 | 29 | /* Check for proper number of input and output arguments */ 30 | if ((nlhs != 1) || (nrhs != 2)){ 31 | mexErrMsgTxt("usage: SPMX = SPARSIFY(MX, THRES)."); 32 | } 33 | /* if matrix is complex threshold the norm of the numbers */ 34 | if (mxIsComplex(prhs[0])){ 35 | /* Check data type of input argument */ 36 | if (mxIsSparse(prhs[0])){ 37 | 38 | /* read input */ 39 | in_pr = mxGetPr(prhs[0]); 40 | in_pi = mxGetPi(prhs[0]); 41 | in_ir = mxGetIr(prhs[0]); 42 | in_jc = mxGetJc(prhs[0]); 43 | nzmax = mxGetNzmax(prhs[0]); 44 | m = mxGetM(prhs[0]); 45 | n = mxGetN(prhs[0]); 46 | thres = mxGetScalar(prhs[1]); 47 | 48 | /* Count new nonzeros */ 49 | newnnz=0; 50 | for(i=0; ithres) {newnnz++;} 52 | } 53 | 54 | if (newnnz>0){ 55 | /* create output */ 56 | plhs[0] = mxCreateSparse(m,n,newnnz,mxCOMPLEX); 57 | if (plhs[0]==NULL) 58 | mexErrMsgTxt("Could not allocate enough memory!\n"); 59 | out_pr = mxGetPr(plhs[0]); 60 | out_pi = mxGetPr(plhs[0]); 61 | out_ir = mxGetIr(plhs[0]); 62 | out_jc = mxGetJc(plhs[0]); 63 | passed = 0; 64 | out_jc[0] = 0; 65 | for (col=0; col thres){ 77 | 78 | out_pr[passed]=in_pr[current_row_index]; 79 | out_pi[passed]=in_pi[current_row_index]; 80 | out_ir[passed]=in_ir[current_row_index]; 81 | out_jc[col+1] = out_jc[col+1]+1; 82 | passed++; 83 | } 84 | } 85 | } 86 | } 87 | } 88 | else{ 89 | plhs[0] = mxCreateSparse(m,n,0,mxCOMPLEX); 90 | } 91 | } 92 | else{ /* for full matrices */ 93 | /* read input */ 94 | in_pr = mxGetPr(prhs[0]); 95 | in_pi = mxGetPr(prhs[0]); 96 | m = mxGetM(prhs[0]); 97 | n = mxGetN(prhs[0]); 98 | thres = mxGetScalar(prhs[1]); 99 | 100 | /* Count new nonzeros */ 101 | newnnz=0; 102 | for(i=0; ithres) {newnnz++;} 104 | } 105 | 106 | if (newnnz>0){ 107 | /* create output */ 108 | plhs[0] = mxCreateSparse(m,n,newnnz,mxCOMPLEX); 109 | if (plhs[0]==NULL) 110 | mexErrMsgTxt("Could not allocate enough memory!\n"); 111 | out_pr = mxGetPr(plhs[0]); 112 | out_pi = mxGetPi(plhs[0]); 113 | out_ir = mxGetIr(plhs[0]); 114 | out_jc = mxGetJc(plhs[0]); 115 | passed = 0; 116 | out_jc[0] = 0; 117 | 118 | for (col=0; col thres){ 123 | 124 | out_pr[passed]=in_pr[current_row_index+m*col]; 125 | out_ir[passed]=current_row_index; 126 | out_jc[col+1] = out_jc[col+1]+1; 127 | passed++; 128 | } 129 | } 130 | } 131 | } 132 | else{ 133 | plhs[0] = mxCreateSparse(m,n,0,mxCOMPLEX); 134 | } 135 | } 136 | } 137 | else { 138 | /* Check data type of input argument */ 139 | if (mxIsSparse(prhs[0])){ 140 | 141 | /* read input */ 142 | in_pr = mxGetPr(prhs[0]); 143 | in_ir = mxGetIr(prhs[0]); 144 | in_jc = mxGetJc(prhs[0]); 145 | nzmax = mxGetNzmax(prhs[0]); 146 | n = mxGetN(prhs[0]); 147 | m = mxGetM(prhs[0]); 148 | thres = mxGetScalar(prhs[1]); 149 | 150 | /* Count new nonzeros */ 151 | newnnz=0; 152 | for(i=0; ithres) {newnnz++;} 154 | } 155 | 156 | if (newnnz>0){ 157 | /* create output */ 158 | plhs[0] = mxCreateSparse(m,n,newnnz,mxREAL); 159 | if (plhs[0]==NULL) 160 | mexErrMsgTxt("Could not allocate enough memory!\n"); 161 | out_pr = mxGetPr(plhs[0]); 162 | out_ir = mxGetIr(plhs[0]); 163 | out_jc = mxGetJc(plhs[0]); 164 | passed = 0; 165 | out_jc[0] = 0; 166 | for (col=0; colthres){ 177 | out_pr[passed]=in_pr[current_row_index]; 178 | out_ir[passed]=in_ir[current_row_index]; 179 | out_jc[col+1] = out_jc[col+1]+1; 180 | passed++; 181 | } 182 | } 183 | } 184 | } 185 | } 186 | else{ 187 | plhs[0] = mxCreateSparse(m,n,0,mxREAL); 188 | } 189 | } 190 | else{ /* for full matrices */ 191 | /* read input */ 192 | in_pr = mxGetPr(prhs[0]); 193 | n = mxGetN(prhs[0]); 194 | m = mxGetM(prhs[0]); 195 | thres = mxGetScalar(prhs[1]); 196 | 197 | /* Count new nonzeros */ 198 | newnnz=0; 199 | for(i=0; ithres) {newnnz++;} 201 | } 202 | 203 | if (newnnz>0){ 204 | /* create output */ 205 | plhs[0] = mxCreateSparse(m,n,newnnz,mxREAL); 206 | if (plhs[0]==NULL) 207 | mexErrMsgTxt("Could not allocate enough memory!\n"); 208 | out_pr = mxGetPr(plhs[0]); 209 | out_ir = mxGetIr(plhs[0]); 210 | out_jc = mxGetJc(plhs[0]); 211 | passed = 0; 212 | out_jc[0] = 0; 213 | 214 | for (col=0; colthres){ 218 | out_pr[passed]=in_pr[current_row_index+m*col]; 219 | out_ir[passed]=current_row_index; 220 | out_jc[col+1] = out_jc[col+1]+1; 221 | passed++; 222 | } 223 | } 224 | } 225 | } 226 | else{ 227 | plhs[0] = mxCreateSparse(m,n,0,mxREAL); 228 | } 229 | } 230 | } 231 | } 232 | 233 | -------------------------------------------------------------------------------- /libs/ncut/a_times_b_cmplx.cpp: -------------------------------------------------------------------------------- 1 | /*================================================================ 2 | a_times_b_cmplx.c = used by a couple of mex functions 3 | provide Matrix vector multiplications, 4 | and solve triangular systems 5 | (sparse matrix and full vector) 6 | 7 | CSC_CmplxVecMult_CAB_double, CSR_CmplxVecMult_CAB_double, 8 | CSCsymm_CmplxVecMult_CAB_double added by Mirko Visontai (10/24/2003) 9 | 10 | *=================================================================*/ 11 | # include "math.h" 12 | 13 | ///*c<-a'*b */ 14 | //void scalar_product( 15 | // const int m, const int k, /*nb_rows, nb_columns*/ 16 | // const double *a, 17 | // const double *b, 18 | // double *c 19 | // ) 20 | //{ 21 | // int i; 22 | // double d; 23 | // d = 0; 24 | // for (i=0;i!=m;i++) 25 | // d+=a[i]*b[i]; 26 | // c[0] = d; 27 | // 28 | //} 29 | 30 | 31 | /*C<-a*A*B+C*/ 32 | void CSC_VecMult_CaABC_double( 33 | const int m, const int k, const double alpha, 34 | const double *val, const int *indx, 35 | const int *pntrb, 36 | const double *b, 37 | double *c) 38 | { 39 | int i,j,jb,je; 40 | 41 | for (i=0;i!=k;i++){ 42 | jb = pntrb[i]; 43 | je = pntrb[i+1]; 44 | for (j=jb;j!=je;j++) 45 | c[indx[j]] += alpha * b[i] * val[j]; 46 | } 47 | } 48 | 49 | /*C<-a*A'*B+C*/ 50 | void CSR_VecMult_CaABC_double( 51 | const int k, const int m, const double alpha, 52 | const double *val, const mwIndex *indx, 53 | const mwIndex *pntrb, 54 | const double *b, 55 | double *c) 56 | { 57 | double t; 58 | const double *pval; 59 | int i,j,jb,je; 60 | 61 | pval = val; 62 | for (i=0;i!=m;i++) { 63 | t = 0; 64 | jb = pntrb[i]; 65 | je = pntrb[i+1]; 66 | for (j=jb;j!=je;j++) 67 | t += alpha * b[indx[j]] * (*pval++); 68 | c[i] += t; 69 | } 70 | } 71 | 72 | 73 | /*C<-A*b */ 74 | void CSC_VecMult_CAB_double( 75 | const int m, const int k, /*nb_rows, nb_columns*/ 76 | const double *val, const int *indx, 77 | const int *pntrb, 78 | const double *b, 79 | double *c 80 | ) 81 | { 82 | int i,j,jb,je; 83 | double *pc=c; 84 | for (i=0;i!=m;i++) *pc++ = 0; 85 | 86 | for (i=0;i!=k;i++){ 87 | jb = pntrb[i]; 88 | je = pntrb[i+1]; 89 | for (j=jb;j!=je;j++) 90 | c[indx[j]] += b[i] * val[j]; 91 | } 92 | } 93 | 94 | /*C<-A*b (complex)*/ 95 | void CSC_CmplxVecMult_CAB_double( 96 | const int m, const int k, 97 | const double *valr, const double *vali, 98 | const int *indx, 99 | const int *pntrb, 100 | const double *br, const double *bi, 101 | double *cr, double *ci 102 | ) 103 | { 104 | int i,j,jb,je; 105 | double *pcr=cr; 106 | double *pci=ci; 107 | for (i=0;i!=m;i++){ 108 | *pcr++ = 0.0; 109 | *pci++ = 0.0; 110 | } 111 | 112 | for (i=0;i!=k;i++){ 113 | jb = pntrb[i]; 114 | je = pntrb[i+1]; 115 | for (j=jb;j!=je;j++){ 116 | cr[indx[j]] += (br[i] * valr[j]) - (bi[i] * vali[j]); 117 | ci[indx[j]] += (br[i] * vali[j]) + (bi[i] * valr[j]); 118 | } 119 | } 120 | } 121 | 122 | /*C<-A'*b 123 | plus rapide que CSC_VecMult_CAB_double */ 124 | void CSR_VecMult_CAB_double( 125 | const int k, const int m, 126 | const double *val, const int *indx, 127 | const int *pntrb, 128 | const double *b, 129 | double *c 130 | ) 131 | { 132 | double t; 133 | const double *pval; 134 | double *pc=c; 135 | int i,j,jb,je; 136 | 137 | for (i=0;i!=m;i++) *pc++ = 0; 138 | 139 | pval = val; 140 | for (i=0;i!=m;i++) { 141 | t = 0; 142 | jb = pntrb[i]; 143 | je = pntrb[i+1]; 144 | for (j=jb;j!=je;j++) 145 | t += b[indx[j]] * (*pval++); 146 | c[i] += t; 147 | } 148 | } 149 | 150 | /*C<-A'*b (complex) 151 | plus rapide que CSC_VecMult_CAB_double */ 152 | void CSR_CmplxVecMult_CAB_double( 153 | const int k, const int m, 154 | const double *valr, const double *vali, 155 | const int *indx, 156 | const int *pntrb, 157 | const double *br, const double *bi, 158 | double *cr, double *ci 159 | ) 160 | { 161 | double tr, ti; 162 | const double *pvalr; 163 | const double *pvali; 164 | double *pcr=cr; 165 | double *pci=ci; 166 | int i,j,jb,je; 167 | 168 | for (i=0;i!=m;i++){ 169 | *pcr++ = 0.0; 170 | *pci++ = 0.0; 171 | } 172 | 173 | pvalr = valr; 174 | pvali = vali; 175 | for (i=0;i!=m;i++) { 176 | tr = 0.0; 177 | ti = 0.0; 178 | jb = pntrb[i]; 179 | je = pntrb[i+1]; 180 | for (j=jb;j!=je;j++){ 181 | tr += (br[indx[j]] * (*pvalr)) - (bi[indx[j]] * (*pvali)); 182 | ti += (br[indx[j]] * (*pvali++)) + (bi[indx[j]] * (*pvalr++)); 183 | } 184 | cr[i] += tr; 185 | ci[i] += ti; 186 | } 187 | } 188 | 189 | 190 | 191 | /* C<-A*b (A is symmetric) */ 192 | void CSRsymm_VecMult_CAB_double( 193 | const int k, const int m, 194 | const double *val, const mwIndex *indx, 195 | const mwIndex *pntrb, 196 | const double *b, 197 | double *c 198 | ) 199 | { 200 | const double *pval; 201 | double *pc=c; 202 | int i,j; 203 | int jj; 204 | int rpntrb, rpntre; 205 | int index, nvals; 206 | 207 | 208 | for (i=0;i!=m;i++) *pc++ = 0; 209 | pval = val; 210 | for (j=0;j!=k;j++){ 211 | rpntrb = pntrb[j]; 212 | rpntre = pntrb[j+1]; 213 | for (jj=rpntrb;jj!=rpntre;jj++) { 214 | index = indx[jj]; 215 | if ( index == j ) { 216 | c[j] += b[j] * (*pval++); 217 | continue; 218 | } 219 | if ( index > j ) { 220 | c[index] += b[j] * (*pval); 221 | 222 | c[j] += b[index] * (*pval++); 223 | } 224 | else { 225 | pval++; 226 | } 227 | } 228 | } 229 | } 230 | 231 | 232 | /* C<-A*b (A is symmetric and complex) */ 233 | void CSRsymm_CmplxVecMult_CAB_double( 234 | const int k, const int m, 235 | const double *valr, const double *vali, 236 | const int *indx, 237 | const int *pntrb, 238 | const double *br, const double *bi, 239 | double *cr, double *ci 240 | ) 241 | { 242 | const double *pvalr, *pvali; 243 | double *pcr=cr; 244 | double *pci=ci; 245 | int i,j; 246 | int jj; 247 | int rpntrb, rpntre; 248 | int index, nvals; 249 | 250 | 251 | for (i=0;i!=m;i++){ 252 | *pcr++ = 0.0; 253 | *pci++ = 0.0; 254 | } 255 | 256 | pvalr = valr; 257 | pvali = vali; 258 | for (j=0;j!=k;j++){ 259 | rpntrb = pntrb[j]; 260 | rpntre = pntrb[j+1]; 261 | for (jj=rpntrb;jj!=rpntre;jj++) { 262 | index = indx[jj]; 263 | if ( index == j ) { 264 | cr[j] += (br[j] * (*pvalr)) - (bi[j] * (*pvali)); 265 | ci[j] += (br[j] * (*pvali++)) + (bi[j] * (*pvalr++)); 266 | continue; 267 | } 268 | if ( index > j ) { 269 | cr[index] += (br[j] * (*pvalr)) - (bi[j] * (*pvali)); 270 | ci[index] += (br[j] * (*pvali)) + (bi[j] * (*pvalr)); 271 | 272 | cr[j] += (br[index] * (*pvalr)) - (bi[index] * (*pvali)); 273 | ci[j] += (br[index] * (*pvali++)) + (bi[index] * (*pvalr++)); 274 | } 275 | else { 276 | pvalr++; 277 | pvali++; 278 | } 279 | 280 | } 281 | } 282 | } 283 | 284 | 285 | /*C<-A\B; with Lower triangular A*/ 286 | void CSC_VecTriangSlvLD_CAB_double( 287 | const int m, 288 | const double *val, 289 | const int *indx, const int *pntrb, 290 | const double *b, 291 | double *c) 292 | { 293 | int i, j, jb, je; 294 | double *pc=c; 295 | double z; 296 | 297 | for (i=0;i!=m;i++){ 298 | *pc = b[i]; 299 | pc++; 300 | } 301 | 302 | pc=c; 303 | for (i=0;i!=m;i++) { 304 | jb = pntrb[i]; 305 | je = pntrb[i+1]; 306 | z = pc[i] / val[jb]; 307 | pc[i] = z; 308 | for (j=jb+1;j 9 | Babel <3.9k> and hyphenation patterns for 78 languages loaded. 10 | (/usr/local/texlive/2014/texmf-dist/tex/latex/base/article.cls 11 | Document Class: article 2007/10/19 v1.4h Standard LaTeX document class 12 | (/usr/local/texlive/2014/texmf-dist/tex/latex/base/size10.clo 13 | File: size10.clo 2007/10/19 v1.4h Standard LaTeX file (size option) 14 | ) 15 | \c@part=\count79 16 | \c@section=\count80 17 | \c@subsection=\count81 18 | \c@subsubsection=\count82 19 | \c@paragraph=\count83 20 | \c@subparagraph=\count84 21 | \c@figure=\count85 22 | \c@table=\count86 23 | \abovecaptionskip=\skip41 24 | \belowcaptionskip=\skip42 25 | \bibindent=\dimen102 26 | ) 27 | (/usr/local/texlive/2014/texmf-dist/tex/latex/hyperref/hyperref.sty 28 | Package: hyperref 2012/11/06 v6.83m Hypertext links for LaTeX 29 | 30 | (/usr/local/texlive/2014/texmf-dist/tex/generic/oberdiek/hobsub-hyperref.sty 31 | Package: hobsub-hyperref 2012/05/28 v1.13 Bundle oberdiek, subset hyperref (HO) 32 | 33 | 34 | (/usr/local/texlive/2014/texmf-dist/tex/generic/oberdiek/hobsub-generic.sty 35 | Package: hobsub-generic 2012/05/28 v1.13 Bundle oberdiek, subset generic (HO) 36 | Package: hobsub 2012/05/28 v1.13 Construct package bundles (HO) 37 | Package: infwarerr 2010/04/08 v1.3 Providing info/warning/error messages (HO) 38 | Package: ltxcmds 2011/11/09 v1.22 LaTeX kernel commands for general use (HO) 39 | Package: ifluatex 2010/03/01 v1.3 Provides the ifluatex switch (HO) 40 | Package ifluatex Info: LuaTeX not detected. 41 | Package: ifvtex 2010/03/01 v1.5 Detect VTeX and its facilities (HO) 42 | Package ifvtex Info: VTeX not detected. 43 | Package: intcalc 2007/09/27 v1.1 Expandable calculations with integers (HO) 44 | Package: ifpdf 2011/01/30 v2.3 Provides the ifpdf switch (HO) 45 | Package ifpdf Info: pdfTeX in PDF mode is detected. 46 | Package: etexcmds 2011/02/16 v1.5 Avoid name clashes with e-TeX commands (HO) 47 | Package etexcmds Info: Could not find \expanded. 48 | (etexcmds) That can mean that you are not using pdfTeX 1.50 or 49 | (etexcmds) that some package has redefined \expanded. 50 | (etexcmds) In the latter case, load this package earlier. 51 | Package: kvsetkeys 2012/04/25 v1.16 Key value parser (HO) 52 | Package: kvdefinekeys 2011/04/07 v1.3 Define keys (HO) 53 | Package: pdftexcmds 2011/11/29 v0.20 Utility functions of pdfTeX for LuaTeX (HO 54 | ) 55 | Package pdftexcmds Info: LuaTeX not detected. 56 | Package pdftexcmds Info: \pdf@primitive is available. 57 | Package pdftexcmds Info: \pdf@ifprimitive is available. 58 | Package pdftexcmds Info: \pdfdraftmode found. 59 | Package: pdfescape 2011/11/25 v1.13 Implements pdfTeX's escape features (HO) 60 | Package: bigintcalc 2012/04/08 v1.3 Expandable calculations on big integers (HO 61 | ) 62 | Package: bitset 2011/01/30 v1.1 Handle bit-vector datatype (HO) 63 | Package: uniquecounter 2011/01/30 v1.2 Provide unlimited unique counter (HO) 64 | ) 65 | Package hobsub Info: Skipping package `hobsub' (already loaded). 66 | Package: letltxmacro 2010/09/02 v1.4 Let assignment for LaTeX macros (HO) 67 | Package: hopatch 2012/05/28 v1.2 Wrapper for package hooks (HO) 68 | Package: xcolor-patch 2011/01/30 xcolor patch 69 | Package: atveryend 2011/06/30 v1.8 Hooks at the very end of document (HO) 70 | Package atveryend Info: \enddocument detected (standard20110627). 71 | Package: atbegshi 2011/10/05 v1.16 At begin shipout hook (HO) 72 | Package: refcount 2011/10/16 v3.4 Data extraction from label references (HO) 73 | Package: hycolor 2011/01/30 v1.7 Color options for hyperref/bookmark (HO) 74 | ) 75 | (/usr/local/texlive/2014/texmf-dist/tex/latex/graphics/keyval.sty 76 | Package: keyval 2014/05/08 v1.15 key=value parser (DPC) 77 | \KV@toks@=\toks14 78 | ) 79 | (/usr/local/texlive/2014/texmf-dist/tex/generic/ifxetex/ifxetex.sty 80 | Package: ifxetex 2010/09/12 v0.6 Provides ifxetex conditional 81 | ) 82 | (/usr/local/texlive/2014/texmf-dist/tex/latex/oberdiek/auxhook.sty 83 | Package: auxhook 2011/03/04 v1.3 Hooks for auxiliary files (HO) 84 | ) 85 | (/usr/local/texlive/2014/texmf-dist/tex/latex/oberdiek/kvoptions.sty 86 | Package: kvoptions 2011/06/30 v3.11 Key value format for package options (HO) 87 | ) 88 | \@linkdim=\dimen103 89 | \Hy@linkcounter=\count87 90 | \Hy@pagecounter=\count88 91 | 92 | (/usr/local/texlive/2014/texmf-dist/tex/latex/hyperref/pd1enc.def 93 | File: pd1enc.def 2012/11/06 v6.83m Hyperref: PDFDocEncoding definition (HO) 94 | ) 95 | \Hy@SavedSpaceFactor=\count89 96 | 97 | (/usr/local/texlive/2014/texmf-dist/tex/latex/latexconfig/hyperref.cfg 98 | File: hyperref.cfg 2002/06/06 v1.2 hyperref configuration of TeXLive 99 | ) 100 | Package hyperref Info: Option `colorlinks' set `true' on input line 4319. 101 | Package hyperref Info: Hyper figures OFF on input line 4443. 102 | Package hyperref Info: Link nesting OFF on input line 4448. 103 | Package hyperref Info: Hyper index ON on input line 4451. 104 | Package hyperref Info: Plain pages OFF on input line 4458. 105 | Package hyperref Info: Backreferencing OFF on input line 4463. 106 | Package hyperref Info: Implicit mode ON; LaTeX internals redefined. 107 | Package hyperref Info: Bookmarks ON on input line 4688. 108 | \c@Hy@tempcnt=\count90 109 | 110 | (/usr/local/texlive/2014/texmf-dist/tex/latex/url/url.sty 111 | \Urlmuskip=\muskip10 112 | Package: url 2013/09/16 ver 3.4 Verb mode for urls, etc. 113 | ) 114 | LaTeX Info: Redefining \url on input line 5041. 115 | \XeTeXLinkMargin=\dimen104 116 | \Fld@menulength=\count91 117 | \Field@Width=\dimen105 118 | \Fld@charsize=\dimen106 119 | Package hyperref Info: Hyper figures OFF on input line 6295. 120 | Package hyperref Info: Link nesting OFF on input line 6300. 121 | Package hyperref Info: Hyper index ON on input line 6303. 122 | Package hyperref Info: backreferencing OFF on input line 6310. 123 | Package hyperref Info: Link coloring ON on input line 6313. 124 | Package hyperref Info: Link coloring with OCG OFF on input line 6320. 125 | Package hyperref Info: PDF/A mode OFF on input line 6325. 126 | LaTeX Info: Redefining \ref on input line 6365. 127 | LaTeX Info: Redefining \pageref on input line 6369. 128 | \Hy@abspage=\count92 129 | \c@Item=\count93 130 | \c@Hfootnote=\count94 131 | ) 132 | 133 | Package hyperref Message: Driver (autodetected): hpdftex. 134 | 135 | (/usr/local/texlive/2014/texmf-dist/tex/latex/hyperref/hpdftex.def 136 | File: hpdftex.def 2012/11/06 v6.83m Hyperref driver for pdfTeX 137 | \Fld@listcount=\count95 138 | \c@bookmark@seq@number=\count96 139 | 140 | (/usr/local/texlive/2014/texmf-dist/tex/latex/oberdiek/rerunfilecheck.sty 141 | Package: rerunfilecheck 2011/04/15 v1.7 Rerun checks for auxiliary files (HO) 142 | Package uniquecounter Info: New unique counter `rerunfilecheck' on input line 2 143 | 82. 144 | ) 145 | \Hy@SectionHShift=\skip43 146 | ) 147 | (/usr/local/texlive/2014/texmf-dist/tex/latex/amsmath/amsmath.sty 148 | Package: amsmath 2013/01/14 v2.14 AMS math features 149 | \@mathmargin=\skip44 150 | 151 | For additional information on amsmath, use the `?' option. 152 | (/usr/local/texlive/2014/texmf-dist/tex/latex/amsmath/amstext.sty 153 | Package: amstext 2000/06/29 v2.01 154 | 155 | (/usr/local/texlive/2014/texmf-dist/tex/latex/amsmath/amsgen.sty 156 | File: amsgen.sty 1999/11/30 v2.0 157 | \@emptytoks=\toks15 158 | \ex@=\dimen107 159 | )) 160 | (/usr/local/texlive/2014/texmf-dist/tex/latex/amsmath/amsbsy.sty 161 | Package: amsbsy 1999/11/29 v1.2d 162 | \pmbraise@=\dimen108 163 | ) 164 | (/usr/local/texlive/2014/texmf-dist/tex/latex/amsmath/amsopn.sty 165 | Package: amsopn 1999/12/14 v2.01 operator names 166 | ) 167 | \inf@bad=\count97 168 | LaTeX Info: Redefining \frac on input line 210. 169 | \uproot@=\count98 170 | \leftroot@=\count99 171 | LaTeX Info: Redefining \overline on input line 306. 172 | \classnum@=\count100 173 | \DOTSCASE@=\count101 174 | LaTeX Info: Redefining \ldots on input line 378. 175 | LaTeX Info: Redefining \dots on input line 381. 176 | LaTeX Info: Redefining \cdots on input line 466. 177 | \Mathstrutbox@=\box26 178 | \strutbox@=\box27 179 | \big@size=\dimen109 180 | LaTeX Font Info: Redeclaring font encoding OML on input line 566. 181 | LaTeX Font Info: Redeclaring font encoding OMS on input line 567. 182 | \macc@depth=\count102 183 | \c@MaxMatrixCols=\count103 184 | \dotsspace@=\muskip11 185 | \c@parentequation=\count104 186 | \dspbrk@lvl=\count105 187 | \tag@help=\toks16 188 | \row@=\count106 189 | \column@=\count107 190 | \maxfields@=\count108 191 | \andhelp@=\toks17 192 | \eqnshift@=\dimen110 193 | \alignsep@=\dimen111 194 | \tagshift@=\dimen112 195 | \tagwidth@=\dimen113 196 | \totwidth@=\dimen114 197 | \lineht@=\dimen115 198 | \@envbody=\toks18 199 | \multlinegap=\skip45 200 | \multlinetaggap=\skip46 201 | \mathdisplay@stack=\toks19 202 | LaTeX Info: Redefining \[ on input line 2665. 203 | LaTeX Info: Redefining \] on input line 2666. 204 | ) 205 | (/usr/local/texlive/2014/texmf-dist/tex/latex/bbm-macros/bbm.sty 206 | Package: bbm 1999/03/15 V 1.2 provides fonts for set symbols - TH 207 | LaTeX Font Info: Overwriting math alphabet `\mathbbm' in version `bold' 208 | (Font) U/bbm/m/n --> U/bbm/bx/n on input line 33. 209 | LaTeX Font Info: Overwriting math alphabet `\mathbbmss' in version `bold' 210 | (Font) U/bbmss/m/n --> U/bbmss/bx/n on input line 35. 211 | ) 212 | (/usr/local/texlive/2014/texmf-dist/tex/latex/graphics/graphicx.sty 213 | Package: graphicx 2014/04/25 v1.0g Enhanced LaTeX Graphics (DPC,SPQR) 214 | 215 | (/usr/local/texlive/2014/texmf-dist/tex/latex/graphics/graphics.sty 216 | Package: graphics 2009/02/05 v1.0o Standard LaTeX Graphics (DPC,SPQR) 217 | 218 | (/usr/local/texlive/2014/texmf-dist/tex/latex/graphics/trig.sty 219 | Package: trig 1999/03/16 v1.09 sin cos tan (DPC) 220 | ) 221 | (/usr/local/texlive/2014/texmf-dist/tex/latex/latexconfig/graphics.cfg 222 | File: graphics.cfg 2010/04/23 v1.9 graphics configuration of TeX Live 223 | ) 224 | Package graphics Info: Driver file: pdftex.def on input line 91. 225 | 226 | (/usr/local/texlive/2014/texmf-dist/tex/latex/pdftex-def/pdftex.def 227 | File: pdftex.def 2011/05/27 v0.06d Graphics/color for pdfTeX 228 | \Gread@gobject=\count109 229 | )) 230 | \Gin@req@height=\dimen116 231 | \Gin@req@width=\dimen117 232 | ) 233 | (/usr/local/texlive/2014/texmf-dist/tex/latex/subfig/subfig.sty 234 | Package: subfig 2005/06/28 ver: 1.3 subfig package 235 | 236 | (/usr/local/texlive/2014/texmf-dist/tex/latex/caption/caption.sty 237 | Package: caption 2013/05/02 v3.3-89 Customizing captions (AR) 238 | 239 | (/usr/local/texlive/2014/texmf-dist/tex/latex/caption/caption3.sty 240 | Package: caption3 2013/05/02 v1.6-88 caption3 kernel (AR) 241 | Package caption3 Info: TeX engine: e-TeX on input line 57. 242 | \captionmargin=\dimen118 243 | \captionmargin@=\dimen119 244 | \captionwidth=\dimen120 245 | \caption@tempdima=\dimen121 246 | \caption@indent=\dimen122 247 | \caption@parindent=\dimen123 248 | \caption@hangindent=\dimen124 249 | ) 250 | \c@ContinuedFloat=\count110 251 | Package caption Info: hyperref package is loaded. 252 | ) 253 | \c@KVtest=\count111 254 | \sf@farskip=\skip47 255 | \sf@captopadj=\dimen125 256 | \sf@capskip=\skip48 257 | \sf@nearskip=\skip49 258 | \c@subfigure=\count112 259 | \c@subfigure@save=\count113 260 | \c@lofdepth=\count114 261 | \c@subtable=\count115 262 | \c@subtable@save=\count116 263 | \c@lotdepth=\count117 264 | \sf@top=\skip50 265 | \sf@bottom=\skip51 266 | ) 267 | (/usr/local/texlive/2014/texmf-dist/tex/latex/algorithms/algorithm.sty 268 | Package: algorithm 2009/08/24 v0.1 Document Style `algorithm' - floating enviro 269 | nment 270 | 271 | (/usr/local/texlive/2014/texmf-dist/tex/latex/float/float.sty 272 | Package: float 2001/11/08 v1.3d Float enhancements (AL) 273 | \c@float@type=\count118 274 | \float@exts=\toks20 275 | \float@box=\box28 276 | \@float@everytoks=\toks21 277 | \@floatcapt=\box29 278 | ) 279 | (/usr/local/texlive/2014/texmf-dist/tex/latex/base/ifthen.sty 280 | Package: ifthen 2001/05/26 v1.1c Standard LaTeX ifthen package (DPC) 281 | ) 282 | \@float@every@algorithm=\toks22 283 | \c@algorithm=\count119 284 | ) 285 | (/usr/local/texlive/2014/texmf-dist/tex/latex/algorithms/algorithmic.sty 286 | Package: algorithmic 2009/08/24 v0.1 Document Style `algorithmic' 287 | \c@ALC@unique=\count120 288 | \c@ALC@line=\count121 289 | \c@ALC@rem=\count122 290 | \c@ALC@depth=\count123 291 | \ALC@tlm=\skip52 292 | \algorithmicindent=\skip53 293 | ) 294 | (/usr/local/texlive/2014/texmf-dist/tex/latex/comment/comment.sty 295 | \CommentStream=\write3 296 | 297 | Excluding comment 'comment') 298 | (/usr/local/texlive/2014/texmf-dist/tex/latex/amsfonts/amssymb.sty 299 | Package: amssymb 2013/01/14 v3.01 AMS font symbols 300 | 301 | (/usr/local/texlive/2014/texmf-dist/tex/latex/amsfonts/amsfonts.sty 302 | Package: amsfonts 2013/01/14 v3.01 Basic AMSFonts support 303 | \symAMSa=\mathgroup4 304 | \symAMSb=\mathgroup5 305 | LaTeX Font Info: Overwriting math alphabet `\mathfrak' in version `bold' 306 | (Font) U/euf/m/n --> U/euf/b/n on input line 106. 307 | )) 308 | (/usr/local/texlive/2014/texmf-dist/tex/latex/multirow/multirow.sty 309 | \bigstrutjot=\dimen126 310 | ) 311 | (./RPCAKit.aux) 312 | \openout1 = `RPCAKit.aux'. 313 | 314 | LaTeX Font Info: Checking defaults for OML/cmm/m/it on input line 17. 315 | LaTeX Font Info: ... okay on input line 17. 316 | LaTeX Font Info: Checking defaults for T1/cmr/m/n on input line 17. 317 | LaTeX Font Info: ... okay on input line 17. 318 | LaTeX Font Info: Checking defaults for OT1/cmr/m/n on input line 17. 319 | LaTeX Font Info: ... okay on input line 17. 320 | LaTeX Font Info: Checking defaults for OMS/cmsy/m/n on input line 17. 321 | LaTeX Font Info: ... okay on input line 17. 322 | LaTeX Font Info: Checking defaults for OMX/cmex/m/n on input line 17. 323 | LaTeX Font Info: ... okay on input line 17. 324 | LaTeX Font Info: Checking defaults for U/cmr/m/n on input line 17. 325 | LaTeX Font Info: ... okay on input line 17. 326 | LaTeX Font Info: Checking defaults for PD1/pdf/m/n on input line 17. 327 | LaTeX Font Info: ... okay on input line 17. 328 | \AtBeginShipoutBox=\box30 329 | 330 | (/usr/local/texlive/2014/texmf-dist/tex/latex/graphics/color.sty 331 | Package: color 2014/04/23 v1.1a Standard LaTeX Color (DPC) 332 | 333 | (/usr/local/texlive/2014/texmf-dist/tex/latex/latexconfig/color.cfg 334 | File: color.cfg 2007/01/18 v1.5 color configuration of teTeX/TeXLive 335 | ) 336 | Package color Info: Driver file: pdftex.def on input line 137. 337 | ) 338 | Package hyperref Info: Link coloring ON on input line 17. 339 | 340 | (/usr/local/texlive/2014/texmf-dist/tex/latex/hyperref/nameref.sty 341 | Package: nameref 2012/10/27 v2.43 Cross-referencing by name of section 342 | 343 | (/usr/local/texlive/2014/texmf-dist/tex/generic/oberdiek/gettitlestring.sty 344 | Package: gettitlestring 2010/12/03 v1.4 Cleanup title references (HO) 345 | ) 346 | \c@section@level=\count124 347 | ) 348 | LaTeX Info: Redefining \ref on input line 17. 349 | LaTeX Info: Redefining \pageref on input line 17. 350 | LaTeX Info: Redefining \nameref on input line 17. 351 | 352 | (./RPCAKit.out) (./RPCAKit.out) 353 | \@outlinefile=\write4 354 | \openout4 = `RPCAKit.out'. 355 | 356 | 357 | (/usr/local/texlive/2014/texmf-dist/tex/context/base/supp-pdf.mkii 358 | [Loading MPS to PDF converter (version 2006.09.02).] 359 | \scratchcounter=\count125 360 | \scratchdimen=\dimen127 361 | \scratchbox=\box31 362 | \nofMPsegments=\count126 363 | \nofMParguments=\count127 364 | \everyMPshowfont=\toks23 365 | \MPscratchCnt=\count128 366 | \MPscratchDim=\dimen128 367 | \MPnumerator=\count129 368 | \makeMPintoPDFobject=\count130 369 | \everyMPtoPDFconversion=\toks24 370 | ) (/usr/local/texlive/2014/texmf-dist/tex/latex/oberdiek/epstopdf-base.sty 371 | Package: epstopdf-base 2010/02/09 v2.5 Base part for package epstopdf 372 | 373 | (/usr/local/texlive/2014/texmf-dist/tex/latex/oberdiek/grfext.sty 374 | Package: grfext 2010/08/19 v1.1 Manage graphics extensions (HO) 375 | ) 376 | Package grfext Info: Graphics extension search list: 377 | (grfext) [.png,.pdf,.jpg,.mps,.jpeg,.jbig2,.jb2,.PNG,.PDF,.JPG,.JPE 378 | G,.JBIG2,.JB2,.eps] 379 | (grfext) \AppendGraphicsExtensions on input line 452. 380 | 381 | (/usr/local/texlive/2014/texmf-dist/tex/latex/latexconfig/epstopdf-sys.cfg 382 | File: epstopdf-sys.cfg 2010/07/13 v1.3 Configuration of (r)epstopdf for TeX Liv 383 | e 384 | )) 385 | Package caption Info: Begin \AtBeginDocument code. 386 | Package caption Info: subfig package v1.3 is loaded. 387 | Package caption Info: float package is loaded. 388 | Package caption Info: End \AtBeginDocument code. 389 | LaTeX Font Info: Try loading font information for U+msa on input line 22. 390 | 391 | (/usr/local/texlive/2014/texmf-dist/tex/latex/amsfonts/umsa.fd 392 | File: umsa.fd 2013/01/14 v3.01 AMS symbols A 393 | ) 394 | LaTeX Font Info: Try loading font information for U+msb on input line 22. 395 | 396 | (/usr/local/texlive/2014/texmf-dist/tex/latex/amsfonts/umsb.fd 397 | File: umsb.fd 2013/01/14 v3.01 AMS symbols B 398 | ) 399 | 400 | LaTeX Warning: Citation `candes2011robust' on page 1 undefined on input line 27 401 | . 402 | 403 | 404 | LaTeX Warning: Citation `candes2011robust' on page 1 undefined on input line 32 405 | . 406 | 407 | 408 | LaTeX Warning: Citation `lin2011linearized' on page 1 undefined on input line 6 409 | 6. 410 | 411 | [1 412 | 413 | {/usr/local/texlive/2014/texmf-var/fonts/map/pdftex/updmap/pdftex.map}] 414 | 415 | LaTeX Warning: Citation `lin2011linearized' on page 2 undefined on input line 7 416 | 9. 417 | 418 | 419 | LaTeX Warning: Citation `candes2011robust' on page 2 undefined on input line 79 420 | . 421 | 422 | 423 | LaTeX Warning: Citation `candes2011robust' on page 2 undefined on input line 88 424 | . 425 | 426 | 427 | LaTeX Warning: Citation `liu2010robust' on page 2 undefined on input line 88. 428 | 429 | No file RPCAKit.bbl. 430 | Package atveryend Info: Empty hook `BeforeClearDocument' on input line 121. 431 | [2] 432 | Package atveryend Info: Empty hook `AfterLastShipout' on input line 121. 433 | (./RPCAKit.aux) 434 | Package atveryend Info: Executing hook `AtVeryEndDocument' on input line 121. 435 | Package atveryend Info: Executing hook `AtEndAfterFileList' on input line 121. 436 | Package rerunfilecheck Info: File `RPCAKit.out' has not changed. 437 | (rerunfilecheck) Checksum: 4AD1C00E1145CD3F4BF65A5C4B9E76E4;139. 438 | 439 | 440 | LaTeX Warning: There were undefined references. 441 | 442 | Package atveryend Info: Empty hook `AtVeryVeryEnd' on input line 121. 443 | ) 444 | Here is how much of TeX's memory you used: 445 | 7469 strings out of 493117 446 | 111426 string characters out of 6135434 447 | 200621 words of memory out of 5000000 448 | 10826 multiletter control sequences out of 15000+600000 449 | 13980 words of font info for 54 fonts, out of 8000000 for 9000 450 | 1141 hyphenation exceptions out of 8191 451 | 44i,17n,42p,621b,413s stack positions out of 5000i,500n,10000p,200000b,80000s 452 | 454 | 473 | Output written on RPCAKit.pdf (2 pages, 194896 bytes). 474 | PDF statistics: 475 | 124 PDF objects out of 1000 (max. 8388607) 476 | 98 compressed objects within 1 object stream 477 | 13 named destinations out of 1000 (max. 500000) 478 | 25 words of extra memory for PDF output out of 10000 (max. 10000000) 479 | 480 | -------------------------------------------------------------------------------- /docs/SubKit.tex: -------------------------------------------------------------------------------- 1 | \documentclass{article} 2 | 3 | \usepackage[colorlinks=true]{hyperref} 4 | \usepackage[cmex10]{amsmath} 5 | \usepackage{bbm} 6 | \usepackage{graphicx} 7 | \usepackage{subfig} 8 | \usepackage{algorithm} 9 | \usepackage{algorithmic} 10 | \usepackage{comment} 11 | \usepackage{amsmath} 12 | \usepackage{amssymb} 13 | \usepackage{multirow} 14 | 15 | \newcommand{\BigO}[1]{\ensuremath{\operatorname{O}\left(#1\right)}} 16 | \DeclareMathOperator*{\argmin}{\mathrm{argmin}} 17 | 18 | \begin{document} 19 | 20 | \title{SubKit: Subspace Clustering Library} 21 | \author{Stephen Tierney, Yi Guo and Junbin Gao} 22 | \maketitle 23 | 24 | \tableofcontents 25 | 26 | \newpage 27 | \section{Motivation} 28 | 29 | SubKit is a library with implementations for subspace clustering learning algorithms. This library was created during the writing of the OSC journal article to ensure fair comparison between different methods. In the original OSC CVPR paper we used implementations provided by authors of SSC and LRR. However these implementations used different noise models to what we suggested with OSC. For example the original LRR implementation expects column wise noise while we expect Gaussian noise in all columns. Therefore we required new implementations with the same noise model for fair comparison in our journal article. 30 | 31 | \section{Preliminaries} 32 | 33 | We introduce required notation. We assume the following noise model 34 | \begin{align} 35 | \mathbf{X = A + N} 36 | \end{align} 37 | where $\mathbf A$ is the noise free data (column wise data samples), $\mathbf N$ is some noise and $\mathbf X$ is the observed data. We assume that each data sample in $\mathbf A$ lies exactly on its corresponding subspace. In an ideal case subspace clustering uses the self expressive model with the noise free data i.e.\ 38 | \begin{align} 39 | \mathbf{A = AZ} 40 | \end{align} 41 | where $\mathbf Z$ is the matrix of coefficients. However this is rarely the case since we do not observe noise free data therefore the self expressive model becomes 42 | \begin{align} 43 | \mathbf{X = XZ + E} 44 | \end{align} 45 | where $\mathbf E$ is a fitting error. Once $\mathbf Z$ has been estimated one performs spectral clustering to obtain the final segmentation. 46 | 47 | \newpage 48 | \section{Function Listing} 49 | 50 | \begin{table}[!h] 51 | {\small{ 52 | \centering 53 | 54 | \begin{tabular}{c | c | c} 55 | \hline 56 | Objective & Function & Section \\ 57 | \hline 58 | 59 | $\begin{array}{c} \min_{\mathbf Z} \; \|\mathbf Z\|_{1} \\ 60 | \text{s.t.} \; \mathbf{A = AZ} \end{array}$ 61 | & ssc\_noisefree & 4.1 \\ 62 | \hline 63 | 64 | \multirow{4}{*}{$\begin{array}{c} \min_{\mathbf Z} \frac12\|\mathbf X - \mathbf X\mathbf Z\|^2_F + \lambda\|\mathbf Z\|_{1} \\ 65 | \text{s.t.} \quad \mathbf{X = XZ + E}\text{, diag}(\mathbf Z) = \mathbf 0 \end{array}$} 66 | & ssc\_relaxed & 4.2 \\ 67 | & ssc\_relaxed\_lin & 4.3.1 \\ 68 | & ssc\_relaxed\_lin\_ext & 4.3.2 \\ 69 | & ssc\_relaxed\_lin\_acc & 4.3.3 \\ 70 | \hline 71 | 72 | $\begin{array}{c} \min_{\mathbf{Z, E}} \frac12\|\mathbf E\|^2_F+ \lambda\|\mathbf Z\|_{1} \\ 73 | \text{s.t.} \quad \mathbf{X = XZ + E}\text{, diag}(\mathbf Z) = \mathbf 0 \end{array}$ 74 | & ssc\_exact\_fro & 4.4 \\ 75 | \hline 76 | 77 | $\begin{array}{c} \min_{\mathbf{Z, E}} \|\mathbf E\|_1+ \lambda\|\mathbf Z\|_{1} \\ 78 | \text{s.t.} \quad \mathbf{X = XZ + E}\text{, diag}(\mathbf Z) = \mathbf 0\end{array}$ 79 | & ssc\_exact\_l1 & 4.4 \\ 80 | \hline 81 | 82 | $\begin{array}{c} \min_{\mathbf{Z, E}} \|\mathbf E\|_{1,2}+ \lambda\|\mathbf Z\|_{1} \\ 83 | \text{s.t.} \quad \mathbf{X = XZ + E}\text{, diag}(\mathbf Z) = \mathbf 0 \end{array}$ 84 | & ssc\_exact\_l1l2 & 4.4 \\ 85 | \hline 86 | 87 | $\begin{array}{c} \min_{\mathbf Z} \; \|\mathbf Z\|_{*} \\ 88 | \text{s.t.} \; \mathbf{A = AZ} \end{array}$ 89 | & lrr\_noisefree & 5.1 \\ 90 | \hline 91 | 92 | \multirow{4}{*}{$\begin{array}{c} \min_{\mathbf Z} \frac12\|\mathbf X - \mathbf X\mathbf Z\|^2_F + \lambda\|\mathbf Z\|_{*} \end{array}$} 93 | & lrr\_relaxed & 5.2 \\ 94 | & lrr\_relaxed\_lin & 5.3 \\ 95 | & lrr\_relaxed\_lin\_ext & 5.3 \\ 96 | & lrr\_relaxed\_lin\_acc & 5.3 \\ 97 | \hline 98 | 99 | $\begin{array}{c} \min_{\mathbf{Z, E}} \frac12\|\mathbf E\|^2_F+ \lambda\|\mathbf Z\|_{*} \\ 100 | \text{s.t.} \quad \mathbf{X = XZ + E} \end{array}$ 101 | & lrr\_exact\_fro & 5.4 \\ 102 | \hline 103 | 104 | $\begin{array}{c} \min_{\mathbf{Z, E}} \|\mathbf E\|_1+ \lambda\|\mathbf Z\|_{*} \\ 105 | \text{s.t.} \quad \mathbf{X = XZ + E} \end{array}$ 106 | & lrr\_exact\_l1 & 5.4 \\ 107 | \hline 108 | 109 | $\begin{array}{c} \min_{\mathbf{Z, E}} \|\mathbf E\|_{1,2}+ \lambda\|\mathbf Z\|_{*} \\ 110 | \text{s.t.} \quad \mathbf{X = XZ + E} \end{array}$ 111 | & lrr\_exact\_l1l2 & 5.4 \\ 112 | \hline 113 | 114 | \multirow{3}{*}{$\begin{array}{c} \min_{\mathbf {Z, A, N}} \; \lambda \|\mathbf{N}\|_{q} + \|\mathbf Z\|_{*} \\ 115 | \text{s.t.} \quad \mathbf{A = AZ, X = A + N} \end{array}$} 116 | & r\_lrr\_fro & 5.5 \\ 117 | & r\_lrr\_l1 & 5.5 \\ 118 | & r\_lrr\_l2 & 5.5 \\ 119 | \hline 120 | 121 | $\begin{array}{c} \min_{\mathbf Z} \frac12\|\mathbf{X - X Z}|^2_F +\lambda_1\|\mathbf Z\|_{1}+\lambda_2\|\mathbf Z\mathbf R\|_{1} \\ 122 | \text{s.t.} \; \text{diag}(\mathbf Z) = \mathbf 0 \end{array}$ 123 | & spatsc\_noisefree & 6.1 \\ 124 | \hline 125 | 126 | $\begin{array}{c} \min_{\mathbf Z} \frac12\|\mathbf{X - X Z}|^2_F +\lambda_1\|\mathbf Z\|_{1}+\lambda_2\|\mathbf Z\mathbf R\|_{1,2} \\ 127 | \text{s.t.} \; \text{diag}(\mathbf Z) = \mathbf 0 \end{array}$ 128 | & osc\_noisefree & 7.1 \\ 129 | \hline 130 | 131 | \end{tabular} 132 | }} 133 | \end{table} 134 | 135 | \newpage 136 | \section{Sparse Subspace Clustering} 137 | 138 | \subsection{Noise Free} 139 | 140 | \begin{align} 141 | \min_{\mathbf Z} \lambda\|\mathbf Z\|_{1} \\ 142 | \text{s.t.} \quad \mathbf{A = AZ} \nonumber 143 | \end{align} 144 | The solution to the above objective has a fast approximate solution, given by the Shape Interaction Matrix. See the low-rank clustering section for further details. Alternatively one can calculate the sample correlation matrix $\mathbf X^T \mathbf X$ and select points with the maximum correlation as neighbours on the graph. 145 | 146 | \subsection{Relaxed SSC ADMM} 147 | 148 | \begin{align} 149 | \min_{\mathbf Z} \frac12\|\mathbf X - \mathbf X\mathbf Z\|^2_F + \lambda\|\mathbf Z\|_{1} 150 | \end{align} 151 | To solve the relaxation via ADMM one must incorporate an auxiliary variable 152 | \begin{align} 153 | \min_{\mathbf{Z, J}} \frac12\|\mathbf X - \mathbf X\mathbf J\|^2_F + \lambda\|\mathbf Z\|_{1} \\ 154 | \text{s.t.} \quad \mathbf{Z = J} \nonumber 155 | \end{align} 156 | \begin{align} 157 | \min_{\mathbf{Z, J}} \frac12\|\mathbf X - \mathbf X\mathbf J\|^2_F + \lambda\|\mathbf Z\|_{1} + \langle \mathbf{Y, Z - J} \rangle + \frac{\mu}{2} \| \mathbf{Z - J} \|_F^2 158 | \end{align} 159 | Then iterate the following 160 | \begin{enumerate} 161 | \item Fix others and solve for $\mathbf J$ 162 | \[ 163 | \min_{\mathbf J} \frac12\|\mathbf X - \mathbf X\mathbf J\|^2_F - \langle \mathbf{Y, J} \rangle + \frac{\mu}{2} \| \mathbf{Z - J} \|_F^2 164 | \] 165 | \[ 166 | \min_{\mathbf J} \frac12\|\mathbf X - \mathbf X\mathbf J\|^2_F + \frac{\mu}{2} \| (\mathbf Z + \frac{1}{\mu} \mathbf Y ) - \mathbf J \|_F^2 167 | \] 168 | \[ 169 | \mathbf X^T(\mathbf X - \mathbf X\mathbf J) + \mu ( (\mathbf Z + \frac{1}{\mu} \mathbf Y ) - \mathbf J ) 170 | \] 171 | \[ 172 | \mathbf X^T\mathbf X\mathbf J + \mu \mathbf J = \mathbf X^T\mathbf X + \mu \mathbf Z + \mathbf Y 173 | \] 174 | \[ 175 | (\mathbf X^T\mathbf X + \mu \mathbf I )\mathbf J = \mathbf X^T\mathbf X + \mu \mathbf Z + \mathbf Y 176 | \] 177 | \[ 178 | \mathbf J = (\mathbf X^T\mathbf X + \mu \mathbf I )^{-1} (\mathbf X^T\mathbf X + \mu \mathbf Z + \mathbf Y) 179 | \] 180 | 181 | \item Fix others and solve for $\mathbf Z$ 182 | \[ 183 | \min_{\mathbf Z} \lambda\|\mathbf Z\|_{1} + \langle \mathbf{Y, Z} \rangle + \frac{\mu}{2} \| \mathbf{Z - J} \|_F^2 184 | \] 185 | \[ 186 | \min_{\mathbf Z} \lambda\|\mathbf Z\|_{1} + \frac{\mu}{2} \| \mathbf Z - (\mathbf J - \frac{1}{\mu} \mathbf Y) \|_F^2 187 | \] 188 | 189 | \item Update $\mathbf Y$ 190 | \[ 191 | \mathbf Y = \mathbf Y + \mu (\mathbf{Z - J}) 192 | \] 193 | 194 | \item Check stopping criteria 195 | \[ 196 | \| \mathbf Z - \mathbf J \|_F < \epsilon_1, \; 197 | \mu \; \textrm{max} ( \| \mathbf Z_{k+1} - \mathbf Z_{k} \|_F , \| \mathbf J_{k+1} - \mathbf J_{k} \|_F) < \epsilon_2 198 | \] 199 | 200 | \end{enumerate} 201 | 202 | \subsection{Relaxed SSC Linearised} 203 | 204 | Instead of using ADMM one can linearise the Frobenius norm term instead. This removes the need to do an expensive matrix inversion. 205 | \begin{align} 206 | \min_{\mathbf Z} L = \frac12\|\mathbf X - \mathbf X\mathbf Z\|^2_F + \lambda\|\mathbf Z\|_{1} 207 | \end{align} 208 | 209 | Let $F = \frac12\|\mathbf X - \mathbf X\mathbf Z\|^2_F$ and $\partial F = - \mathbf X^T \mathbf X + \mathbf X^T \mathbf{X Z}$. 210 | 211 | \subsubsection{Gradient Descent} 212 | 213 | This version consists on iterating the following until convergence 214 | 215 | \[ 216 | \min_{\mathbf Z} \widetilde{L}_{\rho}(\mathbf{Z, Z_k}) = \lambda\|\mathbf Z\|_{1} + \frac{\rho}{2} \| \mathbf Z - ( \mathbf Z_{k-1} - \frac{1}{\rho} \partial F(\mathbf Z_{k-1})) \|_F^2 217 | \] 218 | 219 | \subsubsection{Extended Gradient Algorithm} 220 | 221 | It has been shown that through the correct choice of step size $\rho$ the gradient method can achieve a convergence rate of $\BigO{\frac{1}{k}}$ \cite{ji2009accelerated}. More specifically we require that $\rho \geq C$ where $C$ is the Lipschitz constant. However we do not know the value of $C$ in advance. Fortunately we know that if $L(\mathbf B) \leq \widetilde{L}_{\rho}(\mathbf B, \mathbf Z_{k-1})$ where $\mathbf B = \mathcal S_{\frac{\lambda}{\rho}}(\mathbf Z_{k-1} - \frac1{\lambda}\partial F(\mathbf Z_{k-1}))$ then $\rho \geq C$. 222 | 223 | \begin{algorithm} 224 | \caption{Extended Gradient Descent for Robust MC} 225 | \begin{algorithmic} 226 | 227 | \REQUIRE $k = 1$, $r_0 = \infty$, $\mathbf Z_0 = \mathbf 0$, $\lambda$, $\rho$, $\gamma$, $\epsilon$ 228 | 229 | \WHILE{$r_k - r_{k-1} \geq \epsilon$ } 230 | 231 | \WHILE{$L(\mathbf B) \geq \widetilde{L}_{\rho}(\mathbf B, \mathbf Z_{k-1})$} 232 | 233 | \STATE $\rho = \gamma \rho$ 234 | 235 | \ENDWHILE 236 | 237 | \STATE $\mathbf Z_k = \mathcal S_{\frac{\lambda}{\rho}}(\mathbf Z_{k-1} - \frac1{\rho}\partial F(\mathbf Z_{k-1}))$ 238 | \STATE $r_k = \frac12\|\mathbf X - \mathbf X\mathbf Z_k\|^2_F + \lambda\|\mathbf Z_k\|_{1}$ 239 | \STATE $k = k + 1$ 240 | 241 | \ENDWHILE 242 | 243 | \end{algorithmic} 244 | \end{algorithm} 245 | 246 | \subsubsection{Accelerated Gradient Algorithm} 247 | 248 | We can further improve our convergence rate to $\BigO{\frac{1}{k^2}}$ by adopting Nesterov's accelerated gradient algorithm. This is similar to the algorithm described in \cite{ji2009accelerated}. Let $\mathbf B = \mathcal S_{\frac{\lambda}{\rho}}(\mathbf J_{k-1} - \frac1{\rho}\partial F(\mathbf J_{k-1}))$. 249 | 250 | \begin{algorithm} 251 | \caption{Accelerated Gradient Descent for Robust MC} 252 | \begin{algorithmic} 253 | 254 | \REQUIRE $k = 1$, $r_0 = \infty$, $\mathbf Z_0 = \mathbf 0$, $\mathbf J_0 = \mathbf 0$, $\alpha_0 = 1$, $\lambda$, $\rho$, $\gamma$, $\epsilon$ 255 | 256 | \WHILE{$r_k - r_{k-1} \geq \epsilon$ } 257 | 258 | \WHILE{$L(\mathbf B) \geq \widetilde{L}_{\rho}(\mathbf B, \mathbf J_{k-1})$} 259 | 260 | \STATE $\rho = \gamma \rho$ 261 | 262 | \ENDWHILE 263 | 264 | \STATE $\mathbf Z_k = \mathcal S_{\frac{\lambda}{\rho}}(\mathbf J_{k-1} - \frac1{\rho}\partial F(\mathbf J_{k-1}))$ 265 | \STATE $\alpha_{k} = \frac{1 + \sqrt{1 + 4 \alpha_{k-1}^2)}}{2}$ 266 | \STATE $\mathbf J_{k} = \mathbf Z_k + \left ( \frac{\alpha_{k-1} - 1}{\alpha_{k}} \right ) (\mathbf Z_k - \mathbf Z_{k-1})$ 267 | \STATE $r_k = \frac12\|\mathbf X - \mathbf X\mathbf Z_k\|^2_F + \lambda\|\mathbf Z_k\|_{1}$ 268 | \STATE $k = k + 1$ 269 | 270 | \ENDWHILE 271 | 272 | \end{algorithmic} 273 | \end{algorithm} 274 | 275 | 276 | \subsection{Exact SSC LADM} 277 | 278 | Using LADM and exact constraints allows us to modify the noise term from Gaussian noise only to any other norm. The objective becomes 279 | \begin{align} 280 | \min_{\mathbf{E, Z}} \frac12\|\mathbf E \|^2_q + \lambda\|\mathbf Z\|_{1} \\ 281 | \text{s.t.} \quad \mathbf{X = XZ + E} \nonumber 282 | \end{align} 283 | where $q$ is a placeholder for norms such as $\ell_1, F, \ell_{1,2}$ etc. 284 | \[ 285 | \min_{\mathbf{E, Z}} \frac12\|\mathbf E \|^2_q + \lambda\|\mathbf Z\|_{1} + \langle \mathbf{Y, XZ - X + E } \rangle + \frac{\mu}{2} \|\mathbf{XZ - X + E } \|_F^2 286 | \] 287 | 288 | Iterate the following 289 | \begin{enumerate} 290 | \item Fix others solve for $\mathbf Z$ 291 | \[ 292 | \min_{\mathbf{Z}} \lambda\|\mathbf Z\|_{1} + \langle \mathbf{Y, XZ} \rangle + \frac{\mu}{2} \|\mathbf{XZ - (X - E) } \|_F^2 293 | \] 294 | \[ 295 | \min_{\mathbf{Z}} \lambda\|\mathbf Z\|_{1} + \frac{\mu}{2} \|\mathbf{XZ - (X - E} - \frac{1}{\mu} \mathbf Y ) \|_F^2 296 | \] 297 | Let $F = \frac{\mu}{2} \|\mathbf{XZ - (X - E} - \frac{1}{\mu} \mathbf Y ) \|_F^2$ and $\partial F = \mu \mathbf X^T (\mathbf{XZ - (X - E} - \frac{1}{\mu} \mathbf Y ))$ 298 | \[ 299 | \min_{\mathbf{Z}} \lambda\|\mathbf Z\|_{1} + \frac{\rho}{2} \| \mathbf Z - (\mathbf Z_{k} - \frac{1}{\rho} \partial F(\mathbf Z_{k}) \|_F^2 300 | \] 301 | 302 | 303 | \item Fix others and solve for $\mathbf E$ 304 | \[ 305 | \min_{\mathbf{E}} \frac12\|\mathbf E \|^2_q + \langle \mathbf{Y, E} \rangle + \frac{\mu}{2} \|\mathbf{XZ - X + E } \|_F^2 306 | \] 307 | \[ 308 | \min_{\mathbf{E}} \frac12\|\mathbf E \|^2_q + \langle \mathbf{Y, E} \rangle + \frac{\mu}{2} \|\mathbf{E - (X - XZ)} \|_F^2 309 | \] 310 | \[ 311 | \min_{\mathbf{E}} \frac12\|\mathbf E \|^2_q + \frac{\mu}{2} \|\mathbf{E - (X - XZ} - \frac{1}{\mu} \mathbf Y) \|_F^2 312 | \] 313 | 314 | 315 | \item Update $\mathbf Y$ 316 | \begin{align*} 317 | \mathbf Y =& \mathbf Y + \mu (\mathbf{XZ - X + E}) 318 | \end{align*} 319 | 320 | \item Update $\mu$ 321 | \begin{align*} 322 | \mu = \textrm{min}( \mu_{\text{max}}, \gamma \mu) 323 | \end{align*} 324 | where $\gamma$ is defined as 325 | \[ 326 | \gamma = 327 | \begin{cases} 328 | \gamma_0 & \text{if} \;\; \mu_k \sqrt{\rho} \frac{\textrm{max} ( \| \mathbf Z_{k+1} - \mathbf Z_{k} \|_F , \| \mathbf E_{k+1} - \mathbf E_{k} \|_F)}{\| \mathbf X \|_F} < \epsilon \\ 329 | 1 & \text{otherwise,} 330 | \end{cases} 331 | \] 332 | and $\rho > \| \mathbf X \|_F^2$, $\mu_{\text{max}} >> \mu_0$ and $\epsilon > 0$. 333 | 334 | \item Check stopping criteria 335 | \[ 336 | \frac{\| \mathbf X \mathbf Z_{k+1} - \mathbf X + \mathbf E_{k+1} \|_F}{ \| \mathbf X \|_F} < \epsilon_1, \; 337 | \mu_k \sqrt{\rho} \frac{\textrm{max} ( \| \mathbf Z_{k+1} - \mathbf Z_{k} \|_F , \| \mathbf E_{k+1} - \mathbf E_{k} \|_F)}{\| \mathbf X \|_F} < \epsilon_2 338 | \] 339 | 340 | \end{enumerate} 341 | 342 | \subsection{Diagonal Constraint} 343 | 344 | In some cases it may be desirable to enforce the constraint $\textrm{diag}(\mathbf Z) = \mathbf 0$ i.e.\ we should not allow each data point to be represented by itself. To enforce such a constraint it is not necessary to significantly alter the aforementioned optimisation schemes. This constraint only affects the step involving $\mathbf Z$. Since this step is the soft shrinkage operator and is separable at the element level one can simply set the diagonal entries to $0$ afterwards. 345 | 346 | \newpage 347 | \section{Low-Rank Subspace Clustering} 348 | 349 | \subsection{Noise Free} 350 | 351 | \begin{align} 352 | \min_{\mathbf{Z}} \; \| \mathbf{Z} \|_* \\ 353 | \text{s.t.} \quad \mathbf{A = AZ} \nonumber 354 | \end{align} 355 | 356 | The solution to the above objective is given by the Shape Interaction Matrix (SIM) which is defined as $\mathbf{V V^T}$ where $\mathbf V$ is the right singular vectors of $\mathbf A$ i.e.\ 357 | \[ 358 | \mathbf{A = U \Sigma V^T}, \;\; \mathbf \Sigma = \text{diag}(\{\sigma_i\}_{i=1}^r) 359 | \] 360 | 361 | \subsection{Relaxed LRR ADMM} 362 | 363 | \begin{align} 364 | \min_{\mathbf Z} \frac12\|\mathbf X - \mathbf X\mathbf Z\|^2_F + \tau \|\mathbf Z\|_{*} 365 | \end{align} 366 | This is solved similarly to Relaxed SSC ADMM. Instead of the $\ell_1$ shrinking operator in the update step for $\mathbf Z$ we must use the singular value shrinking operator which is defined as 367 | \begin{align} 368 | \mathcal D_{\tau}(\mathbf Y) = \mathbf U S_{\tau}(\mathbf \Sigma) \mathbf V^T, \;\; S_{\tau}(\mathbf \Sigma) = \text{diag}(\{\text{max}(\sigma_i - \tau, 0)\}). 369 | \end{align} 370 | 371 | \subsection{Relaxed LRR Linearised} 372 | 373 | This is solved similarly to Relaxed SSC ADMM, again replacing the $\ell_1$ with the singular value shrinking operator. 374 | 375 | \subsection{Exact LRR LADM} 376 | 377 | This is solved similarly to Exact SSC LADM, again replacing the $\ell_1$ with the singular value shrinking operator. 378 | 379 | \subsection{Robust LRR} 380 | 381 | An extension of LRR called Robust-LRR (R-LRR) aims to directly deal with noisy data using the previously described data generation model 382 | \begin{align} 383 | \min_{\mathbf {Z, A, N}} \; \lambda \|\mathbf{N}\|_{q} + \|\mathbf Z\|_{*} \\ 384 | \text{s.t.} \quad \mathbf{A = AZ, X = A + N} \nonumber 385 | \end{align} 386 | This objective can be decomposed into two steps. The first step solves a variant of RPCA [CITE] and the second uses the estimated $\mathbf A$ to compute $\mathbf Z$ using the SIM. However it is unclear as to whether such a procedure will be capable of exactly removing all noise, thus the SIM may give poor results. Fortunately further work in nuclear norm based subspace clustering by Vidal and Favaro \cite{Vidal201447} demonstrated a number of other closed form solutions for noisy data. 387 | 388 | \newpage 389 | \section{Spatial Subspace Clustering} 390 | 391 | In \cite{Guo.Y;Gao.J;Li.F-2013} the following spatial subspace clustering (SpatSC) objective was proposed 392 | \begin{align} 393 | \label{YiGuo1} 394 | \min_{\mathbf Z, \mathbf E} \frac12\|\mathbf E|^2_F +\lambda_1\|\mathbf Z\|_{1}+\lambda_2\|\mathbf Z\mathbf R\|_{1} \\ 395 | \text{s.t.} \quad \mathbf{X = XZ + E}\text{, diag}(\mathbf Z) = \mathbf 0 \nonumber 396 | \end{align} 397 | 398 | \subsection{Implementation} 399 | 400 | SpatSC can be implemented similarly to OSC. However the $\ell_{1,2}$ shrinkage operator is replaced with $\ell_1$ shrinkage operator. Please see the following section for details. 401 | 402 | \newpage 403 | \section{Ordered Subspace Clustering} 404 | 405 | \begin{align} 406 | \label{objective} 407 | \min_{\mathbf Z, \mathbf E} \frac12\|\mathbf E \|^2_F +\lambda_1\|\mathbf Z\|_{1}+\lambda_2\|\mathbf Z\mathbf R\|_{1,2} \\ 408 | \text{s.t.} \quad \mathbf{X = XZ + E} \nonumber 409 | \end{align} 410 | 411 | \subsection{Relaxed Constraints} 412 | 413 | First we remove the variable $\mathbf E$ by using the constraint and thus the objective \eqref{objective} can be re-written as follows, 414 | \begin{align} 415 | \label{objective_relaxed} 416 | \min_{\mathbf Z} \frac12\|\mathbf X - \mathbf X\mathbf Z\|^2_F +\lambda_1\|\mathbf Z\|_{1}+\lambda_2\|\mathbf J \|_{1,2}\\ 417 | \text{s.t.} \quad \mathbf{J = ZR} \nonumber 418 | \end{align} 419 | 420 | Then the Augmented Lagrangian for the two introduced constraints is 421 | \begin{align} 422 | \mathcal{L}(\mathbf Z, \mathbf J) = & \frac12\|\mathbf X - \mathbf X\mathbf Z\|^2_F + \lambda_1 \|\mathbf Z\|_{1} + \lambda_2\|\mathbf J\|_{1,2} \notag\\ 423 | & + \langle \mathbf Y_1, \mathbf J - \mathbf Z\mathbf R\rangle +\frac{\mu^k}2\|\mathbf J - \mathbf Z\mathbf R\|^2_F 424 | \label{objectiveADMM} 425 | \end{align} 426 | 427 | We can solve \eqref{objectiveADMM} for $\mathbf Z$ and $\mathbf J$ in an alternative manner when fixing the others, respectively. 428 | 429 | \begin{enumerate} 430 | 431 | \item Set $\mathbf J = \mathbf J^k$, solve for $\mathbf Z^{k+1}$ by 432 | \begin{align*} 433 | \lambda_1 \|\mathbf Z\|_{1} + \frac12\|\mathbf X - \mathbf X\mathbf Z\|^2_F + \langle \mathbf Y, \mathbf J - \mathbf Z\mathbf R\rangle +\frac{\mu^k}2\|\mathbf J - \mathbf Z\mathbf R\|^2_F 434 | \end{align*} 435 | which is equivalent to 436 | \begin{align*} 437 | \lambda_1 \|\mathbf Z\|_{1} + \frac12\|\mathbf X - \mathbf X\mathbf Z\|^2_F + \frac{\mu^k}2\|\mathbf J - \mathbf Z\mathbf R + \frac{1}{\mu} \mathbf Y \|^2_F 438 | \end{align*} 439 | We linearise the last two terms which we call $F$ 440 | \begin{align*} 441 | \min_{\mathbf Z} \lambda_1 \| \mathbf Z \|_1 + \frac{\rho}{2} \| \mathbf Z - (\mathbf Z_{k-1} - \frac{1}{\rho} \partial F) \|_F^2 442 | \end{align*} 443 | and $\partial F = \mathbf X^T(\mathbf{X - XZ}) + \mu (\mathbf J - \mathbf Z\mathbf R + \frac{1}{\mu} \mathbf Y)\mathbf R^T$. 444 | 445 | \item Set $\mathbf Z = \mathbf Z^k$, solve for $\mathbf J^{k+1}$ by 446 | \begin{align*} 447 | \lambda_2\|\mathbf J\|_{1,2} + \langle \mathbf Y_1, \mathbf J - \mathbf Z\mathbf R\rangle +\frac{\mu^k}2\|\mathbf J - \mathbf Z\mathbf R\|^2_F 448 | \end{align*} 449 | which is equivalent to 450 | \begin{align*} 451 | \lambda_2\|\mathbf J\|_{1,2} + \frac{\mu^k}2\|\mathbf J - \mathbf Z\mathbf R + \frac{1}{\mu} \mathbf Y \|^2_F 452 | \end{align*} 453 | We linearise the last term which we call $F$ 454 | \begin{align*} 455 | \min_{\mathbf J} \lambda_2\|\mathbf J\|_{1,2}+ \frac{\rho}{2} \| \mathbf J - (\mathbf J_{k-1} - \frac{1}{\rho} \partial F) \|_F^2 456 | \end{align*} 457 | and $\partial F = \mu (\mathbf J - \mathbf Z\mathbf R + \frac{1}{\mu} \mathbf Y)$. 458 | 459 | \item Update $\mathbf Y$ 460 | \[ 461 | \mathbf Y = \mathbf Y + \mu (\mathbf J - \mathbf Z\mathbf R) 462 | \] 463 | 464 | \item Update $\mu$ 465 | \begin{align*} 466 | \mu^{k+1} = \textrm{min}( \mu_{\text{max}_1}, \gamma \mu^k)\\ 467 | \end{align*} 468 | where $\gamma$ is defined as 469 | \[ 470 | \gamma = 471 | \begin{cases} 472 | \gamma^0 & \text{if} \;\; \mu^k \textrm{max} ( \| \mathbf Z^{k+1} - \mathbf Z^{k} \|_F , \| \mathbf J^{k+1} - \mathbf J^{k} \|_F) < \epsilon_2 \\ 473 | 1 & \text{otherwise,} 474 | \end{cases} 475 | \] 476 | 477 | and $\mu^{\text{max}} \gg \mu^0$. 478 | 479 | \item Check stopping criteria 480 | \[ 481 | \|\mathbf J^{k+1} - \mathbf Z^{k+1} \mathbf R \|_F < \epsilon_1, \; 482 | \mu^k \sqrt{\rho} \; \textrm{max} ( \| \mathbf Z^{k+1} - \mathbf Z^{k} \|_F , \| \mathbf J^{k+1} - \mathbf J^{k} \|) < \epsilon_2 483 | \] 484 | 485 | \end{enumerate} 486 | 487 | \subsection{Exact Constraints} 488 | 489 | Similar to the relaxed version we begin by introducing auxiliary variables 490 | \begin{align} 491 | \label{objective_exact} 492 | \min_{\mathbf Z, \mathbf E, \mathbf J} \frac12\|\mathbf E\|^2_F +\lambda_1\|\mathbf Z\|_{1}+\lambda_2\| \mathbf J \|_{1,2}\\ 493 | \text{s.t.} \quad \mathbf{X = XZ + E}, \mathbf{J = ZR} \nonumber 494 | \end{align} 495 | We then form the Augmented Lagrangian to incorporate our constraints 496 | \begin{align} 497 | \mathcal{L}(\mathbf E, \mathbf Z, \mathbf J) = & \frac12\|\mathbf E\|^2_F + \lambda_1 \|\mathbf Z\|_{1} + \lambda_2\|\mathbf J\|_{1,2} \notag\\ 498 | & + \langle \mathbf Y_1, \mathbf{XZ} - \mathbf X + \mathbf E \rangle +\frac{\mu}2\|\mathbf{XZ} - \mathbf X + \mathbf E\|^2_F \notag\\ 499 | & + \langle \mathbf Y_2, \mathbf J - \mathbf Z\mathbf R\rangle +\frac{\mu}2\|\mathbf J - \mathbf Z\mathbf R\|^2_F 500 | \end{align} 501 | Then we solve for $\mathbf{E, Z, J}$ alternatively while fixing others in the following way 502 | 503 | \begin{enumerate} 504 | 505 | \item Set $\mathbf E = \mathbf E^k$ and $\mathbf J = \mathbf J^k$, solve for $\mathbf Z^{k+1}$ by 506 | \begin{align*} 507 | \min_{\mathbf Z} \lambda_1 \| \mathbf Z \|_1 + \langle \mathbf Y^k_1, \mathbf{XZ} - \mathbf X + \mathbf E \rangle +\frac{\mu^k}2\|\mathbf{XZ} - \mathbf X + \mathbf E\|^2_F\\ 508 | + \langle \mathbf Y^k_2, \mathbf J - \mathbf Z\mathbf R\rangle +\frac{\mu^k}2\|\mathbf J - \mathbf Z\mathbf R\|^2_F 509 | \end{align*} 510 | \begin{align*} 511 | \min_{\mathbf Z} \lambda_1 \| \mathbf Z \|_1 + \frac{\mu^k}2\|\mathbf{XZ} - (\mathbf X - \mathbf E - \frac{1}{\mu^k} \mathbf Y^k_1)\|^2_F \\ + \frac{\mu^k}2\| \mathbf Z\mathbf R - (\mathbf J - \frac{1}{\mu^k} \mathbf Y^k_2)\|^2_F 512 | \end{align*} 513 | We linearise the last two terms which we call $F$ 514 | \begin{align*} 515 | \min_{\mathbf Z} \lambda_1 \| \mathbf Z \|_1 + \frac{\rho}{2} \| \mathbf Z - (\mathbf Z_{k-1} - \frac{1}{\rho} \partial F) \|_F^2 516 | \end{align*} 517 | and $\partial F = \mu^k \mathbf X^T (\mathbf{XZ_{k-1}} - (\mathbf X - \mathbf E - \frac{1}{\mu^k} \mathbf Y^k_1)) + \mu^k(\mathbf{Z_{k-1}R} - (\mathbf J - \frac{1}{\mu^k} \mathbf Y^k_2))\mathbf R^T$. 518 | 519 | \item Set $\mathbf Z = \mathbf Z^k$ and $\mathbf J = \mathbf J^k$ solve for $\mathbf E^{k+1}$ by 520 | \begin{align*} 521 | \min_{\mathbf E} \frac12\|\mathbf E\|^2_F + \langle \mathbf Y^k_1, \mathbf{XZ} - \mathbf X + \mathbf E \rangle \\ + \frac{\mu^k}2\|\mathbf{XZ} - \mathbf X + \mathbf E\|^2_F 522 | \end{align*} 523 | \begin{align*} 524 | \min_{\mathbf E} \frac12\|\mathbf E\|^2_F + \frac{\mu^k}2\| \mathbf E - (\mathbf{XZ} - \mathbf X + \frac{1}{\mu^k} \mathbf Y^k_1) \|^2_F 525 | \end{align*} 526 | 527 | 528 | \item Set $\mathbf Z = \mathbf Z^k$ and $\mathbf E = \mathbf E^k$ solve for $\mathbf J^{k+1}$ by 529 | \begin{align*} 530 | \min_{\mathbf J} \lambda_2\|\mathbf J\|_{1,2} + \langle \mathbf Y^k_2, \mathbf J - \mathbf Z\mathbf R\rangle +\frac{\mu^k}2\|\mathbf J - \mathbf Z\mathbf R\|^2_F 531 | \end{align*} 532 | \begin{align*} 533 | \min_{\mathbf J} \lambda_2\|\mathbf J\|_{1,2} + \frac{\mu^k}2\|\mathbf J - (\mathbf Z\mathbf R - \frac{1}{\mu^k} \mathbf Y^k_2) \|^2_F 534 | \end{align*} 535 | 536 | \item Update $\mathbf Y_1$ and $\mathbf Y_2$ 537 | \begin{align*} 538 | \mathbf Y^{k+1}_1 =& \mathbf Y^k_1 + \mu^k (\mathbf{XZ - X + E})\\ 539 | \mathbf Y^{k+1}_2 =& \mathbf Y^k_2 + \mu^k (\mathbf{J - ZR}) 540 | \end{align*} 541 | 542 | \item Update $\mu$ 543 | \begin{align*} 544 | \mu^{k+1} = \textrm{min}( \mu_{\text{max}_1}, \gamma \mu^k) 545 | \end{align*} 546 | where $\gamma$ is defined as 547 | \[ 548 | \gamma_1 = 549 | \begin{cases} 550 | \gamma^0 & \text{if} \;\; \mu^k \sqrt{\rho} \frac{ \textrm{max} ( \| \mathbf Z^{k+1} - \mathbf Z^{k} \|_F , \| \mathbf E^{k+1} - \mathbf E^{k} \|, \| \mathbf J^{k+1} - \mathbf J^{k} \|_F , \| \mathbf Z^{k+1} \mathbf R - \mathbf Z^{k} \mathbf R \|_F)}{\| \mathbf X \|_F} < \epsilon_2 \\ 551 | 1 & \text{otherwise,} 552 | \end{cases} 553 | \] 554 | 555 | where $\rho > \|\mathbf X\|_F^2$ and $\mu^{\text{max}} \gg \mu^0$. 556 | 557 | \item Check stopping criteria 558 | \[ 559 | \frac{\|\mathbf{XZ^{k+1} - X + E^{k+1}} \|_F}{\| \mathbf X \|_F} < \epsilon_1, \frac{\|\mathbf{J^{k+1} - Z^{k+1}R}\|_F}{\| \mathbf X \|_F} < \epsilon_1 560 | \] 561 | \[ 562 | \mu^k \sqrt{\rho} \frac{ \textrm{max} ( \| \mathbf Z^{k+1} - \mathbf Z^{k} \|_F , \| \mathbf E^{k+1} - \mathbf E^{k} \|, \| \mathbf J^{k+1} - \mathbf J^{k} \|_F , \| \mathbf Z^{k+1} \mathbf R - \mathbf Z^{k} \mathbf R \|_F)}{\| \mathbf X \|_F} < \epsilon_2 563 | \] 564 | 565 | \end{enumerate} 566 | 567 | 568 | 569 | \newpage 570 | \bibliographystyle{plain} 571 | \bibliography{references} 572 | 573 | \end{document} --------------------------------------------------------------------------------