function  [w,Dl]=COMMU_FISTA(dataX,dataY,same_index,diff_index,Dl,B,w,C)
%%FISTA: the method for optimising 
%INPUTS:
%dataX  (nTL, dim)  training data
%dataY  (nTL, nclass) labels of training data
%same_index  (nTL, Ks) Similar constraint set
%diff_index  (nTL, Kr) Dissimilar constraint set
%Dl  (nclass, nclass) example_based similarity
%B   (dim, nclass)  the discriminative bases
% C  the balance factor 
%OUTPUTS:
%w  (1,K) the composional coefficients for metric matrix, here, K is set as the number of labels. 
%%
[n,p]=size(dataX);
q=size(dataY,2);
Dm=eye(p,p);
for i=1:q
 Dm=Dm+w(i)*B(:,i)*B(:,i)';%p*p
end
%initial
wpre=w;
lf=0.01*n*C;
tau(2)=lf;
n1=0.4;
t=zeros(52,1);
t(1)=1;
t(2)=1;
l=2;
iteation_tep=0; 

Fw2=COMMU_Fw(dataX,dataY,same_index,diff_index,w,Dl,B,C);

%FISTA main loop
while(1)
    iteation_tep=iteation_tep+1;
    z=w+(t(l-1)-1)/t(l)*(w-wpre);
    fzdiff=COMMU_fdiff(dataX,dataY,same_index,diff_index,Dl,z,B,C);
    tauo=n1*tau(l);
    while(1) %linear search for lipschitz constant          
        G=z-1/tauo*fzdiff;       
        s=G-1/tauo;     
        s(s<0)=0;
        if(COMMU_Fw(dataX,dataY,same_index,diff_index,s,Dl,B,C)<=COMMU_Q(dataX,dataY,same_index,diff_index,s,z,Dl,tauo,G,fzdiff,B,C))
            tau(l+1)=tauo;
            break
        else
            tauo=1/n1*tauo;
        end
    end
    wpre=w;
    w=s;
    t(l+1)=(1+sqrt(1+4*(t(l))^2))/2;
    l=l+1;
     %stop condition
     Fprew=Fw2;
     Fw2=COMMU_Fw(dataX,dataY,same_index,diff_index,w,Dl,B,C);
      if(abs(Fw2-Fprew)/abs(Fprew)<=0.01 || iteation_tep == 20)   %the stop condition
         break;
      end     
      Dm=eye(p,p);
      for m=1:q
         Dm=Dm+w(m)*B(:,m)*B(:,m)';%p*p
      end    
end
end