function [acc,acc_opt] = RMTMTLSSVM_train_one_vs_one(Xs,ys,Xt,yt,X_test,y_true,m)
%UNTITLED7 Summary of this function goes here
%   Detailed explanation goes here
k=2;M11=[];M22=[];X1=[];X2=[];
Xttot=[Xt X_test];
% [Xs,Xttot]=scaled_data(Xs,Xttot,'1');
Xt=Xttot(:,1:size(Xt,2));X_test=Xttot(:,size(Xt,2)+1:end);
for task=1:k-1
    for i=1:m
        X11{i,task}=Xs(:,ys==i)';
        X1=[X1 X11{i,task}'];
        M11=[M11 mean(X11{i,task})'];
        ns(m*(task-1)+i)=size(X11{i,task},1);
    end
end
for i=1:m
    X22{i}=Xt(:,yt==i)';
    X2=[X2 X22{i}'];
	ns(i+m*(k-1))=floor(size(X22{i},1));
    M22=[M22 mean(X22{i})'];
end
  M=[M11 M22];
X=[X1 X2];
p=size(X,1);
X=X/sqrt(k*p);
gamma=[0.1;1];lambda=1;
% score_th=zeros(m,2*k);score_th_opt=zeros(m,2*k);
% variance_th=zeros(m,2*k);variance_th_opt=zeros(m,2*k);
% %error_s=zeros(m,1);error_t=zeros(m,1);error_s_opt=zeros(m,1);error_t_opt=zeros(m,1);
% y_opt=zeros(2*k,m);y_opt_opt=zeros(2*k,m);
% init_order=1:k*m;
% %score_test=zeros(Nb*m,m);
% lambda_opt=zeros(m,1);
% %
% n=sum(ns);gamma=[0.1;1];lambda=1;
% nsa=zeros(1,2*k);
% nsi=reshape([zeros(1,k);reshape(ns,m,k)],1,k*m+k);
Matrix=combntns(1:m,2);score_opt=[];score=[];
for i=1:size(Matrix,1)
    i
    c1=Matrix(i,1);c2=Matrix(i,2);
%     nsn=ns(init_order);
    M1s=M(:,c1);
    M1t=M(:,m+c1);
    M2s=M(:,c2);
    M2t=M(:,m+c2);
    Ms=[M1s M2s M1t M2t];
    ns2=[0 ns];
    %nsa=[ns(i) sum(ns(1:m))-ns(i) ns(i+m) sum(ns(m+1:k*m))-ns(i+m)];
    X2=[X(:,sum(ns2(1:m+c1))+1:sum(ns2(1:m+c1+1))) X(:,sum(ns2(1:m+c2))+1:sum(ns2(1:m+c2+1)))];
    X1=[X(:,sum(ns2(1:c1))+1:sum(ns2(1:c1+1))) X(:,sum(ns2(1:c2))+1:sum(ns2(1:c2+1)))];
    nn=[ns(c1);ns(c2);ns(m+c1);ns(m+c2)];
    J=zeros(sum(nn),2*k);
    for h=1:2*k
        J(sum(nn(1:h-1))+1:sum(nn(1:h)),h)=ones(nn(h),1);
    end
    %tildey=-ones(2*k,1);tildey(1:2:end)=1;
    tildey=[1;-1;1;-1];
    yc=J*tildey;
%     figure
%     plot(X1(1,:),X1(2,:),'r*');hold on;plot(X2(1,:),X2(2,:),'g*')
Jk=zeros(sum(nn),2*k);
for g=1:2*k
    Jk(sum(nn(1:g-1))+1:sum(nn(1:g)),g)=ones(nn(g),1);
end
       [score1(:,i),pred(:,i),error_th(:,i),alpha2, b,score_th(i,:),variance_th(i,:),score_emp,var_emp,y_opt(:,i)] = MLSSVRTrain_th1_centered(X1,X2, yc, gamma, lambda,Ms,X_test,nn,'task');
       error=@(x) perf_multi(X1,X2, [x(1);x(2)], x(3),Ms,nn);
       init0=[0.1;1;1];
       [param_opt,error_optim]=fmincon(error,init0,[-1 0 0;0 -1 0;0 0 -1],[0;0;0]);
       gamma_opt1(i)=param_opt(1);gamma_opt2(i)=param_opt(2);lambda_opt(i)=param_opt(3);
       yopt=Jk*y_opt(:,i);
       [score1_opt(:,i),pred_opt(:,i),error_th_opt(:,i),alpha2_opt, b_opt,score_th_opt(i,:),variance_th_opt(i,:),score_emp_opt,var_emp_opt,y_opt_opt(:,i)] = MLSSVRTrain_th1_centered(X1,X2, yopt, [gamma(1);gamma(2)], lambda,Ms,X_test,nn,'task');
       scorea=pred_opt(:,i);scorey=pred_opt(:,i);scorea(scorey<0)=c2;scorea(scorey>0)=c1;
       score_opt=[score_opt scorea];
       scoreb=pred(:,i);scoreby=pred(:,i);scoreb(scoreby<0)=c2;scoreb(scoreby>0)=c1;
       score=[score scoreb];
end
 pred=mode(score,2);
error=sum(pred~=y_true');
pred_opt=mode(score_opt,2);
error_opti=sum(pred_opt~=y_true');
acc=1 - error/size(X_test,2);
acc_opt=1 - error_opti/size(X_test,2);
end

