function main_simp_KMUDA_D

num_view = 2;
Label_multiview = cell(num_view,1);
%X_train = cell(num_view,1);
CK_test = cell(num_view,1);
%Label_train = cell(num_view,1);
%Label_test = cell(num_view,1);
accurate_K = zeros(1,num_view+1);
accurate_K_D = zeros(1,num_view+2);
accurate_K_M = zeros(1,num_view+2);
accurate_K_MU = zeros(1,num_view+2);
CK_train_D = cell(num_view+2,1);
CK_train_M = cell(num_view+2,1);
CK_train_MU = cell(num_view+2,1);
CK_test_D = cell(num_view+2,1);
CK_test_M = cell(num_view+2,1);
CK_test_MU = cell(num_view+2,1);
kn=5; % the neighbor number of KNN.
klamda = 10;

%r1 = [6 2 6 6 3 9 4 9 7 6 9 9 9 9 9];
%r2 = [9 9 9 9 6 1 9 9 6 9 9 2 9 6 3];
r1 = [4 4 4 5 4 1 2 4 2 4 4 3 2 1 6]; %scaled
r2 = [1 2 1 3 1 3 3 3 3 2 7 4 5 8 8]; %scaled
%r1 = [4 3 4 4 4 1 4 1 2 3 4 4 2 1 3]; %a3 scaled
%r2 = [1 1 1 2 1 3 2 5 4 1 7 7 6 8 1]; %a3 scaled
width = [2^-3, 2^-2, 2^-1, 1, 2, 2^2, 2^3, 2^4, 2^5, 2^6, 2^7];
randidx = load('RandIdx.txt');

view{1,1} = 'fou'; % 200 * 76
view{2,1} = 'kar'; % 200 * 64
view{3,1} = 'fac'; % 200 * 216
view{4,1} = 'pix'; % 200 * 240
view{5,1} = 'zer'; % 200 * 47
view{6,1} = 'mor'; % 200 * 6

id = 0;

for v1 = 1:5
    for v2 = v1+1:6
        
id = id+1;
r1_v = r1(id);
w1 = width(r1_v);
w11 = num2str(w1);
r2_v = r2(id);
w2 = width(r2_v);
w22 = num2str(w2);
kla = klamda;
X_v1 = load(['./multifeat/',view{v1,1},'.scaled.txt']);
X_v2 = load(['./multifeat/',view{v2,1},'.scaled.txt']);
Y = [repmat(1,1,200) repmat(2,1,200) repmat(3,1,200) repmat(4,1,200) repmat(5,1,200) repmat(6,1,200) repmat(7,1,200) repmat(8,1,200) repmat(9,1,200) repmat(10,1,200)];

num_class = 10;

for iter = 1:10
    
    X_train_v1 = []; %zeros(250,size(X_v1,2));
    X_train_v2 = []; %zeros(250,size(X_v2,2));
    X_test_v1 = []; %zeros(750,size(X_v1,2));
    X_test_v2 = []; %zeros(750,size(X_v2,2));
    Y_train = []; %zeros(1,250);
    Y_test = []; %zeros(1,750);
    
    fprintf('experiment between view %s and view %s in iter %d\n',[view{v1,1}],[view{v2,1}],iter);
    rand = randidx(iter,:);
    idx_train = rand(1:100);
    idx_test = rand(101:200);
    num_train = length(idx_train);
    
for i = 1:num_class
    X_train_v1 = [X_train_v1' X_v1(200*(i-1)+idx_train,:)']';
    X_train_v2 = [X_train_v2' X_v2(200*(i-1)+idx_train,:)']';
    X_test_v1 = [X_test_v1' X_v1(200*(i-1)+idx_test,:)']';
    X_test_v2 = [X_test_v2' X_v2(200*(i-1)+idx_test,:)']';
    Y_train = [Y_train Y(:,200*(i-1)+idx_train)];
    Y_test = [Y_test Y(:,200*(i-1)+idx_test)];
end

