Made main.py work with the new simulation functions
This commit is contained in:
parent
f791a9a086
commit
2fae3ba3be
65
sw/main.py
65
sw/main.py
@ -12,32 +12,6 @@ from decoders import proximal, maximum_likelihood
|
||||
from utility import simulations, codes
|
||||
|
||||
|
||||
def test_decoders(G, decoders: typing.List) -> pd.DataFrame:
|
||||
k, n = G.shape
|
||||
x = np.zeros(n) # All-zeros assumption
|
||||
|
||||
SNRs = np.linspace(1, 7, 7)
|
||||
data = pd.DataFrame({"SNR": SNRs})
|
||||
|
||||
start_time = default_timer()
|
||||
|
||||
for decoder_name in decoders:
|
||||
decoder = decoders[decoder_name]
|
||||
_, BERs_sd = simulations.test_decoder(x,
|
||||
decoder=decoder,
|
||||
SNRs=SNRs,
|
||||
target_frame_errors=100,
|
||||
N_max=50000)
|
||||
|
||||
data[f"BER_{decoder_name}"] = BERs_sd
|
||||
|
||||
stop_time = default_timer()
|
||||
|
||||
print(f"Elapsed time: {stop_time-start_time:.2f}s")
|
||||
|
||||
return data
|
||||
|
||||
|
||||
# TODO: Fix spacing between axes and margins
|
||||
def plot_results():
|
||||
results_dir = "sim_results"
|
||||
@ -78,27 +52,32 @@ def plot_results():
|
||||
def main():
|
||||
Path("sim_results").mkdir(parents=True, exist_ok=True)
|
||||
|
||||
used_codes = [
|
||||
"Hamming_7_4",
|
||||
"Golay_24_12",
|
||||
# "BCH_31_16",
|
||||
# "BCH_31_21",
|
||||
# "BCH_63_16",
|
||||
# used_code = "Hamming_7_4"
|
||||
# used_code = "Golay_24_12"
|
||||
used_code = "BCH_31_16"
|
||||
# used_code = "BCH_31_21"
|
||||
# used_code = "BCH_63_16"
|
||||
|
||||
G = codes.Gs[used_code]
|
||||
H = codes.get_systematic_H(G)
|
||||
|
||||
decoders = [
|
||||
maximum_likelihood.MLDecoder(G, H),
|
||||
proximal.ProximalDecoder(H, gamma=0.01),
|
||||
proximal.ProximalDecoder(H, gamma=0.05),
|
||||
proximal.ProximalDecoder(H, gamma=0.15)
|
||||
]
|
||||
|
||||
for used_code in used_codes:
|
||||
G = codes.Gs[used_code]
|
||||
H = codes.get_systematic_H(G)
|
||||
k, n = G.shape
|
||||
SNRs, BERs = simulations.test_decoders(n, k, decoders, N_max=30000, target_frame_errors=100)
|
||||
|
||||
decoders = {
|
||||
"ML": maximum_likelihood.MLDecoder(G, H),
|
||||
"proximal_0_01": proximal.ProximalDecoder(H, gamma=0.01),
|
||||
"proximal_0_05": proximal.ProximalDecoder(H, gamma=0.05),
|
||||
"proximal_0_15": proximal.ProximalDecoder(H, gamma=0.15),
|
||||
}
|
||||
df = pd.DataFrame({"SNR": SNRs})
|
||||
df["BER_ML"] = BERs[0]
|
||||
df["BER_prox_0_01"] = BERs[0]
|
||||
df["BER_prox_0_05"] = BERs[1]
|
||||
df["BER_prox_0_15"] = BERs[2]
|
||||
|
||||
data = test_decoders(G, decoders)
|
||||
data.to_csv(f"sim_results/{used_code}.csv")
|
||||
df.to_csv(f"sim_results/{used_code}.csv")
|
||||
|
||||
plot_results()
|
||||
|
||||
|
||||
@ -12,8 +12,6 @@ def get_noise_variance_from_SNR(SNR: float, n: int, k: int) -> float:
|
||||
:param k: Length of a dataword of the used code
|
||||
:return: Variance of the noise
|
||||
"""
|
||||
# noise_amp = (1 / np.sqrt(SNR_linear)) * signal_amp
|
||||
|
||||
SNR_linear = 10 ** (SNR / 10)
|
||||
variance = 1 / (2 * (k/n) * SNR_linear)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user