1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| clc clear all N = 100000000; k = 10000000; p = 0.25; dxj = []; bm = []; dxjnum = 0; fdxjnum = 0; zeronum = 0; onenum = 0; W = zeros(N^0.5,N^0.5); Hs = p*log(1/p)/log(2) + (1-p)*log(1/(1-p))/log(2); ipxil = (1-0.96)/0.96*Hs;
for i = 0:1:N LXNLG = (-1) * ((i-1)*log(p)+(N-i+1)*log(1-p)) / log(2) / N; if ((LXNLG >= (Hs-ipxil)) && (LXNLG <= (Hs+ipxil))) dxj = [dxj, i-1]; end end
zuo = min(dxj); you = max(dxj);
for i = 1:1:k temp = rand(N^0.5,N^0.5); W (temp > p) = 0; W (temp <= p) = 1; sum(sum(W)); if ( sum(sum(W))>=zuo ) && ( sum(sum(W))<=you ) dxjnum = dxjnum + 1; else fdxjnum = fdxjnum + 1; end end
for i = zuo:1:you Lx = Lx + nchoosek(N,i); end L = ceil(log(Lx)/log(2)); for i = zuo:1;you bm = [bm, sprintf('%Ld',dec2bin(i-1))]; stemp = num2str(bm(i)) for j = 1:1:length(stemp) if stemp(j) == '0' zeronum = zeronum + nchoosek(N,i); else onenum = onenum + nchoosek(N,i); end end end
zerorate = zeronum / (zeronum + onenum) onerate = onenum / (zeronum + onenum)
det = fdxjnum / k 1 - det
|