Search in sources :

Example 1 with ConvMutator

use of ntuple.operator.ConvMutator 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;
}
Also used : SolutionEvaluator(evodef.SolutionEvaluator) ConvMutator(ntuple.operator.ConvMutator) ConvNTuple(ntuple.ConvNTuple)

Example 2 with ConvMutator

use of ntuple.operator.ConvMutator 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;
}
Also used : SolutionEvaluator(evodef.SolutionEvaluator) ConvMutator(ntuple.operator.ConvMutator) JEasyFrame(utilities.JEasyFrame) ConvNTuple(ntuple.ConvNTuple)

Example 3 with ConvMutator

use of ntuple.operator.ConvMutator in project SimpleAsteroids by ljialin.

the class EvolvePatternTest method main.

public static void main(String[] args) {
    int nTrials = 1;
    SimpleRMHC evoAlg = new SimpleRMHC();
    evoAlg.setMutator(new ConvMutator());
    // evoAlg = new SlidingMeanEDA().setHistoryLength(30);
    // evoAlg = new CompactSlidingGA();
    int nEvals = 50000;
    StatSummary results = new StatSummary();
    EvolvePatternTest ept = new EvolvePatternTest();
    for (int i = 0; i < nTrials; i++) {
        ElapsedTimer timer = new ElapsedTimer();
        results.add(ept.runTrial(evoAlg, nEvals));
        System.out.println(timer);
    }
}
Also used : StatSummary(utilities.StatSummary) ConvMutator(ntuple.operator.ConvMutator) SimpleRMHC(ga.SimpleRMHC) ElapsedTimer(utilities.ElapsedTimer)

Aggregations

ConvMutator (ntuple.operator.ConvMutator)3 SolutionEvaluator (evodef.SolutionEvaluator)2 ConvNTuple (ntuple.ConvNTuple)2 SimpleRMHC (ga.SimpleRMHC)1 ElapsedTimer (utilities.ElapsedTimer)1 JEasyFrame (utilities.JEasyFrame)1 StatSummary (utilities.StatSummary)1