def generate_report_nipbernoulligm(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) x_pred = mdl.predict(t_all) lens = len(mdl.x_orig) err = x_pred[:lens] - mdl.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.subplot(2, 1, 2) plt.stem(t3, err, linefmt="c:", markerfmt="o", basefmt="r-") plt.axvline(x=m, ls="--", lw=1, c='k') # 打印报告 x1 = NewInformationPriorityAccumulation.nipago(mdl.x_orig, mdl.r) x1_pred = NewInformationPriorityAccumulation.nipago(x_pred, mdl.r) model_report = pd.DataFrame({ 'x_orig': mdl.x_orig, 'x1': x1, 'x1_pred': x1_pred, 'x_pred': x_pred, 'error': err, }) # 公式表达 eq = generate_report.formula_expression_bernoulligm(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_nipbernoulligm( mdl, t_train, x0_train, t_test, x0_test)
def generate_report(self, mdl, y_train, t_x_train, y_test, t_x_test, **kwargs): if (mdl.is_fitted == True): y_all = np.concatenate((y_train, y_test), axis=0) t_x = np.concatenate((t_x_train, t_x_test), axis=0) y_pred = mdl.predict(t_x) t_all = t_x[0:, 0] lens = len(mdl.x_orig) m = len(y_train) err = y_pred[:lens] - mdl.x_orig y0_train = y_all[:m] y0_test = y_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, y0_train) plt.plot(t_train, y_pred[:m]) plt.plot(t_test, y0_test) plt.plot(t_test, y_pred[m - 1:lens]) plt.axvline(x=m, ls="--", lw=1, c='k') plt.legend(['x_train', 'x_pred_train', 'x_test', 'x_pred_test']) 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') y1 = NewInformationPriorityAccumulation.nipago(y_all, mdl.r) y1_pred = NewInformationPriorityAccumulation.nipago(y_pred, mdl.r) model_report = pd.DataFrame({ 'x_orig': mdl.x_orig, 'x1': y1, 'x1_pred': y1_pred, 'x_pred': y_pred, 'error': err, }) c1 = [p, model_report] return c1 else: y = np.concatenate((y_train, y_test), axis=0) t_x = np.concatenate((t_x_train, t_x_test), axis=0) mdl.fit(y, t_x) Generate_report_nipagon.generate_report(None, mdl, y_train, t_x_train, y_test, t_x_test)
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 = NewInformationPriorityAccumulation.nipago(x1_pred, -self.r) return x_pred
def fit(self, y): x1 = NewInformationPriorityAccumulation.nipago(y, self.r) z1 = ModelMethods.get_backvalue(x1) z1_square = np.power(z1, self.n) B = ModelMethods.construct_matrix(z1, z1_square) self.x_orig = y self.params = ModelMethods.get_params(B, y) return self
def fit(self, x, y): x1 = NewInformationPriorityAccumulation.nipago(y, self.r) z1 = ModelMethods.based(x1) ones_array = np.diff(x).astype(np.float64) ones_array = ones_array.reshape([-1, 1]) B = ModelMethods.construct_matrix(-z1, ones_array) self.x_orig = y self.params = ModelMethods.get_params(B, x1) return self
def fit(self, x, y): x1 = NewInformationPriorityAccumulation.nipago(y, self.r) z1 = ModelMethods.get_backvalue(x1) arange_array = x[1:] arange_array = arange_array.reshape([-1, 1]) B = ModelMethods.construct_matrix(z1, arange_array) self.x_orig = y self.params = ModelMethods.get_params(B, y) return self
def fit(self, x, y): lens_1 = len(y[0, 0:]) y1 = y.T x1 = np.zeros(y1.shape) for i in range(0, lens_1): x1[i, 0:] = NewInformationPriorityAccumulation.nipago( y1[i, 0:], self.r) x1 = x1.T 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
def fit(self, y, x): x_train = x[0:, 1:] y_conect = np.concatenate((y, x_train), axis=1) lens_1 = len(y_conect[0, 0:]) y1 = y_conect.T x1 = np.zeros(y1.shape) for i in range(0, lens_1): x1[i, 0:] = NewInformationPriorityAccumulation.nipago( y1[i, 0:], self.r) x1 = x1.T 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
def fit(self, x, y): lens_1 = len(y[0, 0:]) y1 = y.T x1 = np.zeros(y1.shape) for i in range(0, lens_1): x1[i, 0:] = NewInformationPriorityAccumulation.nipago( y1[i, 0:], self.r) x1 = x1.T 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
def predict(self, t): all_t = np.arange(0, np.max(t)) x1_pred = _res_func_list.res_funcs[self.mdl_name].compute( self.params, all_t, self.x_orig[0]) x_pred = NewInformationPriorityAccumulation.nipago(x1_pred, -self.r) return x_pred