function summap=YaoBayesianMAP(C)

alpha=C(1:5);
sigma1=C(6);
sigma2r=C(7);
sigma2g=C(8);
sigma2b=C(9);
% [sigma1r sigma1g sigma1b sigma2r sigma2g sigma2c]=C(6:11);
sigma1r=sigma1;
sigma1g=sigma1;
sigma1b=sigma1;


load VARC
load Result

g=g0+alpha'*H;
interval=[0:1/(length(g)-1):1];

lamda1=blen(1)*20;    % parameter1   %20
lamda2=size(ColorS1,1)*10;  % parameter2
DerivativeG=diff(g)*(length(g)-1);
DerivativeG=[DerivativeG  DerivativeG(length(g)-1)];


    indexXmean=ceil((Xmean*(length(g)-1)./255)+eps);   % size: 3*blen
    sum1=(1/blen(1))*sum((sqrt(g(indexXmean(1,1:blen(1)))*sigma1r^2+sigma2r^2)./(DerivativeG(indexXmean(1,1:blen(1))))-Xstd(1,1:blen(1))).^2+eps);
    sum2=(1/blen(2))*sum((sqrt(g(indexXmean(2,1:blen(2)))*sigma1g^2+sigma2g^2)./(DerivativeG(indexXmean(2,1:blen(2))))-Xstd(2,1:blen(2))).^2+eps);
    sum3=(1/blen(3))*sum((sqrt(g(indexXmean(3,1:blen(3)))*sigma1b^2+sigma2b^2)./(DerivativeG(indexXmean(3,1:blen(3))))-Xstd(3,1:blen(3))).^2+eps);
    summap=lamda1*(sum1+sum2+sum3);
    if ColorS1(1,:) ~= [0 0 0]
    indexColorS1=round(ColorS1*(length(g)-1));
    indexColorS2=round(ColorS2*(length(g)-1));
    indexColorEdge=round(ColorEdge*(length(g)-1));
    g1=[g' g' g'];
    V12=g1(indexColorS1)-g1(indexColorS2);
    VE2=g1(indexColorEdge)-g1(indexColorS2);
    C12E=cross(V12,VE2,2);
    DS1S2=sqrt((V12(:,1).^2+V12(:,2).^2+V12(:,3).^2));
    DC12E=sqrt((C12E(:,1).^2+C12E(:,2).^2+C12E(:,3).^2));
    sumh=(1/size(ColorS1,1))* sum ((DC12E.^2)./(DS1S2.^2+eps));
    summap=summap+lamda2*sumh;
    end

% lamda2=100;
% 
% pmap=0; 
% for i=1:size(ColorS1,1)
%     GM1=zeros(1,3);
%     GM2=zeros(1,3);
%     GMp=zeros(1,3);
%     for k=1:3
%     [min1, index]=min(abs(interval-ColorS1(i,k)));
%     GM1(k)=g(index(1));
%     [min1, index]=min(abs(interval-ColorS2(i,k)));
%     GM2(k)=g(index(1));
%      [min1, index]=min(abs(interval-ColorEdge(i,k)));
%     GMp(k)=g(index(1));
%     end
%     D1=GM1-GM2;
%     D2=GM1-GMp;
%     pmap=pmap+lamda*( norm(cross(D1,D2))/ norm(D1) );
%     
% end

prior=sum(0.5* (C(1:5)'.^2)./(VARC));
% lamda3=40;
% dsigma=lamda3*(abs(sigma1r^2-sigma1g^2)+abs(sigma1g^2-sigma1b^2)+abs(sigma1b^2-sigma1r^2)+abs(sigma2r^2-sigma2g^2)+abs(sigma2g^2-sigma2b^2)+abs(sigma2b^2-sigma2r^2));
% dsigma=lamda3*(abs(sigma1r^2-sigma1g^2)+abs(sigma1g^2-sigma1b^2)+abs(sigma1g^2-sigma1b^2)
summap= summap+prior;
end

