def on_episode_end(self, episode, logs):
duration = timeit.default_timer() - self.episode_start[episode]<EOL>episode_steps = len(self.observations[episode])<EOL>metrics = np.array(self.metrics[episode])<EOL>metrics_template = '<STR_LIT>'<EOL>metrics_variables = []<EOL>with warnings.catch_warnings():<EOL><INDENT>warnings.filterwarnings('<STR_LIT:error>')<EOL>for idx, name in enumerate(self.metrics_names):<EOL><INDENT>if idx > <NUM_LIT:0>:<EOL><INDENT>metrics_template += '<STR_LIT:U+002CU+0020>'<EOL><DEDENT>try:<EOL><INDENT>value = np.nanmean(metrics[:, idx])<EOL>metrics_template += '<STR_LIT>'<EOL><DEDENT>except Warning:<EOL><INDENT>value = '<STR_LIT>'<EOL>metrics_template += '<STR_LIT>'<EOL><DEDENT>metrics_variables += [name, value]          <EOL><DEDENT><DEDENT>metrics_text = metrics_template.format(*metrics_variables)<EOL>nb_step_digits = str(int(np.ceil(np.log10(self.params['<STR_LIT>']))) + <NUM_LIT:1>)<EOL>template = '<STR_LIT>' + nb_step_digits + '<STR_LIT>'<EOL>variables = {<EOL>'<STR_LIT>': self.step,<EOL>'<STR_LIT>': self.params['<STR_LIT>'],<EOL>'<STR_LIT>': episode + <NUM_LIT:1>,<EOL>'<STR_LIT>': duration,<EOL>'<STR_LIT>': episode_steps,<EOL>'<STR_LIT>': float(episode_steps) / duration,<EOL>'<STR_LIT>': np.sum(self.rewards[episode]),<EOL>'<STR_LIT>': np.mean(self.rewards[episode]),<EOL>'<STR_LIT>': np.min(self.rewards[episode]),<EOL>'<STR_LIT>': np.max(self.rewards[episode]),<EOL>'<STR_LIT>': np.mean(self.actions[episode]),<EOL>'<STR_LIT>': np.min(self.actions[episode]),<EOL>'<STR_LIT>': np.max(self.actions[episode]),<EOL>'<STR_LIT>': np.mean(self.observations[episode]),<EOL>'<STR_LIT>': np.min(self.observations[episode]),<EOL>'<STR_LIT>': np.max(self.observations[episode]),<EOL>'<STR_LIT>': metrics_text,<EOL>}<EOL>print(template.format(**variables))<EOL>del self.episode_start[episode]<EOL>del self.observations[episode]<EOL>del self.rewards[episode]<EOL>del self.actions[episode]<EOL>del self.metrics[episode]<EOL>
Compute and print training statistics of the episode when done