def test_comparison_adaptive_taylor4_tdrk4(): # define ODE t_0 = 0.0 t_fin = 3.0 ode = ODEs(y, f, dfdt, dfdt, dfdt, f_n, dfdt_n, t_0, t_fin) # define the schemes to test adapt_taylor = AdaptiveTaylor4Scheme(ode, 'taylor4') adapt_tdrk4 = AdaptiveTDRK4Scheme(ode, 'tdrk4') # define tolerances factor = 1e0 eps_abs = np.array([1e-2, 1e-4, 1e-6, 1e-8, 1e-10, 1e-12]) #eps_abs = np.array([1e-8]) eps_rel = factor * eps_abs print('% -------------------------------------------------------------------------------------------- %') print(' adaptive taylor4') print('% -------------------------------------------------------------------------------------------- %\n') test_taylor = Test(examples[example_num], test_params, adapt_taylor, 'example-') test_taylor.test_adaptive(eps_abs, eps_rel) #test_taylor.plot_results('adaptive-taylor4-') print('% -------------------------------------------------------------------------------------------- %') print(' adaptive tdrk4') print('% -------------------------------------------------------------------------------------------- %\n') test_tdrk4 = Test(examples[example_num], test_params, adapt_tdrk4, 'example-') test_tdrk4.test_adaptive(eps_abs, eps_rel) #test_tdrk4.plot_results('adaptive-tdrk4-') test_tdrk4.compare_results([test_taylor], ['tdrk4', 'taylor'], 'taylor4-tdrk4-')
def main(config): from torch.backends import cudnn # For fast training cudnn.benchmark = True data_loader = get_loader( config.mode_data, config.image_size, config.batch_size, config.dataset_fake, config.mode, num_workers=config.num_workers, all_attr=config.ALL_ATTR, c_dim=config.c_dim) from misc.scores import set_score if set_score(config): return if config.mode == 'train': from train import Train Train(config, data_loader) from test import Test test = Test(config, data_loader) test(dataset=config.dataset_real) elif config.mode == 'test': from test import Test test = Test(config, data_loader) if config.DEMO_PATH: test.DEMO(config.DEMO_PATH) else: test(dataset=config.dataset_real)
def test_comparison_srtdrk2_mrtdrk2(): # define ODE t_0 = 0.0 t_fin = 5.0 ode = ODEs(y, f, dfdt, J_y, J_t, f_n, dfdt_n, t_0, t_fin, F, JF_y, dFdt) # define the schemes to test tdrk2_sr = AdaptiveTDRK2SingleRateScheme(ode, 'sr-tdrk2') tdrk2_mr = AdaptiveTDRK2MultiRateScheme(ode, 'mr-tdrk2') # define tolerances factor = 1e0 if examples[example_num] == 2: eps_abs = np.array([1e-2, 1e-3, 1e-4, 1e-5, 1e-6]) else: eps_abs = np.array([1e-4, 1e-5, 1e-6, 1e-7, 1e-8]) eps_rel = factor * eps_abs print('% -------------------------------------------------------------------------------------------- %') print(' adaptive tdrk2 (2 * neq function call per step)') print('% -------------------------------------------------------------------------------------------- %\n') test_sr = Test(examples[example_num], test_params, tdrk2_sr, 'system-') test_sr.test_adaptive(eps_abs, eps_rel) print('% -------------------------------------------------------------------------------------------- %') print(' multirate adaptive tdrk2') print('% -------------------------------------------------------------------------------------------- %\n') test_mr = Test(examples[example_num], test_params, tdrk2_mr, 'system-') test_mr.test_adaptive(eps_abs, eps_rel) test_sr.compare_results([test_mr], ['sr-tdrk2', 'mr-tdrk2'], 'sr-vs-mr-tdrk2-')
def deal_request(self, r_args): method = r_args['method'] online = int(r_args['online_status']) request_nums = int(r_args['requests_nums']) concurrent_num = int(r_args['concurrent_num']) url = r_args['url'] data = r_args['data'] for e in range(request_nums): if online: r = Test('app', self.platform, r_args['username'], r_args['password']) else: r = Test('app', self.platform) if method == 'get': r.get_request(url) elif method == 'post': r.post_request(url, data) elif method == 'put': r.put_request(url, data) elif method == 'delete': r.delete_request(url, data) else: print('暂不支持此种请求方式') exit(0) print(r.response_code, end='\n') #print(r.response_time, end='\n') #print(r.response_data, end='\n') self.write_csv(row = [url, method, data, request_nums, concurrent_num, online, \ r_args['username'], r_args['password'], r_args['remark'], \ r.response_data,r.response_time,r.response_code,str(int(time.time()))])
def test_comparison_adaptive_tdrk2_schemes(): # define ODE t_0 = 0.0 t_fin = 3.0 ode = ODEs(y, f, dfdt, dfdt, dfdt, f_n, dfdt_n, t_0, t_fin) # define the schemes to test adapt_tdrk2 = AdaptiveTDRK2Scheme(ode, 'tdrk2 (our h)') adapt_classic_tdrk2 = AdaptiveClassicTDRK2Scheme(ode, 'tdrk2 (classic h)') # define tolerances factor = 1e0 eps_abs = np.array([1e-2, 1e-4, 1e-6, 1e-8, 1e-10]) eps_rel = factor * eps_abs print('% -------------------------------------------------------------------------------------------- %') print(' classic tdrk2') print('% -------------------------------------------------------------------------------------------- %\n') test_aclassic_tdrk2 = Test(examples[example_num], test_params, adapt_classic_tdrk2, 'comparison-tdrk2-and-4-example-') test_aclassic_tdrk2.test_adaptive(eps_abs, eps_rel) test_aclassic_tdrk2.plot_results('adaptive-classi-tdrk2-') print('% -------------------------------------------------------------------------------------------- %') print(' adaptive tdrk2') print('% -------------------------------------------------------------------------------------------- %\n') test_adapt_tdrk2 = Test(examples[example_num], test_params, adapt_tdrk2, 'comparison-tdrk2-and-4-example-') test_adapt_tdrk2.test_adaptive(eps_abs, eps_rel) test_adapt_tdrk2.plot_results('adaptive-tdrk2-') test_adapt_tdrk2.compare_results([test_aclassic_tdrk2], ['tdrk2 (classic h)'], 'tdrk2s-')
def test(model, test_loader, class_weights, class_encoding): print("Testing...") num_classes = len(class_encoding) criterion = nn.CrossEntropyLoss(weight=class_weights) if use_cuda: criterion = criterion.cuda() # Evaluation metric if args.ignore_unlabeled: ignore_index = list(class_encoding).index('unlabeled') else: ignore_index = None metric = IoU(num_classes, ignore_index=ignore_index) # Test the trained model on the test set test = Test(model, test_loader, criterion, metric, use_cuda) print(">>>> Running test dataset") loss, (iou, miou) = test.run_epoch(args.print_step) class_iou = dict(zip(class_encoding.keys(), iou)) print(">>>> Avg. loss: {0:.4f} | Mean IoU: {1:.4f}".format(loss, miou)) # Print per class IoU for key, class_iou in zip(class_encoding.keys(), iou): print("{0}: {1:.4f}".format(key, class_iou))
def run(args): if args.train == 1: model = GRAM_BIGRU_CRF(params=args) model.run(336) else: Test(args).run() return 1
def main(): '''main function''' parser = argparse.ArgumentParser() parser.add_argument('--state', default='test', help='train or test') parser.add_argument('--n_in', default=3, type=int, help='输入层大小') parser.add_argument('--n_hide', default=5, type=int, help='隐藏层大小') parser.add_argument('--n_out', default=1, type=int, help='输出层大小') parser.add_argument('--epoch', default=100000, type=int, help='训练次数') parser.add_argument('--lr', default=0.001, help='学习速率') parser.add_argument('--data', default='train.csv', help='训练数据集') parser.add_argument('--checkpoint', default='ckpt\\model.ckpt', help='持久化文件名') opt = parser.parse_args() print(opt) if opt.state == 'train': model = train.train_net(opt.n_in, opt.n_hide, opt.n_out, opt.checkpoint, opt.epoch, opt.lr) x, y = get_samples(opt.data, opt.n_in, opt.n_out) model.train(x, y) elif opt.state == 'test': test = Test(opt.n_in, opt.n_hide, opt.n_out, opt.checkpoint) # 14.61,13.49,22.67,17.81 x = np.array([[14.61, 13.49, 22.67]], dtype=np.float32) test.test(x) else: print('Error state, must choose from train and eval!')
def test_adaptive_tdrk2_scheme(): # define ODE t_0 = 0.0 t_fin = 1.0 ode = ODEs(y, f, dfdt, J_y, J_t, f_n, dfdt_n, t_0, t_fin, F, JF_y, dFdt) # define the schemes to test adapt_tdrk2 = AdaptiveTDRK2SingleRateScheme(ode, 'sr-tdrk2') # define tolerances factor = 1e0 if examples[example_num] == 2: eps_abs = np.array([1e-2, 1e-3, 1e-4, 1e-5, 1e-6]) else: eps_abs = np.array([1e-4, 1e-5, 1e-6, 1e-7, 1e-8]) eps_rel = factor * eps_abs print('% -------------------------------------------------------------------------------------------- %') print(' adaptive tdrk2 (2 * neq function call per step)') print('% -------------------------------------------------------------------------------------------- %\n') test = Test(examples[example_num], test_params, adapt_tdrk2, 'system-') test.test_adaptive(eps_abs, eps_rel) test.plot_results('adaptive-tdrk2-') '''
def expand(self, case_filename, case_name, case_values, encoding): frontmatter = self._frontmatter(case_filename, case_values) body = self.expand_regions(self.source, case_values) assert encoding == 'utf-8' return Test(self.attribs['meta']['path'] + case_name + '.js', source=codecs.encode(frontmatter + '\n' + body, encoding))
def __init__(self, monitor, model): self.metrics = monitor.train_metrics(model) self.lr = tf.placeholder(tf.float32, shape=[]) self.optimizer = tf.train.GradientDescentOptimizer( learning_rate=self.lr).minimize( self.metrics[monitor.train_loss_index]) self.tester = Test(monitor, model)
def test_func(self): self.__clear__() check = Test( '/dev/ttyACM0', 115200 ) # initialises a test object and will access the port on a seperate line done = False while not done: QuickyTable("Motors", "LCD", "Sensor", "Servo", "All") try: test_check = int(input("(~) What do you want to test?: ")) except NameError: #self.__clear__() print "(-) Invalid input, please try again " new = Menu() done = True if test_check == 0: check.motor() elif test_check == 1: check.lcd() elif test_check == 2: check.sensor() elif test_check == 3: check.servo() elif test_check == 4: check.full_check() else: done = False print "(-) Invalid input, please try again " check.log() new = Menu()
def run_tests(data_name): test = Test() test.linear_search_grid_test(data_name) test.poly_search_grid_test(data_name) #test.precomputed_search_grid_test(data_name) test.rbf_search_grid_test(data_name) test.sigmoid_search_grid_test(data_name)
def test_adaptive_tdrk4_scheme(): # define ODE t_0 = 0.0 t_fin = 5.0 ode = ODEs(y, f, dfdt, J_y, J_t, f_n, dfdt_n, t_0, t_fin) # define the schemes to test adapt_tdrk4 = AdaptiveTDRK4SingleRateScheme(ode, 'tdrk4') # define tolerances factor = 1e0 if examples[example_num] == 2: eps_abs = np.array([1e-2, 1e-3, 1e-4, 1e-5, 1e-6]) else: eps_abs = np.array([1e-4, 1e-5, 1e-6, 1e-7, 1e-8]) eps_rel = factor * eps_abs print('% -------------------------------------------------------------------------------------------- %') print(' adaptive tdrk4') print('% -------------------------------------------------------------------------------------------- %\n') test = Test(examples[example_num], test_params, adapt_tdrk4, 'system-') test.test_adaptive(eps_abs, eps_rel) test.plot_results('adaptive-tdrk4-') # check if test is passed '''
def schedule_tester(self, cycle=TESTER_CYCLE): """定时测试代理""" test = Test() while True: print(' 测试器开始运行 ') test.run() time.sleep(cycle)
def test_adaptive_tdrk2_scheme(): # define ODE t_0 = 0.0 t_fin = 3.0 ode = ODE(y, f, dfdt, f_n, dfdt_n, t_0, t_fin) # define the schemes to test adapt_tdrk2 = AdaptiveTDRK2Scheme(ode) # define tolerances factor = 1e-2 eps_abs = np.array([1e-2, 1e-4, 1e-6, 1e-8]) eps_rel = factor * eps_abs print( '% -------------------------------------------------------------------------------------------- %' ) print(' adaptive tdrk2') print( '% -------------------------------------------------------------------------------------------- %\n' ) test = Test(examples[example_num], test_params, adapt_tdrk2, 'ode-example-') test.test_adaptive(eps_abs, eps_rel) test.plot_results('adaptive-tdrk2-') '''
def test_adaptive_multirate_tdrk4_scheme(): # define ODE t_0 = 0.0 t_fin = 1.0 ode = ODEs(y, f, dfdt, J_y, J_t, f_n, dfdt_n, t_0, t_fin, F, JF_y, dFdt) # define the schemes to test adapt_tdrk2 = AdaptiveTDRK4MultiRateScheme(ode, 'mr-tdrk4') # define tolerances factor = 1e0 eps_abs = np.array([1e-2, 1e-3, 1e-4]) #eps_abs = np.array([1e-2, 1e-3, 1e-4, 1e-6, 1e-7]) #eps_abs = np.array([1e-2, 1e-4, 1e-6]) eps_rel = factor * eps_abs print('% -------------------------------------------------------------------------------------------- %') print(' adaptive multi-rate tdrk4') print('% -------------------------------------------------------------------------------------------- %\n') test = Test(examples[example_num], test_params, adapt_tdrk2, 'system-') test.test_adaptive(eps_abs, eps_rel) test.plot_results('adaptive-tdrk4-') '''
def test(self, ): """ Test the generator. """ print("\nTesting...\n") num_classes = len(self.class_encoding) # We are going to use the CrossEntropyLoss loss function as it's most # frequently used in classification problems with multiple classes # which fits the problem. This criterion combines LogSoftMax and # NLLLoss. criterion = nn.CrossEntropyLoss(weight=self.class_weights) # Evaluation metric ignore_index = list(class_encoding).index('unlabeled') metric = IoU(num_classes, ignore_index=ignore_index) # Test the trained model on the test set test = Test(self.generator, self.test_loader, criterion, metric, self.device) print(">>>> Running test dataset") loss, (iou, miou) = test.run_epoch(iteration_loss=True) class_iou = dict(zip(class_encoding.keys(), iou)) print(">>>> Avg. loss: {0:.4f} | Mean IoU: {1:.4f}".format(loss, miou)) # Print per class IoU for key, class_iou in zip(class_encoding.keys(), iou): print("{0}: {1:.4f}".format(key, class_iou))
def test(model, test_loader, class_weights, class_encoding): print("\nTesting...\n") num_classes = len(class_encoding) criterion = nn.CrossEntropyLoss(weight=class_weights) # Evaluation metric if args.ignore_unlabeled: ignore_index = list(class_encoding).index('unlabeled') else: ignore_index = None metric = IoU(num_classes, ignore_index=ignore_index) # Test the trained model on the test set test = Test(model, test_loader, criterion, metric, device) print(">>>> Running test dataset") loss, (iou, miou) = test.run_epoch(iteration_loss=False) class_iou = dict(zip(class_encoding.keys(), iou)) print(">>>> Avg. loss: {0:.4f} | Mean IoU: {1:.4f}".format(loss, miou)) # Print per class IoU for key, class_iou in zip(class_encoding.keys(), iou): print("{0}: {1:.4f}".format(key, class_iou)) # Show a batch of samples and labels # if args.imshow_batch: if True: print("A batch of predictions from the test set...") images, _ = next(iter(test_loader)) predict(model, images, class_encoding)
def main(): time = [] back_track = [] # number of tests to be made on a chosen puzzle n_test = 5 # inference specifies which inference to choose for executing the tests # we can choose between: no_inference, forward_checking and mac inference = mac # var_sel specifies the order in which will be chosen the unassigned variable # we can choose between: first_unassigned_variable and mrv (minimum remaining values) var_sel = first_unassigned_variable # level chooses difficulty (higher is more difficult) # level 1 is Easy, level 2 is Medium, level 3 is Hard, level 4 is Evil, level 5 is "Hardest" level = 1 for i in range(n_test): test = Test() test.choose_puzzle(level) test.execute(inference, var_sel) back_track.append(test.bt) time.append(round(test.end - test.start, 5)) print("Average time: " + str(round(sum(time) / len(time), 3))) print("Average backtracks: " + str(round(sum(back_track) / len(back_track))))
def test_adaptive_tdrk4_scheme(): # define ODE t_0 = 0.0 t_fin = 3.0 ode = ODE(y, f, dfdt, f_n, dfdt_n, t_0, t_fin) # define the schemes to test adapt_tdrk4 = AdaptiveTDRK4Scheme(ode) # define tolerances factor = 1e0 eps_abs = np.array([1e-2, 1e-4, 1e-6, 1e-8, 1e-10]) #eps_abs = np.array([1e-2, 1e-4, 1e-6, 1e-8, 1e-10, 1e-12, 1e-14]) eps_rel = factor * eps_abs print( '% -------------------------------------------------------------------------------------------- %' ) print(' adaptive tdrk4') print( '% -------------------------------------------------------------------------------------------- %\n' ) test = Test(examples[example_num], test_params, adapt_tdrk4, 'ode-example-') test.test_adaptive(eps_abs, eps_rel) test.plot_results('adaptive-tdrk4-') # check if test is passed for i in range(0, len(eps_abs)): success = (test.e_glob[i] < eps_abs[i] + eps_rel[i]) assert success, "eps = %4.4e\t e_glob = %4.4e" % ( eps_abs[i] + eps_rel[i], test.e_glob[i])
def test_shuzi(self): #下面三引号对方法的注释会显示在报告的表格中 '''两个数字相加以及两个数字相减''' # 对test文件中的Test类初始化 shuzi = Test(7, 3) self.assertEqual(shuzi.add(), 10) self.assertEqual(shuzi.dele(), 4)
def __init__(self, ioutils): # State machine's state self.state = State() # State machine's transition self.transition = Transition(ioutils) # test class to handle LEDs colors depending on current state self.test = Test()
def main(debug: bool, test: bool): try: if test: Test(debug).run() else: Anaclock(debug).listen() except KeyboardInterrupt: print('Interrupted via keyboard.')
def main(pseudo, mdp): browser = setBrowser() test = Test(browser) test.title('Home Page') action = Action(browser) action.connection(pseudo, mdp) test.connection() browser.quit()
def test_delete_is_working(self): with DB() as database: test = Test().create() test.id = database.execute('''SELECT id FROM tests WHERE title = ?''', \ (test.title,)).fetchone()[0] with DB() as database: test.delete() self.assertEqual(Test.find(test.id), None)
def main(): if args.test_only: t = Test() t.test() else: from train import Train t = Train() t.train()
def wrongPassword(pseudo, mdp): browser = setBrowser() test = Test(browser) test.title('Home Page') action = Action(browser) action.connection(pseudo, mdp) assert "Bibliotheque" not in browser.title browser.quit()
def main(): img_files = glob.glob("oxbuild-images/*.jpg") # img_names = ['all_souls_000000', ...] # query_indices = [11, 21, ...] img_names = utils.get_images_names(img_files) query_indices = utils.get_queries(img_names) files_for_codebook = img_files for index in query_indices: del files_for_codebook[index] del img_names[index] img_names = utils.get_images_names(img_files) land_marks = [ 'all_souls', 'ashmolean', 'balliol', 'bodleian', 'christ_church', 'cornmarket', 'hertford', 'keble', 'magdalen', 'pitt_rivers', 'radcliffe_camera' ] #64 print("leyendo codebook...") codebook = np.loadtxt("clusters64.csv", delimiter=",") print("leyendo vlad matrix...") vlad = np.loadtxt("vlad64.csv", delimiter=",") print("listo") print("vlad matrix shape: ") print(vlad.shape) test = Test(vlad, codebook, img_names, "euclidean") precisions = [] for lm in land_marks: for i in range(5): index = str(i + 1) precision = test.do_query(lm + "_" + index) precisions.append(precision) print("64 euclidean map = "), print(np.average(precisions)) test = Test(vlad, codebook, img_names, "hellinger") precisions = [] for lm in land_marks: for i in range(5): index = str(i + 1) precision = test.do_query(lm + "_" + index) precisions.append(precision) print("64 hellinger map = "), print(np.average(precisions))
def gain_coin(n): request_num = 10 print('Starting Request : '+ str(n) + '\n') r = Test('app', 'test', '18671188982', '123456') for v in range(request_num): print(str(n) + '--- ' + str(v) + '\n') r.get_request('/member/assets/coin') print(str(r.response_code) + '\n') print(r.response_data, '\n')