def __init__(self, name='', Nnodes=0, logic=None, sg=None, stg=None, stg_r=None, _ef=None, attractors=None, constants={}, Nconstants=0, keep_constants=False, bin2num=binstate_to_statenum, num2bin=statenum_to_binstate, verbose=False, *args, **kwargs): self.name = name # Name of the Network self.Nnodes = Nnodes # Number of Nodes self.logic = logic # A dict that contains the network logic {<id>:{'name':<string>,'in':<list-input-node-id>,'out':<list-output-transitions>},..} self._sg = sg # Structure-Graph (SG) self._stg = stg # State-Transition-Graph (STG) self._stg_r = stg_r # State-Transition-Graph Reachability dict (STG-R) self._eg = None # Effective Graph, computed from the effective connectivity self._attractors = attractors # Network Attractors # self.keep_constants = keep_constants # Keep/Include constants in some of the computations self.constants = constants # A dict that contains of constant variables in the network self.Nconstants = len(constants) # Number of constant variables # self.Nstates = 2**Nnodes # Number of possible states in the network 2^N # self.verbose = verbose # Intanciate BooleanNodes self.nodes = list() for i in range(Nnodes): name = logic[i]['name'] k = len(logic[i]['in']) inputs = [logic[j]['name'] for j in logic[i]['in']] outputs = logic[i]['out'] node = BooleanNode(name=name, k=k, inputs=inputs, outputs=outputs) self.nodes.append(node) # self.bin2num = bin2num # Helper function. Converts binstate to statenum. It gets updated by `_update_trans_func` self.num2bin = num2bin # Helper function. Converts statenum to binstate. It gets updated by `_update_trans_func` self._update_trans_func() # Updates helper functions and other variables
from tqdm import tqdm from ..binarize import to_binary from cana.boolean_node import BooleanNode # set up variables n_inputs = 2**2 n_rules = 2**(2**2) df_dict = [] for rule in tqdm(range(n_rules)): canal = {} # becomes row of dataframe arr = to_binary(rule, digits=4) print(arr) # use dit to calculate decomposition bn = BooleanNode.from_output_list(outputs=arr, name=rule) ks = bn.input_symmetry() kr = bn.input_redundancy() sym0, sym1 = bn.input_symmetry(mode='input') red0, red1 = bn.input_redundancy(mode='input') # update the dictionary with the PI values canal['rule'] = rule canal['kr*'] = kr canal['ks*'] = ks canal['r(0)'] = red0 canal['r(1)'] = red1 canal['s(0)'] = sym0 canal['s(1)'] = sym1 df_dict.append(canal)
from cana.boolean_node import BooleanNode from ..binarize import to_binary from ..plotting_functions.display_tables import plot_look_up_table, plot_schemata rules = [2, 3, 4, 6] # rule 7 rule = 7 digits = 4 arr2 = to_binary(rule, digits) bn = BooleanNode.from_output_list(arr2) bn.input_symmetry() plot_look_up_table(rule, bn, snakemake.output.redlut) plot_schemata(rule, bn, snakemake.output.redwc) # rule 3 rule = 3 digits = 4 arr2 = to_binary(rule, digits) bn = BooleanNode.from_output_list(arr2) bn.input_symmetry() plot_look_up_table(rule, bn, snakemake.output.unqlut) plot_schemata(rule, bn, snakemake.output.unqwc) # rule 1 rule = 1 digits = 4 arr2 = to_binary(rule, digits) bn = BooleanNode.from_output_list(arr2)
from cana.boolean_node import BooleanNode from binarize import to_binary from boolean_minimization_stats import find_permutability, find_wildcards, powerset rule = 23 output = to_binary(rule) inputs = 3 print(output) node = BooleanNode.from_output_list(output, name=str(rule), inputs=['0', '1', '2']) # extract redescriptions ts = list(node.ts_coverage().values()) # find all potential group invarient enputs (subsets of cardinality > 1) possible_ts = list(powerset(inputs))[inputs:] ts_dict = {sub: 0 for sub in possible_ts} for inp in ts: print(inp) for inp in ts: if len(inp) > 0: # the entries that cannot be redescribed are len zero # combine the two lists of permutable inputs, I dont care if its zero or 1 ones = inp[0][1].copy() zeros = inp[0][2].copy() gi_enputs = ones + zeros # iterate over each and increase the group invariant enputs that exist if len(gi_enputs) >= 1: for gi in gi_enputs: ts_dict[tuple(gi)] += 1
from tqdm import tqdm from binarize import to_binary from literal_distribution_thing import LiteralDistribution from cana.boolean_node import BooleanNode # set up variables n_inputs = 2**3 n_rules = 2**8 df_dict = [] # figure out what isn't working failing_rules = [] for rule in tqdm(range(n_rules)): pis = {} # becomes row of dataframe output = to_binary(rule, 8) bn = BooleanNode.from_output_list(outputs=output) ld = LiteralDistribution(bn) pis = ld.run_distribute_literals() pis['rule'] = rule df_dict.append(pis) # write out the dataframe df = pd.DataFrame(df_dict) df_fout = open('data/eca_decompositions/boolean.csv', 'w') df.to_csv(df_fout) df_fout.close() with open('data/eca_decompositions/failing_rules.txt', 'w') as ff: text = '\n'.join(failing_rules) ff.write(text)