Package com.barrybecker4.optimization.parameter

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


     * @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

     * @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

    @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

            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

     */
     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

    public void doTest(OptimizationStrategyType optType, Optimizer optimizer,
                       ParameterArray initialGuess, double fitnessRange) {

        pointsList = new PointsList(solutionPosition, EDGE_SIZE);
        ParameterArray solution = null;
        try {
            solution = optimizer.doOptimization(optType, initialGuess, fitnessRange);
        } catch(AbstractMethodError e) {
            // allow continuing if the strategy has simply not been implemented yet.
            e.printStackTrace();
View Full Code Here

        // 3 sample points along each dimension
        gsStrategy.setSamplingRate(NUM_SAMPLES);

        // first find a good place to start
        // perhaps we should try several of the better results from global sampling.
        ParameterArray sampledParams = gsStrategy.doOptimization(params, fitnessRange);

        OptimizationStrategy strategy = new HillClimbingStrategy(optimizee_);
        strategy.setListener(listener_);
        return strategy.doOptimization(sampledParams, fitnessRange);
    }
View Full Code Here

        if (GUIUtil.hasBasicService())
            optimizer = new Optimizer( this );
        else
            optimizer = new Optimizer( this, FileUtil.getHomeDir()+ "performance/liquid/liquid_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

            optimizer = new Optimizer( this, FileUtil.getHomeDir() +"performance/trebuchet/trebuchet_optimization.txt" );
        Parameter[] params = new Parameter[NUM_PARAMS];
        //params[0] = new Parameter( WAVE_SPEED, 0.0001, 0.02, "wave speed" );
        //params[1] = new Parameter( WAVE_AMPLITUDE, 0.001, 0.2, "wave amplitude" );
        //params[2] = new Parameter( WAVE_PERIOD, 0.5, 9.0, "wave period" );
        ParameterArray paramArray = new NumericParameterArray( params );

        setPaused(false);
        optimizer.doOptimizationOptimizationStrategyType.GENETIC_SEARCH, paramArray, 0.3);
    }
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.