use of plot.LineChartAxis in project SimpleAsteroids by ljialin.
the class HyperParamTuneRunner method plotConvergence.
private void plotConvergence(EvolutionLogger logger, int[] solution) {
LineChart lineChart = new LineChart().setBG(Color.gray);
lineChart.plotBG = Color.white;
// now the plots we will add are as follows
ArrayList<Double> bestMatches = new ArrayList<>();
ArrayList<Double> bestCumulative = new ArrayList<>();
ArrayList<Double> sampleMatches = new ArrayList<>();
ArrayList<Double> sampleCumulative = new ArrayList<>();
StatSummary cumul = new StatSummary();
for (int[] best : logger.bestYetSolutions) {
double x = match(best, solution);
bestMatches.add(x);
cumul.add(x);
bestCumulative.add(cumul.mean());
}
StatSummary sample = new StatSummary();
for (int[] sol : logger.solutions) {
double x = match(sol, solution);
sampleMatches.add(x);
sample.add(x);
sampleCumulative.add(sample.mean());
}
// LinePlot matchPlot = new LinePlot().
LineGroup lgMatch = new LineGroup().setName("Best Match").setColor(Color.red).add(bestMatches);
LineGroup lgCumul = new LineGroup().setName("Best Cumul").setColor(Color.black).add(bestCumulative);
lineChart.addLineGroup(lgMatch);
lineChart.addLineGroup(lgCumul);
LineGroup lgSampleMatch = new LineGroup().setName("Sample Match").setColor(Color.green).add(sampleMatches);
LineGroup lgSampleCumul = new LineGroup().setName("Sample Cumul").setColor(Color.magenta).add(sampleCumulative);
lineChart.addLineGroup(lgSampleMatch);
lineChart.addLineGroup(lgSampleCumul);
lineChart.setXLabel("Iteration");
lineChart.setYLabel("Candidate == solution");
lineChart.yAxis = new LineChartAxis(new double[] { 0, 1 });
lineChart.xAxis = new LineChartAxis(new double[] { 0, bestMatches.size() / 2, bestMatches.size() });
new JEasyFrame(lineChart, "NTBEA Best Guess Convergence");
}
use of plot.LineChartAxis in project SimpleAsteroids by ljialin.
the class EvolveMarioLevelTest method plotData.
private void plotData(ArrayList<Double> data) {
LineChart lineChart = LineChart.easyPlot(data);
int mid = (data.size() - 1) / 2;
int end = data.size() - 2;
System.out.println("Endpoint: " + end);
lineChart.xAxis = new LineChartAxis(new double[] { 0, mid, end });
StatSummary ss = new StatSummary().add(data);
lineChart.yAxis = new LineChartAxis(new double[] { ss.min(), ss.max() });
lineChart.title = "Evolution of Fitness";
lineChart.setXLabel("Iterations").setYLabel("Fitness");
new JEasyFrame(lineChart, "KL-Based PCG");
}
use of plot.LineChartAxis in project SimpleAsteroids by ljialin.
the class GameActionSpaceAdapterMulti method evaluate.
@Override
public double evaluate(int[] actions) {
// take a copy of the current game state and accumulate the score as we go along
// System.out.println("Checking action length: " + actions.length + " : " + sequenceLength);
// System.out.println("PLayer id: " + playerID);
StateObservationMulti obs = stateObservation.copy();
// note the score now - for normalisation reasons
// we wish to track the change in score, not the absolute score
double initScore = obs.getGameScore(playerID);
double discount = 1.0;
double denom = 0;
double discountedTot = 0;
double total = 0;
// need to do the visual stuff here ...
LinePlot linePlot = null;
if (visual) {
if (lineChart == null) {
lineChart = new LineChart().setBG(Color.gray);
lineChart.xAxis = new LineChartAxis(new double[] { 0, sequenceLength / 2, sequenceLength });
lineChart.yAxis = new LineChartAxis(new double[] { -50, -25, 0, 25, 50 });
lineChart.plotBG = Color.white;
lineChart.setYLabel("Score");
lineChart.setXLabel("Rollout depth");
frame = new JEasyFrame(lineChart, "Score versus depth");
}
float grey = (nEvals % 100) / 150.0f;
// add in a zero for the first element of the plot, since there
// will be zero difference before any action has been taken
linePlot = new LinePlot().setColor(new Color(grey, grey, grey));
// linePlot = new LinePlot().setColor(Color.red);
}
// deltas.add(0);
for (int i = 0; i < actions.length; i++) {
// Note here that we need to look at the advance method which takes multiple players
// hence an array of actions
// the idea is that we'll pad out the
int myAction = actions[i];
int opAction = random.nextInt(obs.getAvailableActions(opponentID).size());
// opAction = AsteroidsGameState.doNothing;
Types.ACTIONS[] acts = new Types.ACTIONS[2];
acts[playerID] = gvgaiActions[myAction];
acts[opponentID] = gvgaiActions[opAction];
for (int k = 0; k < actionRepeat; k++) {
obs.advance(acts);
}
discountedTot += discount * (obs.getGameScore(playerID) - initScore);
if (useHeuristic && obs instanceof SpaceBattleLinkStateTwoPlayer) {
SpaceBattleLinkStateTwoPlayer state = (SpaceBattleLinkStateTwoPlayer) obs;
discountedTot += state.getHeuristicScore();
}
denom += discount;
discount *= discountFactor;
if (linePlot != null) {
// linePlot.add(discountedTot);
double delta = obs.getGameScore((playerID)) - initScore;
linePlot.add(delta);
deltas.add(delta);
}
}
if (visual) {
linePlots.add(linePlot);
}
nEvals++;
double delta;
if (useDiscountFactor) {
delta = discountedTot / denom;
} else {
delta = obs.getGameScore(playerID) - initScore;
}
delta += noiseLevel * random.nextGaussian();
logger.log(delta, actions, false);
return delta;
}
Aggregations