use of evodef.EvalMaxM in project SimpleAsteroids by ljialin.
the class BanditLandscapeEATest method main.
public static void main(String[] args) {
int nDims = 5;
int mValues = 4;
double noiseLevel = 1.0;
double kExplore = 10;
boolean useTrap = true;
// EvalMaxM is like Noisy OneMax but generalised to M values
// instead of binary
EvalMaxM problem = new EvalMaxM(nDims, mValues, noiseLevel).setTrap(useTrap);
NTupleBanditEA banditEA = new NTupleBanditEA().setKExplore(kExplore);
// set a particlar NTuple System as the model
// if this is not set, then it will use a default model
NTupleSystem model = new NTupleSystem();
// set up a non-standard tuple pattern
model.use1Tuple = true;
model.use2Tuple = false;
model.useNTuple = true;
banditEA.setModel(model);
ElapsedTimer timer = new ElapsedTimer();
int nEvals = 500;
int[] solution = banditEA.runTrial(problem, nEvals);
System.out.println("Report: ");
new NTupleSystemReport().setModel(model).printDetailedReport();
new NTupleSystemReport().setModel(model).printSummaryReport();
System.out.println("Model created: ");
System.out.println(model);
System.out.println("Model used: ");
System.out.println(banditEA.getModel());
System.out.println();
System.out.println("Solution returned: " + Arrays.toString(solution));
System.out.println("Solution fitness: " + problem.trueFitness(solution));
System.out.println("k Explore: " + banditEA.kExplore);
System.out.println(timer);
}
use of evodef.EvalMaxM in project SimpleAsteroids by ljialin.
the class EvoSGATest method runTrial.
public static double runTrial(EvoAlg evoAlg) {
// ok, so the idea here is to modify ...
SimpleGASearchSpace eval = new SimpleGASearchSpace();
System.out.println("Search space size: " + SearchSpaceUtil.size(eval.searchSpace()));
eval.setEvaluator(new EvalMaxM(50, 2, 0.0));
int[] solution = evoAlg.runTrial(eval, 5000);
// int[] solution = {0, 0, 0};
System.out.println("Checking fitness");
StatSummary ss = new StatSummary("Mean fitness");
int nChecks = 50;
for (int i = 0; i < nChecks; i++) {
ss.add(eval.evaluate(solution));
}
System.out.println(ss);
System.out.println("Solution: " + Arrays.toString(solution));
System.out.println(eval.report(solution));
return ss.mean();
}
use of evodef.EvalMaxM in project SimpleAsteroids by ljialin.
the class TestSimpleGA method main.
public static void main(String[] args) {
NoisySolutionEvaluator evaluator = new EvalMaxM(10, 2, 1.0);
EvoAlg evoAlg = new SimpleGA().setPopulationSize(100);
int[] solution = evoAlg.runTrial(evaluator, 10000);
System.out.println(Arrays.toString(solution));
}
use of evodef.EvalMaxM in project SimpleAsteroids by ljialin.
the class TestPlotter method main.
public static void main(String[] args) {
int nDims = 5;
int mValues = 4;
double noiseLevel = 1.0;
double kExplore = 10;
boolean useTrap = true;
// EvalMaxM is like Noisy OneMax but generalised to M values
// instead of binary
EvalMaxM problem = new EvalMaxM(nDims, mValues, noiseLevel).setTrap(useTrap);
NTupleBanditEA banditEA = new NTupleBanditEA().setKExplore(kExplore);
// set a particlar NTuple System as the model
// if this is not set, then it will use a default model
NTupleSystem model = new NTupleSystem();
// set up a non-standard tuple pattern
model.use1Tuple = true;
model.use2Tuple = true;
model.useNTuple = false;
banditEA.setModel(model);
ElapsedTimer timer = new ElapsedTimer();
int nEvals = 200;
int[] solution = banditEA.runTrial(problem, nEvals);
System.out.println(Arrays.toString(solution));
System.out.println(timer);
new Plotter().setModel(model).defaultPlot().plot1Tuples();
System.out.println(timer);
}
use of evodef.EvalMaxM in project SimpleAsteroids by ljialin.
the class PowerOfDifferencePairsTest method main.
// okay this is interesting: the paired idea does not work well when the
// vectors are far apart
// this might have been expected from the way that having the
// sliding history window too big causes deterioration in performance
public static void main(String[] args) {
// create the random vectors, score them
// and put them in a list
// now run an experiment each way to determine the arg max
// and then evaluate the quality of that
ScoredVectorLearner meanLearner = new MeanLearner();
ScoredVectorLearner diffLearner = new PairedDifferenceLearner();
ScoredVectorLearner[] learners = new ScoredVectorLearner[] { meanLearner, diffLearner };
int nTrials = 30;
int n = 100, m = 2;
double noise = 1.0;
NoisySolutionEvaluator evaluator = new EvalMaxM(n, m, noise);
int k = 500;
List<StatSummary> stats = new ArrayList<>();
for (ScoredVectorLearner learner : learners) {
stats.add(new StatSummary(learner.getClass().getSimpleName()));
}
LineChart lineChart = new LineChart();
for (int i = 0; i < nTrials; i++) {
// ProblemInstance problem = new ProblemInstance(n, m, k, evaluator).useRandomVecs();
ProblemInstance problem = new ProblemInstance(n, m, k, evaluator).useVecsAroundRandomPoint();
int ix = 0;
for (ScoredVectorLearner learner : learners) {
System.out.println("Testing: " + learner.getClass().getSimpleName());
int[] p = learner.learn(problem.scoredVecs, problem.evaluator);
// System.out.println(Arrays.toString(p));
System.out.println("True fitness is: " + evaluator.trueFitness(p));
stats.get(ix).add(evaluator.trueFitness(p));
System.out.println();
// now show evolution of fitness
// for (double x : learner.getFitness()) {
// System.out.println(x);
// }
Color color = ix++ % 2 == 0 ? Color.red : Color.blue;
LinePlot linePlot = new LinePlot().setData(learner.getFitness()).setColor(color);
lineChart.addLine(linePlot);
System.out.println(learner.getFitness().length);
}
}
new JEasyFrame(lineChart, "Fitness v. vectors processes");
for (StatSummary ss : stats) System.out.println(ss);
}
Aggregations