function value = valueOfOptimization(w,b,coef,Eps_on_labeledTrain,unlabel_train_data,unlabel_xwb,C2)
% Description:
% Input Argument:
%                 w:                     d*q matrix consisted of weighted vector
%                 b:                     1*q vector consisted of bias
%                 coef:                  1*l vector, C1/(|Yi|*|Yi_bar|) for each element, 1 <= i <= l
%                 Eps_on_labeledTrain:   l*1 cell matrix. In each cell, a q*q eps matrix is stored.
%                 unlabel_train_data:    u*d matrix. Each row represents an instance's feature vector.
%                 unlabel_xwb:           u * q matrix. Each element is <w,x> + b,in which x is unlabel data
%                 C2:                    hyperparameter             
% Output Argument:
%                 value: value of the optimization formula
num_label_train = size(Eps_on_labeledTrain,2);
[num_unlabel_train,num_class] = size(unlabel_xwb);

firstTerm = sum(sum(w.^2,1));

secondTerm = 0;
for i = 1:num_label_train
    secondTerm = secondTerm + coef(1,i)*sum(sum(triu(Eps_on_labeledTrain{i,1})));
end

predictLabel = ones(num_class,num_unlabel_train);  % q * u matrix
predictLabel(unlabel_xwb' < 0) = -1;

thirdTerm = 0;
for j = 1:num_unlabel_train
    for v = 1:num_class
        if predictLabel(v,j) == 1
            if unlabel_xwb(j,v) <= -1
                thirdTerm = thirdTerm + (-2)*(unlabel_train_data(j,:)*w(:,v) + b(1,v));
            else if unlabel_xwb(j,v) <1
                    thirdTerm = thirdTerm + 1 - (unlabel_train_data(j,:)*w(:,v) + b(1,v));
                else
                    thirdTerm = thirdTerm + 0;
                end
            end
        else
            if unlabel_xwb(j,v) >= 1
                thirdTerm = thirdTerm + 2*(unlabel_train_data(j,:)*w(:,v) + b(1,v));
            else if unlabel_xwb(j,v) > -1
                    thirdTerm = thirdTerm + 1 + (unlabel_train_data(j,:)*w(:,v) + b(1,v));
                else
                    thirdTerm = thirdTerm + 1;
                end
            end
        end

    end
end
thirdTerm = thirdTerm * C2;

value = firstTerm + secondTerm + thirdTerm;
end