Renamed Simulator to ProximalDecoderSimulator and added ProximalDecoder specific functionality

This commit is contained in:
Andreas Tsouchlos 2022-11-25 18:52:46 +01:00
parent 5662ba841a
commit ec03f9f5f1
2 changed files with 15 additions and 6 deletions

View File

@ -35,10 +35,10 @@ def start_new_simulation(sim_mgr: simulation.SimulationManager):
"proximal $\\gamma = 0.15$"
]
sim = simulation.Simulator(n=n, k=k, decoders=decoders,
target_frame_errors=100,
SNRs=np.arange(1, 6, 0.5),
max_num_iterations=3000)
sim = simulation.ProximalDecoderSimulator(n=n, k=k, decoders=decoders,
target_frame_errors=100,
SNRs=np.arange(1, 6, 0.5),
max_num_iterations=3000)
sim_mgr.configure_simulation(simulator=sim, name=sim_name,
column_labels=labels)

View File

@ -27,7 +27,7 @@ def count_bit_errors(d: np.array, d_hat: np.array) -> int:
# TODO: Write unit tests
class Simulator:
class ProximalDecoderSimulator:
"""Class allowing for saving of simulations state.
Given a list of decoders, this class allows for simulating the
@ -79,6 +79,7 @@ class Simulator:
self._BERs = [np.zeros(len(SNRs)) for i in range(len(decoders))]
self._dec_fails = [np.zeros(len(SNRs)) for i in range(len(decoders))]
self._avg_K = [np.zeros(len(SNRs)) for i in range(len(decoders))]
self._create_pbars()
@ -144,10 +145,11 @@ class Simulator:
decoder = self._decoders[self._curr_decoder_index]
y = noise.add_awgn(self._x_bpsk, SNR, self._n, self._k)
x_hat = decoder.decode(y)
x_hat, K = decoder.decode(y)
# Handle decoding failure
if x_hat is not None:
self._avg_K[self._curr_decoder_index][self._curr_SNRs_index] += K
return count_bit_errors(self._x, x_hat)
else:
self._curr_num_dec_fails += 1
@ -184,6 +186,10 @@ class Simulator:
self._BERs[self._curr_decoder_index][self._curr_SNRs_index] \
= self._curr_num_bit_errors / (
adj_num_iterations * self._n)
self._avg_K[self._curr_decoder_index][self._curr_SNRs_index]\
= \
self._avg_K[self._curr_decoder_index][
self._curr_SNRs_index] / adj_num_iterations
self._dec_fails[self._curr_decoder_index][self._curr_SNRs_index] \
= self._curr_num_dec_fails
@ -253,6 +259,9 @@ class Simulator:
for i, decoder_dec_fails in enumerate(self._dec_fails):
data[f"DecFails_{i}"] = decoder_dec_fails
for i, avg_K in enumerate(self._avg_K):
data[f"AvgK_{i}"] = avg_K
return pd.DataFrame(data)