当前位置: 首页>>代码示例>>Python>>正文


Python GA.Organism类代码示例

本文整理汇总了Python中Bio.GA.Organism的典型用法代码示例。如果您正苦于以下问题:Python Organism类的具体用法?Python Organism怎么用?Python Organism使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Organism类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: find_schemas

    def find_schemas(self, fitness, num_schemas):
        """Find the given number of unique schemas using a genetic algorithm

        Arguments:

        o fitness - A callable object (ie. function) which will evaluate
        the fitness of a motif.

        o num_schemas - The number of unique schemas with good fitness
        that we want to generate.
        """
        start_population = \
           Organism.function_population(self.motif_generator.random_motif,
                                        self.initial_population,
                                        fitness)
        finisher = SimpleFinisher(num_schemas, self.min_generations)

        # set up the evolver and do the evolution
        evolver = GenerationEvolver(start_population, self.selector)
        evolved_pop = evolver.evolve(finisher.is_finished)

        # convert the evolved population into a PatternRepository
        schema_info = {}
        for org in evolved_pop:
            # convert the Genome from a MutableSeq to a Seq so that
            # the schemas are just strings (and not array("c")s)
            seq_genome = org.genome.toseq()
            schema_info[str(seq_genome)] = org.fitness

        return PatternRepository(schema_info)
开发者ID:Ambuj-UF,项目名称:ConCat-1.0,代码行数:30,代码来源:Schema.py

示例2: main

def main(num_queens):

    print "Calculating for %s queens..." % num_queens

    num_orgs = 1000
    print "Generating an initial population of %s organisms..." % num_orgs
    queen_alphabet = QueensAlphabet(num_queens)

    start_population = Organism.random_population(queen_alphabet, num_queens, num_orgs, queens_fitness)

    print "Evolving the population and searching for a solution..."

    mutator = QueensMutation(mutation_rate=0.05)
    crossover = QueensCrossover(queens_fitness, crossover_prob=0.2, max_crossover_size=4)
    repair = QueensRepair()
    # rw_selector = RouletteWheelSelection(mutator, crossover, repair)
    t_selector = TournamentSelection(mutator, crossover, repair, 5)

    start_time = time.ctime(time.time())
    evolver = GenerationEvolver(start_population, t_selector)
    evolved_pop = evolver.evolve(queens_solved)
    end_time = time.ctime(time.time())

    unique_solutions = []
    for organism in evolved_pop:
        if organism.fitness == num_queens:
            if organism not in unique_solutions:
                unique_solutions.append(organism)

    if VERBOSE:
        print "Search started at %s and ended at %s" % (start_time, end_time)
        for organism in unique_solutions:
            print "We did it!", organism
            display_board(organism.genome)
开发者ID:nuin,项目名称:biopython,代码行数:34,代码来源:test_GAQueens.py

示例3: test_function_population

    def test_function_population(self):
        """Create a population using a function to generate genomes.
        """
        num_orgs = 10
        new_pop = Organism.function_population(genome_generator,
                                               num_orgs, fitness_calculator)

        self.assertEqual(len(new_pop), num_orgs, "Expected %s organisms, "
                         "got %s" % (num_orgs, len(new_pop)))
        for org in new_pop:
            self.assertIsInstance(org, Organism.Organism,
                                  "Expected to get an organism, got %r" % org)

            exp_fit = fitness_calculator(org.genome)
            self.assertEqual(org.fitness, exp_fit, "Expected fitness of %s, "
                             "got %s" % (org.fitness, exp_fit))
开发者ID:mtrellet,项目名称:biopython,代码行数:16,代码来源:test_GAOrganism.py

示例4: test_function_population

    def test_function_population(self):
        """Create a population using a function to generate genomes.
        """
        num_orgs = 10
        new_pop = Organism.function_population(genome_generator,
                                               num_orgs, fitness_calculator)

        assert len(new_pop) == num_orgs, "Expected %s organisms, got %s" \
               % (num_orgs, len(new_pops))

        for org in new_pop:
            assert isinstance(org, Organism.Organism), \
                   "Expected to get an organism, got %r" % org

            exp_fit = fitness_calculator(org.genome)
            assert org.fitness == exp_fit, \
                   "Expected fitness of %s, got %s" % (org.fitness, exp_fit)
开发者ID:BingW,项目名称:biopython,代码行数:17,代码来源:test_GAOrganism.py

示例5: test_random_population_types

    def test_random_population_types(self):
        """Creating a random population with different types of alphabets.
        """
        class DoubleAlphabet:
            letters = [1.0, 2.0]

        class CharacterAlphabet:
            letters = ["a", "b"]

        class IntegerAlphabet:
            letters = [1, 2]

        def test_fitness(genome):
            return 2

        all_alphabets = [DoubleAlphabet(), CharacterAlphabet(),
                         IntegerAlphabet()]

        for alphabet in all_alphabets:
            new_pop = Organism.random_population(alphabet, 5, 10,
                                                 test_fitness)
开发者ID:BingW,项目名称:biopython,代码行数:21,代码来源:test_GAOrganism.py

示例6: test_random_population

    def test_random_population(self):
        """Create a population randomly from a alphabet.
        """
        num_orgs = 10
        genome_size = 5
        new_pop = Organism.random_population(self.alphabet, genome_size,
                                             num_orgs, fitness_calculator)

        assert len(new_pop) == num_orgs, "Expected %s organisms, got %s" \
               % (num_orgs, len(new_pops))

        for org in new_pop:
            assert isinstance(org, Organism.Organism), \
                   "Expected to get an organism, got %r" % org

            exp_fit = fitness_calculator(org.genome)
            assert org.fitness == exp_fit, \
                   "Expected fitness of %s, got %s" % (org.fitness, exp_fit)

            assert len(org.genome) == genome_size, \
                   "Expected genome size of %s, got %s" % (len(org.genome),
                                                           genome_size)
开发者ID:BingW,项目名称:biopython,代码行数:22,代码来源:test_GAOrganism.py

示例7: test_random_population

    def test_random_population(self):
        """Create a population randomly from a alphabet.
        """
        num_orgs = 10
        genome_size = 5
        new_pop = Organism.random_population(self.alphabet, genome_size,
                                             num_orgs, fitness_calculator)

        self.assertEqual(len(new_pop), num_orgs, "Expected %s organisms, "
                         "got %s " % (num_orgs, len(new_pop)))

        for org in new_pop:
            self.assertIsInstance(org, Organism.Organism,
                                  "Expected to get an organism, got %r" % org)

            exp_fit = fitness_calculator(org.genome)
            self.assertEqual(org.fitness, exp_fit, "Expected fitness of %s, "
                             "got %s" % (org.fitness, exp_fit))

            self.assertEqual(len(org.genome), genome_size, "Expected genome "
                             "size of %s, got %s"
                             % (len(org.genome), genome_size))
开发者ID:mtrellet,项目名称:biopython,代码行数:22,代码来源:test_GAOrganism.py


注:本文中的Bio.GA.Organism类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。