timeit_run_statement = """ length = min(E_test.shape[1],template_test.shape[1]) sum(tt.score_template_background_section(template_test[:,:length],bg_test,E_test[:,:length]))""" num_features = 384 length = 20 E_test = (np.random.rand(length*num_features).reshape(num_features,length) > .6).astype(np.uint8) bg_test = (np.random.rand(num_features)*.3 + .1).astype(np.float32) template_test = (np.random.rand(num_features*length).reshape(num_features,length)*.9 + .05).astype(np.float32) out1 = sum(tt.score_template_background_section(template_test,bg_test,E_test)) log_template = np.log(template_test.T) log_invtemplate = np.log(1-template_test.T) E_test_transpose = E_test.T out2 = tt.score_template_background_section_quantizer(log_template, log_invtemplate, bg_test, E_test_transpose) import timeit t = timeit.Timer(timeit_run_statement,timeit_import_statement) t.repeat(5,10000) timeit_import_statement2 = """ import numpy as np root_path = '/home/mark/Template-Speech-Recognition/' import sys, os, cPickle sys.path.append(root_path) import template_speech_rec.test_template as tt
def apply_bms_to_examples(phn_examples,phn_lengths,phn_bgs,bms): return np.array(tuple(max(tt.score_template_background_section_quantizer( bms.log_templates[i], bms.log_invtemplates[i],phn_bgs[j], phn_examples[j][:phn_lengths[j]]) for i in xrange(len(bms.weights)))\ for j in xrange(phn_examples.shape[0])))
20, 1, threshold=.7, edge_orientations = edge_orientations, edge_feature_row_breaks = edge_feature_row_breaks) E = E.T bg = np.clip(np.load(tmp_data_path+'avg_E_bgd.npy'),.01,.4).astype(np.float32) k = ('t','aa') list_of_syllable_models= alexey_nt_list_dict[k] syllable_model = list_of_syllable_models[0] log_template, log_invtemplate = zip(syllable_model.log_templates,syllable_model.log_invtemplates)[0] tuple( tt.score_template_background_section_quantizer(log_template, log_invtemplate, bg, E[t:t+len(log_template)],return_both_summed=True) for t in xrange(len(E)-len(log_template))) alexey_output = dict( # compute the score over the different syllables (k,tuple( # compute the score for each mixture number tuple( # Compute the score for each time period tuple( tt.score_template_background_section_quantizer(log_template, log_invtemplate, bg, E[t:t+len(log_template)],return_both_summed=True) for t in xrange(len(E)-len(log_template))) for log_template, log_invtemplate in zip(syllable_model.log_templates,syllable_model.log_invtemplates)