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

once more with feeling

by Michael C.

Status: Passed
Results: 1415 (cyc: 6, node: 495)
CPU Time: 8.936
Score: 1431.28
Submitted at: 2012-11-03 15:05:08 UTC
Scored at: 2012-11-03 15:10:13 UTC

Current Rank: 1119th (Highest: 6th )
Based on: once more with feeling (diff)
Basis for: TKP_LL_004 (diff)
Basis for: same feeling (diff)

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

randn('seed',2);

N=length(wts);
    
    deg=diag(sum(a));
    [V,~]=eig(deg-a,deg);
    xyOut=V(:,2:3);

for ncut=1:2
    Mbeta=(0.9*eye(N)+0.1*bsxfun(@rdivide,a+eye(N),sum(a,2)+1))^10;
    for n1=1:119
        xyOut=Mbeta*xyOut;
        [c1,D,c2]=svd(cov(xyOut,1));
        xyOut=(bsxfun(@minus,xyOut,mean(xyOut)))*c1*diag(1./sqrt(.1+diag(D)))*c2';
    end
    [i,j]=find(a>0.009); 
    dd=sum((xyOut(i,:)-xyOut(j,:)).^2,2);
    k=find(dd>3.5*mean(dd));
    if isempty(k), break; end
    a(i(k)+N*(j(k)-1))=0.009;
end

xyOut0=sqrt(N)*detrend(xyOut,'constant')*diag(1./max(eps,std(xyOut,1,1)));
k=5;
[sxyOut0,idxequal]=sortrows(round(15*xyOut0)/15);
idxequal=idxequal(all(~diff(sxyOut0,1,1),2));
xyOut=round(xyOut0);
while size(unique(xyOut,'rows'),1)~=N
    k=k*1.1;
    xyOut=xyOut0*k;
    xyOut(idxequal,:)=(xyOut0(idxequal,:)+randn(numel(idxequal),2)/10)*k;
    xyOut=round(xyOut);
end
if N<35 % small map knot lines
 xyOut=3*xyOut+randi([-1,1],N,2);
end

xyOut = FinishingTouches(xyOut,xyIn,N,wts);
end

function best_xy = FinishingTouches(xyOut,xyIn,sz,wts)

if all(mod(xyOut(:),2)==0)
    xyOut = xyOut/2;
elseif all(mod(xyOut(:),2)==1)
    xyOut = (xyOut+1)/2;
end

d_min = inf;

for ii = 1:8
    if ii == 5
        xyOut = fliplr(xyOut);
    end
    xyTest = xyOut.*repmat(sign(mod([ii,ii+1],4)-1.5),sz,1);
    % xyOut = bsxfun(@minus,xyOut,round(wts*(xyOut-xyIn)./sum(wts))); % AV's
    xyTest = xyTest - repmat(round(wts*(xyTest-xyIn)./sum(wts)),sz,1); % AV's
    dXY = xyIn-xyTest;
    d = sum(sqrt(dXY(:,1).^2 + dXY(:,2).^2).*wts');
    if d < d_min
        d_min = d;
        best_xy = xyTest;
    end
end
end