use of utilities.JEasyFrame 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 utilities.JEasyFrame in project SimpleAsteroids by ljialin.
the class SortedBernoulliTest method main.
public static void main(String[] args) {
LineChart lineChart = new LineChart();
LinePlot linePlot = new LinePlot();
LineGroup lineGroup = new LineGroup();
int nTrials = 100;
int nGroups = 288;
double pWin = 0.5;
ArrayList<StatSummary> stats = new ArrayList<>();
for (int i = 0; i < nGroups; i++) {
StatSummary ss = new StatSummary();
stats.add(ss);
for (int j = 0; j < nTrials; j++) {
int result = Math.random() < pWin ? 1 : -1;
ss.add(result);
}
}
Collections.sort(stats);
lineGroup.stats = stats;
lineChart.addLineGroup(lineGroup);
lineChart.bg = Color.gray;
lineChart.plotBG = Color.white;
lineChart.setTitle("Sorted Coin Toss Trials, n=100, p=0.5, error bars 1 std-err");
lineChart.setYLabel("Fitness");
lineChart.setXLabel("Trial");
lineChart.stdErrs = 1.0;
lineChart.xAxis = new LineChartAxis(new double[] { 0, 144, 288 });
lineChart.yAxis = new LineChartAxis(new double[] { -1, 0, 0.8 });
new JEasyFrame(lineChart, "Coin toss");
}
use of utilities.JEasyFrame in project SimpleAsteroids by ljialin.
the class SimpleBattleTest method main.
public static void main(String[] args) {
int nSteps = (int) 2e3;
int nPlayers = 2;
int[] actions = new int[nPlayers];
Random rand = new Random();
SimpleBattleState state = new SimpleBattleState();
state = state.copyState();
StatSummary[] scoreStats = new StatSummary[] { new StatSummary(), new StatSummary() };
ElapsedTimer t = new ElapsedTimer();
BattleView view = new BattleView(state);
if (view != null) {
new JEasyFrame(view, "Simple Battle Game");
}
for (int i = 0; i < nSteps; i++) {
for (int j = 0; j < nPlayers; j++) {
actions[j] = rand.nextInt(state.nActions());
}
// now advance the game to the next step
state.next(actions);
for (int j = 0; j < state.score.length; j++) {
scoreStats[j].add(state.score[j]);
}
if (view != null) {
view.repaint();
try {
Thread.sleep(delay);
} catch (Exception e) {
}
}
}
for (int i = 0; i < scoreStats.length; i++) {
System.out.println("Player: " + i);
System.out.println(scoreStats[i]);
System.out.println();
}
System.out.println(t);
System.out.println();
System.out.println(nSteps + " states written");
}
use of utilities.JEasyFrame in project SimpleAsteroids by ljialin.
the class GameActionSpaceAdapter method plot.
public void plot() {
System.out.println("in plot? " + linePlots == null);
if (linePlots != null) {
LineChart lineChart = new LineChart().setBG(Color.blue);
lineChart.addLines(linePlots);
new JEasyFrame(lineChart, "Evo Plots");
}
}
use of utilities.JEasyFrame in project SimpleAsteroids by ljialin.
the class MazeView method main.
public static void main(String[] args) {
int n = 400;
int[] bits = new int[n];
Random random = new Random();
for (int i = 0; i < n; i++) {
bits[i] = random.nextInt(2);
}
MazeView mazeView = new MazeView(bits);
new JEasyFrame(mazeView, "Maze Test");
MazeModel mazeModel = new MazeModel(bits);
Graph graph = new GraphBuilder().buildGraph(mazeModel);
System.out.println(graph.getArcs());
System.out.println("Finding shortest path:");
Vertex from = new Vertex(0, 0);
Vertex to = new Vertex(2, 2);
System.out.println(new ShortestPath().runShortestPath(graph, from, to));
}
Aggregations