Exemple #1
0
 def predict(self, t_x):
     all_t = t_x[0:, 0]
     x1 = t_x[0:, 1:]
     x1_pred = _res_func_list.res_funcs[self.mdl_name].compute(
         self.params, all_t, x1)
     x_pred = Accumulation.agom(x1_pred, self.x_orig[0][0], False)
     return x_pred
Exemple #2
0
 def fit(self, x, y):
     x1 = Accumulation.agom(y, None, True)
     x1_0 = x1[0:, 0]
     z1 = ModelMethods.get_backvalue(x1_0)
     n_array = x1[1:, 1:]
     B = ModelMethods.construct_matrix(z1, n_array)
     self.x_orig = y
     self.params = ModelMethods.get_params(B, np.array(y)[0:, 0])
     self.x1 = x1
     return x1
Exemple #3
0
 def fit(self, x, y):
     x1 = Accumulation.agom(y, None, True)
     ones_array = np.diff(x).astype(np.float64)
     ones_array = ones_array.reshape([-1, 1])
     x1_0 = x1[0:-1, 0]
     x1_0 = x1_0.reshape([-1, 1])
     x1_n = x1[1:, 1:]
     B_x = ModelMethods.construct_matrix(-x1_0, x1_n)
     B = ModelMethods.construct_matrix(-B_x, ones_array)
     self.x_orig = y
     self.params = ModelMethods.get_params(B, np.array(y)[0:, 0])
     self.x1 = x1
     return x1
Exemple #4
0
 def fit(self, y, x):
     x_train = x[0:, 1:]
     y_conect = np.concatenate((y, x_train), axis=1)
     x1 = Accumulation.agom(y_conect, None, True)
     x1_0 = x1[0:, 0]
     z1 = ModelMethods.get_backvalue(x1_0)
     n_array = x1[1:, 1:]
     self.B = ModelMethods.construct_matrix(z1, n_array)
     self.x_orig = y
     self.params = ModelMethods.get_params(self.B,
                                           np.array(y_conect)[0:, 0])
     self.x1 = x1
     self.is_fitted = True
     return self
Exemple #5
0
 def fit(self, y, x):
     x_train = x[0:, 1:]
     t = x[0:, 0]
     y_conect = np.concatenate((y, x_train), axis=1)
     x1 = Accumulation.agom(y_conect, None, True)
     ones_array = np.diff(t).astype(np.float64)
     ones_array = ones_array.reshape([-1, 1])
     x1_0 = x1[0:-1, 0]
     x1_0 = x1_0.reshape([-1, 1])
     x1_n = x1[1:, 1:]
     B_x = ModelMethods.construct_matrix(-x1_0, x1_n)
     self.B = ModelMethods.construct_matrix(-B_x, ones_array)
     self.x_orig = y
     self.params = ModelMethods.get_params(self.B, np.array(y)[0:, 0])
     self.x1 = x1
     self.is_fitted = True
     return self
Exemple #6
0
    def generate_report_gmn(self, mdl, t_train, x0_train, t_test, x0_test):
        if (mdl.is_fitted == True):
            t_all = np.concatenate((t_train, t_test), axis=0)
            x_all = np.concatenate((x0_train, x0_test), axis=0)
            t_x = np.concatenate((t_all, mdl.x1), axis=1)
            x_pred = mdl.predict(t_x)

            x_orig = mdl.x_orig[0:, 1]
            lens = len(x_orig)
            err = x_pred[:lens] - x_orig
            m = len(t_train)

            x0_train = x_all[:m]
            x0_test = x_all[m - 1:]
            t_train = t_all[:m]
            t_test = t_all[m - 1:]

            rmse = np.sqrt(sum((err)**2 / lens))
            rmse = np.round(rmse, 4)

            t3 = np.arange(lens) + 1

            p = plt.figure()
            plt.subplot(2, 1, 1)
            plt.plot(t_train, x0_train)
            plt.plot(t_train, x_pred[:m])
            plt.plot(t_test, x0_test)
            plt.plot(t_test, x_pred[m - 1:lens])
            plt.axvline(x=m, ls="--", lw=1, c='k')
            plt.legend([
                'x_orig_models', 'x_pred_models', 'x_orig_detected',
                'x_pred_detected'
            ])
            plt.axvline(x=m, ls="--", lw=1, c='k')
            plt.title('Model and Test')
            plt.subplot(2, 1, 2)
            plt.stem(t3, err, linefmt="c:", markerfmt="o", basefmt="r-")
            plt.title('RMSE = {}'.format(rmse))
            plt.axvline(x=m, ls="--", lw=1, c='k')

            # 打印报告
            x1 = Accumulation.agom(mdl.x_orig, None, True)
            x1 = x1[0:, 1]
            x1_pred = Accumulation.agom(x_pred, None, True)
            model_report = pd.DataFrame({
                'x_orig': x_orig,
                'x1': x1,
                'x1_pred': x1_pred,
                'x_pred': x_pred,
                'error': err,
            })

            # 公式表达
            eq = generate_report.formula_expression_gmn(None, mdl)

            c1 = [p, model_report, eq]
            return c1
        else:
            t = np.concatenate((t_train, t_test), axis=1)
            x0 = np.concatenate((x0_train, x0_test), axis=1)
            mdl.fit(t, x0)
            generate_report.generate_report_gmn(mdl, t_train, x0_train, t_test,
                                                x0_test)