Package com.heatonresearch.aifh.evolutionary.train.basic

Examples of com.heatonresearch.aifh.evolutionary.train.basic.BasicEA


        Population pop = new BasicPopulation();
        pop.setGenomeFactory(new IntegerArrayGenomeFactory(5));

        // Create a trainer with a very simple score function.  We do not care
        // about the calculation of the score, as they will never be calculated.
        EvolutionaryAlgorithm train = new BasicEA(pop, new ScoreFunction() {
            @Override
            public double calculateScore(MLMethod method) {
                return 0;
            }

            @Override
            public boolean shouldMinimize() {
                return false;
            }
        });

        // Create a shuffle operator.  Use it 1.0 (100%) of the time.
        MutateShuffle opp = new MutateShuffle();
        train.addOperation(1.0, opp);

        // Create a single parent, the genes are set to 1,2,3,4,5.
        IntegerArrayGenome[] parents = new IntegerArrayGenome[1];
        parents[0] = (IntegerArrayGenome) pop.getGenomeFactory().factor();
        for (int i = 1; i <= 5; i++) {
View Full Code Here


        Population pop = new BasicPopulation();
        pop.setGenomeFactory(new DoubleArrayGenomeFactory(5));

        // Create a trainer with a very simple score function.  We do not care
        // about the calculation of the score, as they will never be calculated.
        EvolutionaryAlgorithm train = new BasicEA(pop, new ScoreFunction() {
            @Override
            public double calculateScore(MLMethod method) {
                return 0;
            }

            @Override
            public boolean shouldMinimize() {
                return false;
            }
        });


        MutatePerturb opp = new MutatePerturb(0.1);
        train.addOperation(1.0, opp);


        // Create a peterb operator.  Use it 1.0 (100%) of the time.
        DoubleArrayGenome[] parents = new DoubleArrayGenome[1];
        parents[0] = (DoubleArrayGenome) pop.getGenomeFactory().factor();
View Full Code Here

        Population pop = initPopulation();

        ScoreFunction score = new TSPScore(cities);

        genetic = new BasicEA(pop, score);

        genetic.addOperation(0.9, new SpliceNoRepeat(CITIES / 3));
        genetic.addOperation(0.1, new MutateShuffle());

        int sameSolutionCount = 0;
View Full Code Here

            Population pop = initPopulation(rnd, codec);

            ScoreFunction score = new ScoreRegressionData(trainingData);

            BasicEA genetic = new BasicEA(pop, score);
            genetic.setSpeciation(new ArraySpeciation<DoubleArrayGenome>());
            genetic.setCODEC(codec);
            genetic.addOperation(0.7, new Splice(codec.size() / 5));
            genetic.addOperation(0.3, new MutatePerturb(0.1));


            performIterations(genetic, 100000, 0.05, true);

            RBFNetwork winner = (RBFNetwork) codec.decode(genetic.getBestGenome());

            queryOneOfN(winner, trainingData, species);


        } catch (Throwable t) {
View Full Code Here

            Population pop = initPopulation(rnd, codec);

            ScoreFunction score = new ScoreRegressionData(trainingData);

            BasicEA genetic = new BasicEA(pop, score);
            genetic.setCODEC(codec);
            genetic.addOperation(0.7, new Splice(codec.size() / 3));
            genetic.addOperation(0.3, new MutatePerturb(0.1));


            performIterations(genetic, 100000, 0.05, true);

            RBFNetwork winner = (RBFNetwork) codec.decode(genetic.getBestGenome());

            queryOneOfN(winner, trainingData, species);


        } catch (Throwable t) {
View Full Code Here

        GenerateRandom rnd = new MersenneTwisterGenerateRandom();
        EvaluateExpression eval = new EvaluateExpression(rnd);
        Population pop = initPopulation(rnd, eval);
        ScoreFunction score = new ScoreSmallExpression(training,30);

        EvolutionaryAlgorithm genetic = new BasicEA(pop, score);
        genetic.addOperation(0.3, new MutateTree(3));
        genetic.addOperation(0.7, new CrossoverTree());
        genetic.setShouldIgnoreExceptions(false);


        int sameSolutionCount = 0;
        int iteration = 1;
        double lastSolution = Double.MAX_VALUE;
        StringBuilder builder = new StringBuilder();

        while (sameSolutionCount < MAX_SAME_SOLUTION && iteration<1000) {
            genetic.iteration();

            double thisSolution = genetic.getLastError();

            builder.setLength(0);
            builder.append("Iteration: ");
            builder.append(iteration++);
            builder.append(", Current error = ");
            builder.append(thisSolution);
            builder.append(", Best Solution Length = ");
            builder.append(genetic.getBestGenome().size());

            System.out.println(builder.toString());

            if (Math.abs(lastSolution - thisSolution) < 1.0) {
                sameSolutionCount++;
            } else {
                sameSolutionCount = 0;
            }

            lastSolution = thisSolution;
        }

        System.out.println("Good solution found:");
        TreeGenome best = (TreeGenome) genetic.getBestGenome();
        System.out.println(eval.displayExpressionNormal(best.getRoot()));
        genetic.finishTraining();
    }
View Full Code Here

        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);


        this.pop = initPopulation();
        this.score = new PlantScore();
        this.genetic = new BasicEA(pop, score);

        this.genetic.setSpeciation(new ArraySpeciation<DoubleArrayGenome>());

        genetic.addOperation(0.9, new Splice(PlantUniverse.GENOME_SIZE / 3));
        genetic.addOperation(0.1, new MutatePerturb(0.1));
View Full Code Here

        Population pop = new BasicPopulation();
        pop.setGenomeFactory(new IntegerArrayGenomeFactory(10));

        // Create a trainer with a very simple score function.  We do not care
        // about the calculation of the score, as they will never be calculated.
        EvolutionaryAlgorithm train = new BasicEA(pop, new ScoreFunction() {
            @Override
            public double calculateScore(MLMethod method) {
                return 0;
            }

            @Override
            public boolean shouldMinimize() {
                return false;
            }
        });

        // Create a splice operator, length = 5.  Use it 1.0 (100%) of the time.
        Splice opp = new Splice(5);
        train.addOperation(1.0, opp);

        // Create two parents, the genes are set to 1,2,3,4,5,7,8,9,10
        // and 10,9,8,7,6,5,4,3,2,1.
        IntegerArrayGenome[] parents = new IntegerArrayGenome[2];
        parents[0] = (IntegerArrayGenome) pop.getGenomeFactory().factor();
View Full Code Here

        Population pop = new BasicPopulation();
        pop.setGenomeFactory(new IntegerArrayGenomeFactory(10));

        // Create a trainer with a very simple score function.  We do not care
        // about the calculation of the score, as they will never be calculated.
        EvolutionaryAlgorithm train = new BasicEA(pop, new ScoreFunction() {
            @Override
            public double calculateScore(MLMethod method) {
                return 0;
            }

            @Override
            public boolean shouldMinimize() {
                return false;
            }
        });

        // Create a splice (no repeat) operator, length = 5.  Use it 1.0 (100%) of the time.
        SpliceNoRepeat opp = new SpliceNoRepeat(5);
        train.addOperation(1.0, opp);

        // Create two parents, the genes are set to 1,2,3,4,5,7,8,9,10
        // and 10,9,8,7,6,5,4,3,2,1.
        IntegerArrayGenome[] parents = new IntegerArrayGenome[2];
        parents[0] = (IntegerArrayGenome) pop.getGenomeFactory().factor();
View Full Code Here

        GenerateRandom rnd = new MersenneTwisterGenerateRandom();

        // Create a trainer with a very simple score function.  We do not care
        // about the calculation of the score, as they will never be calculated.
        // We only care that we are maximizing.
        EvolutionaryAlgorithm train = new BasicEA(pop, new ScoreFunction() {
            @Override
            public double calculateScore(MLMethod method) {
                return 0;
            }
View Full Code Here

TOP

Related Classes of com.heatonresearch.aifh.evolutionary.train.basic.BasicEA

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.