def train_with_dic(): print("training with dic") from my_model_selectors import SelectorDIC training = asl.build_training( features_ground ) # Experiment here with different feature sets defined in part 1 sequences = training.get_all_sequences() Xlengths = training.get_all_Xlengths() for word in words_to_train: start = timeit.default_timer() model = SelectorDIC(sequences, Xlengths, word, min_n_components=2, max_n_components=15, random_state=14).select() end = timeit.default_timer() - start if model is not None: print( "Training complete for {} with {} states with time {} seconds". format(word, model.n_components, end)) else: print("Training failed for {}".format(word))
def run_dic(asl, features_ground, words_to_train, min_c, max_c, rand_s): # Copied from asl_recognizer.ipynb for IDE debugging using breakpoints. # Execute the implementation of SelectorDIC in module my_model_selectors.py from my_model_selectors import SelectorDIC training = asl.build_training(features_ground) print("DIC Available Training words - words: ", training.words) print("DIC Quantity of Training words - num_items: ", training.num_items) print("DIC Chosen Training words: ", words_to_train) print("DIC Chosen Features: ", features_ground) sequences = training.get_all_sequences() Xlengths = training.get_all_Xlengths() for word in words_to_train: start = timeit.default_timer() model = SelectorDIC(sequences, Xlengths, word, min_n_components=min_c, max_n_components=max_c, random_state=rand_s).select() end = timeit.default_timer() - start if model is not None: print( "Training complete for {} with {} states with time {} seconds". format(word, model.n_components, end)) else: print("Training failed for {}".format(word))
def test_selectorDIC(): for word in words_to_train: start = timeit.default_timer() model = SelectorDIC(sequences, Xlengths, word, min_n_components=2, max_n_components=15, random_state=14).select() end = timeit.default_timer() - start if model is not None: print( "Training complete for {} with {} states with time {} seconds". format(word, model.n_components, end)) else: print("Training failed for {}".format(word))
else: print("Training failed for {}".format(word)) # TODO: Implement SelectorDIC in module my_model_selectors.py from my_model_selectors import SelectorDIC training = asl.build_training( features_ground ) # Experiment here with different feature sets defined in part 1 sequences = training.get_all_sequences() Xlengths = training.get_all_Xlengths() for word in words_to_train: start = timeit.default_timer() model = SelectorDIC(sequences, Xlengths, word, min_n_components=2, max_n_components=15, random_state=14).select() end = timeit.default_timer() - start if model is not None: print("Training complete for {} with {} states with time {} seconds". format(word, model.n_components, end)) else: print("Training failed for {}".format(word)) from asl_test_model_selectors import TestSelectors suite = unittest.TestLoader().loadTestsFromModule(TestSelectors()) unittest.TextTestRunner().run(suite) # PART 3: Recognizer¶
def test_select_dic_interface(self): model = SelectorDIC(self.sequences, self.xlengths, 'MARY').select() self.assertGreaterEqual(model.n_components, 2) model = SelectorDIC(self.sequences, self.xlengths, 'TOY').select() self.assertGreaterEqual(model.n_components, 2)
'BOOK').select() self.assertGreaterEqual(model.n_components, 2) #def test_select_bic_interface(self): # model = SelectorBIC(self.sequences, self.xlengths, 'FRANK').select() # self.assertGreaterEqual(model.n_components, 2) # model = SelectorBIC(self.sequences, self.xlengths, 'VEGETABLE').select() # self.assertGreaterEqual(model.n_components, 2) def test_select_cv_interface(self): model = SelectorCV(self.sequences, self.xlengths, 'JOHN').select() self.assertGreaterEqual(model.n_components, 2) model = SelectorCV(self.sequences, self.xlengths, 'CHICKEN').select() self.assertGreaterEqual(model.n_components, 2) #def test_select_dic_interface(self): # model = SelectorDIC(self.sequences, self.xlengths, 'MARY').select() # self.assertGreaterEqual(model.n_components, 2) # model = SelectorDIC(self.sequences, self.xlengths, 'TOY').select() # self.assertGreaterEqual(model.n_components, 2) if __name__ == '__main__': asl = AslDb() training = asl.build_training(FEATURES) sequences = training.get_all_sequences() xlengths = training.get_all_Xlengths() #SelectorCV(sequences, xlengths, 'JOHN').select() SelectorDIC(sequences, xlengths, 'FRANK').select()