www.pudn.com > RobustSF.zip > test.m, change:2014-09-01,size:1607b


 
%% load data 
downsample=3; 
path=fullfile('E:\算法代码\实验AR - 统计时间-ourmethod',sprintf('Data_Mixed_downsample%d',downsample),num2str(1)); 
%     path=fullfile('E:\算法代码\实验AR - 统计时间-ourmethod',sprintf('Data_Scraf_downsample%d',downsample),num2str(i)); 
%     path=fullfile('E:\算法代码\实验AR - 统计时间-ourmethod',sprintf('Data_sumglass_downsample%d',downsample),num2str(i)); 
load(fullfile(path,'ts_label.mat')); 
load(fullfile(path,'tr_label.mat')); 
load(fullfile(path,'X1.mat')); 
load(fullfile(path,'X2.mat')); 
 
 
 
 
 
nclass=length(unique(tr_label)); 
%% Step1.KSVD训练字典,是一类一类的训练,然后把每一类的字典拼排在一起 
singleclass=5; 
D_ini=TrainDictionary(X1,tr_label,nclass,singleclass); 
 
%% Step2. 初始化X 
alpha=0.01; 
beta=10; 
gamma=1; 
tol=1e-4; 
max_iter=30; 
X_ini=compute_representation(X1, D_ini, alpha, tol, max_iter); 
 
%% Step3. 初始化W 
W_ini=H*X_ini'*pinv(X_ini*X_ini'+gamma*eye(size(X_ini,1))); 
 
%% Step4. 生成H 
m=length(tr_label); 
H=zeros(nclass,m); 
for il=1:m 
    H(tr_label(il),il)=1; 
end 
 
%% Step5. 生成L 
L=compute_laplase(X1); 
 
%% Step6. 开始学习字典和低秩表示 
tol=1-6; 
max_iter=500; 
[D,~] = DictionaryLearning(X1, X_ini, H, W_ini, D_ini, L, alpha, beta, gamma, tol, max_iter); 
 
%% Step6. 计算测试样本的表示 
[Z] = compute_representation([X1,X2], D, alpha, tol, max_iter); 
Z1=Z(:,1:length(tr_label)); 
Z2=Z(:,lenth(tr_label)+1:lenth(tr_label)+lenth(ts_label)); 
 
 
%% 依据学习得到的W进行预测 
[W] = compute_classifier_parametrs( Z1,tr_label); 
acc  = predic_labels( Z2,ts_label,W); 
fprintf('LLR without Dictionary: %f\n',acc);