1
0
Fork 0
mirror of https://github.com/Findus23/collision-analyisis-and-interpolation.git synced 2024-09-19 15:13:50 +02:00

add simple visualisation of RBF for the bachelor thesis

This commit is contained in:
Lukas Winkler 2019-07-29 14:00:42 +02:00
parent 5060745880
commit 1de9034954
Signed by: lukas
GPG key ID: 54DE4D798D244853

59
rbf-vis.py Normal file
View file

@ -0,0 +1,59 @@
import numpy as np
from matplotlib import pyplot as plt
np.random.seed(15)
def theta(r):
return np.exp(-r ** 2)
points = [0, 3, 5]
values = [0.2, 0.8, 0.1]
# points = np.random.rand(15) * 5
# values = np.sin(points)
plt.scatter(points, values, label="data points")
subtract = np.zeros((len(points), len(points)))
for i in range(len(points)):
for j in range(len(points)):
subtract[i][j] = abs(points[i] - points[j])
print(subtract)
left_side = theta(subtract)
print(left_side)
lambdas = np.linalg.solve(left_side, values)
print(lambdas)
def s(x, i=None):
running_sum = 0
for index, lam in enumerate(lambdas):
if i is None or i == index:
running_sum += lam * theta(x - points[index])
return running_sum
x = np.linspace(0, 5, 100)
y = s(x)
plt.plot(x, y, label="$s(x)$", zorder=-1)
for i in range(len(points)):
plt.plot(x, s(x, i), label=f"RBF {i}",zorder=-2)
plt.legend()
# x_interpol = 2.3
# y_interpol = s(x_interpol)
# plt.scatter(x_interpol,y_interpol,color="green")
plt.savefig("../arbeit/images/rbf1.pdf")
# plt.savefig("../arbeit/images/rbf2.pdf")
plt.show()