use of utilities.ElapsedTimer in project SimpleAsteroids by ljialin.
the class OneMaxTest method main.
public static void main(String[] args) {
int minDim = 10;
int maxDim = 10;
int step = 10;
int nReps = 100;
ElapsedTimer t = new ElapsedTimer();
ArrayList<Double> means = new ArrayList<>();
System.out.println("N Samples per Fitness Eval = " + nVirtualSamples);
for (int i = minDim; i <= maxDim; i += step) {
// see how well actual evals matches prediction
StatSummary ss = new StatSummary();
for (int j = 0; j < nReps; j++) {
Integer nEvals = runTest(i);
if (nEvals != null)
ss.add(nEvals * nVirtualSamples);
}
System.out.println(ss);
means.add(ss.mean());
System.out.println(i + "\t " + ss.mean() + "\t " + predictNEvals(i));
}
System.out.println(t);
BarChart.display(means, "OneMax Scaling");
}
use of utilities.ElapsedTimer in project SimpleAsteroids by ljialin.
the class OneMaxTestResampled method main.
public static void main(String[] args) {
int minDim = 100;
int maxDim = 100;
int step = 10;
int nReps = 100;
ElapsedTimer t = new ElapsedTimer();
ArrayList<Double> means = new ArrayList<>();
System.out.println("N Samples per Fitness Eval = " + nActualSamples);
for (int i = minDim; i <= maxDim; i += step) {
// see how well actual evals matches prediction
StatSummary ss = new StatSummary();
for (int j = 0; j < nReps; j++) {
Integer nEvals = runTest(i);
if (nEvals != null)
ss.add(nEvals);
}
System.out.println(ss);
means.add(ss.mean());
System.out.println(i + "\t " + ss.mean() + "\t " + predictNEvals(i));
}
System.out.println(t);
BarChart.display(means, "OneMax Scaling");
}
use of utilities.ElapsedTimer in project SimpleAsteroids by ljialin.
the class AsteroidsSimpleTest method runOnce.
public static double runOnce() throws Exception {
AsteroidsLinkState stateObs = new AsteroidsLinkState();
ElapsedCpuTimer timer = new ElapsedCpuTimer();
AbstractPlayer player = new controllers.singlePlayer.discountOLMCTS.Agent(stateObs, timer);
int depth = 100;
int ticks = 2000;
SingleTreeNode.DEFAULT_ROLLOUT_DEPTH = depth;
SingleTreeNode.scoreDiscountFactor = 0.999;
SingleTreeNode.useScoreDiscount = true;
SingleTreeNode.DEFAULT_ROLLOUT_DEPTH = depth;
controllers.singlePlayer.discountOLMCTS.Agent.MCTS_ITERATIONS = ticks / depth;
// in milliseconds
int thinkingTime = 10;
int delay = 20;
int nSteps = 1000;
ElapsedTimer t = new ElapsedTimer();
View view = new View(stateObs.state);
// set view to null to run fast with no visuals
view = null;
JEasyFrame frame;
if (view != null) {
frame = new JEasyFrame(view, "Asteroids");
}
for (int i = 0; i < nSteps && !stateObs.isGameOver(); i++) {
timer = new ElapsedCpuTimer();
timer.setMaxTimeMillis(thinkingTime);
Types.ACTIONS action = player.act(stateObs.copy(), timer);
stateObs.advance(action);
if (view != null) {
view.repaint();
Thread.sleep(delay);
}
}
System.out.println(stateObs.getGameScore());
System.out.println(stateObs.isGameOver());
System.out.println(t);
System.out.println("Agent of type: " + player.getClass().getSimpleName());
return stateObs.getGameScore();
}
use of utilities.ElapsedTimer in project SimpleAsteroids by ljialin.
the class AsteroidsTest method runOnce.
public static double runOnce() throws Exception {
// make an agent to test
// AsteroidsLinkState.defaultStartLevel = 1;
AsteroidsLinkState stateObs = new AsteroidsLinkState();
System.out.println(stateObs.getGameScore());
System.out.println(stateObs.copy().getGameScore());
ElapsedCpuTimer timer = new ElapsedCpuTimer();
AbstractPlayer player;
controllers.singlePlayer.sampleOLMCTS.Agent olmcts = new controllers.singlePlayer.sampleOLMCTS.Agent(stateObs, timer);
controllers.singlePlayer.discountOLMCTS.Agent discountOlmcts = new controllers.singlePlayer.discountOLMCTS.Agent(stateObs, timer);
controllers.singlePlayer.nestedMC.Agent nestedMC = new controllers.singlePlayer.nestedMC.Agent(stateObs, timer);
int depth = 100;
int ticks = 2000;
controllers.singlePlayer.discountOLMCTS.SingleTreeNode.DEFAULT_ROLLOUT_DEPTH = depth;
SingleTreeNode.scoreDiscountFactor = 0.999;
SingleTreeNode.useScoreDiscount = true;
controllers.singlePlayer.discountOLMCTS.SingleTreeNode.DEFAULT_ROLLOUT_DEPTH = depth;
controllers.singlePlayer.discountOLMCTS.Agent.MCTS_ITERATIONS = ticks / depth;
// player = olmcts;
player = discountOlmcts;
int nResamples = 1;
EvoAlg evoAlg = new SimpleRMHC(nResamples);
int nEvals = 20;
double kExplore = 10;
int nNeighbours = 100;
// evoAlg = new NTupleBanditEA(kExplore, nNeighbours);
// evoAlg = new SlidingMeanEDA();
DefaultMutator.totalRandomChaosMutation = true;
Agent.useShiftBuffer = true;
controllers.singlePlayer.ea.Agent.SEQUENCE_LENGTH = ticks / nEvals;
player = new controllers.singlePlayer.ea.Agent(stateObs, timer, evoAlg, nEvals);
// player = new controllers.singlePlayer.ea.Agent(stateObs, timer);
// nestedMC.maxRolloutLength = 5;
// nestedMC.nestDepth = 5;
// player = nestedMC;
// in milliseconds
int thinkingTime = 10;
int delay = 20;
// player = new controllers.singlePlayer.sampleRandom.Agent(stateObs, timer);
// check that we can play the game
Random random = new Random();
// this is how many steps we'll take in the actual game ...
int nSteps = 1000;
ElapsedTimer t = new ElapsedTimer();
View view = new View(stateObs.state);
// set view to null to run fast with no visuals
view = null;
JEasyFrame frame;
if (view != null) {
frame = new JEasyFrame(view, "Asteroids");
}
for (int i = 0; i < nSteps && !stateObs.isGameOver(); i++) {
timer = new ElapsedCpuTimer();
timer.setMaxTimeMillis(thinkingTime);
Types.ACTIONS action = player.act(stateObs.copy(), timer);
// System.out.println("Selected: " + action); // + "\t " + action.ordinal());
stateObs.advance(action);
// System.out.println(stateObs.getGameScore());
if (view != null) {
view.repaint();
Thread.sleep(delay);
}
}
System.out.println(stateObs.getGameScore());
System.out.println(stateObs.isGameOver());
System.out.println(t);
System.out.println("Agent of type: " + player.getClass().getSimpleName());
return stateObs.getGameScore();
}
use of utilities.ElapsedTimer in project SimpleAsteroids by ljialin.
the class ArrayCopyTest method main.
public static void main(String[] args) {
ElapsedTimer timer = new ElapsedTimer();
double gameTick = 40;
int nCopies = (int) 1e7;
// size of array
int n = 1000;
double[] game = new double[n];
double tot = 0;
for (int i = 0; i < n; i++) {
game[i] = Math.random();
tot += game[i];
}
System.out.println("Tot = " + tot);
for (int i = 0; i < nCopies; i++) {
game = arrayCopy(game);
}
System.out.println("n = " + n);
System.out.format("Made %d copies\n", nCopies);
System.out.format("Copies per milli-second: %.1f\n\n", nCopies / (double) timer.elapsed());
System.out.format("Game tick time = %d ms\n", (int) gameTick);
System.out.format("Copies per game tick: %d\n\n", (int) (gameTick * nCopies / (double) timer.elapsed()));
System.out.println(timer);
tot = 0;
for (double x : game) tot += x;
System.out.println("Total check" + tot);
}
Aggregations