1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- function [minDh, iCminDist]=QuantHammingCanonicalIndices_ceil(CWidx,nNets)
- N=size(CWidx,1);
- iCminDist=zeros(1,N);
- idxs=1:nNets;
- %rPermidx=randperm(N,nNets);
- pperc=[];
- minDh=0;
- [~, ~, icw]=unique(CWidx,'rows');
- uicw=unique(icw);
- luicw=length(uicw);
- %uniNets=nNets/luicw;
- rPermidx=[];
- for jj=1:luicw
- ficw=find(icw==uicw(jj));
- adaptidx=randperm(length(ficw),ceil(nNets*length(ficw)/N));
- %size(adaptidx)
- %size(ficw(adaptidx))
- rPermidx=[rPermidx ficw(adaptidx)'];
- end
- moreidx=length(rPermidx)-nNets;
- if moreidx>0
- remrand=randperm(length(rPermidx),moreidx);
- rPermidx(remrand)=[];
- end
- %size(rPermidx)
- for ii=1:N
- if any(rPermidx==ii)
- iCminDist(ii)=find(rPermidx==ii,1,'first');
- else
- % Approximation of half of the hamming distance
- dH=sum(bsxfun(@ne,CWidx(rPermidx,:),repmat(CWidx(ii,:),nNets,1))');
- minDh=minDh+min(dH);
- allOfTheMins=idxs(dH==min(dH));
- iCminDist(ii)=allOfTheMins(randi(length(allOfTheMins)));
- %[~,iCminDist(ii)]=min(dH);
- end
- perc=sprintf('%2.2f%%',ii/N*100);
- fprintf(1,'%s',sprintf('\b')*ones(1,length(pperc)));
- fprintf(1,'%s',perc);pperc=perc;
- end
- minDh=minDh/N;
- fprintf(1,'%s',sprintf('\b')*ones(1,length(pperc)));
- end
|