Simulator class now returns pandas dataframe instead of raw data
This commit is contained in:
parent
8599ea9662
commit
3c27a0cc18
@ -199,30 +199,27 @@ class Simulator:
|
|||||||
"""Stop the simulation."""
|
"""Stop the simulation."""
|
||||||
self._sim_running = False
|
self._sim_running = False
|
||||||
|
|
||||||
@property
|
def get_current_results(self) -> pd.DataFrame:
|
||||||
def SNRs_and_BERs(self) -> typing.Tuple[np.array, np.array]:
|
|
||||||
"""Get the current results.
|
"""Get the current results.
|
||||||
|
|
||||||
If the simulation has not yet completed, the BERs which have not yet been calculated are set to 0.
|
If the simulation has not yet completed, the BERs which have not yet been calculated are set to 0.
|
||||||
|
|
||||||
:return: Tuple of numpy arrays of the form (SNRs, BERs), where BERs is a list of the form
|
:return: pandas Dataframe with the columns ["SNR", "BER_1", "BER_2", ...]
|
||||||
[BER_decoder_1, BER_decoder_2, ...]
|
|
||||||
"""
|
"""
|
||||||
SNRs = np.array(self._SNRs)
|
data = {"SNR": np.array(self._SNRs)}
|
||||||
|
|
||||||
# If the BERs of a decoder have not been calculated for all SNRs,
|
# If the BERs of a decoder have not been calculated for all SNRs,
|
||||||
# fill the rest up with zeros to match the length of the 'SNRs' array
|
# fill the rest up with zeros to match the length of the 'SNRs' array
|
||||||
BERs = []
|
for i, decoder_BER_list in enumerate(self._BERs):
|
||||||
for decoder_BER_list in self._BERs:
|
|
||||||
padded = np.pad(decoder_BER_list, (0, len(self._SNRs) - len(decoder_BER_list)))
|
padded = np.pad(decoder_BER_list, (0, len(self._SNRs) - len(decoder_BER_list)))
|
||||||
BERs.append(padded)
|
data[f"BER_{i}"] = padded
|
||||||
|
|
||||||
# If the BERs have not been calculated for all decoders, fill up the BERs list
|
# If the BERs have not been calculated for all decoders, fill up the BERs list
|
||||||
# with zero-vectors to match the length of the 'decoders' list
|
# with zero-vectors to match the length of the 'decoders' list
|
||||||
for i in range(len(self._decoders) - len(BERs)):
|
for i in range(len(self._decoders), len(self._BERs)):
|
||||||
BERs.append(np.zeros(len(self._SNRs)))
|
data[f"BER_{i}"] = np.zeros(len(self._SNRs))
|
||||||
|
|
||||||
return SNRs, BERs
|
return pd.DataFrame(data)
|
||||||
|
|
||||||
|
|
||||||
# TODO: Fix typing.Any or Simulator
|
# TODO: Fix typing.Any or Simulator
|
||||||
@ -310,13 +307,7 @@ class SimulationDeSerializer:
|
|||||||
json.dump(metadata, f, ensure_ascii=False, indent=4)
|
json.dump(metadata, f, ensure_ascii=False, indent=4)
|
||||||
|
|
||||||
# Save results
|
# Save results
|
||||||
SNRs, BERs = simulator.SNRs_and_BERs
|
df = simulator.get_current_results()
|
||||||
|
|
||||||
data_dict = {"SNR": SNRs}
|
|
||||||
for i, BER in enumerate(BERs):
|
|
||||||
data_dict[f"BER_{i}"] = BER
|
|
||||||
|
|
||||||
df = pd.DataFrame(data_dict)
|
|
||||||
df.to_csv(self._get_results_path(sim_name))
|
df.to_csv(self._get_results_path(sim_name))
|
||||||
|
|
||||||
def read_results(self, sim_name: str) -> typing.Tuple[pd.DataFrame, typing.Dict]:
|
def read_results(self, sim_name: str) -> typing.Tuple[pd.DataFrame, typing.Dict]:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user