in ml3/shaped_sine_utils.py [0:0]
def render(theta_ranges,loss,color,freq=0.5,file_path='./ml3_loss_sine.gif', mode='gif'):
""" When the method is called it saves an animation
of what happened until that point in the episode.
Ideally it should be called at the end of the episode,
and every k episodes.
ATTENTION: It requires avconv and/or imagemagick installed.
@param file_path: the name and path of the video file
@param mode: the file can be saved as 'gif' or 'mp4'
"""
fig = plt.figure(figsize=(5,5))
ax = fig.add_subplot(111,autoscale_on=False, xlim=(-7.0, 7.0), ylim=(0.0, 1.0))
ax.axvline(x=freq, c='red')
delta_t = 1.0/10.0
dot, = ax.plot([], [],color=color)
time_text = ax.text(0.25, 1.05, '', transform=ax.transAxes,fontsize=14)
_theta_ranges = theta_ranges
_loss = loss
_delta_t = delta_t
def _init():
dot.set_data([], [])
time_text.set_text('')
return dot, time_text
def _animate(i):
x = _theta_ranges[i]
y = _loss[i]
dot.set_data(x, y)
time_text.set_text("Iteration: "+str(i))
return dot, time_text
ani = animation.FuncAnimation(fig, _animate, np.arange(1, len(theta_ranges)),
blit=True, init_func=_init, repeat=False)
if mode == 'gif':
ani.save(file_path, writer='imagemagick', fps=int(1 / delta_t))
# Clear the figure
fig.clear()
plt.close(fig)