示例#1
0
    def Recalibration(self):
        y_s_cal = deal_4_1(self.y_s_cal, self.i)
        y_s_test = deal_4_1(self.y_s_test, self.i)
#         print self.y_m_cal.shape , self.y_m_std.shape , self.y_m_test.shape , self.y_s_cal.shape
        pls=Partial_LS(self.X_s_cal,y_s_cal,self.max_folds,self.max_components)  
        W,T,P,comp_best,coefs_B,RMSECV=pls.pls_fit()
        RMSEC,RMSEP,yte_predict=pls.pls_pre(self.X_s_test,y_s_test,coefs_B)
        cal_RMSEC,cal_RMSEP,ycal_predict=pls.pls_pre(self.X_s_cal,y_s_cal,coefs_B)
        
        return comp_best,RMSECV,RMSEP,yte_predict,RMSEC,ycal_predict
示例#2
0
    def pls(self,n_folds):
        y_s_std = deal_4_1(self.y_s_std, self.i)
        y_s_cal = deal_4_1(self.y_s_cal, self.i)
        y_s_test = deal_4_1(self.y_s_test, self.i)
        pls=Partial_LS(self.x_s_std,y_s_std,n_folds,self.max_components)  
        W,T,P,comp_best,coefs_B,RMSECV=pls.pls_fit()
        RMSEC,RMSEP,yte_predict=pls.pls_pre(self.x_s_test,y_s_test,coefs_B)
        cal_RMSEC,cal_RMSEP,ycal_predict=pls.pls_pre(self.x_s_cal,y_s_cal,coefs_B)

        
        return comp_best,RMSECV,RMSEP,yte_predict,RMSEC,ycal_predict
示例#3
0
    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
示例#4
0
    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