p3: make visualise.py useful

This commit is contained in:
leo 2023-03-12 16:21:26 +01:00
parent e80fcaa5ca
commit 82b91b5c6a
Signed by: wanderer
SSH Key Fingerprint: SHA256:Dp8+iwKHSlrMEHzE3bJnPng70I7LEsa3IJXRH/U+idQ

@ -1 +1,66 @@
print("visualise")
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.
th_columns = ["$ \hat{a}_1 $","$ \hat{a}_2 $","$ \hat{b}_1 $","$ \hat{b}_2 $"]
for i in theta:
plt.plot(theta[i], label=th_columns[i])
plt.locator_params(axis='x', nbins=12)
plt.legend()
plt.xlabel("$ \mathit{k}T $")
plt.title("ARX Theta (Θ) Parameter Estimation using Recursive Least Squares")
plt.savefig('res/theta.png', dpi=300)
plt.clf()
error = pd.read_csv('data/estimate_error.csv', header=None)
plt.plot(error, label="$ ê(\mathit{k}T) $")
plt.locator_params(axis='x', nbins=12)
plt.legend()
plt.xlabel("$ \mathit{k}T $")
plt.title("ARX RLSq Theta (Θ) Parameter Estimation Error")
plt.savefig('res/error.png', dpi=300)
plt.clf()