Loss smoothing
The problem:
import numpy as np
import matplotlib.pyplot as plt
x = np.array([1, 2, 3])
y = np.array([0.2572527229785919, 2.5656850993982516e-05, 9.75140892478521e-07])
plt.plot(x, y[0:len(y)], 'r*', label='loss', markersize=9)
for a, b in zip(range(len(y)), y):
plt.text(a + 1, b, '%.8f' % b, ha='center', va='bottom', fontsize=12)
plt.plot(x, y)
plt.xticks(x)
plt.yscale('log')
plt.grid(True, linestyle='dashed')
plt.xlabel('number of updates')
plt.ylabel('MSE loss with logarithmic scale')
plt.show()
The plot graph from above:
Solution:
Instead of “make_interp_spline” from sicpy I use “CubicSpline” from scipy.interpolate:
from scipy.interpolate import CubicSpline
import numpy as np
import matplotlib.pyplot as plt
x = np.array([1, 2, 3])
y = np.log10([0.2572527229785919, 2.5656850993982516e-05, 9.75140892478521e-07])
plt.plot(x, y[0:len(y)], 'r*', label='loss', markersize=9)
for a, b in zip(range(len(y)), y):
plt.text(a + 1, b, '%.8f' % b, ha='center', va='bottom', fontsize=12)
x_smooth =np.linspace(1, 3, 300)
y_smooth = CubicSpline(x, y)(x_smooth)
plt.plot(x_smooth, y_smooth)
plt.xticks(x)
plt.grid(True, linestyle='dashed')
plt.xlabel('number of updates')
plt.ylabel('MSE loss with logarithmic scale')
plt.show()
Reference:
[1] : https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.CubicSpline.html
[2] : https://python-decompiler.com/article/2011-03/plot-smooth-line-with-pyplot