%ECE 602 Project - Cost function to minimize
%Function name: f0
%Parameters: data (e.g. feature 1,...,feature n, class)
function f0 = f0(x, c, M, Xi, eta, y_ij, n_samples)
    sum_left = 0;
    sum_right = 0;
    
    %Define cost function
    %First term
    
    IND = find(eta==1);
    [indx,jndx] = ind2sub(size(eta),IND);
    indx = indx.';
    jndx = jndx.';
    clear IND;
        
    for n = length(indx)
        i = indx(n);
        j = jndx(n);
        lndx = find(y_ij(i,:)==0);
        sum_left = sum_left + ((x(:,i)-x(:,j)).'*M*(x(:,i)-x(:,j)));
        for l = lndx
            sum_right = sum_right + (1-y_ij(i,l))*Xi(i,j,l);
        end
    end
    f0 = sum_left + c*sum_right;
end
