Finish 2012-11-07 16:00:00 UTC

Friday !!!

by Amitabh Verma

Status: Passed
Results: 1484 (cyc: 6, node: 730)
CPU Time: 10.086
Score: 1509.47
Submitted at: 2012-11-02 20:59:22 UTC
Scored at: 2012-11-02 21:44:34 UTC

Current Rank: 1365th (Highest: 25th )
Based on: try09 (diff)

Comments
Please login or create a profile.
Code
function xyOut = solver_amitabh(a, xyIn, wts)

if (mean(diag(cov(a))') > 0.1)
    [xyOut] = solver_Hannes(a, xyIn, wts);
else 
    [xyOut] = solver_Alfonso(a, xyIn, wts);
end

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5
%% by Alfonso Nieto-Castanon
function xyOut = solver_Alfonso(a, xyIn, wts)

N=size(xyIn,1);
D=min(N,mindist(a));
mD=mean(D,1);
E=D-repmat(mD,[size(D,1),1])-repmat(mD',[1,size(D,2)])+mean(mD);
[x,~]=svd(E);

xyOut=x(:,1:2); 

beta1=10;
beta2=120;
lambda=.1;
thr=.01;

for ncut=1:2
    M=a; M(1:size(M,1)+1:end)=1;
    M=bsxfun(@rdivide,M,sum(M,2));
    Mbeta=(((1-lambda)*eye(N)+lambda*M)^beta1);
    for n1=1:beta2
        xyOut=Mbeta*xyOut;
        mxyOut=mean(xyOut,1);
        cxyOut=cov(xyOut,1);
        [c1,d1,c2]=svd(cxyOut);
        xyOut=(xyOut-mxyOut(ones(N,1),:))*c1*diag(1./sqrt(.1+diag(d1)))*c2'; %sqrtm(pinv(.1*eye(2)+cxyOut));
    end
    [i,j]=find(a>thr); 
    dd=sum((xyOut(i,:)-xyOut(j,:)).^2,2);
    k=find(dd>4*mean(dd));
    if isempty(k), break; end
    a(i(k)+N*(j(k)-1))=thr;
end
xyOut0=xyOut;


xyOut0=sqrt(N)*detrend(xyOut0,'constant')*diag(1./max(eps,std(xyOut0,1,1)));
K=10;
k=1;
[sxyOut0,idxequal]=sortrows(round(K*xyOut0)/K);
idxequal=idxequal(all(~diff(sxyOut0,1,1),2));
xyOut=round(xyOut0*k);
while size(unique(xyOut,'rows'),1)~=N
    k=k*2;
    xyOut=xyOut0*k;
    xyOut(idxequal,:)=(xyOut0(idxequal,:) + (randn(numel(idxequal),2))/K)*k;
    xyOut=round(xyOut);
end
if N<30 % small map knot lines ( Richard Zapor)
 xyOut=2*xyOut+(randi(3,size(xyOut))-2);
end
%xyOut=bsxfun(@plus,xyOut,round(median(xyIn,1)-median(xyOut,1)));
dxy = round(wts*(xyOut-xyIn)./sum(wts)); % Howe's
xyOut = round(bsxfun(@minus,xyOut,dxy));

end

function D=mindist(C)

N=size(C,1);
X=logical(speye(N));
D=inf(N,N);

D(X)=0;
for n=1:N,
    X=(C*X)>0;
    X=X&(D>n);
    if ~any(X(:)),break;end
    D(X)=n;
end

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% by Hannes Naudé
function xyOut = solver_Hannes(a, xyIn, wts)

sz=size(a,1);
deg=diag(sum(a));
L=diag(sum(a))-a;
[V,D]=eig(L,deg);
xyOut=0;
outdiam=sqrt(sum((max(V(:,2:3))-min(V(:,2:3))).^2));
indiam=sqrt(sum((max(xyIn)-min(xyIn)).^2));
mult=indiam/outdiam;
while size(unique(xyOut,'rows'),1)<sz
    xyOut=round(V(:,2:3)*mult);
    [u,i]=unique(xyOut,'rows');
    m=setdiff(1:sz,i);
    xyOut(m,:)=xyOut(m,:)+round(randn(length(m),2))*2-1;
    mult=mult*3;
end

end