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

lasttry05

by Alfonso Nieto-Castanon

Status: Passed
Results: 1168 (cyc: 7, node: 874)
CPU Time: 30.274
Score: 1199.71
Submitted at: 2012-11-07 15:45:05 UTC
Scored at: 2012-11-07 20:56:18 UTC

Current Rank: 4th (Highest: 3rd )

Comments
Please login or create a profile.
Code
function xyOut = solver(a, xyIn, wts)
N=size(a,1);
[p1i,p2i] = find( triu(a,1));
[pickr,pickc] = find(tril(true(numel(p1i)),-1));
dsa=diag(sum(a));
[x,nill]=eig(dsa-a,dsa);
x=x(:,2:3);
Nss=4;
for ss=1:Nss
    [xy{ss+(0:2)*Nss}] = solver_alf(a, xyIn, wts, x, ss+1);
end
NN=inf(1,numel(xy));
for ss=find(cellfun('length',xy))
    NN(ss)=gradeIt(p1i,p2i,pickr,pickc,xy{ss});
end
[ZBest,best] = min(NN);
xyOut = xy{best};
end

function varargout = solver_alf(a, xyIn, wts, xyOut0, ss)

N=size(xyIn,1);
beta1=10;
beta2=117+ss;
lambda=ss/15;
thr=0.001+ss*5.1e-2;
thr_d=(3.15 + ss*0.102);
xyOut=N*xyOut0+randn(size(xyOut0))/1e3;
XYOUT0=cell(1,3);
ww=(.05:.9/N:.9499999999)';
ww=(ww-.5)./sqrt(ww.*(1-ww));
for ncut=1:3
    M=eye(N)+a;
    M=bsxfun(@rdivide,M,sum(M,2));
    Mbeta=(((1-lambda)*eye(N)+lambda*M)^beta1);
    
    for n1=1:beta2
        xyOut=Mbeta*xyOut;
        
        wxy0=2*pi*rand;
        wxy=[cos((0:3)/4*pi+wxy0);sin((0:3)/4*pi+wxy0)];
        [nill,wz]=sort(xyOut*wxy,1);
        for n2=1:size(wz,2), wz(wz(:,n2),n2)=ww; end
        xyOut=.5*xyOut+.5*wz*wxy';
        
    end
    
    XYOUT0{ncut}=xyOut;
    [ai,aj]=find(a>thr);
    dd=sum((xyOut(ai,:)-xyOut(aj,:)).^2,2);
    dd=dd/max(eps,mean(dd));
    k=find(dd>thr_d);
    if isempty(k), break; end
    a(ai(k)+N*(aj(k)-1))=thr*thr_d./dd(k);
end

for ncut=1:ncut
    xyOut0=XYOUT0{ncut};
    xyOut0=sqrt(N)*detrend(xyOut0,'constant')*diag(1./max(eps,std(xyOut0,1,1)));
    k=4;
    K=9+ss;
    [sxyOut0,idxequal]=sortrows(round(15*xyOut0));
    idxequal=idxequal(all(~diff(sxyOut0,1,1),2));
    xyOut=round(xyOut0*k);
    while size(unique(xyOut,'rows'),1)~=N
        k=k*(1.0+ss*0.055);%1.1;
        xyOut=xyOut0*k;
        xyOut(idxequal,:)=(xyOut0(idxequal,:)+randn(numel(idxequal),2)/K)*k;
        xyOut=round(xyOut);
    end
    xyOut=bsxfun(@plus,xyOut,round(median(xyIn,1)-median(xyOut,1)));
    XYOUT0{ncut}=xyOut;
end
varargout=XYOUT0;
end

function ans = gradeIt(p1i,p2i,pickr,pickc,XYnew)
X = [XYnew(p1i,:) XYnew(p2i,:)];
xa = X(pickr,:);
xb = X(pickc,:);
A13 = xa(:,1) - xa(:,3);
A24 = xa(:,2) - xa(:,4);
B13 = xb(:,1) - xb(:,3);
B24 = xb(:,2) - xb(:,4);
A = xb(:,1).*xb(:,4) - xb(:,2).*xb(:,3);
B = xa(:,1).*xa(:,4) - xa(:,2).*xa(:,3);
AA = (xa(:,1).*B24 - xa(:,2).*B13 + A) ...
    .*(xa(:,3).*B24 - xa(:,4).*B13 + A);
BB = (xb(:,1).*A24 - xb(:,2).*A13 + B) ...
    .*(xb(:,3).*A24 - xb(:,4).*A13 + B);

sum(all([ abs(A13) .* AA <=0  ...
    abs(A24) .* AA <=0  ...
    abs(B13) .* BB <=0  ...
    abs(B24) .* BB <=0  ...
    ],2));
end