• No results found

Node Mutation

In document Evolving Graphs by Graph Programming (Page 129-132)

5.3 Mutation

5.3.2 Node Mutation

Node mutation in EGGP consists of 4 steps:

1. Pick a function node to mutate uniformly at random.

2. Mutate the function node, associating it with some new function from the function set. 3. Correct the arity of the function node. Either:

a) If the outdegree of the function node is less than the new function’s arity, identify all nodes for which there is a path from that node to the mutated node. Add new edges to nodes for which there is no such path until the outdegree matches the new function’s arity.

b) If the outdegree of the function node is greater than the new function’s arity, delete edges until the outdegree matches the new function’s arity.

Main := [pick_node]; [mutate_node_f1, . . . , mutate_node_fk]; mark_output!; [add_edge]!; [delete_edge]!; store_edge!; [order_edge]!; clean_node; unmark_node!

pick_node(s:string; a:list) s:a

1

s:a

1

where s != "INPUT" and s != "OUTPUT" mark_output(a,b,c:list) a 1 c 2 b a 1 c 2 b

add_edge(a,b:list; x:int; s:string) a:x

1 s:b 2

a:x

1 s:b 2

where outdeg(1) < x and s!="OUTPUT"

delete_edge(a,b,c:list; x:int) a:x 1 c 2 b a:x 1 c 2 where outdeg(1) > x store_edge(a,b,c:list) a 1 c 2 b a 1 c 2 order_edge(a,b,c:list) a:x 1 c 2 a:x-1 1 c 2 x-1 clean_node(a:list; x:int) a:x 1 a 1 unmark_node(a:list) a 1 a 1

Figure 5.9: A program for mutating a function node in an AFG. For each function in our func- tion set, we have a rule mutate_node_fx, which is visualised in Figure 5.10. This mutation respects arity and acyclicity, and shuffles the mutated node’s outgoing edges.

This process is implemented by the P-GP 2 program shown in Figure 5.9. An overview of this program is:

1. [pick_node]. This rule call selects a function node to mutate uniformly at random and marks that node red. By the rule’s condition, the selected node cannot be an input or output node.

2. [mutate_node_f1, . . . , mutate_node_fk]. For each function fx in our set of functions

F = {f1, . . . , fk}, we have a unique rule mutate_node_fx in our probabilistically called

mutate_node_fx(s:string; a:list) s:a 1 p(fx):a(fx) 1 where s!=p(fx)

Figure 5.10: When we construct a mutation program such as the one shown in Figure 5.9, we generate a rule mutate_node_fx for each function fx ∈ F where F is the

function set, a is the arity function and p is the naming function. A red marked node is relabelled with the name and arity of the function fx.

of the corresponding function. The general model of these rules is shown in Figure 5.10. The mutated node remains marked red. The result of this command is that the chosen function node is mutated to be associated with some other function. The condition of each rule guarantees that the new function is different from the previous function. 3. mark_output!. It may be necessary to add new outgoing edges to the mutated node to

ensure that its outdegree matches its arity. In the same manner as in edge mutation, we call a rule mark_output which iteratively marks every node with a path to the mutated node blue. We can then safely insert edges from the mutated node to unmarked nodes in the knowledge that this will not introduce a cycle.

4. [add_edge]!. This rule adds edges at random from the red marked mutated node to unmarked nodes. The condition guarantees that the rule is called as long as possible while new edges need to be added to make the outdegree match the arity. The newly created edges are unlabelled, as their labels will be assigned when edges are shuffled. 5. [delete_edge]!. This rule deletes at random from the red marked mutated node.

The condition guarantees that the rule is called as long as possible while edges need to be deleted to make the outdegree match the arity.

6. store_edge!. This rule marks edges from the red marked mutated node to unmarked nodes red and removes their labels. By calling this rule as long as possible, we are constructing an ordered set of the mutated nodes outgoing edges as the first stage in shuffling them with respect to ordering indices.

7. [order_edge]!. This rule unmarks red marked edges from the red marked mutated node to unmarked nodes and labels them with the function node’s integer label minus 1. At the same time the function node’s integer label is decremented by 1. By prob-

mutate_node_and(s:string; a:list)

s:a

1 "AND":2 1

where s!="AND"

Figure 5.11: An instantiation of the node mutation rule shown in Figure 5.10 with fx= ∧ =

and, a(fx) = 2 and p(fx) = "AND".

abilistically calling this rule as long as possible, the result is that the mutated node’s outgoing edges are assigned an order at random.

8. clean_node. This rule unmarked the red mutated node and removes the integer com- ponent of its label. This returns the mutated node to a normal function node state. 9. unmark_node!. This rule removes blue marks from the graph, reversing the marking

effect of the mark_output! call.

As a clarifying visual, we give an instantiation of the node mutation rule shown in Figure 5.10 with fx= ∧ = and, a(fx) = 2 and p(fx) = "AND", shown in Figure 5.11.

We give an example execution of our mutation in Figure 5.12. In this diagram, most node and edge labels are not shown to aid visual clarity. A function node associated with a negation function ¬ is relabelled to be associated with a AND function ∧. An edge is inserted to respect the new node’s arity while preserving acylicity, and the node’s outgoing edges are shuffled to a random order. The correctness of node mutation with respect to acylicity follows as an extension of the correctness of edge mutation described in Section 5.3.1. The correctness with respect to arity is straightforwardly seen in the semantics of our program with the rules add_edge and delete_edge and does not therefore require an extended proof.

In document Evolving Graphs by Graph Programming (Page 129-132)