Examples of ParameterArray


Examples of com.barrybecker4.optimization.parameter.ParameterArray

     * @return list of moves to a solution.
     */
    @Override
    public TilePlacementList solve()  {

        ParameterArray initialGuess = new TantrixPath(board);
        assert(initialGuess.size() > 0) : "The random path should have some tiles!";
        long startTime = System.currentTimeMillis();

        Optimizer optimizer = new Optimizer(this);
        optimizer.setListener(this);

        ParameterArray solution =
            optimizer.doOptimization(strategy, initialGuess, SOLVED_THRESH);

        solution_ =
            new TantrixBoard(((TantrixPath)solution).getTilePlacements(), board.getPrimaryColor());

View Full Code Here

Examples of com.barrybecker4.optimization.parameter.ParameterArray

     * The search for the best computer move happens on a separate thread so the UI does not lock up.
     * @param player1 if true then the computer moving is player1
     * @return the move the computer selected (may return null if no move possible)
     */
    TwoPlayerMove findComputerMove( boolean player1 ) {
        ParameterArray weights;
        player1sTurn_ = player1;

        // we cannot find a computer move if no move played yet.
        if (getMoveList().isEmpty()) return null;

View Full Code Here

Examples of com.barrybecker4.optimization.parameter.ParameterArray

     * @return the resulting optimized parameters.
     */
    public ParameterArray runOptimization() {
        Optimizer optimizer = new Optimizer( this.getOptimizee(), getTwoPlayerOptions().getAutoOptimizeFile() );

        ParameterArray optimizedParams;
        optimizedParams =
                optimizer.doOptimization(OptimizationStrategyType.HILL_CLIMBING,
                                         getComputerWeights().getDefaultWeights(),
                                         WINNING_VALUE);
        return optimizedParams;
View Full Code Here

Examples of com.barrybecker4.optimization.parameter.ParameterArray

    /**
     * run many games and use hill-climbing to find optimal weights.
     */
    private void runOptimization() {
        ParameterArray optimizedParams = get2PlayerController().runOptimization();

        JOptionPane.showMessageDialog(this, GameContext.getLabel("OPTIMIZED_WEIGHTS_TXT") +
                optimizedParams, GameContext.getLabel("OPTIMIZED_WEIGHTS"), JOptionPane.INFORMATION_MESSAGE);
    }
View Full Code Here

Examples of com.barrybecker4.optimization.parameter.ParameterArray

     * @return list of moves to a solution.
     */
    @Override
    public List<Piece> solve()  {

        ParameterArray initialGuess = new PieceParameterArray(pieces_);
        solution_ = pieces_;
        long startTime = System.currentTimeMillis();

        Optimizer optimizer = new Optimizer(this);

        optimizer.setListener(this);

        ParameterArray solution =
            optimizer.doOptimization(strategy, initialGuess, MAX_FITS);

        solution_ = ((PieceParameterArray)solution).getPieceList();
        List<Piece> moves;
        if (evaluateFitness(solution) >= MAX_FITS) {
View Full Code Here

Examples of com.barrybecker4.optimization.parameter.ParameterArray

     * @return the optimized params.
     */
    @Override
    public ParameterArray doOptimization( ParameterArray params, double fitnessRange ) {

        ParameterArray currentParams = params.copy();

        double jumpSize = INITIAL_JUMP_SIZE;

        if (!optimizee_.evaluateByComparison()) {
            // get the initial baseline fitness value.
            currentParams.setFitness(optimizee_.evaluateFitness(currentParams));
        }
        int numIterations = 0;
        log(0, currentParams.getFitness(), 0.0, 0.0, currentParams, "initial test");
        notifyOfChange(currentParams);

        double fitnessEps = fitnessRange * FITNESS_EPS_PERCENT / 100.0;

        // Use cache to avoid repeats. This can be a real issue if  we have a discrete problem space.
        Set<ParameterArray> cache = new HashSet<ParameterArray>();
        cache.add(currentParams);

        Improvement improvement = null;
        boolean improved = true;

        // iterate until there is no significant improvement between iterations,
        // of the jumpSize is too small (below some threshold).
        do {
            //System.out.println( "iter=" + numIterations + " FITNESS = " + currentParams.getFitness() + "  ------------");

            improvement = currentParams.findIncrementalImprovement(optimizee_, jumpSize, improvement, cache);

            numIterations++;
            currentParams = improvement.getParams();
            jumpSize = improvement.getNewJumpSize();
            notifyOfChange(currentParams);
View Full Code Here

Examples of com.barrybecker4.optimization.parameter.ParameterArray

     * @param previousBest the best solution from the previous iteration
     * @return the new best solution.
     */
    @Override
    protected ParameterArray evaluatePopulation(List<ParameterArray> population, ParameterArray previousBest) {
        ParameterArray bestFitness = previousBest;

        Parallelizer<EvaluationWorker> parallelizer =
                new Parallelizer<EvaluationWorker>();

        List<Runnable> workers = new ArrayList<Runnable>(population.size());

        for (ParameterArray candidate : population) {
            workers.add(new EvaluationWorker(candidate, previousBest));
        }

        // blocks until all Callables are done running.
        parallelizer.invokeAllRunnables(workers);

        for (Runnable worker : workers)  {

            EvaluationWorker eworker = (EvaluationWorker)worker;
            double fitness = eworker.getResult();
            if (fitness > bestFitness.getFitness()) {
                bestFitness = eworker.getCandidate();
            }
        }

        return bestFitness.copy();
    }
View Full Code Here

Examples of com.barrybecker4.optimization.parameter.ParameterArray

    @Override
    public ParameterArray doOptimization( ParameterArray params, double fitnessRange ) {

        List<ParameterArray> samples = params.findGlobalSamples(numSamples_);
        double bestFitness = -Double.MAX_VALUE;
        ParameterArray bestParams = params.copy();

        for (ParameterArray sample : samples) {

            double fitness;
            if (optimizee_.evaluateByComparison())
View Full Code Here

Examples of com.barrybecker4.optimization.parameter.ParameterArray

            params.setFitness(currentFitness);
        }

        // store the best solution we found at any given temperature iteration and use that as the initial
        // start of the next temperature iteration.
        ParameterArray bestParams = params.copy();
        ParameterArray currentParams;

        do { // temperature iteration (temperature drops each time through)
             currentParams = bestParams;

             do {
                 currentParams = findNeighbor(currentParams, ct, temperature, fitnessRange);

                 if (currentParams.getFitness() > bestParams.getFitness()) {
                     bestParams = currentParams.copy();
                     notifyOfChange(bestParams);
                 }
                 ct++;

             } while (ct < N * currentParams.size() && !isOptimalFitnessReached(currentParams));

             ct = 0;
             // keep Reducing the temperature until it reaches tempMin
             temperature *= TEMP_DROP_FACTOR;

View Full Code Here

Examples of com.barrybecker4.optimization.parameter.ParameterArray

     */
     private ParameterArray findNeighbor(ParameterArray params, int ct, double temperature, double fitnessRange) {

        //double r = (tempMax_/5.0+temperature) / (8.0*(N/5.0+ct)*tempMax_);
        double r = temperature / ((N + ct) * tempMax_);
        ParameterArray newParams = params.getRandomNeighbor(r);
        double dist = params.distance(newParams);

        double deltaFitness;
        double newFitness;
        if (optimizee_.evaluateByComparison()) {
            deltaFitness = optimizee_.compareFitness(newParams, params);
        }
        else {
            newFitness = optimizee_.evaluateFitness(newParams);
            newParams.setFitness(newFitness);
            deltaFitness = newFitness - params.getFitness();
        }

        double probability = Math.pow(Math.E, tempMax_ * deltaFitness / temperature);
        boolean useWorseSolution = RAND.nextDouble() < probability;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.