コード例 #1
0
    def Build_Weight_Database(  self,
                                database,
                                version,
                                num_of_kpts,
                                cutoff,
                                force_update = False,
                                K = 10,
                                depth = 4,
                                nleaves = 10000):
                

        
        updated = self.Train_Database_Sign(database,version, num_of_kpts, force_update, K, depth, nleaves)
        
        #load signature
        sign_dir = os.path.join(self.SIGN_DIR, 'db_version_' + str(version))
        sign = Signature()
        sign.load_sign(sign_dir, self.SIGN_FILE+str(num_of_kpts))
        
        print 'Siganture Loaded'
        
        wt_file = os.path.join(sign_dir, self.WEIGHT_FILE+str(num_of_kpts)+'_'+str(cutoff))
        wts_file = os.path.join(sign_dir, self.WEIGHT_SIGN_FILE+str(num_of_kpts)+'_'+str(cutoff))
        
        if updated or (not os.path.isfile(wt_file) and not os.path.isfile(wts_file)):
            wt = Weight(cutoff)
            wt.get_weight(sign.sign_database)        
            wt.weight_train_database(sign.sign_database)
        
            wt.save_weights(sign_dir, self.WEIGHT_FILE+str(num_of_kpts)+'_'+str(cutoff))
            wt.save_weighted_sign(sign_dir, self.WEIGHT_SIGN_FILE+str(num_of_kpts)+'_'+str(cutoff))
            
            print ' '
            print 'Wegihted Sign Generated'
        
        else:
            print 'Weighted Sign Has Already Been Generated'
コード例 #2
0
ファイル: Weight.py プロジェクト: Amos-zq/PatternRecognition
        
    def load_weighted_sign(self, file_dir, file_name):
        try:
            with open(os.path.join(file_dir, file_name), 'rb') as file_data:
                self.weighted_sign = np.load(file_data)
        except IOError as ioerror:
            print ioerror     
        
        
if __name__ == '__main__':
         
    # load signature
    L = (10**(4+1)-1) / (10-1) - 1
    sign_database = np.empty(shape=(180, L))
    sign = Signature()
    sign.load_sign('./Signature/1000/', 'sign_1000')
    
    wt = Weight(0.01)    
    wt.get_weight(sign.sign_database)
    
    #print wt.weights  
    wt.weight_train_database(sign.sign_database)
    
    wt.save_weights('./Signature/1000/', 'weights')
    wt.save_weighted_sign('./Signature/1000/', 'weighted_sign')