ak9im/p3/visualise.py

87 lines
1.9 KiB
Python
Raw Normal View History

2023-03-12 16:21:26 +01:00
import pandas as pd
import numpy as np
import seaborn as sb
import scipy
import matplotlib.pyplot as plt
uy = pd.read_csv('data/m.csv')
print(uy)
u = uy['u']
u = u[1:len(u)]
y = uy['y']
y = y[1:len(y)]
plt.plot(u)
plt.xlabel("$ \mathit{k}T $")
plt.title("Signal u")
plt.savefig('res/signal_u.png', dpi=300)
plt.clf()
# ----
plt.plot(y)
plt.xlabel("$ \mathit{k}T $")
plt.title("Signal y")
plt.savefig('res/signal_y.png', dpi=300)
plt.clf()
correlation=scipy.stats.pearsonr(uy['u'], uy['y'])
print(correlation)
p = sb.lmplot(
data=uy,
x='u',
y='y',
fit_reg=True,
order=2,
)
p.set(title='Correlation UY')
p.savefig('res/uy_correlation.png', dpi=300)
plt.clf()
plt.close()
theta = pd.read_csv('data/theta.csv', header=None)
# theta = np.transpose(theta) # -> no need to transpose.
2023-03-15 19:00:59 +01:00
th_columns = ["$\hat{a}_1 $", "$\hat{a}_2 $", "$\hat{b}_1$", "$\hat{b}_2$"]
2023-03-12 16:21:26 +01:00
for i in theta:
plt.plot(theta[i], label=th_columns[i])
plt.locator_params(axis='x', nbins=12)
plt.legend()
2023-03-15 19:00:59 +01:00
plt.xlabel("$\mathit{k}T$")
plt.title("ARX Theta (θ) Parameter Estimation using RLSq")
2023-03-12 16:21:26 +01:00
plt.savefig('res/theta.png', dpi=300)
plt.clf()
error = pd.read_csv('data/estimate_error.csv', header=None)
2023-03-15 19:00:59 +01:00
plt.plot(error, label="$\hat{e}(\mathit{k}T)$")
2023-03-12 16:21:26 +01:00
plt.locator_params(axis='x', nbins=12)
plt.legend()
2023-03-15 19:00:59 +01:00
plt.xlabel("$\mathit{k}T$")
plt.title("Error of ARX Theta (θ) Parameter Estimation using RLSq")
2023-03-12 16:21:26 +01:00
plt.savefig('res/error.png', dpi=300)
plt.clf()
explicitTheta = pd.read_csv('data/explicit_theta.csv', header=None)
2023-03-15 19:00:59 +01:00
eTx = explicitTheta[0:4]
eTy = explicitTheta[4:8]
eTxy = [eTx, eTy]
explicitTheta = np.array(eTxy)
print(explicitTheta)
explicitError = pd.read_csv('data/explicit_error.csv', header=None)
2023-03-15 19:00:59 +01:00
plt.plot(explicitError, label="$ê(\mathit{k}T)$")
plt.locator_params(axis='x', nbins=12)
plt.legend()
2023-03-15 19:00:59 +01:00
plt.xlabel("$\mathit{k}T$")
plt.title("Error of ARX Theta (θ) Parameter Estimation using ELSq")
plt.savefig('res/explicit_error.png', dpi=300)
plt.clf()