"""
This file loads the error rate data and plots the average error and computation time for the 
25 random networks.

The files error_wPC_freq.npy, error_wPH_freq.npy, error_wPC_time.npy, comp_wPC_freq.npy,
comp_wPH_freq.npy, and comp_wPC_time.npy are obtained using the FD based W-PC, Wiener-phase,
and TD based W-PC algorithms. These files were generated using the script
"Wiener_PC_time_vs_FFT_random_networks_sparsity_tuned.py" 
"""


import matplotlib.pyplot as plt
import numpy as np

error_wPC_freq = np.load('error_wPC_freq.npy')
error_wPH_freq = np.load('error_wPH_freq.npy')
error_wPC_time = np.load('error_wPC_time.npy')
comp_wPC_freq = np.load('comp_wPC_freq.npy')
comp_wPH_freq = np.load('comp_wPH_freq.npy')
comp_wPC_time = np.load('comp_wPC_time.npy')

nSamples_list = [640, 3200, 6400, 32000, 128*10**3, 32*10**4]
nNetworks = 25
nFFT = 32

plt.rcParams['text.usetex'] = True
plt.rcParams['font.family'] = 'serif'
scaleFac = 0.5

plt.style.use('seaborn-v0_8-colorblind')
FONTSIZE=28 *scaleFac
WIDTH_SIZE=8 *scaleFac
HEIGHT_SIZE=6 *scaleFac
LEGENDSIZE=14 *scaleFac
LINEWIDTH=3 *scaleFac
tickFONTSIZE = 24 *scaleFac
legendFONTSIZE = 24 *scaleFac
markerSIZE = 11 *scaleFac

plt.figure(figsize=(WIDTH_SIZE,HEIGHT_SIZE))
plt.semilogx(nSamples_list,sum(error_wPC_freq)/nNetworks,'b>-',label="FD WPC",linewidth=LINEWIDTH,markersize=markerSIZE)
plt.semilogx(nSamples_list,sum(error_wPH_freq)/nNetworks,'cx--',label="Win-Ph",linewidth=LINEWIDTH,markersize=markerSIZE)
plt.semilogx(nSamples_list,sum(error_wPC_time)/nNetworks,'gD-.',label="TD WPC",linewidth=LINEWIDTH,markersize=markerSIZE)

plt.legend(loc="upper right", fontsize=LEGENDSIZE)
# plt.title("Time vs Freq Average Error Rate Comparison", fontsize=15)
plt.xlabel("Number of samples",fontsize=FONTSIZE)
plt.ylabel("Error rate", fontsize=FONTSIZE)
plt.xticks(fontsize=tickFONTSIZE)
plt.yticks(fontsize=tickFONTSIZE)
plt.legend(fontsize=legendFONTSIZE)
plt.savefig("avg error random network sparsity tuned.png", bbox_inches='tight')
plt.show()

plt.figure(figsize=(WIDTH_SIZE,HEIGHT_SIZE))
plt.semilogx(nSamples_list,sum(comp_wPC_freq)/nNetworks,'b>-',label="FD WPC",linewidth=LINEWIDTH,markersize=markerSIZE)
plt.semilogx(nSamples_list,sum(comp_wPH_freq)/nNetworks,'cx--',label="Win-Ph",linewidth=LINEWIDTH,markersize=markerSIZE)
plt.semilogx(nSamples_list,sum(comp_wPC_time)/nNetworks,'gD-.',label="TD WPC",linewidth=LINEWIDTH,markersize=markerSIZE)
plt.legend(loc="upper left", fontsize=LEGENDSIZE)
# plt.title("Time vs Freq  Average Computation Time Comparison", fontsize=15)
plt.xlabel("Number of samples",fontsize=FONTSIZE)
plt.ylabel("Computation time", fontsize=FONTSIZE)
plt.xticks(fontsize=tickFONTSIZE)
plt.yticks(fontsize=tickFONTSIZE)
plt.legend(fontsize=legendFONTSIZE)
plt.savefig("avg computation time random network sparsity tuned.png", bbox_inches='tight')
plt.show()