Search in sources :

Example 11 with JEasyFrame

use of utilities.JEasyFrame in project SimpleAsteroids by ljialin.

the class EvolvePatternTest method runTrial.

public double runTrial(SimpleRMHC ea, int nEvals) {
    ConvNTuple convNTuple = getTrainedConvNTuple();
    ea.setMutator(new ConvMutator().setConvNTuple(convNTuple));
    int nDims = imageWidth * imageHeight;
    int mValues = 3;
    SolutionEvaluator evaluator = new EvalConvNTuple(nDims, mValues).setConvNTuple(convNTuple);
    int[] solution = ea.runTrial(evaluator, nEvals);
    double fitness = evaluator.evaluate(solution);
    String label = String.format("Fitness: %.6f", fitness);
    System.out.println(label);
    System.out.println(Arrays.toString(solution));
    LevelView.showMaze(solution, imageWidth, imageHeight, label);
    new JEasyFrame(LineChart.easyPlot(evaluator.logger().fa), "Evolution of Fitness");
    return fitness;
}
Also used : SolutionEvaluator(evodef.SolutionEvaluator) ConvMutator(ntuple.operator.ConvMutator) JEasyFrame(utilities.JEasyFrame) ConvNTuple(ntuple.ConvNTuple)

Example 12 with JEasyFrame

use of utilities.JEasyFrame 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");
}
Also used : StatSummary(utilities.StatSummary) LineChartAxis(plot.LineChartAxis) LinePlot(plot.LinePlot) JEasyFrame(utilities.JEasyFrame) ArrayList(java.util.ArrayList) LineGroup(plot.LineGroup) LineChart(plot.LineChart)

Example 13 with JEasyFrame

use of utilities.JEasyFrame 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");
}
Also used : StatSummary(utilities.StatSummary) Random(java.util.Random) JEasyFrame(utilities.JEasyFrame) ElapsedTimer(utilities.ElapsedTimer)

Example 14 with JEasyFrame

use of utilities.JEasyFrame in project SimpleAsteroids by ljialin.

the class GameActionSpaceAdapter method plot.

public void plot() {
    System.out.println("in plot? " + linePlots == null);
    if (linePlots != null) {
        LineChart lineChart = new LineChart().setBG(Color.blue);
        lineChart.addLines(linePlots);
        new JEasyFrame(lineChart, "Evo Plots");
    }
}
Also used : JEasyFrame(utilities.JEasyFrame) LineChart(plot.LineChart)

Example 15 with JEasyFrame

use of utilities.JEasyFrame in project SimpleAsteroids by ljialin.

the class MazeView method main.

public static void main(String[] args) {
    int n = 400;
    int[] bits = new int[n];
    Random random = new Random();
    for (int i = 0; i < n; i++) {
        bits[i] = random.nextInt(2);
    }
    MazeView mazeView = new MazeView(bits);
    new JEasyFrame(mazeView, "Maze Test");
    MazeModel mazeModel = new MazeModel(bits);
    Graph graph = new GraphBuilder().buildGraph(mazeModel);
    System.out.println(graph.getArcs());
    System.out.println("Finding shortest path:");
    Vertex from = new Vertex(0, 0);
    Vertex to = new Vertex(2, 2);
    System.out.println(new ShortestPath().runShortestPath(graph, from, to));
}
Also used : Vertex(graph.Vertex) Graph(graph.Graph) Random(java.util.Random) JEasyFrame(utilities.JEasyFrame) ShortestPath(graph.ShortestPath) GraphBuilder(graph.GraphBuilder)

Aggregations

JEasyFrame (utilities.JEasyFrame)30 Random (java.util.Random)9 StatSummary (utilities.StatSummary)8 LineChart (plot.LineChart)7 ElapsedTimer (utilities.ElapsedTimer)7 LineChartAxis (plot.LineChartAxis)6 EvoAlg (evodef.EvoAlg)5 SimpleRMHC (ga.SimpleRMHC)5 ElapsedCpuTimer (tools.ElapsedCpuTimer)5 Types (ontology.Types)4 AbstractPlayer (core.player.AbstractPlayer)3 ArrayList (java.util.ArrayList)3 Scanner (java.util.Scanner)3 LevelView (ntuple.LevelView)3 NTupleBanditEA (ntuple.NTupleBanditEA)3 LineGroup (plot.LineGroup)3 LinePlot (plot.LinePlot)3 View (asteroids.View)2 BattleView (battle.BattleView)2 Agent (controllers.singlePlayer.ea.Agent)2