Back to index

python-biopython  1.60
Classes | Functions
Bio.GA.Organism Namespace Reference

Classes

class  Organism

Functions

def function_population
def random_population

Detailed Description

Deal with an Organism in a Genetic Algorithm population.

Function Documentation

def Bio.GA.Organism.function_population (   new_genome,
  num_organisms,
  fitness_calculator 
)
Generate a population given a function to create genomes

Arguments:

o new_genome - A function or callable object that will return
a genome that can be used for a new organism. This new genome
should be a MutableSeq object with a specified alphabet.

o num_organisms - The number of individuals we want in the population.

o fitness_calculator -- A funtion that will calculate the fitness
of the organism when given the organisms genome.

Definition at line 11 of file Organism.py.

00011 
00012 def function_population(new_genome, num_organisms, fitness_calculator):
00013     """Generate a population given a function to create genomes
00014 
00015     Arguments:
00016 
00017     o new_genome - A function or callable object that will return
00018     a genome that can be used for a new organism. This new genome
00019     should be a MutableSeq object with a specified alphabet.
00020 
00021     o num_organisms - The number of individuals we want in the population.
00022 
00023     o fitness_calculator -- A funtion that will calculate the fitness
00024     of the organism when given the organisms genome.
00025     """
00026     all_orgs = []
00027 
00028     for org_num in range(num_organisms):
00029         cur_genome = new_genome()
00030         all_orgs.append(Organism(cur_genome, fitness_calculator))
00031 
00032     return all_orgs

Here is the call graph for this function:

def Bio.GA.Organism.random_population (   genome_alphabet,
  genome_size,
  num_organisms,
  fitness_calculator 
)
Generate a population of individuals with randomly set genomes.

Arguments:

o genome_alphabet -- An Alphabet object describing all of the
possible letters that could potentially be in the genome of an
organism.

o genome_size -- The size of each organisms genome.

o num_organism -- The number of organisms we want in the population.

o fitness_calculator -- A funtion that will calculate the fitness
of the organism when given the organisms genome.

Definition at line 34 of file Organism.py.

00034 
00035                       fitness_calculator):
00036     """Generate a population of individuals with randomly set genomes.
00037 
00038     Arguments:
00039 
00040     o genome_alphabet -- An Alphabet object describing all of the
00041     possible letters that could potentially be in the genome of an
00042     organism.
00043 
00044     o genome_size -- The size of each organisms genome.
00045 
00046     o num_organism -- The number of organisms we want in the population.
00047 
00048     o fitness_calculator -- A funtion that will calculate the fitness
00049     of the organism when given the organisms genome.
00050     """
00051     all_orgs = []
00052 
00053     # a random number generator to get letters for the genome
00054     letter_rand = random.Random()
00055 
00056     # figure out what type of characters are in the alphabet
00057     if type(genome_alphabet.letters[0]) == type("A"):
00058         if sys.version_info[0] == 3:
00059             alphabet_type = "u" #Use unicode string on Python 3
00060         else:
00061             alphabet_type = "c" #Use byte string on Python 2
00062     elif type(genome_alphabet.letters[0]) == type(1):
00063         alphabet_type = "i"
00064     elif type(genome_alphabet.letters[0]) == type(1.0):
00065         alphabet_type = "d"
00066     else:
00067         raise ValueError(\
00068             "Alphabet type is unsupported: %s" % genome_alphabet.letters)
00069 
00070     for org_num in range(num_organisms):
00071         new_genome = MutableSeq(array.array(alphabet_type), genome_alphabet)
00072 
00073         # generate the genome randomly
00074         for gene_num in range(genome_size):
00075             new_gene = letter_rand.choice(genome_alphabet.letters)
00076             new_genome.append(new_gene)
00077 
00078         # add the new organism with this genome
00079         all_orgs.append(Organism(new_genome, fitness_calculator))
00080 
00081     return all_orgs

Here is the caller graph for this function: