def run_episode(self, params, num_runs=3):
        esn = self.params_to_model(params)

        errors = np.zeros(num_runs)

        for run_num in range(num_runs):
            esn.train(self.data_train[0], self.data_train[1])

            # Run generative test, calculate NRMSE
            y_pred = []
            u_n = self.data_val[0][0]
            for _ in range(len(self.data_val[1])):
                u_n = esn.forward(u_n)
                y_pred.append(u_n)

            y_pred = np.array(y_pred).squeeze()
            y_vals = self.data_val[1].squeeze()
            # print(np.hstack((y_pred[:, None], y_vals[:, None])))
            nr = nrmse(y_vals, y_pred, self.MEAN_OF_DATA)
            if nr > 1000000000: nr = 1000000000
            errors[run_num] = nr

        # for r in esn.reservoirs:
        #     print("E:{}, S:{}, W:{}, REG:{}, SIZE:{},  SPARSE:{}".format(r.echo_param, r.spectral_scale, r.input_weights_scale, esn.regulariser, r.N, r.sparsity))

        # plt.plot(range(len(y_pred)), y_pred, label="pred")
        # plt.plot(range(len(y_vals)), y_vals, label="true")
        # plt.legend()
        # plt.show()

        return -np.mean(np.log(errors)), np.std(np.log(errors))
    def run_episode2(self, params):
        esn = self.params_to_model(params)

        esn.train(self.data_train[0], self.data_train[1])

        # run generative and check
        y_pred = []

        # GENERATIVE =================================================
        u_n_ESN = self.data_val[0][0]
        for _ in range(len(self.data_val[1])):
            u_n_ESN = esn.forward(u_n_ESN)
            y_pred.append(u_n_ESN)

        y_pred = np.array(y_pred).squeeze()
        y_vals = self.data_val[1].squeeze()
        nrmse_err = nrmse(y_vals, y_pred, self.MEAN_OF_DATA)

        # avoid explosions
        if nrmse_err > 10:
            nrmse_err = MAX_REWARD

        return -nrmse_err
Exemple #3
0
            #esn_outputs = []
            eesn_outputs = []

            # GENERATIVE =================================================
            #u_n_ESN = data[split]
            u_n_EESN = np.array(X_valid[0])
            for _ in range(len(data[split:])):
                #u_n_ESN = esn.forward(u_n_ESN)
                #esn_outputs.append(u_n_ESN)
                u_n_EESN = eesn.forward(u_n_EESN)
                eesn_outputs.append(u_n_EESN)

            #esn_outputs = np.array(esn_outputs).squeeze()
            eesn_outputs = np.array(eesn_outputs).squeeze()

            error = nrmse(y_valid, eesn_outputs, data_mean)
            #print('  ESN MSE: %f' % mse(y_valid, esn_outputs))
            print('EESN NRMSE: %f' % error)

            key = eesn.info()
            if key not in to_save.keys():
                to_save[key] = []
            to_save[key].append(error)
            
            if 0:
                f, ax = plt.subplots(figsize=(12, 12))
                #ax.plot(range(len(esn_outputs)), esn_outputs, label='ESN')
                ax.plot(range(len(eesn_outputs)), eesn_outputs, label='EESN')
                ax.plot(range(len(y_valid)), y_valid, label='True')
                plt.legend()
                plt.show()
                                        # SUPERVISED ====
                                        # for u_n in X_valid:
                                        #     esn_outputs.append(esn.forward(u_n))
                                        #     lcesn_outputs.append(lcesn.forward(u_n))
                                        # ============================================================

                                        # esn_outputs = np.array(esn_outputs).squeeze()
                                        eesn_outputs = np.array(eesn_outputs).squeeze()
                                        y_vals = y_valid.squeeze()
                                        # print(np.shape(eesn_outputs))
                                        # print(np.shape(y_vals))
                                        # print(np.vstack((eesn_outputs, y_vals)))

                                        # print('  ESN MSE: %f' % mse(y_valid, esn_outputs))
                                        # print('EESN MSE: %f' % mse(y_valid, eesn_outputs))
                                        nrmse_err = nrmse(y_vals, eesn_outputs, MEAN_OF_DATA)
                                        if nrmse_err > 100000:
                                            nrmse_err = 100000
                                        print('DHESN NRMSE: %f' % nrmse_err)
                                        #print('-log(NRMSE): %f' % -np.log(nrmse_err))
                                        _errors.append(nrmse_err)
                                        # plt.plot(range(len(eesn_outputs)), eesn_outputs, label="predicted")
                                        # plt.plot(range(len(y_vals)), y_vals, label="true")
                                        # plt.legend()
                                        # plt.show()

                                        # we = eesn.W_out.squeeze()
                                        # plt.bar(range(len(we)), we)
                                        # plt.show()

                                    data_csv[idx, 0] = n
Exemple #5
0
                                        # for u_n in X_valid:
                                        #     esn_outputs.append(esn.forward(u_n))
                                        #     lcesn_outputs.append(lcesn.forward(u_n))
                                        # ============================================================

                                        # esn_outputs = np.array(esn_outputs).squeeze()
                                        eesn_outputs = np.array(
                                            eesn_outputs).squeeze()
                                        y_vals = y_valid.squeeze()
                                        # print(np.shape(eesn_outputs))
                                        # print(np.shape(y_vals))
                                        # print(np.vstack((eesn_outputs, y_vals)))

                                        # print('  ESN MSE: %f' % mse(y_valid, esn_outputs))
                                        # print('EESN MSE: %f' % mse(y_valid, eesn_outputs))
                                        nrmse_err = nrmse(
                                            y_vals, eesn_outputs, MEAN_OF_DATA)
                                        if nrmse_err > 100000:
                                            nrmse_err = 100000
                                        print('DHESN NRMSE: %f' % nrmse_err)
                                        #print('-log(NRMSE): %f' % -np.log(nrmse_err))
                                        _errors.append(nrmse_err)
                                        # plt.plot(range(len(eesn_outputs)), eesn_outputs, label="predicted")
                                        # plt.plot(range(len(y_vals)), y_vals, label="true")
                                        # plt.legend()
                                        # plt.show()

                                        # we = eesn.W_out.squeeze()
                                        # plt.bar(range(len(we)), we)
                                        # plt.show()

                                    data_csv[idx, 0] = n