Added iteration limit

This commit is contained in:
Andreas Tsouchlos 2022-11-24 12:48:32 +01:00
parent 6e64119874
commit d6ce89cbeb

View File

@ -42,7 +42,8 @@ class Simulator:
def __init__(self, n: int, k: int,
decoders: typing.Sequence[typing.Any],
SNRs: typing.Sequence[float],
target_frame_errors: int):
target_frame_errors: int,
max_num_iterations: int):
"""Construct and object of type simulator.
:param n: Number of bits in a codeword
@ -59,6 +60,7 @@ class Simulator:
self._decoders = decoders
self._SNRs = SNRs
self._target_frame_errors = target_frame_errors
self._max_num_iterations = max_num_iterations
self._x = np.zeros(self._n)
self._x_bpsk = 1 - 2 * self._x # Map x from [0, 1]^n to [-1, 1]^n
@ -90,7 +92,7 @@ class Simulator:
decoder = self._decoders[self._current_decoder_index]
self._decoder_pbar = tqdm(total=len(self._SNRs),
desc=f"Calculatin"
desc=f"Calculating"
f"g BERs"
f" for {decoder.__class__.__name__}",
leave=False,
@ -165,7 +167,9 @@ class Simulator:
This function also appends a new BER value to the self._BERs array
if the number of target frame errors has been reached
"""
if self._curr_num_frame_errors >= self._target_frame_errors:
if (self._curr_num_frame_errors >= self._target_frame_errors) or (
self._curr_num_iterations > self._max_num_iterations):
self._BERs[self._current_decoder_index] \
.append(self._curr_num_bit_errors / (
self._curr_num_iterations * self._n))