use of evodef.SolutionEvaluator in project SimpleAsteroids by ljialin.
the class EvolveMarioLevelTest method runTrial.
// this should really take any type of EA, but at the moment it
// is restricted to the SimpleRMHC to allow a bespoke mutation operator
// to be plugged in
public double runTrial(SimpleRMHC ea, int nEvals, int[][] sample) {
int nDims = imageWidth * imageHeight;
int mValues = distinctValues(sample);
System.out.println("Distinct values = " + mValues);
ConvNTuple convNTuple = getTrainedConvNTuple(sample, mValues);
System.out.println("nSamples: " + convNTuple.nSamples());
// set the "clever" mutation operator
ea.setMutator(new ConvMutator().setConvNTuple(convNTuple).setForceBorder(true));
if (useInitialSeed) {
ea.setInitialSeed(generateSeed(sample));
}
SolutionEvaluator evaluator = new EvalConvNTuple(nDims, mValues).setConvNTuple(convNTuple);
SolutionEvaluator trainingEvaluator = new EvalConvNTuple(nDims, mValues).setConvNTuple(convNTuple);
double fitnessFull = trainingEvaluator.evaluate(flatten(sample));
String labelFull = String.format("Full Width Training Sample: %.6f", fitnessFull);
LevelView.showMaze(flatten(sample), sample.length, sample[0].length, labelFull, tileColors);
showSamples(sample, trainingEvaluator);
evaluator.logger().setListener(this);
int[] solution = ea.runTrial(evaluator, nEvals);
// can set entire solution to the most likely individual
// solution = setAll(solution, 2);
double fitness = evaluator.evaluate(solution);
String label = String.format("Fitness: %.6f", fitness);
// solution = flatten(toRect())
plotData(evaluator.logger().fa);
LevelView.showMaze(solution, imageWidth, imageHeight, label, tileColors);
return fitness;
}
use of evodef.SolutionEvaluator in project SimpleAsteroids by ljialin.
the class EvolvePatternTest method runTrial.
public double runTrial(SimpleRMHC ea, int nEvals) {
ConvNTuple convNTuple = getTrainedConvNTuple();
ea.setMutator(new ConvMutator().setConvNTuple(convNTuple));
int nDims = imageWidth * imageHeight;
int mValues = 3;
SolutionEvaluator evaluator = new EvalConvNTuple(nDims, mValues).setConvNTuple(convNTuple);
int[] solution = ea.runTrial(evaluator, nEvals);
double fitness = evaluator.evaluate(solution);
String label = String.format("Fitness: %.6f", fitness);
System.out.println(label);
System.out.println(Arrays.toString(solution));
LevelView.showMaze(solution, imageWidth, imageHeight, label);
new JEasyFrame(LineChart.easyPlot(evaluator.logger().fa), "Evolution of Fitness");
return fitness;
}
use of evodef.SolutionEvaluator in project SimpleAsteroids by ljialin.
the class EvoNTupleTest method main.
public static void main(String[] args) {
// the number of bandits is equal to the size of the array
int nDims = 5;
int nTrials = 50;
int nFitnessEvals = 10000;
EvoAlg ea = new MBanditEA();
ea = new SimpleRMHC();
SolutionEvaluator evaluator = new TenFitnessEval(nDims);
System.out.println("Best fitness stats:");
System.out.println(runTrials(ea, evaluator, nTrials, nFitnessEvals));
// evaluator.
}
Aggregations