When ECJ wants to print an ERC in a fashion that humans find legible
(printing the best individual of a generation to a file, for
example), it calls Individual.printIndividualForHumans, which in turn
calls GPTree.printTreeForHumans on its trees, which in turn call
GPNode.printRootedTreeForHumans, which in turn calls
GPNode.printNodeForHumans on each GPNode. You can override this last
method or use the default form (easier) which simply calls
GPNode.toStringForHumans, which you have overridden.
1. You should override toStringForHumans to provide more meaningful
information. Instead of a hard-coded string <-1...1>, why not print
out the actual value so humans can see it? As in ("" + value) or
2. When you intend to write something that's going to be read back in
again, you should call Individual.printIndividual at the top level,
not Individual.printIndividualForHumans. This will in turn call
GPTree.printTree -> GPNode.printRootedTree -> GPNode.printNode ->
GPNode.toString -> GPNode.encode(). If you've written the encode and
decode code right already, then if you call printIndividual at the
top level you'll get what you're hoping for. Tutorial 3 shows how to
go about reading and writing individuals to a file.
3. If you're just encoding a double, why not just use
ec.app.regression.func.RegERC? It does what you're looking for already.
On Oct 27, 2005, at 7:14 PM, George Coles wrote:
> I may have implemented my ERC incorrectly or incompletely. I have
> an ERC
> called DoubleRange that holds a Double sampled from a range from -1 to
> 1. I added this class to the function set defined in the tutorial4
> params file. I set the "toStringForHumans" method to return
> <-1..1>, and
> overrode the name to be "DoubleRange". I wrote code() and decode()
> the lawnmower ERCs as an example. Here is a typical example of an
> individual's tree expression:
> Tree 0:
> (+ y (+ (- (* (* y x) (+ y <-1...1>)) (*
> (* x x) (+ <-1...1> x))) (- (* (+ x y) (+
> <-1...1> x)) x)))
> Just the name, not the value.
> Sean Luke wrote:
>> ERCs should output their values already. Could you give me an
>> example of an individual that is causing you problems?
>> Other terminals by default only output their name because by default
>> terminals only *have* a name -- no embedded data. But if you have a
>> terminals with embedded information, it's straightforward to write it
>> so that it prints out this information in a readable fashion. But
>> before I get into doing that, riddle me the first question above.
>> On Oct 27, 2005, at 6:30 PM, George Coles wrote:
>>> When reading or saving an individual, is it possible to see the
>>> actual values of ERCs and other terminals that are embedded in the
>>> individual's expression? As opposed to just the name of the ERC or