def affine_pls2(self , j ): pls_demo = Partial_LS(self.X_m_cal, self.y_m_cal, folds=10 , max_comp=15) W_m_cal, T_m_cal, P_m_cal, comp_best, coefs_cal, RMSECV = pls_demo.pls2_fit() RMSEC, RMSEP , ytrain_pre , ytest_pre = pls_demo.pls_pre_train_test(self.X_m_test, self.y_m_test, coefs_cal) print RMSEP[self.i], "RMSEP.SELF.I" y_ = deal_4_2(self.y_m_cal, self.i, j) coef = deal_4_2(coefs_cal, self.i, j) y_s_test_ = deal_4_2(self.y_s_test, self.i, j) y_s_cal_ = deal_4_2(self.y_s_cal, self.i, j) T_m_std, T_s_std, y_m_pre, y_s_pre, T_s_test, ys_test_pre = Pre_deal(self.X_m_cal, self.X_s_cal, W_m_cal, P_m_cal, coef, self.X_m_cal, y_, self.X_s_test) y0_m = y_m_pre[:, 0:1] y1_m = y_m_pre[:, 1:2] y0_s = y_s_pre[:, 0:1] y1_s = y_s_pre[:, 1:2] y0_s_test = ys_test_pre[:, 0:1] y1_s_test = ys_test_pre[:, 1:2] demo = Affine_trans1(y0_m, y0_s, y1_m, y1_s, comp_best) bia, sin_x, cos_x, x, b_s , k_m , b_m = demo.AT_train() # print bia, sin_x, cos_x, b_s RMSEP_y0, RMSEP_y1 , y0_pre = demo.AT_pre(y0_s_test, y1_s_test, bia, cos_x, sin_x, y_s_test_, b_s) RMSEC_y0, RMSEC_y1 , y_cal_pre = demo.AT_pre(y0_s, y1_s, bia, cos_x, sin_x, y_s_cal_, b_s) RMSEP_y0_,RMSEP_y1_,y0_pre_ = demo.AT_pre_no_trans(y0_s_test, y1_s_test, y_s_test_) # print 'RMSEP_y0/RMSEP_y1:', RMSEP_y0, RMSEP_y1 # print ytrain_pre[:,[self.i]] , ytest_pre[:,[self.i]] return comp_best,RMSEP_y0,y0_pre,RMSEC_y0,y_cal_pre , y0_s_test , y1_s_test, RMSEP_y0_ , RMSEC[self.i] , RMSEP[self.i] , ytrain_pre[:,[self.i]] , ytest_pre[:,[self.i]]
def affine_pls2(self, j): pls_demo = Partial_LS(self.X_m_cal, self.y_m_cal, folds=10, max_comp=15) W_m_cal, T_m_cal, P_m_cal, comp_best, coefs_cal, RMSECV = pls_demo.pls2_fit( ) # print self.y_s_test.shape , gg RMSEC, RMSEP, ytest_pre = pls_demo.pls_pre(self.X_m_test, self.y_m_test, coefs_cal) y_ = deal_4_2(self.y_m_cal, self.i, j) coef = deal_4_2(coefs_cal, self.i, j) y_s_test_ = deal_4_2(self.y_s_test, self.i, j) y_s_cal_ = deal_4_2(self.y_s_cal, self.i, j) T_m_std, T_s_std, y_m_pre, y_s_pre, T_s_test, ys_test_pre = Pre_deal( self.X_m_cal, self.X_s_cal, W_m_cal, P_m_cal, coef, self.X_m_cal, y_, self.X_s_test) y0_m = y_m_pre[:, 0:1] y1_m = y_m_pre[:, 1:2] y0_s = y_s_pre[:, 0:1] y1_s = y_s_pre[:, 1:2] y0_s_test = ys_test_pre[:, 0:1] y1_s_test = ys_test_pre[:, 1:2] demo = Affine_trans1(y0_m, y0_s, y1_m, y1_s, comp_best) bia, sin_x, cos_x, x, b_s, k_m, b_m = demo.AT_train() KS_master_std = KennardStone(self.X_s_cal, 16) CalInd_master_std, ValInd_master_std = KS_master_std.KS() # print CalInd_master_std , ValInd_master # KS_master_std = KennardStone(self.X_s_cal, 32) # CalInd_master_std, ValInd_master_std = KS_master_std.KS() # # print CalInd_master_std , ValInd_master # y0_s_sure = y0_s[CalInd_master_std] # y1_s_sure = y1_s[CalInd_master_std] # y_sure_real = y_s_cal_[CalInd_master_std] y0_s_sure = y0_s[48:64, :] y1_s_sure = y1_s[48:64, :] y_sure_real = y_s_cal_[48:64, :] # print bia, sin_x, cos_x, b_s RMSEC_y0, RMSEC_y1, y0_cal_pre = demo.AT_pre(y0_s, y1_s, bia, cos_x, sin_x, y_s_cal_, b_s) RMSEP_y0, RMSEP_y1, y0_pre = demo.AT_pre(y0_s_test, y1_s_test, bia, cos_x, sin_x, y_s_test_, b_s) RMSEP_sure_y0, RMSEP_sure_y1, y_cal_pre = demo.AT_pre( y0_s_sure, y1_s_sure, bia, cos_x, sin_x, y_sure_real, b_s) print y_cal_pre.shape, "shapesss" RMSEP_no_trans_0, RMSEP_no_trans_1, y_no_pre = demo.AT_pre_no_trans( y0_s_test, y1_s_test, y_s_test_) # print y0_s_test[:,0] print RMSEP_sure_y0, RMSEP_sure_y1, "SURE ", RMSEP_y0 # print RMSEP_no_trans_0 ,"no_trans" # return comp_best,RMSEP_y0,y0_pre,y_cal_pre , y0_s_test , y1_s_test, RMSEP_y0_ # print y_sure_real.shape , y_cal_pre.shape , "shape" return comp_best, RMSEP_y0, y0_pre, RMSEC_y0, y_cal_pre, y0_s_test, y1_s_test, RMSEP_no_trans_0, y_sure_real
def affine_pls2(self, j): pls_demo = Partial_LS(self.X_m_cal, self.y_m_cal, folds=10, max_comp=15) W_m_cal, T_m_cal, P_m_cal, comp_best, coefs_cal, RMSECV = pls_demo.pls2_fit( ) # print self.y_s_test.shape , gg RMSEC, RMSEP, ytest_pre = pls_demo.pls_pre(self.X_m_test, self.y_m_test, coefs_cal) y_ = deal_4_2(self.y_m_cal, self.i, j) coef = deal_4_2(coefs_cal, self.i, j) y_s_test_ = deal_4_2(self.y_s_test, self.i, j) y_s_cal_ = deal_4_2(self.y_s_cal, self.i, j) T_m_std, T_s_std, y_m_pre, y_s_pre, T_s_test, ys_test_pre = Pre_deal( self.X_m_cal, self.X_s_cal, W_m_cal, P_m_cal, coef, self.X_m_cal, y_, self.X_s_test) y0_m = y_m_pre[:, 0:1] y1_m = y_m_pre[:, 1:2] y0_s = y_s_pre[:, 0:1] y1_s = y_s_pre[:, 1:2] y0_s_test = ys_test_pre[:, 0:1] y1_s_test = ys_test_pre[:, 1:2] demo = Affine_trans1(y0_m, y0_s, y1_m, y1_s, comp_best) bia, sin_x, cos_x, x, b_s, k_m, b_m = demo.AT_train() y0_s_sure = y0_s[276:367, :] y1_s_sure = y1_s[276:367, :] y_sure_real = y_s_cal_[276:367, :] # print bia, sin_x, cos_x, b_s RMSEP_y0, RMSEP_y1, y0_pre = demo.AT_pre(y0_s_test, y1_s_test, bia, cos_x, sin_x, y_s_test_, b_s) RMSEP_sure_y0, RMSEP_sure_y1, y_cal_pre = demo.AT_pre( y0_s_sure, y1_s_sure, bia, cos_x, sin_x, y_sure_real, b_s) RMSEP_no_trans_0, RMSEP_no_trans_1, y_no_pre_ = demo.AT_pre_no_trans( y0_s_test, y1_s_test, y_s_test_) RMSEC_y0, RMSEC_y1_, y0_cal_pre_ = demo.AT_pre(y0_s, y1_s, bia, cos_x, sin_x, y_s_cal_, b_s) # print RMSEP_no_trans_0 , "no_trans" # print RMSEP_sure_y0 , RMSEP_sure_y1 , "SURE " # return comp_best,RMSEP_y0,y0_pre,y_cal_pre , y0_s_test , y1_s_test, RMSEP_y0_ return comp_best, RMSEP_y0, y0_pre, RMSEP_no_trans_0, y0_cal_pre_, y0_s_test, y1_s_test, RMSEP_no_trans_0, RMSEP_sure_y0
for j in range(4): if(i == 0 and j == 1) or (i == 1 and j == 0) or (i==2 and j==3) or (i == 3 and j ==2): y_s_test_ = deal_4_2(y_s_test, i, j) y_s_cal_ = deal_4_2(y_s_cal,i, j) y_ = deal_4_2(y_m_cal, i, j) print "ok" coef = deal_4_2(coefs_cal, i, j) T_m_std, T_s_std, y_m_pre, y_s_pre, T_s_test, ys_test_pre = Pre_deal(X_m_cal, X_s_cal, W_m_cal, P_m_cal, coef, X_m_cal, y_, X_s_test) y0_m = y_m_pre[:, 0:1] y1_m = y_m_pre[:, 1:2] y0_s = y_s_pre[:, 0:1] y1_s = y_s_pre[:, 1:2] y0_s_test = ys_test_pre[:, 0:1] y1_s_test = ys_test_pre[:, 1:2] # print y0_m , y1_m demo = Affine_trans1(y0_m, y0_s, y1_m, y1_s, comp_best) bia, sin_x, cos_x, x, b_s , k_m , b_m = demo.AT_train() RMSEP_y0, RMSEP_y1 , y0_pre = demo.AT_pre(y0_s_test, y1_s_test, bia, cos_x, sin_x, y_s_test_, b_s) RMSEC_y0, RMSEC_y1 , y_cal_pre = demo.AT_pre(y0_s, y1_s, bia, cos_x, sin_x, y_s_cal_, b_s) # plt.subplot(2,3,i + 1) plt.plot(ranges_x[i] , ranges_x[i] , color="black") plt.scatter(y_s_test[:,i], y0_pre[:,0], s = 10, c = "red" , label="corrected" , marker="x") plt.scatter(y_s_test[:,i], y0_s_test[:,0], s = 10, c = "green" , label="uncorrected") plt.legend(loc="upper left") plt.xlabel("reference values") plt.ylabel("predicted values") plt.title(name[i]) # ���������᷶Χ