def test_atm_generation(self):

        atms = []

        N, K, P, Q, I, O = 5, 2, 0.5, 0.0, 1, 0

        g1 = template_selector_generator(
            N,
            K,
            P,
            Q,
            I,
            O,
            F=lambda a, b: random_neighbors_generator(a, b, self_loops=True))

        for _ in range(100):
            bn = g1.new_selector()
            atms.append(bn.atm.dtableau)
            # print(bn.atm.tableau)

        self.assertTrue(
            all([
                sum(a == b for b in atms) <= 1 + int(len(atms) / 2)
                for a in atms
            ]))

        atms.clear()

        # print('#######################################################')

        g2 = template_selector_generator(N, K, P, Q, I, O)

        for _ in range(100):
            bn = g2.new_selector()
            atms.append(bn.atm.dtableau)
            # print(bn.atm.tableau)

        self.assertTrue(
            all([
                sum(a == b for b in atms) <= 1 + int(len(atms) / 2)
                for a in atms
            ]))

        atms.clear()
    def test_bn_noisy_run(self):

        N, K, P, Q, I, O = 5, 2, 0.5, 0.0, 1, 0
        g = template_selector_generator(N, K, P, Q, I, O)
        bn = g.new_selector()
        atm = bn.atm

        states = [
            bn.noisy_update(noise_rho=0.2)
            for _ in range(max(map(len, atm.attractors)) * len(bn) * 10)
        ]

        self.assertTrue(
            len(states) == max(map(len, atm.attractors)) * len(bn) * 10)
        self.assertTrue(all(x == 5 for x in map(len, states)))
def generate_consistent_bnselector(executor=None) -> SelectiveBooleanNetwork:

    bn_params = GLOBALS.bn_params

    max_iters = GLOBALS.sd_max_iters
    na = GLOBALS.slct_target_n_attractors
    at_taus = GLOBALS.slct_target_transition_tau
    n_rho = GLOBALS.slct_noise_rho
    i_phi = GLOBALS.slct_input_steps_phi

    generator = template_selector_generator(*bn_params)

    gnt = GenerateNTest(
        sol_generator=lambda: generate_rbn(generator.new_selector,
                                           force_consistency=True),
        sol_test=lambda sol: step1_evaluation(sol, na, at_taus, n_rho) and
        step2_evaluation(sol, i_phi, executor),
        sol_evaluator=lambda score: score)

    return gnt(max_iters)
    def test_bnselector_atm_similarity(self):

        N, K, P, Q, I, O = 5, 2, 0.5, 0.0, 1, 0

        bnsg = template_selector_generator(N, K, P, Q, I, O)

        atms = []

        for _ in range(1000):
            s = bnsg.new_selector()
            if constraints.test_attractors_number(s, 2):
                atms.append(s.atm.tableau)
                # print(s.atm.tableau)

        flatatm = [flat(list(a), to=tuple) for a in atms]

        # print(len(set(flatatm)))

        self.assertTrue(
            all([
                sum(a == b for b in atms) <= 1 + int(len(atms) / 2)
                for a in atms
            ]))

        ############################################################

        atms2 = []

        for _ in range(1000):
            s = bnsg.new_selector()
            if constraints.test_attractors_number(s, 2):
                atms2.append(s.atm.tableau)
                # print(s.atm.tableau)

        flatatm2 = [flat(list(a), to=tuple) for a in atms2]

        # print(len(set(flatatm2)))

        self.assertFalse(flatatm == flatatm2)
Example #5
0
    prod = itertools.product(aNs, Ns, Ks, Ps, Qs, Is, Os, nRhos, tTaus, iPhis)

    mpath = get_dir(GLOBALS.sim_data_path / 'stats/models', create_if_dir=True)
    dpath = get_dir(GLOBALS.sim_data_path / 'stats/data', create_if_dir=True)

    for nA, N, K, P, Q, I, O, nRho, tTau, isPhi in prod:

        bns = []
        files = []
        c1s = []
        c2s = []
        c2no1s = []
        c3s = []
        c4s = []

        generator = template_selector_generator(N, K, P, Q, I, O)

        for i in range(instances):

            bn = generate_rbn(generator.new_selector, force_consistency=True)

            tTau_map = build_tmap(tTau, len(bn.atm.attractors))

            it = max(map(len, bn.atm.attractors)) * len(bn) * 20

            c1 = constraints.test_attractors_number(bn, nA)
            c2 = constraints.test_attractors_transitions(
                bn, tTau_map)  # if len(bn.atm.attractors) > 1 else False
            c2no1 = constraints.test_attractors_transitions(
                bn, tTau_map) if len(bn.atm.attractors) > 1 else False
            c3 = constraints.test_bn_state_space_homogeneity(bn, it, nRho)