コード例 #1
0
def train_behavioural_bn(bn: OpenBooleanNetwork) -> (OpenBooleanNetwork, VNSOutput):

    spawn_points = GLOBALS.generate_spawn_points()

    terminal_nodes = get_terminal_nodes(bn)
    to_never_flip = set(map(hash, bn.input_nodes + terminal_nodes))

    train_scores_cmp = GLOBALS.eval_cmp_function
    train_eval_fn = lambda bn, ct: pt_evaluation_for_train(bn, ct, spawn_points)
    train_scramble_strategy = lambda bn, nf, e: bn_scramble_strategy(bn, nf, e.union(to_never_flip))
    train_tidy_strategy = edit_boolean_network

    pvns = VNS(
        sol_evaluator=train_eval_fn,
        sols_comparator=train_scores_cmp,
        sol_scrambler=train_scramble_strategy,
        sol_tidier=train_tidy_strategy
    )

    params = VNSParameters(
        target_score=flat((GLOBALS.sd_target_score, float('+inf')), to=tuple),
        min_flips=GLOBALS.sd_min_flips,
        max_flips=sum(2**n.arity for n in bn.nodes if hash(n.label) not in to_never_flip),
        max_iters=GLOBALS.sd_max_iters,
        max_stalls=GLOBALS.sd_max_stalls,
        max_stagnation=GLOBALS.sd_max_stagnation
    )

    return pvns(bn, params)
コード例 #2
0
def test_bncontrollers(bns: dict):
    '''
    Test each BN in the collection on the same set of points.

    Return the collected evaluation data for each test.
    '''

    spawn_points = GLOBALS.generate_spawn_points()

    data = dict()

    for k in bns:

        logger.info(f"Boolean Network {k}")

        test_params = generate_test_params(spawn_points)

        data[k] = test_bncontroller(bns[k], test_params)

    return data