def add_safe(self, name, mat): if self.verbose == 1: return func = Function(name, self.order, self.dimension) func.transform(mat) if func.signature == self.signature: self.add(name)
def setUp(self): self.name = 6 self.func1 = Function(self.name, 2, 4) self.had1 = [] create_had(self.had1, 2, 4) self.wt_vec1 = array('i', []) create_wt_vec(self.wt_vec1, 4) self.func1.transform(self.had1) self.func1.compute_entropy_influence(self.wt_vec1) self.func2 = Function(self.name, 3, 8) self.had2 = [] create_had(self.had2, 3, 8) self.wt_vec2 = array('i', []) create_wt_vec(self.wt_vec2, 8) self.func2.transform(self.had2) self.func2.compute_entropy_influence(self.wt_vec2)
from classes.function import Function from utils.utils import * num_args = 4 dim = 2 ** num_args num_func = 2 ** dim had = [] create_had(had, num_args, dim) wt_vec = array('i', []) create_wt_vec(wt_vec, dim) centre = [] eigs = [] for fI in xrange(num_func): f = Function(fI, num_args, dim) f.transform(had) f.compute_entropy_influence(wt_vec) # if (f.is_eig() == 1): if f.fEntropy == 4.0: centre.append(f) # eigs.append(f) if (f.is_character() == 1): centre.append(f) max_mindist = 0 max_f = Function(0, num_args, dim) for fI in xrange(num_func): f = Function(fI, num_args, dim)
import sys import timeit from array import array from classes.function import Function from classes.eqc import EqCF from utils.utils import * num_args = 4 dim = 2 ** num_args num_func = 2 ** dim wt_by_2 = dim/2 had = [] create_had(had, num_args, dim) wt_vec = array('i', []) create_wt_vec(wt_vec, dim) start_time = timeit.default_timer() curr_dir = os.path.dirname(__file__) parent_dir = os.path.split(curr_dir)[0] data_dir = os.path.join(parent_dir, 'data') fo_balanced = open(os.path.join(data_dir, "balanced_" + str(num_args)), "w") for fI in xrange(num_func): f = Function(fI, num_args, dim) if f.wt != wt_by_2: continue f.transform(had) f.compute_entropy_influence(wt_vec) f.print_info(fo_balanced)
class FunctionTestCase(unittest.TestCase): def setUp(self): self.name = 6 self.func1 = Function(self.name, 2, 4) self.had1 = [] create_had(self.had1, 2, 4) self.wt_vec1 = array('i', []) create_wt_vec(self.wt_vec1, 4) self.func1.transform(self.had1) self.func1.compute_entropy_influence(self.wt_vec1) self.func2 = Function(self.name, 3, 8) self.had2 = [] create_had(self.had2, 3, 8) self.wt_vec2 = array('i', []) create_wt_vec(self.wt_vec2, 8) self.func2.transform(self.had2) self.func2.compute_entropy_influence(self.wt_vec2) def tearDown(self): self.func1 = None self.func2 = None self.had1 = None self.had2 = None def test_degree(self): self.assertEqual(self.func1.deg, 2, 'degree 2 expected, received ' + str(self.func1.deg)) self.assertEqual(self.func2.deg, 3, 'degree 3 expected, received ' + str(self.func2.deg)) def test_signature(self): self.assertEqual(self.func1.signature, '0,0,0,4', 'Wrong signature in case 1: ' + str(self.func1.signature)) self.assertEqual(self.func2.signature, '0,0,0,0,4,4,4,4', 'Wrong signature in case 2: ' + str(self.func2.signature)) def test_ssignature(self): self.assertEqual(self.func1.ssignature, '0,0,0,4', 'Wrong ssignature in case 1: ' + str(self.func1.ssignature)) self.assertEqual(self.func2.ssignature, '-4,0,0,0,0,4,4,4', 'Wrong ssignature in case 2: ' + str(self.func2.ssignature)) def test_entropy(self): self.assertEqual(self.func1.fEntropy, 0, 'Wrong entropy in case 1: ' + str(self.func1.fEntropy)) self.assertEqual(self.func2.fEntropy, 2, 'Wrong entropy in case 2: ' + str(self.func2.fEntropy)) def test_influence(self): self.assertEqual(self.func1.tInf, 2, 'Wrong tInf in case 1: ' + str(self.func1.tInf)) self.assertEqual(self.func2.tInf, 1.5, 'Wrong tInf in case 2: ' + str(self.func2.fEntropy))
had = [] create_had(had, num_args, dim) wt_vec = array('i', []) create_wt_vec(wt_vec, dim) start_time = timeit.default_timer() curr_dir = os.path.dirname(__file__) parent_dir = os.path.split(curr_dir)[0] data_dir = os.path.join(parent_dir, 'data') fo_level3 = open(os.path.join(data_dir, "level3_" + str(num_args)), "w") levels01 = [] num = 0 for fI in xrange(num_func): f = Function(fI, num_args, dim) f.transform(had) f.compute_entropy_influence(wt_vec) if (f.is_bent() == 1) or (f.is_character() == 1): levels01.append(f) num += 1 # f.display_info() print num #print len(levels01) max = 0 max_vecs = [] for fI in xrange(num_func): heartbeat(fI, start_time, 10000)