Skip to content
Snippets Groups Projects

clean scripts

4 files
+ 80
10
Compare changes
  • Side-by-side
  • Inline

Files

  • 5e990b2b
    - Finish plot_losses implementation; · 5e990b2b
    Charly LAMOTHE authored
    - Fix bug of resolve_experiment_id after 10 exp ids;
    - Display the new experiment id at the beginning of the training;
    - For now there's only a simple losses plot in compute_results.
@@ -6,17 +6,14 @@ from sklearn.neighbors.kde import KernelDensity
class Plotter(object):
@staticmethod
def weight_density(weights):
"""
TODO: to complete
"""
def weight_density(weights, X, file_path):
X_plot = [np.exp(elem) for elem in weights]
fig, ax = plt.subplots()
for kernel in ['gaussian', 'tophat', 'epanechnikov']:
kde = KernelDensity(kernel=kernel, bandwidth=0.5).fit(X_plot)
log_dens = kde.score_samples(X_plot)
ax.plot(X_plot[:, 0], np.exp(log_dens), '-',
ax.plot(X_plot, np.exp(log_dens), '-',
label="kernel = '{0}'".format(kernel))
ax.legend(loc='upper left')
@@ -24,4 +21,46 @@ class Plotter(object):
ax.set_xlim(-4, 9)
ax.set_ylim(-0.02, 0.4)
plt.show()
fig.savefig(file_path, dpi=fig.dpi)
plt.close(fig)
@staticmethod
def plot_mean_and_CI(ax, mean, lb, ub, x_value, color_mean=None, facecolor=None, label=None):
# plot the shaded range of the confidence intervals
ax.fill_between(x_value, ub, lb, facecolor=facecolor, alpha=.5)
# plot the mean on top
ax.plot(x_value, mean, c=color_mean, label=label)
@staticmethod
def plot_losses(file_path, all_experiment_scores, x_value, xlabel, ylabel, all_labels, title):
fig, ax = plt.subplots()
n = len(all_experiment_scores)
colors = Plotter.get_colors_from_cmap(n)
for i in range(n):
experiment_scores = list(all_experiment_scores[i].values())
mean_experiment_scores = np.average(experiment_scores, axis=0)
std_experiment_scores = np.std(experiment_scores, axis=0)
Plotter.plot_mean_and_CI(
ax=ax,
mean=mean_experiment_scores,
lb=mean_experiment_scores + std_experiment_scores,
ub=mean_experiment_scores - std_experiment_scores,
x_value=x_value,
color_mean=colors[i],
facecolor=colors[i],
label=all_labels[i]
)
plt.xlabel(xlabel)
plt.ylabel(ylabel)
plt.title(title)
plt.legend(loc='upper right')
fig.savefig(file_path, dpi=fig.dpi)
plt.close(fig)
@staticmethod
def get_colors_from_cmap(n_colors, colormap_name='nipy_spectral'):
return [plt.get_cmap(colormap_name)(1. * i/n_colors) for i in range(n_colors)]
Loading