Commit 8285b235 authored by Martin Řepa's avatar Martin Řepa

Experiment with convergence plotting

parent f0a0f81b
experiments_per_setup: 2 # 6
legacy_folder: /home/ignac/experiments/learning_epochs/2000and22000_2times_bignn_gaussdata_plot # Change in regards with configuration
experiments_per_setup: 1 # 6
legacy_folder: /home/ignac/experiments/learning_epochs/2000and22000_1time_bignn_gaussdata_plot#2 # Change in regards with configuration
epochs:
lower_bound: 2000
number_of_steps: 2 # 8 (6-8 should be enough)
......
......@@ -45,35 +45,54 @@ class LearningEpochsPlotter:
x, _ = np_matrix_from_scored_csv(data_filename, 0)
self.dataset = np.unique(x, axis=0)
# Variables to plot value of the game convergence
self.last_zero_sum_value = None
self.last_zero_sum_att_value = None
self.last_zero_sum_def_value = None
self.fig, self.ax = plt.subplots()
self.ax.set_xlabel('Double oracle iteration')
self.ax.set_ylabel('Zero-sum game value')
def plot_iteration(self, iteration, zero_sum_val, p1_br_value, p2_br_value,
played_p2, probs_p2, played_p1, probs_p1, br_p1, br_p2):
if not self.conf.plot_enabled:
return
fig, ax = plt.subplots()
ax.set_xlim(0., 1.)
ax.set_ylim(0., 1.)
plt.tight_layout()
# Plot benign data-set --- TMP ---
ax.scatter(self.dataset[:, 0], self.dataset[:, 1], c='blue', s=1.)
# ---------------
# Plot defender's best response
res = br_p2.latency_predict(self.actions) \
.cpu().numpy().reshape((101, 101), order='F')
ax.imshow(res, cmap='Reds', vmin=0, vmax=1, origin='lower', extent=(0., 1., 0., 1.))
# Plot attacker nash strategy
for point, prob in zip(played_p1, probs_p1):
if prob == 0:
continue
ax.scatter(point[0], point[1], c='green', marker='^')
ax.annotate(f'{round(prob, 2)}', (point[0], point[1]), color='green')
# fig, ax = plt.subplots()
# plt.tight_layout()
# ax.set_xlim(0., 1.)
# ax.set_ylim(0., 1.)
# # ----------- Plot defender best response -----------------------
# # Plot benign data-set --- TMP ---
# ax.scatter(self.dataset[:, 0], self.dataset[:, 1], c='blue', s=1.)
# # ---------------
#
# # Plot defender's best response
# res = br_p2.latency_predict(self.actions) \
# .cpu().numpy().reshape((101, 101), order='F')
# ax.imshow(res, cmap='Reds', vmin=0, vmax=1, origin='lower', extent=(0., 1., 0., 1.))
#
# # Plot attacker nash strategy
# for point, prob in zip(played_p1, probs_p1):
# if prob == 0:
# continue
# ax.scatter(point[0], point[1], c='green', marker='^')
# ax.annotate(f'{round(prob, 2)}', (point[0], point[1]), color='green')
# -----------Plot game value convergence----------------------
if self.last_zero_sum_value is not None:
x_vals = [iteration - 1, iteration]
self.ax.plot(x_vals, [self.last_zero_sum_value, zero_sum_val], c='blue')
self.ax.plot(x_vals, [self.last_zero_sum_att_value, p1_br_value], c='red')
self.ax.plot(x_vals, [self.last_zero_sum_def_value, p2_br_value], c='green')
self.last_zero_sum_value = zero_sum_val
self.last_zero_sum_att_value = p1_br_value
self.last_zero_sum_def_value = p2_br_value
fig.savefig(f'{self.conf.output_svg_dir}/iteration{iteration}.svg',
self.fig.savefig(f'{self.conf.output_svg_dir}/convergence_iteration{iteration}.svg',
format='svg', bbox_inches='tight')
plt.close(fig)
class DebugPlotter:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment