diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..0e40fe8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ + +# Default ignored files +/workspace.xml \ No newline at end of file diff --git a/.idea/Canalizing-Depth-Dynamics.iml b/.idea/Canalizing-Depth-Dynamics.iml new file mode 100644 index 0000000..6711606 --- /dev/null +++ b/.idea/Canalizing-Depth-Dynamics.iml @@ -0,0 +1,11 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..67f7a02 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..86a3c1c --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/core/discrete_dynamical_system.pyx b/core/discrete_dynamical_system.pyx index 01fc3a3..76a9baf 100644 --- a/core/discrete_dynamical_system.pyx +++ b/core/discrete_dynamical_system.pyx @@ -1,6 +1,7 @@ """ This is my boilerplate code. """ + import math import numpy as np @@ -84,4 +85,21 @@ class Dynamical(object): def placeholder(self): """ Not enough public methods otherwise""" - pass \ No newline at end of file + pass + + +def generate_boolean_functions(length): + rows = [] + functionvalues = [] + for j in range(2**length): + rows.append(list([int(i)for i in binary_fixed_length(j,length)])) + functionvalues.append(0) + rows.append(list([int(i)for i in binary_fixed_length(j,length)])) + functionvalues.append(1) + """appended twice as it can be 0 or 1 """ + + return rows, functionvalues + """ith element of functionvalues is the value for the ith element of row""" + + + diff --git a/core/find_attractors.pyx b/core/find_attractors.pyx index 1b82781..2468b19 100644 --- a/core/find_attractors.pyx +++ b/core/find_attractors.pyx @@ -1,4 +1,5 @@ """Find attractors using the other new method discussed at the meeting on 6/3/18""" + import numpy as np import pyximport pyximport.install() diff --git a/core/generate_k_canalyzing.py b/core/generate_k_canalyzing.py index 28de4c2..2e96e94 100644 --- a/core/generate_k_canalyzing.py +++ b/core/generate_k_canalyzing.py @@ -14,6 +14,9 @@ def all_numbers_but(exceptions, maxn): temp.append(i) return temp +def find_canalizing_depth( ): + + def random_k_canalyzing(num_vars, depth): """Method to generate a random k-canalyzing function""" if depth == 0: diff --git a/core/optimized_find_attractors.pyx b/core/optimized_find_attractors.pyx index 108ccfa..860470b 100644 --- a/core/optimized_find_attractors.pyx +++ b/core/optimized_find_attractors.pyx @@ -1,4 +1,5 @@ """Find attractors using the other new method discussed at the meeting on 6/3/18""" + import numpy as np import pyximport pyximport.install() diff --git a/core/random_noncanalysing.py b/core/random_noncanalysing.py index c11618d..6677db9 100644 --- a/core/random_noncanalysing.py +++ b/core/random_noncanalysing.py @@ -88,13 +88,34 @@ def overwrite_at(my_list, index, seq): def is_canalizing(table, var): """Checks whether var (counting from the right) is a canalizing for a function given by the table""" io_pairs_seen = {} - for i in xrange(len(table)): + for i in range(len(table)): inp = (i >> var) % 2 io_pairs_seen[table[i] * 2 + inp] = 1 if len(io_pairs_seen) == 4: return False return len(io_pairs_seen) < 4 +def is_canalizing_function(table): + for var in range(len(table)): + if is_canalizing(table, var): + return True + break + return False + +def find_canalizing_depth(table): + depth = 0 + for var in range(len(table)): + new_table = table[var:] + if is_canalizing(new_table, len(table)-1-var): + depth = depth +1 + if is_canalizing_function(table[var+1:]) == False: + break + return depth + + + + + #Main function def random_noncanalysing_func(num_vars): """Generates a random non-canalysing function on num_vars variables. diff --git a/tests/unit_tests/boolean_function&canalizing_depth_tests.py b/tests/unit_tests/boolean_function&canalizing_depth_tests.py new file mode 100644 index 0000000..d724c7a --- /dev/null +++ b/tests/unit_tests/boolean_function&canalizing_depth_tests.py @@ -0,0 +1,62 @@ +import unittest +import pyximport +pyximport.install() +import numpy as np +from math import * +import sys +sys.path.insert(0, '../../core') +import discrete_dynamical_system as dds +import generate_k_canalyzing as gkc + +def generate_boolean_functions(length): + rows = [] + functionvalues = [] + for j in range(2**length): + rows.append(list([int(i)for i in dds.binary_fixed_length(j,length)])) + functionvalues.append(0) + rows.append(list([int(i)for i in dds.binary_fixed_length(j,length)])) + functionvalues.append(1) + return rows, functionvalues + + +def find_canalizing_depth(table): + depth = 0 + for var in range(len(table)): + new_table = table[var:] + if gkc.is_canalizing(new_table, len(table)-1-var): + depth = depth +1 + if gkc.is_canalizing_function(table[var+1:]) == False: + break + return depth + +class Test(unittest.TestCase): + def setUp(self): + pass + + def test_boolean_functions(self): + n = 10 + (rows, functionvalues) = generate_boolean_functions(n) + + flag = True + + if len(rows) != 2**(2**n): + flag = False + + """ check whether number of boolean functions are correct """ + + self.assertEqual (flag, True) + + def test_find_canalyzing_depth(self): + num_vars = 10 + depth = 5 + + flag = True + table = gkc.random_k_canalyzing(num_vars,depth) + + if find_canalizing_depth(table) != depth: + flag = False + + self.assertEqual (flag, True) + +if __name__ == '__main__': + unittest.main()