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

pale blue

by Vicente Parot

Status: Passed
Results: 1444 (cyc: 7, node: 433)
CPU Time: 10.674
Score: 1456.99
Submitted at: 2012-11-03 03:06:42 UTC
Scored at: 2012-11-03 03:14:18 UTC

Current Rank: 1205th (Highest: 1st )
Basis for: cerulean (diff)
Basis for: Now17 (diff)
Basis for: cyan (diff)
...and 2 others.

Comments
Vicente Parot
03 Nov 2012
This entry was based on
http://www.mathworks.com/matlabcentral/contest/contests/38/submissions/67988
diff:
changed
E=D-repmat(mean(D),N,1)-repmat(mean(D)',1,N)+mean(D(:));
for
mD=mean(D);
E=bsxfun(@plus,bsxfun(@plus,D,-mD)',-mD)'+mean(mD);

and also used simplification from
http://www.mathworks.com/matlabcentral/contest/contests/38/submissions/67990
Please login or create a profile.
Code
function xyOut = solver(a, xyIn, wts)

rand('seed',2) % Make xyIn cases independent. Currently optimizing as a whole set

N=length(wts);


X=logical(speye(N));
D=inf(N);

D(X)=0;
for n=1:20,
    X=((a*X)>0)&(D>n);
%    if ~any(X(:)),break;end % Howe's
    D(X)=n;
end

mD=mean(D);
E=bsxfun(@plus,bsxfun(@plus,D,-mD)',-mD)'+mean(mD);

[xyOut0,nill]=svd(E);
xyOut0=xyOut0(:,1:2); 

xyOut = xyOut0;

for ncut=1:2
    M=a+eye(size(a)); 
    Mbeta=(((0.9)*eye(N)+0.1*bsxfun(@rdivide,M,sum(M,2)))^10);
    for n1=1:120
        xyOut=Mbeta*xyOut;
        [c1,d1,c2]=svd(cov(xyOut,1));
        xyOut=(bsxfun(@minus,xyOut,mean(xyOut)))*c1*diag(1./sqrt(.1+diag(d1)))*c2'; %sqrtm(pinv(.1*eye(2)+cxyOut));
    end
    [i,j]=find(a>0.01); 
    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))=0.009;
end
xyOut0=xyOut;

xyOut0=sqrt(N)*detrend(xyOut0,'constant')*diag(1./max(eps,std(xyOut0,1,1)));
% K=10;
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(3,N,2)-2);
end

dxy = round(wts*(xyOut-xyIn)./sum(wts)); % Howe's
xyOut = bsxfun(@minus,xyOut,dxy);

end