use of utilities.JEasyFrame in project SimpleAsteroids by ljialin.
the class OneMaxVisual method run.
public Integer run(int nEvals) {
view = new BitView(bestYet);
frame = new JEasyFrame(view, "One Max Test");
for (int i = 1; i <= nEvals; i++) {
// randomly mutate the best yet
int[] mut = randMut(bestYet);
view.v = mut;
int test = countOnes(mut);
// frame.setTitle(i + " : " + countOnes(mut));
view.repaint();
delay();
// if it's better then adopt the mutation as the new best
if (countOnes(mut) + noise * random.nextGaussian() >= countOnes(bestYet) + noise * random.nextGaussian()) {
bestYet = mut;
}
frame.setTitle(i + " : " + countOnes(bestYet) + " : " + test);
// System.out.println(Arrays.toString(bestYet));
if (countOnes(bestYet) == bestYet.length) {
// return how many evals it took to reach perfection
return i;
}
System.out.println(Arrays.toString(bestYet));
}
// failed to find a solution
return null;
}
use of utilities.JEasyFrame in project SimpleAsteroids by ljialin.
the class SimpleRandomTest method main.
public static void main(String[] args) throws Exception {
GameState game = new GameState().setNPlanets(10).setRandomOwnerships().setRandomGrowthRates();
PlanetWarView view = new PlanetWarView(game);
JEasyFrame frame = new JEasyFrame(view, "Test View");
KeyController controller = new KeyController();
frame.addKeyListener(controller);
// now p;ay
Random random = new Random();
for (int i = 0; i < 1000; i++) {
int p1 = random.nextInt(GameState.nActions);
p1 = controller.action(game);
int p2 = random.nextInt(GameState.nActions);
int[] a = new int[] { p1, p2 };
game.next(a);
// game.update();
view.update(game);
Thread.sleep(100);
}
}
use of utilities.JEasyFrame in project SimpleAsteroids by ljialin.
the class TwoPlayerTest method main.
public static void main(String[] args) throws Exception {
// AsteroidsGameState game = new AsteroidsGameState().setNPlanets(10).setRandomOwnerships().setRandomGrowthRates();
// .setNPlanets(10).setDOwnerships().setRandomGrowthRates();
GameState game = new GameState().defaultState();
GameState.includeBuffersInScore = true;
GameState.wrapAround = false;
PlanetWarView view = new PlanetWarView(game);
JEasyFrame frame = new JEasyFrame(view, "Test View");
KeyController controller = new KeyController();
frame.addKeyListener(controller);
int nResamples = 1;
EvoAlg evoAlg = new SimpleRMHC(nResamples);
int nEvals = 100;
int seqLength = 20;
// evoAlg = new SlidingMeanEDA().setHistoryLength(20);
System.out.println("Initial score: " + game.getScore());
EvoAgent evoAgent = new EvoAgent().setEvoAlg(evoAlg, nEvals).setSequenceLength(seqLength);
evoAgent.setUseShiftBuffer(true);
evoAgent.setVisual();
int delay = 2000;
GameActionSpaceAdapterMulti.visual = true;
Random random = new Random();
for (int i = 0; i < 500; i++) {
int p1, p2;
p1 = evoAgent.getAction(game, 0);
// p1 = random.nextInt(AsteroidsGameState.nActions);
p2 = controller.action(game);
// p2 = AsteroidsGameState.doNothing;
int[] a = new int[] { p1, p2 };
game.next(a);
// game.update();
view.update(game);
Thread.sleep(delay);
}
}
use of utilities.JEasyFrame in project SimpleAsteroids by ljialin.
the class ScatterPlot method main.
public static void main(String[] args) {
Random random = new Random();
ScatterPlot scatterPlot = new ScatterPlot().setTitle("Gaussian Test");
for (int i = 0; i < 50; i++) {
scatterPlot.addPoint(new DataPoint(String.format("%d", i), random.nextGaussian(), random.nextGaussian()));
}
LineChart lineChart = new LineChart(new Dimension(800, 800)).setTitle(scatterPlot.title);
// now add the scatterPlot
lineChart.xAxis = new LineChartAxis(new double[] { -4, -2, 0, 2, 4 });
// lineChart.yAxis = new LineChartAxis(new double[]{40, 50, 60, 70, 80, 90, 100});
//
lineChart.yAxis = new LineChartAxis(new double[] { -4, -2, 0, 2, 4 });
lineChart.setScatterPlot(scatterPlot);
new JEasyFrame(lineChart, "Scatter Test");
}
use of utilities.JEasyFrame in project SimpleAsteroids by ljialin.
the class OptimalResampleTest method visualise.
public static void visualise(int nBits, int k) {
int nIterationsMax = 100000;
RMHCOneMaxProbabilityDiffuser diffuser = new RMHCOneMaxProbabilityDiffuser(nBits);
double resampled = noiseStdDev / Math.sqrt(k);
GaussTable gaussTable = new GaussTable();
double pCorrect = gaussTable.erf(1 / resampled);
double pErr = 1 - pCorrect;
// use this of we need to keep stats later
Integer iterationsNeeded = null;
// diffuser.
String title = "P Mass Diffusion, nEvals: ";
BarChart bc = new BarChart(new Dimension(640, 480), diffuser.p);
JEasyFrame frame = new JEasyFrame(bc, title);
for (int i = 0; i < nIterationsMax; i++) {
// System.out.println(i);
// diffuser.updateStandard(false);
bc.update(diffuser.p);
frame.setTitle(title + (i * k));
diffuser.updateNoisy(false, pErr);
try {
Thread.sleep(50);
} catch (Exception e) {
}
;
if (diffuser.pSolved() >= 0.5) {
return;
// iterationsNeeded = i;
// System.out.println("K = " + k);
// System.out.println("nBits = " + nBits );
// System.out.println("Solved in iterations: " + i);
// System.out.println("Fitness evals: " + i * k);
}
}
}
Aggregations