Beispiel #1
0
def step1_evaluation(bn: SelectiveBooleanNetwork, na: int, ataus: dict,
                     nrho: float):

    i = 4 * max(map(len, bn.atm.attractors)) * len(bn)**2

    return test_contraints(bn, [
        lambda o: constraints.test_attractors_number(o, na),
        lambda o: constraints.test_attractors_transitions(o, ataus),
        lambda o: constraints.test_bn_state_space_homogeneity(o, i, nrho)
    ])
    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)
        if isinstance(GLOBALS.slct_target_transition_tau, list):
            tTau_map = {
                'a0': {
                    'a1': max(GLOBALS.slct_target_transition_tau)
                },
                'a1': {
                    'a0': max(GLOBALS.slct_target_transition_tau)
                }
            }
        else:
            tTau_map = GLOBALS.slct_target_transition_tau

        print(bn.atm.dtableau)

        c1 = constraints.test_attractors_number(
            bn, GLOBALS.slct_target_n_attractors)
        c2 = constraints.test_attractors_transitions(bn, tTau_map)
        c3 = constraints.test_bn_state_space_homogeneity(
            bn, i, GLOBALS.slct_noise_rho)
        print(time.perf_counter() - t)

        t = time.perf_counter()
        c4 = constraints.test_attraction_basins(bn,
                                                GLOBALS.slct_input_steps_phi,
                                                executor=mapper)
        print(time.perf_counter() - t)

        print(c1, c2, c3, bool(c4), end='\n\n')

    pool.close()
 def test_selector_constraint_1(self):
     bn = SelectiveBooleanNetwork.from_json(
         read_json('./test/bn_for_test.json'))
     self.assertTrue(constraints.test_attractors_number(bn, 2))
     self.assertFalse(constraints.test_attractors_number(bn, 4))
Beispiel #5
0
        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)
            c4 = bool(constraints.test_attraction_basins(bn, isPhi))

            files.append(
                mpath /
                f'{i}_bns_n{N}_k{K}_nrho{int(nRho*100)}_ttau{int(tTau*100)}_iphi{isPhi}_{FROZEN_DATE}.json'
            )

            write_json(bn.to_json(), files[-1])

            c1s.append(c1)