示例#1
0
from bncontroller.sim.utils import GLOBALS, load_global_config
from bncontroller.filelib.utils import get_dir, FROZEN_DATE
from bncontroller.stubs.selector.utils import template_selector_generator
from bncontroller.stubs.selector.generation import generate_consistent_bnselector as generate_consistent_bnselector

if __name__ == "__main__":

    load_global_config()

    N, K, P, I, O = GLOBALS.bn_n, GLOBALS.bn_k, GLOBALS.bn_p, GLOBALS.bn_n_inputs, GLOBALS.bn_n_outputs

    path = get_dir(Path(GLOBALS.bn_model_path), create_if_dir=True)

    for l in range(GLOBALS.sd_max_iters):

        bn = GLOBALS.app_core_function()

        Path(path /
             f'{l}_bn_n{N}_k{K}_p{int(P*100)}_{FROZEN_DATE}.ebnf').write_text(
                 bn.to_ebnf())

        Path(path /
             f'{l}_bn_n{N}_k{K}_p{int(P*100)}_{FROZEN_DATE}.json').write_text(
                 bn.to_json())

        df = DataFrame(bn.atm.dtableau)

        df.to_csv(str(path / f'{l}_atm_{FROZEN_DATE}.csv'))

    exit(1)
示例#2
0
            key=GLOBALS.app['mode'],
            date=futils.FROZEN_DATE,
        ))

    ### Load Test Model(s) from Template paths ####################################

    files, bns = collect_bn_models(GLOBALS.bn_model_path)

    ### Test ######################################################################
    t = time.perf_counter()

    for i in range(GLOBALS.test_n_instances):

        logger.info(f'Test instance n°{i}')

        instance_data = GLOBALS.app_core_function(bns)

        for k, test_data in instance_data.items():

            name = futils.gen_fname(
                futils.get_simple_fname(files[k].name,
                                        futils.FNAME_PATTERN,
                                        uniqueness=2),
                template='rtest_data_{name}' + f'_in{i}.json',
            )

            test_data.to_json(GLOBALS.test_data_path / name,
                              default_handler=jsonrepr)

            logger.info(
                f'Test data saved into {str(GLOBALS.test_data_path / name)}')
示例#3
0
            date=FROZEN_DATE,
        ))

    ### BN Generation / Loading ####################################################

    bn = generate_or_load_bn(params=GLOBALS.bn_params,
                             path=GLOBALS.bn_model_path,
                             save_virgin=True)

    ### Launch search algorithm ##############################################

    if not GLOBALS.train_generate_only:

        t = time.perf_counter()

        bn, ctx = GLOBALS.app_core_function(bn)

        logger.info(f"Search time: {time.perf_counter() - t}s")

        logger.info(ctx)

        savepath = GLOBALS.bn_model_path / 'behavioural_bn_{date}.json'.format(
            mode=GLOBALS.app['mode'], date=FROZEN_DATE)

        write_json(bn, savepath)

        logger.info(f'Output model saved to {savepath}.')

    logger.info('Closing...')

    logger.flush()
示例#4
0
        GLOBALS.bn_params = N, K, P, Q, I, O

        if not isinstance(tTau, dict):
            GLOBALS.slct_target_transition_tau = {
                "a0": {"a0": tTau, "a1": tTau},
                "a1": {"a0": tTau, "a1": tTau}
            }

        GLOBALS.slct_noise_rho = nRho
        GLOBALS.slct_target_n_attractors = aN
        GLOBALS.slct_input_steps_phi = iPhi
        
        t = time.perf_counter()

        bn = GLOBALS.app_core_function(mapper)

        logger.info(time.perf_counter() - t)

        while bn is None or not bn.attractors_input_map or None in bn.attractors_input_map:
            logger.info('Failure. Retrying...')
            t = time.perf_counter()
            bn = GLOBALS.app_core_function()
            logger.info(time.perf_counter() - t)

        logger.info(dict(**bn.attractors_input_map))
        logger.info(dict(**bn.atm.dtableau))
        logger.info(dict(**bn.atm.dattractors))

        path = FOLDER / f'selective_bn_{iso8106(ms=3)}.json'