Package com.barrybecker4.optimization.parameter

Examples of com.barrybecker4.optimization.parameter.ParameterArray


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

         ParameterArray lastBest;
         desiredPopulationSize_ = params.getSamplePopulationSize();

         // create an initial population based on params and POPULATION_SIZE-1 other random candidate solutions.
         List<ParameterArray> population = new LinkedList<ParameterArray>();
         population.add(params);

         for (int i = 1; i < desiredPopulationSize_; i++) {
             ParameterArray nbr = params.getRandomNeighbor(INITIAL_RADIUS);
             if (!population.contains(nbr)) {
                 population.add(nbr);
             }
         }
         assert(population.size() > 0);
View Full Code Here


     * Find the new best candidate.
     * @return the new best candidate.
     */
    private ParameterArray findNewBest(ParameterArray params, ParameterArray lastBest,
                                       List<ParameterArray> population) {
        ParameterArray currentBest;
        int ct = 0;
        double deltaFitness;
        ParameterArray recentBest = lastBest;

        // each iteration represents a new generation of the population.
        do {
            int keepSize = cullPopulation(population);
            replaceCulledWithKeeperVariants(population, keepSize);
View Full Code Here

            // do the best one twice to avoid terminating too quickly
            // in the event that we got a very good fitness score on an early iteration.
            if (keeperIndex == keepSize-1) {
                keeperIndex = 0;
            }
            ParameterArray p = population.get(keeperIndex);

            // add a permutation of one of the keepers
            // we multiply the radius by m because we want the worse ones to have
            // higher variability.
            double r = (keeperIndex + NBR_RADIUS_SOFTENER)/NBR_RADIUS_SOFTENER * nbrRadius_;
            ParameterArray nbr = p.getRandomNeighbor(r);
            if (!population.contains(nbr)) {
                population.add(nbr);
                notifyOfChange(p);
            }
            k++;
View Full Code Here

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

        for (ParameterArray p : population) {

            double fitness;
            if (optimizee_.evaluateByComparison()) {
                fitness = optimizee_.compareFitness(p, previousBest);
            } else {
                fitness = optimizee_.evaluateFitness(p);
            }
            System.out.println("f="+fitness);
            p.setFitness(fitness);
            if (fitness > bestFitness.getFitness()) {
                bestFitness = p;
                // show it if better than what we had before
                notifyOfChange(p);
                ThreadUtil.sleep(500);
            }
        }
        return bestFitness.copy();
    }
View Full Code Here

        if (GUIUtil.hasBasicService())
            optimizer = new Optimizer( this );
        else
            optimizer = new Optimizer( this, FileUtil.getHomeDir() +"performance/fluid/fluid_optimization.txt" );
        Parameter[] params = new Parameter[3];
        ParameterArray paramArray = new NumericParameterArray( params );

        setPaused(false);
        optimizer.doOptimization(OptimizationStrategyType.GENETIC_SEARCH, paramArray, 0.3);
    }
View Full Code Here

     * Draw one of the tile paths which takes one of three forms.
     */
    public void drawPath(Graphics2D g2, int pathNumber, TilePlacement tilePlacement,
                         Point position, double size) {

        HexTile tile = tilePlacement.getTile();
        int pathStartIndex = getPathStartIndex(tile, pathNumber);

        int i = pathStartIndex + 1;

        PathColor pathColor = tile.getEdgeColor(pathStartIndex);
        while (pathColor != tile.getEdgeColor(i++)) {
            assert(i<6): "Should never exceed 6";
        }

        int pathEndIndex = i-1;
        int diff = pathEndIndex - pathStartIndex;
View Full Code Here

        this.numTiles = numTiles;
    }

    public TantrixBoard initialPosition() {
        //MathUtil.RANDOM.setSeed(1);
        return new TantrixBoard(new HexTiles().createRandomList(numTiles));
    }
View Full Code Here

    public boolean isGoal(TantrixBoard position) {
        return position.isSolved();
    }

    public TilePlacementList legalMoves(TantrixBoard position) {
        return new MoveGenerator(position).generateMoves();
    }
View Full Code Here

        HexTile tile = tilePlacement.getTile();
        int pathStartIndex = getPathStartIndex(tile, pathNumber);

        int i = pathStartIndex + 1;

        PathColor pathColor = tile.getEdgeColor(pathStartIndex);
        while (pathColor != tile.getEdgeColor(i++)) {
            assert(i<6): "Should never exceed 6";
        }

        int pathEndIndex = i-1;
View Full Code Here

     */
    private int getPathStartIndex(HexTile tile, int pathNumber) {
        Set<PathColor> set = new HashSet<PathColor>();
        int i = 0;
        do {
            PathColor c = tile.getEdgeColor(i++);
            set.add(c);
        } while (set.size() <= pathNumber);
        return i-1;
    }
View Full Code Here

TOP

Related Classes of com.barrybecker4.optimization.parameter.ParameterArray

Copyright © 2018 www.massapicom. 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.