示例#1
0
文件: settings.py 项目: zorzr/TSL
 def set_bad_names(self):
     self.bad_names = [""]
     if config.data_config is not None:
         data_col = config.get_datafile().get_data_header()
         labels, _ = config.get_labels_info()
         functions = config.get_functions()
         self.bad_names += data_col + labels + functions
示例#2
0
文件: gui.py 项目: zorzr/TSL
    def update_functions(self):
        self.remove_function.clear()

        for i, func in enumerate(config.get_functions()):
            func_entry = self.remove_function.addAction(func)
            func_entry.triggered.connect(
                make_caller(self.open_function_removal, i))
示例#3
0
文件: datafile.py 项目: zorzr/TSL
    def get_function_columns(self):
        functions = config.get_functions()

        func_col = []
        for i, key in enumerate(self.df):
            if key in functions:
                func_col.append(i)
        return func_col
示例#4
0
文件: datafile.py 项目: zorzr/TSL
    def get_original_columns(self):
        functions = config.get_functions()

        orig_col = []
        for i, key in enumerate(self.df):
            if key not in functions:
                orig_col.append(i)
        return orig_col
示例#5
0
                print("gene{0}:     {1}".format(i, node.getData()))

    def write_result(self, path):
        wd = open(path, 'w')
        for ind in self.p:
            wd.write("fitness:   {0}\n".format(ind.getFitness()))
            wd.write("registers: {0}\n".format(ind.getRegisters()))
            for i, node in enumerate(ind.getGene()):
                wd.write("gene{0}:     {1}\n".format(i, node.getData()))


if __name__ == "__main__":
    from config import get_functions, get_registers, get_constants
    print("..set up functions")
    inputs = [[0, 0], [0, 1], [1, 0], [1, 1]]
    func = get_functions()
    print("..Done!")

    print("..create Population")
    ppl = Population()
    ppl.show()
    print("..Done!")

    print("..create Population")
    constants = get_constants(bit=True)
    n_register = 10
    ppl.createPopulation(functions=func,
                         constants=constants,
                         n_ind=5,
                         n_gene=5,
                         n_register=n_register)
示例#6
0
文件: xor.py 项目: BiggieBoo18/gp
# config
gc.enable()
inputs = [[0, 0], [0, 1], [1, 0], [1, 1]]
revolution = 300
n_register = 3
n_ind = 50
n_gene = 10
elite_size = 3
tourn_size = 3
cross_rate = 0.7
mutate_rate = 0.5
path = "./result/result.txt"

# init
ppl = Population()
functions = get_functions()
constants = get_constants(lower=-10, upper=10, bit=True)
ppl.createPopulation(functions=functions,
                     constants=constants,
                     n_ind=n_ind,
                     n_gene=n_gene,
                     n_register=n_register)
eval_function = lambda x: x[0] ^ x[1]  # xor
ppl.excute_all(inputs, eval_function)

# revolution
p = ProgressBar(0, revolution)
for i in range(revolution):
    #print("revolution: ", i)
    p.update(i + 1)
    elite = Selection.elite(ppl, elite_size)