QuantHammingCanonicalIndices_ceil.m 1.2 KB

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