if __name__ == '__main__': strt_tm = time.time() objf = TestFuncs.F5 parms_func = { 'func_name': objf.__name__, 'x_lb': -10, 'x_ub': 10, 'dim': 5, 'kwargs': {} } parms_opter = {'opter_name': 'GWO-test', 'PopSize': 20, 'Niter': 1000} # logger = simple_logger() logger = get_logger('./test/GWO_test.txt', screen_show=True) # parms_log = {'logger': logger, 'nshow': 10} parms_log = {'logger': logger, 'nshow': 100} func_opter_parms = FuncOpterInfo(parms_func, parms_opter, parms_log) func_opter_parms = GWO(objf, func_opter_parms) vals = pd.DataFrame({ 'fval_best': func_opter_parms.convergence_curve, 'fval_mean': func_opter_parms.convergence_curve_mean }) plot_Series(vals, {'fval_best': '-r', 'fval_mean': '-b'}, figsize=(10, 6)) # best_x = func_opter_parms.best_x # func_opter_parms.parms_log['logger'].info(f'best x: {best_x}')
#%% # 目标函数和参数 objf = LR_cls_bin_objf parms_func = {'func_name': objf.__name__, 'x_lb': -20, 'x_ub': 20, 'dim': 3, 'kwargs': {'X_train': X_train, 'y_train': y_train, 'p_cut': 0.5}} # 统一参数 PopSize = 10 Niter = 1000 # logger # logger = simple_logger() logger = get_logger('./test/HeuristicLRcls_bin.txt', screen_show=True) # parms_log = {'logger': logger, 'nshow': 10} parms_log = {'logger': logger, 'nshow': Niter} fvals = pd.DataFrame() #%% # GA parms_ga = {'opter_name': 'GA', 'PopSize': PopSize, 'Niter': Niter, 'Pcrs': 0.7, 'Pmut': 0.1, 'Ntop': 2} ga_parms = FuncOpterInfo(parms_func, parms_ga, parms_log) ga_parms = GA(objf, ga_parms) fvals['GA'] = ga_parms.convergence_curve
# -*- coding: utf-8 -*- from utils_hoo.utils_logging import logger_utils from utils_hoo.utils_logging import logger_general from utils_hoo.utils_logging import logger_Rotating from utils_hoo.utils_logging import logger_TimedRotating from test_func import test_func import time if __name__ == '__main__': #%% logger = logger_general.get_logger(fpath='./test_log/log_test1.log', fmode='w', screen_show=True) logger.info('Log start here *********************************************') test_func(3, 5, 'this is a warning.', logger) logger.info('测试结束.') logger_utils.close_log_file(logger) logger_utils.remove_handlers(logger) #%% logger = logger_Rotating.get_logger(fpath='./test_log/log_test2.log', fmode='w', maxK=1, bkupCount=3, screen_show=True) logger.info('Log start here *********************************************') test_func(3, 1, 'this is a warning.', logger) logger.info('测试结束.')
objf = TestFuncs.F7 parms_func = { 'func_name': objf.__name__, 'x_lb': -30, 'x_ub': 30, 'dim': 100, 'kwargs': {} } # 统一参数 PopSize = 30 Niter = 1000 # logger # logger = simple_logger() logger = get_logger('./test/Heuristic-test.txt', screen_show=True) # parms_log = {'logger': logger, 'nshow': 10} parms_log = {'logger': logger, 'nshow': Niter} fvals = pd.DataFrame() # GA parms_ga = { 'opter_name': 'GA', 'PopSize': PopSize, 'Niter': Niter, 'Pcrs': 0.7, 'Pmut': 0.1, 'Ntop': 2 }