use of utilities.StatSummary in project SimpleAsteroids by ljialin.
the class TestDiffGame method runTrial.
public static double runTrial(boolean runVisible) {
// make an agent to test
DiffGame.nValues = 21;
DiffGame.minscore = 0;
StateObservationMulti stateObs = new DiffGame();
DefaultMutator.totalRandomChaosMutation = false;
ElapsedCpuTimer timer = new ElapsedCpuTimer();
AbstractMultiPlayer player1, player2;
int idPlayer1 = 0;
int idPlayer2 = 1;
// try the evolutionary players
int nResamples = 10;
EvoAlg evoAlg = new SimpleRMHC(nResamples);
EvoAlg evoAlg2 = new SimpleRMHC(nResamples);
double kExplore = 2;
int nNeighbours = 50;
int nEvals = 1500;
// evoAlg = new NTupleBanditEA(kExplore, nNeighbours);
controllers.multiPlayer.ea.Agent agentEAShift = new controllers.multiPlayer.ea.Agent(stateObs, timer, evoAlg, idPlayer1, nEvals);
agentEAShift.useShiftBuffer = true;
agentEAShift.sequenceLength = 5;
player1 = agentEAShift;
controllers.multiPlayer.ea.Agent agentEANoShift = new controllers.multiPlayer.ea.Agent(stateObs, timer, evoAlg2, idPlayer2, nEvals);
agentEANoShift.useShiftBuffer = true;
agentEANoShift.sequenceLength = 25;
player2 = agentEANoShift;
// player2 = new controllers.multiPlayer.discountOLMCTS.Agent(stateObs, timer, idPlayer2);
// player2 = new controllers.multiPlayer.doNothing.Agent(stateObs, timer, idPlayer2);
// player2 = new controllers.multiPlayer.sampleRandom.Agent(stateObs, timer, idPlayer2);
// player1 = new controllers.multiPlayer.smlrand.Agent();
// EvoAlg evoAlg2 = new SimpleRMHC(1);
// player1 = new controllers.multiPlayer.ea.Agent(linkState, timer, evoAlg2, idPlayer1, nEvals / 5);
// in milliseconds
int thinkingTime = 50;
int delay = 10;
// player = new controllers.singlePlayer.sampleRandom.Agent(stateObs, timer);
// check that we can play the game
Random random = new Random();
int nSteps = 50;
StatSummary sst1 = new StatSummary("Player 1 Elapsed Time");
StatSummary sst2 = new StatSummary("Player 2 Elapsed Time");
StatSummary ssTicks1 = new StatSummary("Player 1 nTicks");
StatSummary ssTicks2 = new StatSummary("Player 2 nTicks");
for (int i = 0; i < nSteps && !stateObs.isGameOver(); i++) {
timer = new ElapsedCpuTimer();
timer.setMaxTimeMillis(thinkingTime);
ElapsedTimer t1 = new ElapsedTimer();
// keep track of the number of game ticks used by each algorithm
int ticks;
ticks = DiffGame.nTicks;
Types.ACTIONS action1 = player1.act(stateObs.copy(), timer);
sst1.add(t1.elapsed());
ticks = DiffGame.nTicks - ticks;
ssTicks1.add(ticks);
System.out.println("Player 1 Ticks = " + ticks);
ElapsedTimer t2 = new ElapsedTimer();
ticks = DiffGame.nTicks;
Types.ACTIONS action2 = player2.act(stateObs.copy(), timer);
sst2.add(t2.elapsed());
ticks = DiffGame.nTicks - ticks;
ssTicks2.add(ticks);
stateObs.advance(new Types.ACTIONS[] { action1, action2 });
// System.out.println(multi.getGameScore());
System.out.println(stateObs);
}
System.out.println(stateObs.getGameScore());
System.out.println(stateObs.isGameOver());
// System.out.println(SingleTreeNode.rollOutScores);
System.out.println(sst1);
System.out.println(sst2);
System.out.println(ssTicks1);
System.out.println(ssTicks2);
return stateObs.getGameScore(0);
}
use of utilities.StatSummary in project SimpleAsteroids by ljialin.
the class HyperParamTuneRunner method runChecks.
public double runChecks(AnnotatedFitnessSpace eval, int[] solution, int nChecks) {
ElapsedTimer timer = new ElapsedTimer();
StatSummary ss = new StatSummary("Mean fitness");
// System.out.println("Running checks: " + nChecks);
for (int i = 0; i < nChecks; i++) {
ss.add(eval.evaluate(solution));
}
// System.out.println(ss);
System.out.println("Checks complete: " + timer.toString());
System.out.println("Solution: " + Arrays.toString(solution));
System.out.println(ss);
System.out.println();
// but also find out the details
return ss.mean();
}
use of utilities.StatSummary 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 utilities.StatSummary in project SimpleAsteroids by ljialin.
the class NTuple method add.
public void add(int[] x, double v) {
// for each address that occurs, we're going to store something
StatSummary ss = getStatsForceCreate(x);
ss.add(v);
nSamples++;
}
use of utilities.StatSummary in project SimpleAsteroids by ljialin.
the class NTuple method printNonEmpty.
public void printNonEmpty(Param[] params) {
for (int i : tuple) {
System.out.println(params[i].getName() + "\t ");
}
System.out.println();
TreeSet<IntArrayPattern> orderedKeys = new TreeSet<>();
orderedKeys.addAll(ntMap.keySet());
for (IntArrayPattern key : orderedKeys) {
StatSummary ss = ntMap.get(key);
System.out.println(key + "\t " + ss.n() + "\t " + ss.mean());
}
}
Aggregations