Exemplo n.º 1
0
    def _compile_model(self):
        with open(os.path.join(Context.config['env.assets'], 'env.xml'),
                  'r') as f:
            model = f.read()

        world, sensors, actuators = self.world.read_model()
        model = model.\
            replace('{{world}}', world).\
            replace("{{sensors}}", sensors). \
            replace("{{actuators}}", actuators)

        path = os.path.join(Context.work_path, 'environment/env_model.xml')
        path = os.path.abspath(path)
        make_dir_if_not_exists(path)

        with open(path, 'w') as f:
            f.write(model)

        return path
Exemplo n.º 2
0
 def _create_diagram(self, name, arr, x_idx, y_idx):
     path = os.path.join(self._work_path, name + ".png")
     x = np.asarray(arr)[:, x_idx]
     y = np.asarray(arr)[:, y_idx]
     plt.clf()
     plt.grid(True)
     plt.plot(x, y)
     plt.title(name)
     plt.xlabel(['episodes', 'time'][x_idx])
     plt.savefig(make_dir_if_not_exists(path))
     return [name, path]
Exemplo n.º 3
0
 def _create_mean_diagram(self, name, arr, x_idx, y_idx):
     path = os.path.join(self._work_path, name + ".png")
     x = np.asarray(arr)[:, x_idx]
     y = np.asarray(arr)[:, y_idx]
     m = running_mean(y, Context.config['report.diagram_mean_frame'])
     plt.clf()
     plt.grid(True)
     plt.plot(x, y, 'c-', x, m, 'b-')
     plt.title(name)
     plt.xlabel(['episodes', 'time'][x_idx])
     plt.savefig(make_dir_if_not_exists(path))
     return [name, path]
Exemplo n.º 4
0
    def write_html_report(self, info):
        s = "<HTML><HEAD>%s<TITLE>%s</TITLE></HEAD><BODY><H1>%s</H1>\n" % (
            "<meta http-equiv='refresh' content='%d'>" %
            Context.config['report.refresh_html_every_secs'],
            "Exp #%s" % Context.experiment.id,
            "Experiment #%s" % Context.experiment.id,
        )

        s += self._urgent_section(info)
        s += self._passport_section()
        s += self._config_section()
        s += self._progress_section(info)
        s += self._results_section(info)
        s += self._diagrams_section(info)
        s += self._instances_section()

        s += "</BODY></HTML>\n"
        with open(make_dir_if_not_exists(self.html_path), 'w') as f:
            f.write(s)
Exemplo n.º 5
0
 def save(self, path):
     self._save_weights(make_dir_if_not_exists(self._weights_path(path)))
     self._save_state(make_dir_if_not_exists(self._state_path(path)))
Exemplo n.º 6
0
 def save(self):
     with open(make_dir_if_not_exists(self._report_path), "w") as f:
         f.write(self.content)
     self.page.update_files()
Exemplo n.º 7
0
 def _save_state(self):
     with open(make_dir_if_not_exists(self._state_path), 'w') as f:
         pickle.dump(
             [self.time_spent, self._train_history, self._eval_history],
             f,
             protocol=pickle.HIGHEST_PROTOCOL)