clear all; close all; clc;

%% load the data, one fold for training and 4 folds for testing
path = 'data\';
load([path, 'X']);
load([path, 'image_bag_tr_mat_idx']);
load([path, 'image_bag_te_mat_idx']);
load([path, 'Ya']);
load([path, 'Yc']);
load([path, 'Yc_init']);
load([path, 'Ya_init']);
addpath('utility\');
%% parameter settign for PRW
% # of k nearest neighbor when using self-tuning to construct the gaussian
% kernel for the data layer of PRW method
para.k = 9; 
para.alpha = 0; % parameter for label correlation.
para.gamma = [0.2]; % parameter for random walk restart
para.lambda = [0.42]; % the jumping between class label graph and annotation label graph
para.beta1 = 0.42; % the jumping between the data graph and the class label graph
para.beta2 = 0.42; % the jumping between the data graph and the annotation label graph
para.eta = 0.99; % parameter for p0 init 
%% PRW on Tri-graph
NCV = size(image_bag_te_mat_idx, 2);
for foldInd = 1:NCV
    t1 = cputime;
    fprintf('processing fold %d...\n', foldInd);
    % 1 fold for train, 4 folds for test
    image_bag_test_ind = image_bag_tr_mat_idx(:,foldInd);
    image_bag_train_ind = image_bag_te_mat_idx(:,foldInd);
    %3 layers PRW
    [perf{foldInd}, Yc_pred{foldInd}, Ya_pred{foldInd}, FMat{foldInd}, thres_using{foldInd}, learnedMat{foldInd}] = ...
        PRW_Tri_Driver(X, Yc, Ya, image_bag_train_ind, image_bag_test_ind, para, mapVec2Mat(Yc_init{foldInd}), Ya_init{foldInd});
    t2 = cputime;
    t_elapse = t2 - t1;
    fprintf('finish processing %d fold, using %f sec.\n', foldInd, t_elapse);
end
sum_stat_info_a = zeros(1, 8); 
sum_accuacy_c = 0;
for foldInd = 1:NCV
    sum_stat_info_a = sum_stat_info_a + perf{foldInd}.stat_info_a;
    sum_accuacy_c = sum_accuacy_c + perf{foldInd}.accuacy_c;
end
avg_stat_info_a = sum_stat_info_a/NCV
avg_accuracy_c = sum_accuacy_c/NCV
