function [P,B]=GLCC(X,T,C,lmada,gamm,Omega,L,m)
%% Input
% X: a cell of the multi-features. for example: X={X_task{1},X_task{2},...,X_task{m}}'; 
% T: the global target (label vector)
% C: the number of classes
% lmada,gamm: the regularization coefficients
% Omega:the Hessian matrix cell: for example:
% Omega={O1,O2,...,Om};% refer to Hessian_Laplacian_matrix.m
% L: the Laplacian matrix cell: for example: L={L1,L2,...,Lm};% refer to
% Hessian_Laplacian_matrix.m
% m: the number of features/modalities
%% Output
% P: Learned prediction weights in cell; for example P={P1,P2,...,Pm}
% B: Bias of predictors in cell; for example B={B1,B2,...,Bm}

% please kindly cite the following paper:
% L. Zhang and D. Zhang, Visual Understanding via Multi-Feature Shared
% Learning with Global Consistency, IEEE Transactions on Multimedia, vol.
% 18, no. 2, pp. 247-259, 2016.


N=length(T);
D=size(X{1},2);

if label_percent~=1
    Y=-ones(N,C);
for i=1:N
    for j=1:C
        if T(i)==j
            Y(i,j)=1;
        end
    end
end
Y_tr=Y;
[n,c] = size(Y_tr);
unlabeled_id = (find(sum(Y_tr')==-c));
u = 10.^10*ones(1,n);
u(unlabeled_id) = 1;
W = diag(u);
else
M=1000;
Y=-ones(N,C);
for i=1:N
    for j=1:C
        if T(i)==j
            Y(i,j)=1;%T(i); % can operate as a classifier not only regression
        end
    end
end
w=-M*ones(1,length(T));%zeros(1,length(T));
for i=1:length(T)
    if T(i)~=-M
       w(i) = length(find(T==T(i)))/sum(length(T));
    end
end
 W=diag(w);
end

 % initial parameter setting

 lamda=1e-0;% regularization on the loss function term
 miu=0.5;
 yita=0.5;
 sita=10^(-4);
 r1=10; 
 r2=10;
 e1=1;
 e2=gamm; 
 e3=lmada;
 
 alpha=repmat(1/m,1,m);
 beta=repmat(1/m,1,m);

 temp1=0;
 temp2=0;
 for i=1:m
     temp1=temp1+alpha(i)^r1*Omega{i};
     temp2=temp2+beta(i)^r2*L{i};
 end
 % Initialization of F
if lamda==0
   F=Y;
else
   F=inv(lamda*W+miu*temp1+yita*temp2)*lamda*W*Y;
end
 
 iter=0;
 pre_F=0;
 pre_P={0,0,0,0,0,0,0}; % if m=7
 
 fprintf('-------------Start Multimodal Learning------------- \n');   
 
%  B={zeros(1,C),zeros(1,C),zeros(1,C),zeros(1,C),zeros(1,C),zeros(1,C),zeros(1,C)};
 B={rand(1,C),rand(1,C),rand(1,C),rand(1,C),rand(1,C),rand(1,C),rand(1,C)};% if m=7
 tic;
 Dm=0;
 MaxIt=5;
 while iter<MaxIt
     iter=iter+1;
     % update Pi
     for i=1:m       
           P{i}=inv(e2*eye(D)+e1*(X{i})'*X{i}+sita*Dm)*(e1*(X{i})'*F-X{i}'*ones(N,1)*B{i});
           B{i}=inv(ones(1,N)*ones(N,1))*(ones(1,N)*F-ones(1,N)*X{i}*P{i});
     end
     Wm=[P{1},P{2},P{3},P{4},P{5},P{6},P{7}];% if m=7
     Dm = 0.5*(Wm*Wm'+eps).^(-0.5);
     Dm = diag(diag(0.5*((Wm*Wm'+eps).^(-0.5))));
     % update F
     temp1_1=0; 
     temp2_1=0;
     temp2_2=0;
     temp2_3=0;
     temp2_4=0;
     for i=1:m
         temp1_1=temp1_1+alpha(i)^r1*Omega{i};
         temp2_1=temp2_1+beta(i)^r2*L{i};
         temp2_2=temp2_2+X{i}*P{i};
         temp2_4=temp2_4+ones(N,1)*B{i};
     end
     F=inv(lamda*W+e3*miu*temp1_1+e3*yita*temp2_1+m*e1*eye(N))*(lamda*W*Y+e1*temp2_2+e1*temp2_4);
    % update alpha and beta
     temp3=0;
     temp4=0;
     for i=1:m
         temp3=temp3+(1/trace(F'*Omega{i}*F))^(1/(r1-1));
         temp4=temp4+(1/trace(F'*L{i}*F))^(1/(r2-1));        
     end
 
     for i=1:m         
         alpha(i)=(1/trace(F'*Omega{i}*F))^(1/(r1-1))/temp3;
         beta(i)=(1/trace(F'*L{i}*F))^(1/(r2-1))/temp4;       
     end
     
    for i=1:N  
        [p1(i),index1(i)]=max(F(i,:));
        [p2(i),index2(i)]=max(Y(i,:));
    end
    error(iter)=mean((p1-p2).^2);
    % calculate the objective function value
    temp5=0;
    temp6=0;
    for i=1:m
        temp5=temp5+miu*alpha(i)^r1*Omega{i}+yita*beta(i)^r2*L{i};
        temp6=temp6+e1*norm((F-X{i}*P{i}-ones(N,1)*B{i}),'fro')^2+e2*norm(P{i},'fro')^2;
    end
    
    objFun(iter)=e3*trace(F'*temp5*F)+lamda*trace((F-Y)'*W*(F-Y))+temp6;
    
    dif1(iter)=norm(F-pre_F,'fro');
    if iter==1
       dif2(iter)=norm(F-pre_F,'fro');
    else
       dif2(iter)=norm(F-pre_F,'fro')/norm(pre_F,'fro');
    end
    
    % calculate norm P of m modalities
    temp7=0;
    for i=1:m
        temp7=temp7+norm(P{i}-pre_P{i},'fro');
    end
    diffP1(iter)=temp7;
    
    temp8=0;
    temp9=0;
    temp10=0;
    if iter==1
        for i=1:m
            temp8=temp8+norm(P{i}-pre_P{i},'fro');
        end
            diffP2(iter)=temp8;
    else
        for i=1:m
            temp9=temp9+norm(P{i}-pre_P{i},'fro');
            temp10=temp10+norm(P{i},'fro');
        end
        diffP2(iter)=temp9/temp10;
    end
    pre_F=F;
    pre_P={P{1},P{2},P{3},P{4},P{5},P{6},P{7}};% if m=7
 end
 toc
 fprintf('-------------End Multimodal Learning------------- \n');   