%compute the squared distances of the training matrix
p1 = pdist(X_train_v1);
p2 = pdist(X_train_v2);
c1 = sum(p1)/length(p1);
c2 = sum(p2)/length(p2);
r1_var = w1*c1;
r2_var = w2*c2;
     
Label_multiview{1,1} = Y_train';
Label_multiview{2,1} = Y_train';

K_train_v1 = RBFKernel(X_train_v1',X_train_v1',r1_var);
K_train_v2 = RBFKernel(X_train_v2',X_train_v2',r2_var);
K_test_v1 = RBFKernel(X_test_v1',X_train_v1',r1_var);
K_test_v2 = RBFKernel(X_test_v2',X_train_v2',r2_var);
%kerfPara1.type = 'rbf';
%kerfPara1.pars = [5,5];
%kerfPara1.pars = r1_var;
%kerfPara2.type = 'rbf';
%kerfPara2.pars = [5,5];
%kerfPara2.pars = r2_var;
%K_train_v1 = kernelfun(X_train_v1,kerfPara1);K_train_v2 = kernelfun(X_train_v2,kerfPara2);
%K_test_v1 = kernelfun(X_train_v1,kerfPara1,X_test_v1);K_test_v2 = kernelfun(X_train_v2,kerfPara2,X_test_v2);
[CK_train_v1,CK_test_v1] = centerTrTsKernels(K_train_v1,K_test_v1);
[CK_train_v2,CK_test_v2] = centerTrTsKernels(K_train_v2,K_test_v2);

CK_train = cell(num_view,1);
CK_train{1,1} = CK_train_v1;
CK_train{2,1} = CK_train_v2;
CK_train_total = [CK_train_v1 CK_train_v2];
CK_test{1,1} = CK_test_v1;
CK_test{2,1} = CK_test_v2;
CK_test{3,1} = [CK_test_v1 CK_test_v2];

%KDCCA
A_kdcca = KDCCA(CK_train,Label_multiview,num_class,num_train);
A1_D = A_kdcca{1,1};
A2_D = A_kdcca{2,1};
A_I_D = [A1_D;A2_D];
A_II_D = [A1_D zeros(size(A1_D,1),size(A2_D,2));zeros(size(A2_D,1),size(A1_D,2)) A2_D];

%KMUDA
[A_kmda A_kmuda] = KMUDA_D(CK_train,Label_multiview,kla,num_class,num_train);
A1 = A_kmda{1,1};
A2 = A_kmda{2,1};
A_I = [A1;A2];
A_II = [A1 zeros(size(A1,1),size(A2,2)); zeros(size(A2,1),size(A1,2)) A2];
A1_mu = A_kmuda{1,1};
A2_mu = A_kmuda{2,1};
A_I_mu = [A1_mu;A2_mu];
A_II_mu = [A1_mu zeros(size(A1_mu,1),size(A2_mu,2)); zeros(size(A2_mu,1),size(A1_mu,2)) A2_mu];

%KDCCA KMDA KMUDA_D project
CK_train{3,1} = CK_train_total;
CK_train_D{1,1} = CK_train_v1 * A1_D;
CK_train_D{2,1} = CK_train_v2 * A2_D;
CK_train_D{3,1} = CK_train_total * A_I_D;
CK_train_D{4,1} = CK_train_total * A_II_D;
CK_test_D{1,1} = CK_test_v1 * A1_D;
CK_test_D{2,1} = CK_test_v2 * A2_D;
CK_test_D{3,1} = CK_test{3,1} * A_I_D;
CK_test_D{4,1} = CK_test{3,1} * A_II_D;

CK_train_M{1,1} = CK_train_v1 * A1;
CK_train_M{2,1} = CK_train_v2 * A2;
CK_train_M{3,1} = CK_train_total * A_I;
CK_train_M{4,1} = CK_train_total * A_II;
CK_test_M{1,1} = CK_test_v1 * A1;
CK_test_M{2,1} = CK_test_v2 * A2;
CK_test_M{3,1} = CK_test{3,1} * A_I;
CK_test_M{4,1} = CK_test{3,1} * A_II;

