def sepTests(): gestures = ["circle", "l", "m", "round", "x", "z"] count = 0 for gesture in gestures: data = dataflow.dataflow("data", gesture) test = data.get_test_xyz() for i in range(test.shape[1]): count = count + 1 Ef = open("data\\tests\\" + str(count) + ".csv", "w") Ewriter = csv.writer(Ef, delimiter = ',', quotechar = '', quoting = csv.QUOTE_NONE, dialect = csv.unix_dialect) Ewriter.writerows(test[:,i,:]) Ef.close() print(test.shape)
def main(): print(math.log(2.14727368714e-64)) return path = "data" + os.sep + "unitytrain" name = "circle-r-cw" dtf = dataflow(path, name) (E, P, Pi, cent, thr) = dtf.load_model() testFile = "2014-3-31--16-50-44.csv" alltests = get_xyz_data(path + os.sep + "circle-r-cw" + os.sep + testFile) joint = "Hand_R" test = alltests[joint] clusters = numpy.empty(len(test)) #f = open ("output.txt", "wt") for i in range(len(test)): clusters[i] = get_point_cluster(test[i,:], cent) # f.write(str(clusters[i]) + "\n") score = pr_hmm(clusters, P, E, Pi) print(score)
def main (): data = dataflow.dataflow("data", gesture) training = data.get_train_xyz() testing = data.get_test_xyz() ''' **************************************************** * Initializing **************************************************** ''' TRTS = classifier.classifier() centroids = TRTS.get_point_centroids(training, N, D) cent2 = TRTS.get_point_centroids(testing, N, D) ATrainBinned = TRTS.get_point_clusters(training, centroids, D) ATestBinned = TRTS.get_point_clusters(testing, centroids, D) ATestBinned2 = TRTS.get_point_clusters(testing, cent2, D) ''' **************************************************** * Training **************************************************** ''' # Set priors pP = TRTS.prior_transition_matrix(M, LR) # Train the model: b = [x for x in range(N)] cyc = 5 E, P, Pi, LL = TRTS.dhmm_numeric(ATrainBinned, pP, b, M, cyc, .00001) ''' **************************************************** * Testing **************************************************** ''' sumLik = 0 minLik = numpy.Infinity ATrainBinned = ATrainBinned[:,:,0] ATestBinned = ATestBinned[:,:,0] for j in range(len(ATrainBinned)): lik = TRTS.pr_hmm(ATrainBinned[j], P, E.transpose(), Pi) if lik < minLik: minLik = lik sumLik = sumLik + lik gestureRecThreshold = 2.0 * sumLik / len(ATrainBinned) #Uncomment the following to store the models. # data.store_model(E, P, Pi, centroids, gestureRecThreshold) # data.store_Binned(ATrainBinned[:,:,0],ATestBinned[:,:,0]) print('\n********************************************************************') print('Testing %d sequences for a log likelihood greater than %.4f' % (len(ATestBinned), gestureRecThreshold)) print('********************************************************************\n') recs = 0 tLL = numpy.zeros(shape=(len(ATestBinned))) for j in range(len(ATestBinned)): tLL[j] = TRTS.pr_hmm(ATestBinned[j], P, E.transpose(), Pi) if tLL[j] > gestureRecThreshold: recs = recs + 1 print("Log Likelihood: %.3f > %.3f (threshold) -- FOUND %s Gesture" % (tLL[j], gestureRecThreshold, gesture)) else: print("Log Likelihood: %.3f < %.3f (threshold) -- NO %s Gesture" % (tLL[j], gestureRecThreshold, gesture)) print('Recognition success rate: %.2f percent\n' % (100 * recs / len(ATestBinned)))