def get_LLRdictWU(channel_plist, design_p, I, N, runsim, RI): LLRdictWU = {} G = len(I) stamp = datetime.now().strftime("%y-%m-%d_%H-%M-%S") f2name = "./simresults/llrsgndict" + "-" + str(N) + "-" + str( design_p).replace(".", "p") + "-" + stamp + ".txt" f2 = open( "./simresults/llrsgndict" + "-" + str(N) + "-" + str(design_p).replace(".", "p") + "-" + stamp + ".txt", 'w') n = int(ma.log(N, 2)) for channel_p in channel_plist: print "\nrunning for " + str(channel_p) + "..." LLRdictWU[str(channel_p)] = [] for i in range(runsim): UN = np.random.randint(2, size=G) FD = np.random.randint(2, size=N - len(I)) #the following are intermediate steps of encoding # done to get VN # same as XN=ec.polarencodeG(UN,N,I,list(FD),False) VN = ec.formVN_u(list(UN), N, I, list(FD)) XN = ec.polarencrec(VN, n - 1, n) YN = pl.BSCN(channel_p, XN) (llr, UN_hat) = ec.polarSCdecodeG(YN, N, design_p, I, FD, True) UN_decoded = ec.getUN(UN_hat, I, False) #--------------------------------- LLRdictWU[str(channel_p)].append([ ec.getchannel(llr, RI, False), "".join(str(x) for x in ec.getchannel(VN, RI, False)), "".join(str(x) for x in ec.getchannel(UN_hat, RI, False)) ]) json.dump(LLRdictWU, f2) for channel_p in channel_plist: with open( "./simresults/llrsgndict" + "-" + str(N) + "-" + str(design_p).replace(".", "p") + "-On-" + str(channel_p).replace(".", "p") + "-" + stamp + ".csv", 'wb') as resultFile: wr = csv.writer(resultFile, dialect='excel') wr.writerow(["", "LLR in RI"] + [""] * (N - 1) + ["Data in RI"] + ["Recovered Data in RI"]) wr.writerow([""] + RI) for sim in range(runsim): wr.writerow( [str(sim + 1)] + LLRdictWU[str(channel_p)][sim][0] + [str('"') + LLRdictWU[str(channel_p)][sim][1] + str('"')] + [str('"') + LLRdictWU[str(channel_p)][sim][2] + str('"')]) return f2name
def perc_bad_channel_Irv_WU_llr(llr, F, LT, Frozen_data, use_func_for_LT): B = len(F) if use_func_for_LT: LT = f_Irv_abs(LT) LLRbadchannels = ec.getchannel(llr, F, False) SentBitchannels = Frozen_data perc = float( sum( f_Irv(llr, int(sentbit)) >= LT for llr, sentbit in zip( LLRbadchannels, SentBitchannels))) * 100 / B return perc
def P_allgood(channel_plist, design_p, I, N, LT, runsim, RI, LLRdict_needed): LLRdict = {} Pdict = {} stamp = datetime.now().strftime("%y-%m-%d_%H-%M-%S") f1 = open( "./simresults/llrdict" + "-" + str(N) + "-" + str(design_p).replace(".", "p") + "-" + stamp + ".txt", 'w') FD = np.zeros(N - len(I), dtype=int).tolist() for channel_p in channel_plist: print "\nrunning for " + str(channel_p) + "..." Count_all_good = 0 LLRdict[str(channel_p)] = [] for i in range(runsim): UN = np.random.randint(2, size=len(I)) UN_encoded = ec.polarencodeG(UN, N, I, list(FD), False) YN = pl.BSCN(channel_p, UN_encoded) (llr, d) = ec.polarSCdecodeG(YN, N, design_p, I, list(FD), True) L = abs(llr) #--------------------------------- llr_Gmin = min(ec.getchannel(L, I, False)) LLRdict[str(channel_p)].append(ec.getchannel(L, RI, False)) Count_all_good += (llr_Gmin >= LT) Pdict[str(channel_p)] = float(Count_all_good) / runsim json.dump(LLRdict, f1) if LLRdict_needed: return (LLRdict, Pdict) else: return Pdict
def frac_goodchannel(channel_plist, design_p, I, N, LT, runsim, RI, LLRdict_needed): LLRdict = {} Fdict = {} G = len(I) stamp = datetime.now().strftime("%y-%m-%d_%H-%M-%S") #f1=open("./simresults/llrdict"+"-"+str(N)+"-"+str(design_p).replace(".","p")+"-"+stamp+".txt",'w') f2 = open( "./simresults/llrsgndict" + "-" + str(N) + "-" + str(design_p).replace(".", "p") + "-" + stamp + ".txt", 'w') FD = np.zeros(N - len(I), dtype=int).tolist() for channel_p in channel_plist: print "\nrunning for " + str(channel_p) + "..." LLRdict[str(channel_p)] = [] Fdict[str(channel_p)] = [] for i in range(runsim): UN = np.random.randint(2, size=len(I)) UN_encoded = ec.polarencodeG(UN, N, I, list(FD), False) YN = pl.BSCN(channel_p, UN_encoded) (llr, d) = ec.polarSCdecodeG(YN, N, design_p, I, list(FD), True) L = abs(llr) #--------------------------------- LLRdict[str(channel_p)].append(ec.getchannel(llr, RI, False)) LLRgoodchannels = abs(np.array( LLRdict[str(channel_p)][i][:G])).tolist() num_goodchannel = sum(llr > LT for llr in LLRgoodchannels) Fdict[str(channel_p)].append(float(num_goodchannel) / N) #json.dump(LLRdict,f1); json.dump(LLRdict, f2) if LLRdict_needed: return (LLRdict, Fdict) else: return Fdict
def perc_goodchannel_llr(llr, I, LT): G = len(I) L = abs(llr) LLRgoodchannels = ec.getchannel(L, I, False) perc = float(sum(llr >= LT for llr in LLRgoodchannels)) * 100 / G return perc
#Frozen data D = np.zeros(N - len(I), dtype=int).tolist() #---------------------------------------------finding lambda-threshold lambda_thresholdlist = np.zeros(N) lambda_threshold1list = np.zeros(N) lambda_threshold2list = np.zeros(N) for i in range(runsim_th): UN = np.random.randint(2, size=len(I)) UN_encoded = ec.polarencodeG(UN, N, I, list(D), False) YN = pl.BSCN(design_p, UN_encoded) (llr, d) = ec.polarSCdecodeG(YN, N, design_p, I, list(D), True) L = abs(llr) / runsim_th lambda_thresholdlist = lambda_thresholdlist + L lambda_threshold1 = min(ec.getchannel(lambda_thresholdlist, I, False)) lambda_threshold2 = max(ec.getchannel(lambda_thresholdlist, B, False)) lambda_threshold = (lambda_threshold1 + lambda_threshold2) / 2 print[lambda_threshold1, lambda_threshold2, lambda_threshold] json.dump([lambda_threshold1, lambda_threshold2, lambda_threshold], f1) f1.write("\n") used_lambda_threshold = lambda_threshold1 print used_lambda_threshold json.dump("used_lambda_threshold" + str(used_lambda_threshold), f1) f1.write("\n") json.dump("p,Pr(Gmin>thr),Pr(Fmax<thr)::Pr(gmin>Fmax)", f1) f1.write("\n") #-----------------------------------------checking channels
for channel_p in channel_plist: lambda_thresholdlist = np.zeros(N) lambda_Emin = 0 for i in range(runsim_th): UN = np.random.randint(2, size=len(I)) UN_encoded = ec.polarencodeG(UN, N, I, list(D), False) YN = pl.BSCN(channel_p, UN_encoded) (llr, d) = ec.polarSCdecodeG(YN, N, design_p, I, list(D), True) L = abs(llr) / runsim_th # expected value of min of good channels lambda_Emin += min(ec.getchannel(L, I, False)) # expected Value of all channels(a vector) lambda_thresholdlist = lambda_thresholdlist + L lambda_Emindict[str(channel_p)] = lambda_Emin # minimum of expected value of goodchannels lambda_minE = min(ec.getchannel(lambda_thresholdlist, I, False)) lambda_minEdict[str(channel_p)] = lambda_minE print "channel_p:" + str(channel_p) print "Lambda Min(E(LLR))" + str(lambda_minE) print "Lambda E(min(LLR))" + str(lambda_Emin) json.dump("channel_p:" + str(channel_p), f1);
for i in range(runsim): UN = np.random.randint(2, size=len(I)) UN_encoded = ec.polarencodeG(UN, N, I, list(D), False) YN = pl.BSCN(psim, UN_encoded) (L, d) = ec.polarSCdecodeG(YN, N, p, I, list(D), True) #print abs(L)/runsim psim_llr_sum += abs(L) / runsim #psim_llr=[float(x)/runsim for x in psim_llr_sum] psim_llr = psim_llr_sum.tolist() print psim_llr if p == psim: #sets the threshold of lambda as the min of goodchannels #for the highest rate channel lambda_threshold = min(ec.getchannel(psim_llr, I, False)) print ec.getchannel(psim_llr, I, False) llr_dict[psim] = psim_llr print lambda_threshold #---------------------------------------------------decodable condition # all bad channels are within lambda threshold HiBad = [] for ch in B: if llr_dict[psim][ch] >= lambda_threshold: HiBad.append(ch) print "Decodable Condition:"