Closed Parvfect closed 1 year ago
yeah dk what it is - will need to run a cProfile test - but can be done later
Code is
def belief_propagation(self, max_iterations=100):
""" Belief Propagation decoding for the general case (currently only works for BEC) )"""
filled_vns = sum(list([1 for i in self.vns if not np.isnan(i.value)]))
resolved_vns = 0
for iteration in range(max_iterations):
# Iterating through all the check nodes
for i in self.cns:
# Iterating through all the connected variable nodes for the check node
for j in i.links:
sum_vns = 0
erasure_check = False
for k in i.links:
if k != j:
if np.isnan(self.vns[k].value):
erasure_check = True
break
sum_vns += self.vns[k].value
if erasure_check:
continue
# Need a better Resolved VNs check for the general case, will have to be adapted for the Coupon collector
if np.isnan(self.vns[j].value):
resolved_vns += 1
self.vns[j].value = sum_vns % 2 # in coupon collector, this is going to be intersection with the set of symbols
if filled_vns + resolved_vns == self.n:
return np.array([i.value for i in self.vns])
return np.array([i.value for i in self.vns])
better commented
def belief_propagation(self, max_iterations=100):
""" Belief Propagation decoding for the general case (currently only works for BEC) )"""
filled_vns = sum(list([1 for i in self.vns if not np.isnan(i.value)]))
resolved_vns = 0
for iteration in range(max_iterations):
# Iterating through all the check nodes
for i in self.cns:
# Iterating through all the connected variable nodes for the check node
for j in i.links:
sum_vns = 0
erasure_check = False
# Iterating through the other variable nodes for the check node to obtain the possible value for the selected variable node
for k in i.links:
if k != j:
# For BEC - if any of the connected variable nodes are erased, then the value of the selected variable node is erased
if np.isnan(self.vns[k].value):
erasure_check = True
break
# Update the sum of the variable nodes
sum_vns += self.vns[k].value
# If any of the connected variable nodes are erased, then the value of the selected variable node is erased
if erasure_check:
continue
# Need a better Resolved VNs check for the general case, will have to be adapted for the Coupon collector
if np.isnan(self.vns[j].value):
resolved_vns += 1
self.vns[j].value = sum_vns % 2 # in coupon collector, this is going to be intersection with the set of symbols
if filled_vns + resolved_vns == self.n:
return np.array([i.value for i in self.vns])
return np.array([i.value for i in self.vns])
Implemented BP Decoding - can be easily generalised to coupon collector case. Seems to be slower but results are the same as compared to bec decoding. Going to make it a little faster if I can.