1 | /* |
---|
2 | Copyright 2006 by Sean Luke |
---|
3 | Licensed under the Academic Free License version 3.0 |
---|
4 | See the file "LICENSE" for more information |
---|
5 | */ |
---|
6 | |
---|
7 | |
---|
8 | package ec.gp.koza; |
---|
9 | import ec.gp.*; |
---|
10 | import ec.*; |
---|
11 | import ec.util.*; |
---|
12 | |
---|
13 | /* |
---|
14 | * FullBuilder.java |
---|
15 | * |
---|
16 | * Created: Thu Oct 7 18:03:25 1999 |
---|
17 | * By: Sean Luke |
---|
18 | */ |
---|
19 | |
---|
20 | /** |
---|
21 | FullBuilder is a GPNodeBuilder which implements the FULL tree building method described in Koza I/II. |
---|
22 | |
---|
23 | <p>GROW works by choosing a random integer <i>d</i> between minDepth and maxDepth, inclusive. It then grows a full tree of depth <i>d</i>. |
---|
24 | |
---|
25 | <p>Actually, claiming to implement the Koza I/II approach is a bit of a fib -- Koza's original code is somewhat ad-hoc. In the Koza approach, <i>d</i> is chosen in a kind of round-robin fashion rather than at random, if RAMPED HALF/HALF is used. Also, for all three algorithms (RAMPED HALF/HALF, GROW, FULL), the algorithm will not generate a tree consisting of a single terminal, unless forced to. |
---|
26 | |
---|
27 | <p>This implementation instead follows lil-gp's approach, which is to choose <i>d</i> at random from between minDepth and maxDepth, inclusive, and to allow trees consisting of single terminals. |
---|
28 | |
---|
29 | <p>Determining what various algorithms do is a little confusing, mostly because the source code for lil-gp and Koza don't actually quite do what they claim. The table below lists the depth values actually used (counting nodes, rather than edges, for depth). It's probably not what you had expected! |
---|
30 | |
---|
31 | |
---|
32 | <br> |
---|
33 | <br> |
---|
34 | <div align="center"> |
---|
35 | <table border="0" cellspacing="1" cellpadding="2"> |
---|
36 | <tr> |
---|
37 | <td bgcolor="#ffffff"><font size="-1" face="simple,geneva,arial,helvetica" color="#ffffff" ></font><br></td> |
---|
38 | <td bgcolor="#3366cc"><font size="-1" face="simple,geneva,arial,helvetica" color="#ffffff" >Koza I Min</font><br></td> |
---|
39 | <td bgcolor="#3366cc"><font size="-1" face="simple,geneva,arial,helvetica" color="#ffffff" >Koza I Max</font><br></td> |
---|
40 | <td bgcolor="#3366cc"><font size="-1" face="simple,geneva,arial,helvetica" color="#ffffff" >Koza II Min</font><br></td> |
---|
41 | <td bgcolor="#3366cc"><font size="-1" face="simple,geneva,arial,helvetica" color="#ffffff" >Koza II Max</font><br></td> |
---|
42 | <td bgcolor="#3366cc"><font size="-1" face="simple,geneva,arial,helvetica" color="#ffffff" >lil-gp Min</font><br></td> |
---|
43 | <td bgcolor="#3366cc"><font size="-1" face="simple,geneva,arial,helvetica" color="#ffffff" >lil-gp Max</font><br></td> |
---|
44 | <td bgcolor="#3366cc"><font size="-1" face="simple,geneva,arial,helvetica" color="#ffffff" >ECJ Min</font><br></td> |
---|
45 | <td bgcolor="#3366cc"><font size="-1" face="simple,geneva,arial,helvetica" color="#ffffff" >ECJ Max</font><br></td> |
---|
46 | </tr><tr> |
---|
47 | <td bgcolor="#3366cc"><font size="-1" face="simple,geneva,arial,helvetica" color="#ffffff">GROW (mut)</font><br></td> |
---|
48 | <td bgcolor="#cccccc"><font size="-1" face="simple,geneva,arial,helvetica">5</font><br></td> |
---|
49 | <td bgcolor="#cccccc"><font size="-1" face="simple,geneva,arial,helvetica">5</font><br></td> |
---|
50 | <td bgcolor="#cccccc"><font size="-1" face="simple,geneva,arial,helvetica">5</font><br></td> |
---|
51 | <td bgcolor="#cccccc"><font size="-1" face="simple,geneva,arial,helvetica">5</font><br></td> |
---|
52 | <td bgcolor="#cccccc"><font size="-1" face="simple,geneva,arial,helvetica"> </font><br></td> |
---|
53 | <td bgcolor="#cccccc"><font size="-1" face="simple,geneva,arial,helvetica"> </font><br></td> |
---|
54 | <td bgcolor="#cccccc"><font size="-1" face="simple,geneva,arial,helvetica">5</font><br></td> |
---|
55 | <td bgcolor="#cccccc"><font size="-1" face="simple,geneva,arial,helvetica">5</font><br></td> |
---|
56 | <tr></tr> |
---|
57 | <td bgcolor="#3366cc"><font size="-1" face="simple,geneva,arial,helvetica" color="#ffffff">GROW (new)</font><br></td> |
---|
58 | <td bgcolor="#cccccc"><font size="-1" face="simple,geneva,arial,helvetica">7</font><br></td> |
---|
59 | <td bgcolor="#cccccc"><font size="-1" face="simple,geneva,arial,helvetica">7</font><br></td> |
---|
60 | <td bgcolor="#cccccc"><font size="-1" face="simple,geneva,arial,helvetica">6? 7?</font><br></td> |
---|
61 | <td bgcolor="#cccccc"><font size="-1" face="simple,geneva,arial,helvetica">6? 7?</font><br></td> |
---|
62 | <td bgcolor="#cccccc"><font size="-1" face="simple,geneva,arial,helvetica">3</font><br></td> |
---|
63 | <td bgcolor="#cccccc"><font size="-1" face="simple,geneva,arial,helvetica">7</font><br></td> |
---|
64 | <td bgcolor="#cccccc"><font size="-1" face="simple,geneva,arial,helvetica">5</font><br></td> |
---|
65 | <td bgcolor="#cccccc"><font size="-1" face="simple,geneva,arial,helvetica">5</font><br></td> |
---|
66 | <tr></tr> |
---|
67 | <td bgcolor="#3366cc"><font size="-1" face="simple,geneva,arial,helvetica" color="#ffffff">FULL (new)</font><br></td> |
---|
68 | <td bgcolor="#cccccc"><font size="-1" face="simple,geneva,arial,helvetica">7</font><br></td> |
---|
69 | <td bgcolor="#cccccc"><font size="-1" face="simple,geneva,arial,helvetica">7</font><br></td> |
---|
70 | <td bgcolor="#cccccc"><font size="-1" face="simple,geneva,arial,helvetica">6? 7?</font><br></td> |
---|
71 | <td bgcolor="#cccccc"><font size="-1" face="simple,geneva,arial,helvetica">6? 7?</font><br></td> |
---|
72 | <td bgcolor="#cccccc"><font size="-1" face="simple,geneva,arial,helvetica">3</font><br></td> |
---|
73 | <td bgcolor="#cccccc"><font size="-1" face="simple,geneva,arial,helvetica">7</font><br></td> |
---|
74 | <td bgcolor="#cccccc"><font size="-1" face="simple,geneva,arial,helvetica"> </font><br></td> |
---|
75 | <td bgcolor="#cccccc"><font size="-1" face="simple,geneva,arial,helvetica"> </font><br></td> |
---|
76 | <tr></tr> |
---|
77 | <td bgcolor="#3366cc"><font size="-1" face="simple,geneva,arial,helvetica" color="#ffffff">HALF (new)</font><br></td> |
---|
78 | <td bgcolor="#cccccc"><font size="-1" face="simple,geneva,arial,helvetica">2</font><br></td> |
---|
79 | <td bgcolor="#cccccc"><font size="-1" face="simple,geneva,arial,helvetica">6</font><br></td> |
---|
80 | <td bgcolor="#cccccc"><font size="-1" face="simple,geneva,arial,helvetica">2</font><br></td> |
---|
81 | <td bgcolor="#cccccc"><font size="-1" face="simple,geneva,arial,helvetica">5? 6?</font><br></td> |
---|
82 | <td bgcolor="#cccccc"><font size="-1" face="simple,geneva,arial,helvetica">3</font><br></td> |
---|
83 | <td bgcolor="#cccccc"><font size="-1" face="simple,geneva,arial,helvetica">7</font><br></td> |
---|
84 | <td bgcolor="#cccccc"><font size="-1" face="simple,geneva,arial,helvetica">2</font><br></td> |
---|
85 | <td bgcolor="#cccccc"><font size="-1" face="simple,geneva,arial,helvetica">6</font><br></td> |
---|
86 | </tr></table> |
---|
87 | </div> |
---|
88 | <br> |
---|
89 | <br> |
---|
90 | |
---|
91 | The table cell is empty when that parameter is not defined by the system by default. Koza II has two values each because of a possible typo in the text -- while page 656 gives one maximum, page 671 gives another. Note the odd fact that in Koza I/II GROW and FULL have <i>effectively</i> one-deeper tree values than HALF does, even though they use the same code parameters! This is because of a quirk in Koza's code. |
---|
92 | |
---|
93 | <p> This algorithm ignores <tt>requestedSize</tt>, so no pipelines can ask it to grow a tree of a specific fixed size. The algorithm also ignores any user-provided size distributions. |
---|
94 | |
---|
95 | <p><b>Parameters</b><br> |
---|
96 | <table> |
---|
97 | <tr><td valign=top><i>base</i>.<tt>min-depth</tt><br> |
---|
98 | <font size=-1>int >= 1</font></td> |
---|
99 | <td valign=top>(smallest "maximum" depth the builder may use for building a tree. 2 is the default.)</td></tr> |
---|
100 | |
---|
101 | <tr><td valign=top><i>base</i>.<tt>max-depth</tt><br> |
---|
102 | <font size=-1>int >= <i>base</i>.<tt>min-depth</tt></font></td> |
---|
103 | <td valign=top>(largest "maximum" depth the builder may use for building a tree. 6 is the default.)</td></tr> |
---|
104 | </table> |
---|
105 | |
---|
106 | <p><b>Default Base</b><br> |
---|
107 | gp.koza.full |
---|
108 | |
---|
109 | * @author Sean Luke |
---|
110 | * @version 1.0 |
---|
111 | */ |
---|
112 | |
---|
113 | |
---|
114 | |
---|
115 | public class FullBuilder extends KozaBuilder |
---|
116 | { |
---|
117 | public static final String P_FULLBUILDER = "full"; |
---|
118 | |
---|
119 | public Parameter defaultBase() |
---|
120 | { |
---|
121 | return GPKozaDefaults.base().push(P_FULLBUILDER); |
---|
122 | } |
---|
123 | |
---|
124 | public GPNode newRootedTree(final EvolutionState state, |
---|
125 | final GPType type, |
---|
126 | final int thread, |
---|
127 | final GPNodeParent parent, |
---|
128 | final GPFunctionSet set, |
---|
129 | final int argposition, |
---|
130 | final int requestedSize) |
---|
131 | { |
---|
132 | return fullNode(state,0,state.random[thread].nextInt(maxDepth-minDepth+1) + minDepth,type,thread,parent,argposition,set); |
---|
133 | } |
---|
134 | } |
---|