Пример #1
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()
        
        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]]
Пример #2
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
Пример #3
0
    def Cal_model(self, max_comp, folds):

        X_m_cal, y_m_cal, X_m_std, y_m_std, X_s_std, y_s_std, X_s_test, y_s_test, X_s_cal, y_s_cal, X_m_test = self.Dataset_split(
        )

        pls_cal = Partial_LS(X_m_cal, y_m_cal, folds, max_comp)
        W_m_cal, T_m_cal, P_m_cal, comp_best, coefs_cal, RMSECV = pls_cal.pls2_fit(
        )

        return W_m_cal, T_m_cal, P_m_cal, comp_best, coefs_cal
Пример #4
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
Пример #5
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
Пример #6
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
Пример #7
0
def deal_4_2(x , i , j):
    x_ = np.zeros((x.shape[0] , 2))
    x_[:,0] = x[:, i].ravel()
    x_[:,1] = x[:, j].ravel()
    return x_

if __name__ == "__main__":
    
    
    dataImport = Dataset_Import(type = 14, std_num = 8 , bool = 0)
    X_master , X_slave , y = dataImport.dataset_return()
    num = int(X_master.shape[0]*0.8)
    
    X_m_cal, y_m_cal, X_s_cal, y_s_cal, X_s_test, y_s_test, X_m_test, y_m_test , X_m_std , y_m_std , X_s_std , y_s_std = Dataset_KS_split_std(X_master , X_slave , y , num , std_num = 8)
    
    pls_demo = Partial_LS(X_m_cal,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()
#       
    ranges_x = [(9.5 , 11.5) , (3,4) , (7.5,10) , (62.5 , 66.5)]
    ranges_y = [(7 , 12.5) , (3,4.5), (6,10) , (62.5 , 68)]
    name=["A","B","C","D"]
    
#    
    plt.figure(dpi = 80)
    for i in range(4):
        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"