ECJ Quick Help FAQs
- Q: Where/how can I perform pre-execution actions such as setting up my training/testing sets, printing my params to the console, etc?
A) Within your problem implementation file, implement your pre-execution actions in a method with the following signature:
public void setup(final EvolutionState state, final Parameter base)
- Q: Where/how can I evaluate an individuals fitness using my designated fitness function?
A) Within your problem implementation file, implement your fitness calculation algorithm in a method with the following signature:
public void evaluate(final EvolutionState state,
final Individual ind,
final int subpopulation,
final int threadnum)
*Note that ind references the current individual being evaluated.
- Q: Where/how can I perform post-execution actions such as printing out the performance of the best individual on the testing set, printing out a confusion matrix, etc?
A) Within your problem implementation file, implement your post-execution actions in a method with the following signature:
public void describe(EvolutionState state, Individual bestIndividual, int subpopulation, int threadnum, int log)
*Note that bestIndividual
allows one to access the overall best performing individual of the entire run.
- Q: Where/how can I print statistics after each generation such as the population average fitness, etc?
A) Within the file ecj/ec/simple/SimpleStatistics.java, you can calculate and print statistics after each generation in the postEvaluationStatistics
method.
- Q: Where/how can I print statistics after the final generation such as the average population fitness over all generations, etc?
A) Within the file ecj/ec/simple/SimpleStatistics.java, you can calculate and print final statistics in the finalStatistics
method.
Tip: Use the postInitializationStatistics
method to initialize any needed data structures.
- Q: How can I retrieve a parameter value from my .param file into my problem implementation file?
A) state.parameters.getInt(base.push(<name of parameter here>)
*Note that if your parameter was of type double you would use getDouble, etc...
- Q: How can I print a message to the console?
A) state.output.message(String message)
- Q: How can I throw a fatal error to stop program execution?
A) state.output.fatal(String message,Parameter paramCausingError)
- Q: How can I output a warning to the console?
A) state.output.warning(String message,Parameter paramCausingWarning)
- Q: How can I output a message to the output log?
A) state.output.println(String message,int log)
- Q: Where do I modify the elitism parameter?
A) ecj/ec/simple/simple.params
- Q: Where do I modify parameters such as crossover rate, mutation rate, max tree depth, tournament selection size, etc?
A) ecj/ec/simple/koza.params, assuming you are using koza GP.
- Q: Where do I create my own runtime parameters and modify the function set to use?
A) Params files are created in a separate directory from the problem: resources/ec/app/myProblem/myProblem.params .
This is because maven uses the resources folder for building.
- Q: Can I modify parameters without modifying the defaults?
A) Yes, you can edit them in your own .params file. This will leave the defaults alone (e.g. /ecj/ec/simple/simple.params can be left untouched).
- Q: Do I need to recompile after changing a .params file?
A) If you want to make changes to the .params file without recompiling, you have to go to:
target/classes/ec/app/myProblem/myProblem.params
which is where the class files are after compiling.
Any changes in the target/classes don't change the resources files so if you changed the target/classes .params and then recompile, it will use the .params file in the resources directory.
- Q: Can I modify parameters on a command line, say, while working in a Linux shell?
A) Yes. Add this to your command line: -p param1 param2...
So for example, adding this will add a seed and new max generation to your run: -p seed.0=1, generation=50
Back to COSC 5P71 home