clear
addpath('.\LEAD\LEAD')
addpath('.\liblinear\matlab');
addpath('.\ICML2012_Code\ICML2012_Code');
addpath(genpath('E:/Project_Codes/MultiLabel/LEAD'))

% Loading the file containing the necessary inputs for calling the function

load('scene-matlab.mat');
Label = Y;
Y = double(Label);
X = double(X);
[n_total, n_feat] = size(X);
n_test = round(0.2*n_total);
n_train = n_total - n_test;

nCross = 5; %here we use 5-cross-validation
rand_sq = randperm(n_total);
for i=1:nCross-1
    test_sq{i} = rand_sq((i-1)*n_test+1:i*n_test);
    temp = 1:n_total;
    temp(test_sq{i}) = [];
    train_sq{i} = temp;
end
 i = nCross;
 test_sq{i} = rand_sq((i-1)*n_test+1:end);
 temp = 1:n_total;
 temp(test_sq{i}) = [];
 train_sq{i} = temp;

 


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%Please uncomment the following script if you would like to compare other
%methods, like BR, LEAD, and MMOC et al.
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% address = 'E:\Project_Codes\MultiLabel\ExperimentalResult\SCENE_LG21NEW_RESULT';
% result_L2G21 = run_L2G21(X,Label,train_sq,test_sq,address,10100);
% save(address, 'result_L2G21');
% 
% 
% C = 1;
% address = '.\ExperimentalResult\Scence_BR_RESULT';
% result_BR = runBR(X,Label,train_sq,test_sq,address,C);
% 
% address = '.\ExperimentalResult\Scence_PLST_RESULT';
% resul_PLST = run_PLST(X,Label,train_sq,test_sq,address,5);
% 
% address = '.\ExperimentalResult\Scence_BR_GUO_RESULT';
% result_GUO = runBR_GUO(X,Label,train_sq,test_sq,address,C);
% 
% address = '.\ExperimentalResult\Scence_LEAD_RESULT';
% result_LEAD = run_LEAD(X,Label,train_sq,test_sq,address);
% 
% [model_SSVM_CT_TREE] = main_SSVM_CT_TREE(prob, param);
% address = '.\ExperimentalResult\SCENE_SSVM_CT_TREE_RESULT';
% save(address, 'model_SSVM_CT_TREE');
% %%
% address = '.\ExperimentalResult\SCENE_MMOC_RESULT';
% [result_MMOC] =  run_MMOC(X,Label,train_sq,test_sq,address);


%%
%run CGM using five cross-validation
%%

param.B = 2;
param.C = 1;
param.lambda = 0.001;
param.out_put_loss = 1;
param.update_close_form = 1;
prob.scale = 10;
prob.num_label = size(Label,2);
prob.Dim = size(X,2);%size(X,2)
prob.num_cliques = 0;

for i=1:nCross
    % Calling the main function LEAD
    prob.X = X(train_sq{i},1:prob.Dim);
    prob.y = Label(train_sq{i},:);
    prob.X_te = X(test_sq{i},1:prob.Dim);
    prob.y_te = Label(test_sq{i},:);
    prob.num_inst = size(prob.X,1);
    prob.num_inst_te = size(prob.X_te,1);
    param.lambda = 0.00001;
    [model_] = main_CGM_real_v1(prob,param,5);
    model_CGM{i} = model_;
end
result = plot_CGM_edge(model_CGM)
save(['.\ExperimentalResult\Result_CGM_SCENE' num2str(param.lambda)], 'model_CGM', 'result');

