import os
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
from matplotlib.ticker import FixedLocator, NullLocator, FixedFormatter
from common import HERE
import e_gaussian_regression as e

sigma, tr, te = e.gaussian_regression()

fig, ax = plt.subplots(figsize=(6, 4))
ax.plot(e.KS, tr, 'o-', color='teal', label='Training')
ax.plot(e.KS, te, 's-', color='darkorange', label='Test')
ax.set_yscale('log')
ticks = [0.3, 0.5, 1, 2, 5, 10, 20, 50, 100]
ax.yaxis.set_major_locator(FixedLocator(ticks))
ax.yaxis.set_major_formatter(FixedFormatter([str(t) for t in ticks]))
ax.yaxis.set_minor_locator(NullLocator())
ax.set_xlabel('Number of Gaussian basis functions')
ax.set_ylabel('RMS error ($1000s, log scale)')
ax.set_title('Gaussian basis regression, no regularization')
ax.set_xticks(e.KS)
ax.grid(alpha=0.3)
ax.legend()
fig.tight_layout()
fig.savefig(os.path.join(HERE, 'media', 'e_rms_vs_basis_count_ticks.png'), dpi=200)
print('saved media/e_rms_vs_basis_count_ticks.png')
