def setUp(self): # config and mutation self.config = { "cartesian": { "rows": 4, "columns": 4, "levels_back": 2, "num_inputs": 4, "num_outputs": 4 }, "function_nodes": [{ "type": "FUNCTION", "name": "ADD", "arity": 2 }, { "type": "FUNCTION", "name": "SUB", "arity": 2 }, { "type": "FUNCTION", "name": "MUL", "arity": 2 }, { "type": "FUNCTION", "name": "DIV", "arity": 2 }, { "type": "FUNCTION", "name": "COS", "arity": 1 }, { "type": "FUNCTION", "name": "SIN", "arity": 1 }, { "type": "FUNCTION", "name": "RAD", "arity": 1 }], "mutation": { "methods": ["POINT_MUTATION"], "probability": 1.0 } } self.mutator = CartesianMutation(self.config) # make cartesian self.data = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]] self.chromosome = [[0, 0, 2], [0, 0, 3], [3, 4, 5], [0, 1, 2], [0, 1, 3], [2, 5, 7], [2, 6, 9], [0, 5, 7], [2, 11, 8], [0, 11, 8]] self.output_nodes = [4, 9, 12, 13] self.cartesian = Cartesian(config={}, rows=1, columns=14, levels_back=0, func_nodes=self.chromosome, input_nodes=self.data, output_nodes=self.output_nodes)
def generate_new_cartesian(self): # cartesian details rows = self.config["cartesian"]["rows"] columns = self.config["cartesian"]["columns"] num_inputs = self.config["cartesian"]["num_inputs"] num_outputs = self.config["cartesian"]["num_outputs"] num_funcs = (rows * columns) # function nodes func_nodes = [] for i in range(num_funcs): func_nodes.append(self.gen_random_func_node(i + num_inputs)) # output nodes output_nodes = [] for i in range(num_outputs): output_nodes.append(self.gen_random_output_node()) # input nodes input_nodes = self.prep_input_nodes() # create new cartesian obj return Cartesian( config=self.config, rows=self.config["cartesian"]["rows"], columns=self.config["cartesian"]["columns"], levels_back=self.config["cartesian"]["levels_back"], func_nodes=func_nodes, input_nodes=input_nodes, output_nodes=output_nodes )
def setUp(self): # make cartesian self.data = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]] self.chromosome = [[0, 0, 2], [0, 0, 3], [3, 4, 5], [0, 1, 2], [0, 1, 3], [2, 5, 7], [2, 6, 9], [0, 5, 7], [2, 11, 8], [0, 11, 8]] self.output_nodes = [4, 9, 12, 13] self.cartesian = Cartesian(config={}, rows=1, columns=14, levels_back=0, func_nodes=self.chromosome, input_nodes=self.data, output_nodes=self.output_nodes)
def setUp(self): self.config = { "cartesian": { "rows": 1, "columns": 4, "levels_back": 4, "num_inputs": 12, "num_outputs": 1 }, "input_variables": [{ "type": "INPUT", "name": "x" }, { "type": "CONSTANT", "name": "0.0" }, { "type": "CONSTANT", "name": "1.0" }, { "type": "CONSTANT", "name": "2.0" }, { "type": "CONSTANT", "name": "3.0" }, { "type": "CONSTANT", "name": "4.0" }, { "type": "CONSTANT", "name": "5.0" }, { "type": "CONSTANT", "name": "6.0" }, { "type": "CONSTANT", "name": "7.0" }, { "type": "CONSTANT", "name": "8.0" }, { "type": "CONSTANT", "name": "9.0" }, { "type": "CONSTANT", "name": "10.0" }], "function_nodes": [{ "type": "FUNCTION", "name": "ADD", "arity": 2 }, { "type": "FUNCTION", "name": "SUB", "arity": 2 }, { "type": "FUNCTION", "name": "MUL", "arity": 2 }, { "type": "FUNCTION", "name": "DIV", "arity": 2 }, { "type": "FUNCTION", "name": "SIN", "arity": 1 }, { "type": "FUNCTION", "name": "COS", "arity": 1 }, { "type": "FUNCTION", "name": "RAD", "arity": 1 }], "response_variables": [{ "name": "y" }], "data_file": "../../data/sine.dat", } script_path = os.path.dirname(os.path.realpath(sys.argv[0])) load_data(self.config, script_path) # add constants rows = len(self.config["data"]["y"]) for i in range(11): i = float(i) self.config["data"][str(i) + ".0"] = [i for j in range(rows)] self.functions = [ functions.add_function, functions.sub_function, functions.mul_function, functions.div_function, functions.sin_function, functions.cos_function, functions.rad_function ] self.input_nodes = [ "x", "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "6.0", "7.0", "8.0", "9.0", "10.0" ] self.func_nodes = [ [2, 11, 11], # 12 [6, 0], # 13 [2, 12, 13], # 14 [4, 14], # 15 ] self.output_nodes = [15] self.cartesian = Cartesian(config={}, rows=1, columns=4, levels_back=4, func_nodes=self.func_nodes, input_nodes=self.input_nodes, output_nodes=self.output_nodes)