use of utilities.ElapsedTimer in project SimpleAsteroids by ljialin.
the class SpaceBattleLinkTestTwoPlayer method main.
public static void main(String[] args) {
StatSummary ss = new StatSummary();
int nTrials = 10;
ElapsedTimer t = new ElapsedTimer();
ArrayList<Double> results = new ArrayList<>();
for (int i = 0; i < nTrials; i++) {
double result = runTrial(runVisible);
ss.add(result);
results.add(result);
}
System.out.println(ss);
System.out.println();
System.out.println(results);
System.out.println(t);
}
use of utilities.ElapsedTimer in project SimpleAsteroids by ljialin.
the class TestDiffGame method main.
public static void main(String[] args) {
StatSummary ss = new StatSummary();
int nTrials = 10;
ElapsedTimer t = new ElapsedTimer();
ArrayList<Double> results = new ArrayList<>();
for (int i = 0; i < nTrials; i++) {
double result = runTrial(runVisible);
ss.add(result);
results.add(result);
}
System.out.println(ss);
System.out.println();
System.out.println(results);
System.out.println(t);
}
use of utilities.ElapsedTimer 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.ElapsedTimer 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.ElapsedTimer in project SimpleAsteroids by ljialin.
the class TestSolutionAsteroids method main.
public static void main(String[] args) {
// use this code to re-rest a particular point in the search space
ElapsedTimer timer = new ElapsedTimer();
int[] solution = { 0, 1, 1, 0, 5 };
int nChecks = 10;
new HyperParamTuneRunner().runChecks(new EvoAgentSearchSpaceAsteroids(), solution, nChecks);
System.out.println(timer);
}
Aggregations