CK_train_MU{1,1} = CK_train_v1 * A1_mu;
CK_train_MU{2,1} = CK_train_v2 * A2_mu;
CK_train_MU{3,1} = CK_train_total * A_I_mu;
CK_train_MU{4,1} = CK_train_total * A_II_mu;
CK_test_MU{1,1} = CK_test_v1 * A1_mu;
CK_test_MU{2,1} = CK_test_v2 * A2_mu;
CK_test_MU{3,1} = CK_test{3,1} * A_I_mu;
CK_test_MU{4,1} = CK_test{3,1} * A_II_mu;

% perform classification

results_K = knn_classify(CK_train,CK_test,kn,Y_train',num_view);
results_K_D = knn_classify(CK_train_D,CK_test_D,kn,Y_train',num_view);
results_K_M = knn_classify(CK_train_M,CK_test_M,kn,Y_train',num_view);
results_K_MU = knn_classify(CK_train_MU,CK_test_MU,kn,Y_train',num_view);


for i = 1:num_view
    accurate_K(i) = length(find(Y_test == results_K{i,1}))/length(Y_test);
    fprintf('View = %d, Accuracy of kernel by KNN is: %f\n',i,accurate_K(i));
    accurate_K_D(i) = length(find(Y_test == results_K_D{i,1}))/length(Y_test);
    fprintf('View = %d, Accuracy of kernel by KNN after KDCCA is: %f\n',i,accurate_K_D(i));
    accurate_K_M(i) = length(find(Y_test == results_K_M{i,1}))/length(Y_test);
    fprintf('View = %d, Accuracy of kernel by KNN after KMDA is: %f\n',i,accurate_K_M(i));
    accurate_K_MU(i) = length(find(Y_test == results_K_MU{i,1}))/length(Y_test);
    fprintf('View = %d, Accuracy of kernel by KNN after KMUDA is: %f\n',i,accurate_K_MU(i));
end

accurate_K(num_view+1) = length(find(Y_test == results_K{num_view+1,1})) / length(Y_test);
fprintf('Accuracy of kernel by KNN is: %f\n', accurate_K(num_view+1));
accurate_K_D(num_view+1) = length(find(Y_test == results_K_D{num_view+1,1})) / length(Y_test);
fprintf('Accuracy of kernel by KNN with FFS_I after KDCCA is: %f\n', accurate_K_D(num_view+1));
accurate_K_D(num_view+2) = length(find(Y_test == results_K_D{num_view+2,1})) / length(Y_test);
fprintf('Accuracy of kernel by KNN with FFS_II after KDCCA is: %f\n', accurate_K_D(num_view+2));
accurate_K_M(num_view+1) = length(find(Y_test == results_K_M{num_view+1,1})) / length(Y_test);
fprintf('Accuracy of kernel by KNN with FFS_I after KMDA is: %f\n', accurate_K_M(num_view+1));
accurate_K_M(num_view+2) = length(find(Y_test == results_K_M{num_view+2,1})) / length(Y_test);
fprintf('Accuracy of kernel by KNN with FFS_II after KMDA is: %f\n', accurate_K_M(num_view+2));  %we choose these results.
accurate_K_MU(num_view+1) = length(find(Y_test == results_K_MU{num_view+1,1})) / length(Y_test);
fprintf('Accuracy of kernel by KNN with FFS_I after KMUDA is: %f\n', accurate_K_MU(num_view+1));
accurate_K_MU(num_view+2) = length(find(Y_test == results_K_MU{num_view+2,1})) / length(Y_test);
fprintf('Accuracy of kernel by KNN with FFS_II after KMUDA is: %f\n', accurate_K_MU(num_view+2));  %we choose these results.

% ACCURACY
Accuracy = [accurate_K accurate_K_D accurate_K_M accurate_K_MU];
dlmwrite(['./KMUDAD/',view{v1,1},'-',view{v2,1},'.a3.Kscaled.w',w11,'-',w22,'.txt'],Accuracy,'-append','delimiter','\t');

end
    end
end
