Package com.heatonresearch.aifh.evolutionary.genome

Examples of com.heatonresearch.aifh.evolutionary.genome.Genome


    @Override
    public double calculateScore(final MLMethod algo) {
        ErrorCalculation ec = this.errorCalc.create();

        final RegressionAlgorithm ralgo = (RegressionAlgorithm) algo;
        final Genome genome = (Genome)ralgo;

        if( genome.size()>this.maxLength ) {
            return Double.POSITIVE_INFINITY;
        }

        // evaulate
        ec.clear();
View Full Code Here


        while (speciesNum < getSpecies().size()) {
            Species species = getSpecies().get(speciesNum);

            int genomeNum = 0;
            while (genomeNum < species.getMembers().size()) {
                Genome genome = species.getMembers().get(genomeNum);
                if (Double.isInfinite(genome.getScore())
                        || Double.isInfinite(genome.getAdjustedScore())
                        || Double.isNaN(genome.getScore())
                        || Double.isNaN(genome.getAdjustedScore())) {
                    species.getMembers().remove(genome);
                } else {
                    genomeNum++;
                }
            }
View Full Code Here

            // Add elite genomes directly
            if (species.getMembers().size() > 5) {
                final int idealEliteCount = (int) (species.getMembers().size() * getEliteRate());
                final int eliteCount = Math.min(numToSpawn, idealEliteCount);
                for (int i = 0; i < eliteCount; i++) {
                    final Genome eliteGenome = species.getMembers().get(i);
                    if (getOldBestGenome() != eliteGenome) {
                        numToSpawn--;
                        if (!addChild(eliteGenome)) {
                            break;
                        }
View Full Code Here

     * {@inheritDoc}
     */
    @Override
    public int performAntiSelection(final GenerateRandom rnd, final Species species) {
        int worstIndex = rnd.nextInt(species.getMembers().size());
        Genome worst = species.getMembers().get(worstIndex);
        BasicEA.calculateScoreAdjustment(worst,
                this.trainer.getScoreAdjusters());

        for (int i = 0; i < this.rounds; i++) {
            final int competitorIndex = rnd.nextInt(species.getMembers().size());
            final Genome competitor = species.getMembers().get(competitorIndex);

            // force an invalid genome to lose
            if (Double.isInfinite(competitor.getAdjustedScore())
                    || Double.isNaN(competitor.getAdjustedScore())) {
                return competitorIndex;
            }

            BasicEA.calculateScoreAdjustment(competitor,
                    this.trainer.getScoreAdjusters());
View Full Code Here

     * {@inheritDoc}
     */
    @Override
    public int performSelection(final GenerateRandom rnd, final Species species) {
        int bestIndex = rnd.nextInt(species.getMembers().size());
        Genome best = species.getMembers().get(bestIndex);
        BasicEA.calculateScoreAdjustment(best, this.trainer.getScoreAdjusters());

        for (int i = 0; i < this.rounds; i++) {
            final int competitorIndex = rnd.nextInt(species.getMembers().size());
            final Genome competitor = species.getMembers().get(competitorIndex);

            // only evaluate valid genomes
            if (!Double.isInfinite(competitor.getAdjustedScore())
                    && !Double.isNaN(competitor.getAdjustedScore())) {
                BasicEA.calculateScoreAdjustment(competitor,
                        this.trainer.getScoreAdjusters());
                if (this.trainer.getSelectionComparator().isBetterThan(
                        competitor, best)) {
                    best = competitor;
View Full Code Here

        Population pop = new BasicPopulation();
        Species species = pop.createSpecies();

        // Create 1000 genomes, assign the score to be the index number.
        for (int i = 0; i < 1000; i++) {
            Genome genome = new IntegerArrayGenome(1);
            genome.setScore(i);
            genome.setAdjustedScore(i);
            pop.getSpecies().get(0).add(genome);
        }

        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;
            }

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

        // Perform the test for round counts between 1 and 10.
        for (int roundCount = 1; roundCount <= 10; roundCount++) {
            TournamentSelection selection = new TournamentSelection(train, roundCount);
            int sum = 0;
            int count = 0;
            for (int i = 0; i < 100000; i++) {
                int genomeID = selection.performSelection(rnd, species);
                Genome genome = species.getMembers().get(genomeID);
                sum += genome.getAdjustedScore();
                count++;
            }
            sum /= count;
            System.out.println("Rounds: " + roundCount + ", Avg Score: " + sum);
        }
View Full Code Here

TOP

Related Classes of com.heatonresearch.aifh.evolutionary.genome.Genome

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.