function info = run_svm_fr(C, kernel_types, gamma_oct_set, feat_types, level_set)
if ~exist('results', 'dir');
mkdir('results');
end
result_file = fullfile('results', 'result_svm_fr.txt');
data = load_YouTube_Consumer();
aps = zeros(5, size(data.Y,2));
for r = 1 : 5
fprintf('Run %d\n', r);
train_idx = data.train_idx{r};
test_idx = data.test_idx{r};
Ytrain = data.Y(train_idx,:);
Ytest = data.Y(test_idx,:);
%###loop for different concept
for c = 1 : size(data.Y,2)
training_labels = Ytrain(:,c);
test_labels = Ytest(:,c);
test_dv = [];
%### loop for differnt kernels
for feat_type = feat_types
for level = level_set
D = data.distMat.get(sprintf('D_%s_%d', feat_type{1}, level));
D = D.^2;
gamma0 = 1./mean(mean(D(train_idx,train_idx)));
clear kernel_params;
for j = 1 : length(gamma_oct_set)
kernel_params{j} = gamma_oct_set{j}.*gamma0;
end
base_kernels = construct_basekernels_D2(kernel_types, kernel_params, D);
K = zeros(size(D));
dv_concept = zeros(length(test_labels),size(base_kernels,1));
for k = 1 : size(base_kernels,1)
K(:,:) = base_kernels(k,:,:);
%### this is the key differnt from SVM_AT, the kernel entries of the data from the same domain are multiplied by 2
K(data.idx_s,data.idx_s) = 2*K(data.idx_s,data.idx_s);
K(data.idx_t,data.idx_t) = 2*K(data.idx_t,data.idx_t);
Ktrain = K(train_idx, train_idx);
Ktest = K(train_idx, test_idx);
model = svmtrain(training_labels, [(1:size(Ktrain,1))', Ktrain], sprintf('-t 4 -c %g -q', C));
dv = Ktest(model.SVs,:)'*model.sv_coef - model.rho;
dv = dv*training_labels(1);
dv_concept(:,k) = dv;
end
dv(:) = mean( 1./(1+exp(-dv_concept)) , 2);
test_dv = [test_dv, dv];
end
end
test_dv = mean(test_dv,2);
aps(r,c) = calc_ap(test_labels,test_dv);
end
disp(aps);
end
info.aps = aps;
info.map = mean(mean(aps));
info.std = std(mean(aps,2));
%### print out the results
log_print(result_file, sprintf('<== SVM_FR @ %s ===>\n', datestr(now)));
log_print(result_file, sprintf('C=%g, feat_types=(%s),levels=(%s)\n', C, cell2mat(strcat(feat_types, {','})), sprintf('%d,',level_set)));
for i = 1 : length(kernel_types)
log_print(result_file, sprintf('kernel:%s, gamma_oct_set:%s\n', kernel_types{i}, sprintf('%g,', gamma_oct_set{i})));
end
dlmwrite(result_file, aps, 'delimiter', '\t', '-append');
log_print(result_file, '---\n');
dlmwrite(result_file, mean(aps), 'delimiter', '\t', '-append');
dlmwrite(result_file, std(aps), 'delimiter', '\t', '-append');
log_print(result_file, '---\n');
log_print(result_file, sprintf('%g\t%g\n', mean(mean(aps)),std(mean(aps,2))));