def test_select_cv_interface(self): print("TESTING FOR JOHN") model = SelectorCV(self.sequences, self.xlengths, 'JOHN').select() self.assertGreaterEqual(model.n_components, 2) print("TESTING FOR CHICKEN") model = SelectorCV(self.sequences, self.xlengths, 'CHICKEN').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) model = SelectorCV(self.sequences, self.xlengths, 'WRITE').select() self.assertGreaterEqual(model.n_components, 2) model = SelectorCV(self.sequences, self.xlengths, 'HOMEWORK').select() self.assertGreaterEqual(model.n_components, 2)
def run_cv(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 SelectorCV in module my_model_selectors.py from my_model_selectors import SelectorCV training = asl.build_training(features_ground) print("CV Available Training words - words: ", training.words) print("CV Quantity of Training words - num_items: ", training.num_items) print("CV Chosen Training words: ", words_to_train) print("CV 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 = SelectorCV(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_selectorCV(): for word in words_to_train: start = timeit.default_timer() model = SelectorCV(sequences, Xlengths, word, verbose=False, 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 train_with_cv(): from my_model_selectors import SelectorCV 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 = SelectorCV(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 select_models(asl): import warnings from hmmlearn.hmm import GaussianHMM def train_a_word(word, num_hidden_states, features): warnings.filterwarnings("ignore", category=DeprecationWarning) training = asl.build_training(features) X, lengths = training.get_word_Xlengths(word) model = GaussianHMM(n_components=num_hidden_states, n_iter=1000).fit(X, lengths) logL = model.score(X, lengths) return model, logL def show_model_stats(word, model): print("Number of states trained in model for {} is {}".format( word, model.n_components)) variance = np.array( [np.diag(model.covars_[i]) for i in range(model.n_components)]) for i in range(model.n_components): # for each hidden state print("hidden state #{}".format(i)) print("mean = ", model.means_[i]) print("variance = ", variance[i]) print() features_ground = ['grnd-rx', 'grnd-ry', 'grnd-lx', 'grnd-ly'] features_polar = ['polar-rr', 'polar-rtheta', 'polar-lr', 'polar-ltheta'] features_norm = ['norm-rx', 'norm-ry', 'norm-lx', 'norm-ly'] features_delta = ['delta-rx', 'delta-ry', 'delta-lx', 'delta-ly'] features_custom = [ 'grnd-rx', 'grnd-ry', 'grnd-lx', 'grnd-ly', 'delta-rx', 'delta-ry', 'delta-lx', 'delta-ly' ] #my_testword = 'CHOCOLATE' #model, logL = train_a_word(my_testword, 3, features_norm) # Experiment here with different parameters #print("Number of states trained in model for {} is {}".format(my_testword, model.n_components)) #print("logL = {}".format(logL)) #show_model_stats(my_testword, model) words_to_train = ['FISH', 'BOOK', 'VEGETABLE', 'FUTURE', 'JOHN'] import timeit from my_model_selectors import SelectorBIC from my_model_selectors import SelectorDIC from my_model_selectors import SelectorCV training = asl.build_training( features_norm ) # 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 = SelectorCV(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))
words_to_train = ['FISH', 'BOOK', 'VEGETABLE', 'FUTURE', 'JOHN'] import timeit # TODO: Implement SelectorCV in my_model_selector.py from my_model_selectors import SelectorCV 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 = SelectorCV(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)) # TODO: Implement SelectorBIC in module my_model_selectors.py from my_model_selectors import SelectorBIC training = asl.build_training( features_ground ) # Experiment here with different feature sets defined in part 1
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, 'MARY').select() self.assertGreaterEqual(model.n_components, 2)