function s=DSSeye(V,r);
%Same as DSS(V,I,r) where we set U to be the n x n identity matrix
%UU^T = I_n and VV^T=I_l
%k<r, we will choose k columns.
%s are the scaling weights for each column (the non-zeros).
%The sampled, rescaled columns of U and V satisfy Lemma 3.5 in the paper: 
%http://arxiv.org/abs/1103.0995
%
%This function is much more efficient than calling DSS(V,I,r);
%
%Copyright Malik Magdon-Ismail

[k,n]=size(V);
l=n;

if(r<=k)
	s='k<r please'
	return
end


s=zeros(n,1);
Atau=zeros(k,k);
delL=1;
delU=(1+sqrt(l/r))/(1-sqrt(k/r));
Ik=eye(k);

for tau=0:r-1;
	Ltau=tau-sqrt(r*k);
	Utau=delU*(tau+sqrt(r*l));
	ALinv=inv(Atau-(Ltau+delL)*Ik);
	ALinv2=ALinv*ALinv;
	lamAtau=svd(Atau);
	phiL1=sum(1./(lamAtau-Ltau-delL));
	phiL2=sum(1./(lamAtau-Ltau));
	lamBtau=s;
	phiU1=sum(1./(Utau-lamBtau));
	phiU2=sum(1./(Utau+delU-lamBtau));
	for i=1:n
		vi=V(:,i);
		Lower=vi'*ALinv2*vi/(phiL1-phiL2)-vi'*ALinv*vi;
		BUinv=(Utau+delU-s(i))^(-1);
		Upper=BUinv^2/(phiU1-phiU2)+BUinv;
		if(Upper<=Lower)
			t=2/(Upper+Lower);
			s(i)=s(i)+t;
			Atau=Atau+t*vi*vi';
			break;
		end
	end
end

s=s*(1-sqrt(k/r))/r;
