コード例 #1
0
ファイル: smcgp_test.py プロジェクト: thanos/ecspy
 def test_too_few_outputs(self):
     enc = SMCGPEncoding(2, 1, 1, 2)
     enc.set_functions(io_functions)
     gen = [input_gene(), input_gene(), output_gene(2)]
     input = [5,2]
     func = SMCGPPhenotype(enc, gen)    
     res = func(input)
     
     assert res[0] == input[0]
     assert res[1] == input[1]  
コード例 #2
0
ファイル: smcgp_test.py プロジェクト: thanos/ecspy
 def test_input_output(self):
     enc = SMCGPEncoding(2, 1, 1, 2)
     enc.set_functions(io_functions)
     gen = [input_gene(), input_gene(), output_gene(2), output_gene(2), output_gene(3)]
     
     #gen = list_to_genes([[0,0],[0,0], [2, 2], [2,2], [2,3]])
     input = [5,2]
     func = SMCGPPhenotype(enc, gen)
     #print "funcs", func.functions
     res = func(input)
     assert res[0] == input[0]
     assert res[1] == input[1]
     assert res[2] == input[1]
コード例 #3
0
ファイル: smcgp_test.py プロジェクト: thanos/ecspy
 def test_arithmetics(self):
     def add(gene, a, b):
         
         return a + b
     def sub(gene, a, b):
         return a - b
     enc = SMCGPEncoding(2, 2, 1, 1)
     
     enc.set_functions(io_functions+[add, sub])
     gen1 = [input_gene(),input_gene(), func_gene(3,[2,1]), func_gene(4,[2,1]), output_gene(1)]
     
     #gen1 = list_to_genes([[0,0,0],[0,0,0], [3,2,1], [3,2,2], [4, 2, 1], [2,1,0]])
     func = SMCGPPhenotype(enc, gen1) 
     input = [1,10]
     #(1 + 10) - (10 + 10) 
     res = func(input)
     #print "RES", res
     assert res[0] == -1
コード例 #4
0
ファイル: smcgp_parity_example.py プロジェクト: thanos/ecspy
    wrap("BF3", lambda g,a,b: (a and (not b))or(a and b)), 
    wrap("BF4", lambda g,a,b: (not  a) and b),
    wrap("BF5", lambda g,a,b: ((not a) and b) or (a and b)), 
    wrap("BF6", lambda g,a,b: ((not  a) and b) or (a and (not  b))), 
    wrap("BF7", lambda g,a,b: ((not  a) and b) or (a and not (b)) or (a and b)), 
    wrap("BF8", lambda g,a,b: ((not  a) and (not  b))),
    wrap("BF9", lambda g,a,b: ((not  a) and (not  b)) or (a and b)), 
    wrap("BF10", lambda g,a,b: ((not  a) and (not  b)) or (a and not  (b))), 
    wrap("BF11", lambda g,a,b: ((not a) and (not b) or a and (not b) or a and b)), 
    wrap("BF12", lambda g,a,b: ((not  a) and (not  b) or (not  a) and b)),
    wrap("BF13", lambda g,a,b: ((not a) and (not b) or (not a) and b or a and b)), 
    wrap("BF14", lambda g,a,b: ((not a) and (not b) or (not a) and b or a and (not b))), 
    wrap("BF15", lambda g,a,b: ((not a) and (not b) or (not a) and b or a and (not b) or a and b))
]

enc = SMCGPEncoding(length=25, max_arity=2, levelsback=15, min_outputs=1)
enc.set_functions(io_functions+user_functions+modification_functions.all_functions)


def int2bin(n, count=24):
    """returns the binary of integer n, using count number of digits"""
    return [(n >> y) & 1 for y in range(count-1, -1, -1)]

def get_test_cases(max_bits):
    return [[int2bin(i, bits) for i in xrange(2**bits)] for bits in xrange(2,max_bits+2)]

def get_targets(all_cases):
    return [[not sum(case) % 2 for case in cases] for cases in all_cases]

def select_test_cases(all_cases, all_targets, max_cases=100):
    cases = []
コード例 #5
0
ファイル: smcgp_test.py プロジェクト: thanos/ecspy
 def test_no_inputs(self):
     enc = SMCGPEncoding(2, 1, 1, 2)
     enc.set_functions(io_functions)
     gen = [output_gene(2), output_gene(2)]
     func = SMCGPPhenotype(enc, gen)
     assert func([1,2]) == [1,1] #first node becomes input