% platt's dag method

function [p] = method4(r)
k=size(r,1);
i=1;
j=k;
p=-ones(k,1); p(1)=1;
while (i<j) 
  if(p(i)>0)  % p_j = p_i * r_ji / r_ij
    p(j) = p(i)*r(j,i)/r(i,j);
  elseif (p(j)>0) % p_i = p_j * r_ij / r_ji
      p(i) = p(j)*r(i,j)/r(j,i);
  end
  
  if r(i,j)> r(j,i)
    j=j-1;
  else
    i=i+1;
  end
end
p = p/sum(p);
