use of utilities.StatSummary in project SimpleAsteroids by ljialin.
the class EvolvePatternTest method main.
public static void main(String[] args) {
int nTrials = 1;
SimpleRMHC evoAlg = new SimpleRMHC();
evoAlg.setMutator(new ConvMutator());
// evoAlg = new SlidingMeanEDA().setHistoryLength(30);
// evoAlg = new CompactSlidingGA();
int nEvals = 50000;
StatSummary results = new StatSummary();
EvolvePatternTest ept = new EvolvePatternTest();
for (int i = 0; i < nTrials; i++) {
ElapsedTimer timer = new ElapsedTimer();
results.add(ept.runTrial(evoAlg, nEvals));
System.out.println(timer);
}
}
use of utilities.StatSummary 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.StatSummary 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.StatSummary in project SimpleAsteroids by ljialin.
the class BattleTestEA method runTrials.
public static StatSummary runTrials(EvoAlg ea, SolutionEvaluator evaluator, int nTrials, int nFitnessEvals) {
// record the time stats
StatSummary ss = new StatSummary();
for (int i = 0; i < nTrials; i++) {
ElapsedTimer t = new ElapsedTimer();
evaluator.reset();
System.out.println("Running trial: " + i);
int[] solution = ea.runTrial(evaluator, nFitnessEvals);
System.out.println(t);
System.out.println("Solution: " + Arrays.toString(solution));
System.out.println(evaluator.logger().ss);
System.out.println();
evaluator.logger().report();
System.out.println();
ss.add(evaluator.logger().ss.max());
}
return ss;
}
use of utilities.StatSummary in project SimpleAsteroids by ljialin.
the class TestEA method sweepSamplingRate.
public static void sweepSamplingRate(int from, int to) {
EvoAlg ea = new MBanditEA();
// SolutionEvaluator evaluator = new EvalMaxM(nDims, mValues, 1.0);
// SolutionEvaluator noiseFree = new EvalMaxM(nDims, mValues, 0.0);
SolutionEvaluator evaluator = new EvalNoisyWinRate(nDims, mValues, 1.0);
SolutionEvaluator noiseFree = new EvalNoisyWinRate(nDims, mValues, 0.0);
for (int i = from; i <= to; i++) {
ea = new SimpleRMHC(i);
// ea = new MBanditEA();
ea = new NTupleBanditEA();
StatSummary ss = runTrials(ea, evaluator, noiseFree, nTrials, nFitnessEvals);
// System.out.format("%d\t %.2f \t %.3f \t %.3f \t %.2f\n", i, ss.mean(), ss.stdErr(), ssOpt.mean(), nOpt.mean());
System.out.format("%d\t %.3f \t %.3f \t %.3f \t %.2f\t %.3f\n", i, ss.mean(), nOpt.mean(), ssOpt.mean(), ntOpt.mean(), ntPerf.mean());
// System.out.format("%d\t %.2f \t %.2f \t %.2f \n", i, ss.mean(), ss.stdErr(), ssOpt.mean());
}
}
Aggregations