def __init__(self, identical_testcases, width, height): self.identical_testcases = identical_testcases self.width = width self.height = height self.cell_count = height * height self.testcase1 = rand_test_case(width, height) self.testcase2 = None if identical_testcases: self.testcase2 = self.testcase1 else: self.testcase2 = rand_test_case(width, height) self.cost_table = init_cost_table(height) self.similarity = float("inf")
def dtw_between_two_testcases(width, height, iteration): ts_sum = 0 tp_sum = 0 for i in range(iteration): a = rand_test_case(width, height) b = rand_test_case(width, height) cs, ts = find_similarity_in_sequential(a,b,True) cp, tp =find_similarity_in_parallel(a,b,2,True) ts_sum += ts tp_sum += tp ts_avg = ts_sum / iteration tp_avg = tp_sum / iteration print print 'sequential: {0:.4f}'.format(ts_avg) print 'parallel: {0:.4f}'.format(tp_avg)
def dtw_between_two_testcases(width, height, iteration): ts_sum = 0 tp_sum = 0 for i in range(iteration): a = rand_test_case(width, height) b = rand_test_case(width, height) cs, ts = find_similarity_in_sequential(a, b, True) cp, tp = find_similarity_in_parallel(a, b, 2, True) ts_sum += ts tp_sum += tp ts_avg = ts_sum / iteration tp_avg = tp_sum / iteration print print 'sequential: {0:.4f}'.format(ts_avg) print 'parallel: {0:.4f}'.format(tp_avg)
def dtw_among_n_testcases(w, h, n, iteration, log): global width global height global workload global captured global predefined width = w height = h workload = n ts = 0 tp = 0 for i in range(iteration): captured = rand_test_case(width, height) predefined = [rand_test_case(width, height) for i in range(workload)] if log: print '----------------------' start_t = time.time() if log: print 'running sequential DTWs...' for i in range(workload): find_similarity(i) run_t = time.time() - start_t ts += run_t if log: print 'run in sequential for {0:.4f} seconds'.format(run_t) start_t = time.time() if log: print 'running parallel DTWs...' result = multiprocessing.Pool(processes=4).map(find_similarity, range(workload)) run_t = time.time() - start_t tp += run_t if log: print 'run in parallel for {0:.4f} seconds'.format(run_t) print '----------------------' print #print 'sequential:{0:.4f}'.format(ts/iteration) #print 'parallel:{0:.4f}'.format(tp/iteration) print "{0},{1:.4f},{2:.4f}".format(n, ts / iteration, tp / iteration)
def dtw_among_n_testcases(w, h, n, iteration, log): global width global height global workload global captured global predefined width = w height = h workload = n ts = 0 tp = 0 for i in range(iteration): captured = rand_test_case(width, height) predefined = [rand_test_case(width, height) for i in range(workload)] if log: print '----------------------' start_t = time.time() if log: print 'running sequential DTWs...' for i in range(workload): find_similarity(i) run_t = time.time() - start_t ts += run_t if log: print 'run in sequential for {0:.4f} seconds'.format(run_t) start_t = time.time() if log: print 'running parallel DTWs...' result = multiprocessing.Pool(processes=4).map(find_similarity, range(workload)) run_t = time.time() - start_t tp += run_t if log: print 'run in parallel for {0:.4f} seconds'.format(run_t) print '----------------------' print #print 'sequential:{0:.4f}'.format(ts/iteration) #print 'parallel:{0:.4f}'.format(tp/iteration) print "{0},{1:.4f},{2:.4f}".format(n,ts/iteration,tp/iteration)