Example #1
0
    def test_default_scramble_strategy(self):

        bn = template_behaviour_generator(5, 2, 0.5, 0.0, 1, 0).new()
        bn_copy = BooleanNetwork.from_json(bn.to_json())

        bn_copy, flips = bn_scramble_strategy(bn_copy, 1)

        self.assertFalse(bn.to_json() == bn_copy.to_json())

        bn_copy = edit_boolean_network(bn_copy, flips)

        self.assertTrue(bn.to_json() == bn_copy.to_json())
Example #2
0
    def test_bn_update(self):
        bn = template_behaviour_generator(5, 2, 0.5, 0.0, 1, 0).new()

        bn_copy = BooleanNetwork.from_json(bn.to_json())

        matching_states = []

        for _ in range(10):

            s1 = binstate(bn.update())
            s2 = binstate(bn_copy.update())

            matching_states.append(s1 == s2)

        self.assertTrue(all(matching_states))
def test_bn_state_space_homogeneity(bn: BooleanNetwork, i: int,
                                    noise_rho: float):
    '''
    Checks whether the attractor space is:
        * Deaf to inputs values in presence of "ambient" noise.

            That is, setting an input node state to a certain value 
            doesn't lock the trajectory of the BN to a single attractor.

        * Displays, to some degree of alternance, all the attractors (see ATM).
    '''
    states = [bn.noisy_update(noise_rho) for _ in range(i)]

    found_attrs = search_attractors(states, bn.atm.dattractors)

    return len(set(found_attrs)) == len(bn.atm.attractors)
Example #4
0
from pathlib import Path
from pandas import DataFrame
from pprint import pprint
from bncontroller.sim.utils import GLOBALS, load_global_config
from bncontroller.boolnet.selector import SelectiveBooleanNetwork
from bncontroller.boolnet.structures import BooleanNetwork
from bncontroller.jsonlib.utils import read_json
from bncontroller.filelib.utils import get_dir

if __name__ == "__main__":

    load_global_config()

    for path in get_dir(GLOBALS.bn_model_path).iterdir():

        if path.is_file():
            bn: BooleanNetwork = BooleanNetwork.from_json(read_json(path))

            print(str(path))
            print(DataFrame(bn.atm.dtableau).T)
            print(bn.atm.tableau)
            for k, a in bn.atm.dattractors.items():
                print(k, a)
            print(bn.atm.attractors)
Example #5
0
    def new(self) -> BooleanNetwork:

        nodes = self.__connect_nodes(self.__build_nodes())

        return BooleanNetwork(nodes)
Example #6
0
    def test_ebnf(self):
        bn = template_behaviour_generator(5, 2, 0.5, 0.0, 1, 0).new()

        bn_copy = BooleanNetwork.from_json(bn.to_json())

        self.assertTrue(bn.to_ebnf(), bn_copy.to_ebnf())
Example #7
0
 def c2no1(bnname, c):
     # bnname, c = cols
     print(bnname)
     bn = BooleanNetwork.from_json(
         read_json(GLOBALS.bn_model_path / 'stats/models' / bnname))
     return c if len(bn.atm.attractors) > 1 else False