1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- function [iCminDist]=QuantHammingCanonicalIndices(CWidx,nNets)
- N=size(CWidx,1);
- iCminDist=zeros(1,N);
- idxs=1:nNets;
- %rPermidx=randperm(N,nNets);
- pperc=[];
- [~, ~, 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),floor(nNets*length(ficw)/N));
- %size(adaptidx)
- %size(ficw(adaptidx))
- rPermidx=[rPermidx ficw(adaptidx)'];
- end
- newidx=nNets-length(rPermidx);
- if newidx>0
- totpermidx=randperm(N);
- toremidx=rPermidx(rPermidx==newidx);
- totpermidx(toremidx)=[];
- selectidx=randperm(length(totpermidx),newidx);
- rPermidx=[rPermidx totpermidx(selectidx)];
- 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))');
- 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
- fprintf(1,'%s',sprintf('\b')*ones(1,length(pperc)));
- end
|