QuantHammingCanonicalIndices.m 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. function [iCminDist]=QuantHammingCanonicalIndices(CWidx,nNets)
  2. N=size(CWidx,1);
  3. iCminDist=zeros(1,N);
  4. idxs=1:nNets;
  5. %rPermidx=randperm(N,nNets);
  6. pperc=[];
  7. [~, ~, icw]=unique(CWidx,'rows');
  8. uicw=unique(icw);
  9. luicw=length(uicw);
  10. %uniNets=nNets/luicw;
  11. rPermidx=[];
  12. for jj=1:luicw
  13. ficw=find(icw==uicw(jj));
  14. adaptidx=randperm(length(ficw),floor(nNets*length(ficw)/N));
  15. %size(adaptidx)
  16. %size(ficw(adaptidx))
  17. rPermidx=[rPermidx ficw(adaptidx)'];
  18. end
  19. newidx=nNets-length(rPermidx);
  20. if newidx>0
  21. totpermidx=randperm(N);
  22. toremidx=rPermidx(rPermidx==newidx);
  23. totpermidx(toremidx)=[];
  24. selectidx=randperm(length(totpermidx),newidx);
  25. rPermidx=[rPermidx totpermidx(selectidx)];
  26. end
  27. size(rPermidx);
  28. for ii=1:N
  29. if any(rPermidx==ii)
  30. iCminDist(ii)=find(rPermidx==ii,1,'first');
  31. else
  32. % Approximation of half of the hamming distance
  33. dH=sum(bsxfun(@ne,CWidx(rPermidx,:),repmat(CWidx(ii,:),nNets,1))');
  34. allOfTheMins=idxs(dH==min(dH));
  35. iCminDist(ii)=allOfTheMins(randi(length(allOfTheMins)));
  36. %[~,iCminDist(ii)]=min(dH);
  37. end
  38. perc=sprintf('%2.2f%%',ii/N*100);
  39. fprintf(1,'%s',sprintf('\b')*ones(1,length(pperc)));
  40. fprintf(1,'%s',perc);pperc=perc;
  41. end
  42. fprintf(1,'%s',sprintf('\b')*ones(1,length(pperc)));
  43. end