From eaf6ed81482406c6ec7b88fc83b140b88a2052ca Mon Sep 17 00:00:00 2001
From: JKigotthisbro <63543399+JKigotthisbro@users.noreply.github.com>
Date: Tue, 4 Aug 2020 16:38:18 +0900
Subject: [PATCH 1/2] canalyzing depth & boolean functions
---
.idea/.gitignore | 3 +++
.idea/Canalizing-Depth-Dynamics.iml | 11 ++++++++++
.../inspectionProfiles/profiles_settings.xml | 6 +++++
.idea/misc.xml | 4 ++++
.idea/modules.xml | 8 +++++++
.idea/vcs.xml | 6 +++++
core/discrete_dynamical_system.pyx | 22 ++++++++++++++++++-
core/find_attractors.pyx | 1 +
core/generate_k_canalyzing.py | 3 +++
core/optimized_find_attractors.pyx | 1 +
core/random_noncanalysing.py | 21 ++++++++++++++++++
11 files changed, 85 insertions(+), 1 deletion(-)
create mode 100644 .idea/.gitignore
create mode 100644 .idea/Canalizing-Depth-Dynamics.iml
create mode 100644 .idea/inspectionProfiles/profiles_settings.xml
create mode 100644 .idea/misc.xml
create mode 100644 .idea/modules.xml
create mode 100644 .idea/vcs.xml
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..0c3a9e4 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,23 @@ 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 = [] """rows"""
+ functionvalues = [] """ values"""
+ 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..c4ca815 100644
--- a/core/random_noncanalysing.py
+++ b/core/random_noncanalysing.py
@@ -95,6 +95,27 @@ def is_canalizing(table, var):
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.
From bfec9c9b2295dff6e7c713b29ca59706baf9ea0f Mon Sep 17 00:00:00 2001
From: JKigotthisbro <63543399+JKigotthisbro@users.noreply.github.com>
Date: Mon, 31 Aug 2020 20:36:50 +0900
Subject: [PATCH 2/2] tests
---
core/discrete_dynamical_system.pyx | 10 ++-
core/random_noncanalysing.py | 2 +-
...boolean_function&canalizing_depth_tests.py | 62 +++++++++++++++++++
3 files changed, 67 insertions(+), 7 deletions(-)
create mode 100644 tests/unit_tests/boolean_function&canalizing_depth_tests.py
diff --git a/core/discrete_dynamical_system.pyx b/core/discrete_dynamical_system.pyx
index 0c3a9e4..76a9baf 100644
--- a/core/discrete_dynamical_system.pyx
+++ b/core/discrete_dynamical_system.pyx
@@ -89,14 +89,12 @@ class Dynamical(object):
def generate_boolean_functions(length):
- rows = [] """rows"""
- functionvalues = [] """ values"""
+ rows = []
+ functionvalues = []
for j in range(2**length):
- rows.append(list(
- [int(i)for i in binary_fixed_length(j,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)]))
+ 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 """
diff --git a/core/random_noncanalysing.py b/core/random_noncanalysing.py
index c4ca815..6677db9 100644
--- a/core/random_noncanalysing.py
+++ b/core/random_noncanalysing.py
@@ -88,7 +88,7 @@ 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:
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()