예제 #1
0
    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}')

    close_log_file(logger)

    print(f'used time: {round(time.time()-strt_tm, 6)}.')
예제 #2
0
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('测试结束.')

    logger_utils.close_log_file(logger)
    logger_utils.remove_handlers(logger)