Ejemplo n.º 1
0
 def fill_features_dicts(self):
     if self.mode == 'Basic':
         BasicModelFeatures.fill_features_dicts(self)
     elif self.mode == 'Improved':
         ImprovedModelFeature.fill_features_dicts(self)
     else:
         CompModelFeature.fill_features_dicts(self)
Ejemplo n.º 2
0
 def calculate_all_dot_f_for_tuple(self):
     if self.mode == 'Basic':
         BasicModelFeatures.calculate_all_dot_f_for_tuple(self)
     elif self.mode == 'Improved':
         ImprovedModelFeature.calculate_all_dot_f_for_tuple(self)
     else:
         CompModelFeature.calculate_all_dot_f_for_tuple(self)
Ejemplo n.º 3
0
 def get_frequented_features(self):
     if self.mode == 'Basic':
         BasicModelFeatures.get_frequented_features(self)
     elif self.mode == 'Improved':
         ImprovedModelFeature.get_frequented_features(self)
     else:
         CompModelFeature.get_frequented_features(self)
Ejemplo n.º 4
0
    def train(self, improved_mode):
        start_start = datetime.now()

        if improved_mode == 'Improved' or improved_mode == 'Basic' or improved_mode == 'Comp':
            self.mode = improved_mode
        else:
            print('You need to choose improved/basic/comp mode!')
            return

        self.get_history_tag_tuples()
        print('\nFound ' + str(len(self.history_tag_tuples)) + ' different history_tag tuples')
        print('Found ' + str(len(self.tags)) + ' different tags\n')

        self.find_freq_tags()

        print('Searching for all seen features in data...')
        self.fill_features_dicts()
        print('Done features searching. Found ' + str(self.num_features) + ' different features\n')
        print('Removing unfrequented features...')
        self.get_frequented_features()
        print('After optimization, only ' + str(self.num_features) + ' features left\n')

        print('Calculate features on all (history,tag) options - wait a minute...')
        self.calculate_all_dot_f_for_tuple()
        print('Done calculating all possible features!\n')
        np.seterr(all='ignore')
        v_vector_temp = np.zeros(shape=self.num_features)
        print('Lets try to find the best v... may take some time...(approximately 18 minutes)')
        start = datetime.now()
        res = fmin_l_bfgs_b(self.func_l_new, x0=v_vector_temp, fprime=self.get_gradient_vector)
        self.v_vec = res[0]
        print('Found the best v only in ' + str(datetime.now()-start) + '!! ITS A NEW RECORD!!!')
        print('\nSaving the data...')
        if self.mode == 'Basic':
            BasicModelFeatures.save_data_to_files(self)
        elif self.mode == 'Improved':
            ImprovedModelFeature.save_data_to_files(self)
        else:
            CompModelFeature.save_data_to_files(self)
        print('ALL DONE!')
        print('THE ALL: ' + str(datetime.now() - start_start))