def heat4(): from template import Pts4 as HOOP HOOP /= 2 HOOP = HOOP[2] route = '../data/heat4.route.npy' routes = np.load(route) team = routes[-1,:,1] coord = np.array( map(np.vstack, routes[...,0])) m, n, _ = coord.shape coord = movingaverage(coord.reshape(-1, 2*n), 10).reshape(m,n,2) polar = cart2polar(coord.reshape(-1, 2), HOOP).reshape(m,n,2) defScore = defenceScore(polar, team) pScore = pickScore(polar, team) sampleData = pickVector(polar,team) sampleData = np.hstack((sampleData, defVector(polar,team), coord.reshape(-1, 8))) #sampleData = defScore[0,:] #import ipdb; ipdb.set_trace() grammar = PR_tactic4() #grammar = pickGrammar() #grammar = defGrammar() #grammar = blockGrammar() model = PCFG(grammar) #import ipdb; ipdb.set_trace() lik, tree = model.decode(sampleData) decodes = [] for x in tree.BFS(): #if x[1][0] == x[1][1]: decodes.append(x) for x in sorted(decodes, key=lambda x:x[1][0]): print x
def parse(ptables): pdict, length, idx = buildTable(ptables) #g = grammar() #g = sampleGrammar() g = grammarWithNA() model = PCFG(g) #import ipdb; ipdb.set_trace() lik, tree = model.ptable(pdict, length) #for k, v in model.viterbi_.iteritems(): # if not np.isinf(v): # print k, v decodes = [] d = [] for x in tree.BFS(): print x if isinstance(x[0], Terminal): d.append(x) return d
def recognition(args): from template import Pts4 as HOOP import pandas as pd hoop = HOOP / 2 routes = np.load(args['route']) #import ipdb; ipdb.set_trace() dst = args['dst'] team = routes[-1,:,1] coord = np.array( map(np.vstack, routes[...,0])) m, n, _ = coord.shape coord = movingaverage(coord.reshape(-1, 2*n), 10).reshape(m,n,2) if np.mean(coord[...,0]) > 800: hoop = hoop[2] team = np.logical_not(team) else: hoop = hoop[0] print hoop polar = cart2polar(coord.reshape(-1, 2), hoop).reshape(m,n,2) sampleData = np.hstack((pickVector(polar,team), defVector(polar,team), coord.reshape(-1, 8))) grammar = prGrammar() model = PCFG(grammar) #import ipdb; ipdb.set_trace() lik, tree = model.decode(sampleData) df = pd.DataFrame(model._dtable) df.plot(subplots=True) #plt.show() decodes = [] for x in tree.BFS(): if x[1][0] == x[1][1]: decodes.append(x) with open(dst, "wb") as csv_file: writer = csv.writer(csv_file, delimiter=',') for a, (b,c), d, e in sorted(decodes, key=lambda x:x[1][0]): writer.writerow([a, b, d, e])