gaIndividual

Creates an Imsls_d_individual data structure from user supplied phenotypes.

Synopsis

gaIndividual (chromosome)

Required Arguments

Imsls_d_chromosome chromosome (Input)
A chromosome data structure created by gaChromosome. This structure is cloned and stored in the Imsls_d_individual data structure.

Return Value

The function gaIndividual returns an Imsls_d_individual data structure, which is required input to gaPopulation. The memory allocated to this data structure can be freed using gaFreeIndividual.

Optional Arguments

t_print, (Input)
By default, intermediate results are not printed. This option turns on printing of intermediate results.
grayEncoding, (Input)

Specifies whether alleles are encoded using Base-2 or Gray encoding for integer and real phenotypes.

Default: Base-2 encoding.

binary, int binaryPhenotype[] (Input)
An array of length chromosome.n_binary containing the integer values for any binary phenotypes. This is a required argument when chromosome.n_binary> 0.
nominal, int nominalPhenotype[] (Input)
An array of length chromosome.nNominal containing the integer values for any nominal phenotypes. This is a required argument when chromosome.nNominal is greater than zero. The value of nominalPhenotype[i] must be one of the integers 0, 1, …, chromosome > nCategories[i]-1.
integer, int integerPhenotype[] (Input)

An array of length chromosome>n_integer containing the integer values for any integer phenotypes. This is a required argument when chromosome.n_integer>0. The value of integerPhenotype[i] must conform to the inequality:

chromosome.iBounds[2*i]integerPhenotype[i]chromosome.i_bounds[2*i+1]

real, float realPhenotype[] (Input)

An array of length chromosome.n_real containing the floating point values for any real phenotypes. This is a required argument when chromosome.n_real is greater than zero. The value of realPhenotype[i] must conform to the inequality:

chromosome.r_bounds[2*i]realPhenotype[i] <chromosome.r_bounds[2*i+1]

Description

The geneticAlgorithm operates on a population of individuals. Individuals can be created automatically using geneticAlgorithm or systematically using gaPopulation. If the initial population is created using randomly selected individuals, then this function is not needed. However, if the initial population is to be constructed systematically, then the individuals for that population must first be created using this function.

This function takes the phenotype values in the optional arguments and creates an Imsls_d_individual data structure. This structure contains a chromosome created by encoding the phenotypes into their respective allele representations using the chromosome map described in Imsls_d_chromosome.

It also allows for incorporating parentage information for the individual, although this is typically not done for the individuals in the initial population.

Memory allocated for this data structure is released using gaFreeIndividual. The chromosome data structure passed to this function is copied into the individual and left unaltered. Hence, releasing memory using gaFreeIndividual does not release memory allocated to the original chromosome. The original chromosome can be released using free.

Example

This example creates an individual using a chromosome with 1 binary, 2 nominals, 3 integers and 2 real phenotypes. The t_print argument is used to print a description of the data structure. By default, Base-2 encoding is used for encoding integer and real phenotypes.

Note that gaFreeIndividual frees the Imsls_d_chromosome data structure within the individual.

from numpy import *
from pyimsl.stat.free import free
from pyimsl.stat.gaChromosome import gaChromosome
from pyimsl.stat.gaIndividual import gaIndividual
from pyimsl.stat.gaFreeIndividual import gaFreeIndividual

n_binary = 1
n_nominal = 2
n_integer = 3
n_real = 2
# binary phenotype
binaryPhenotype = [1]
# number of categories for nomial phenotypes
n_categories = [2, 3]
# nominal phenotype values
nominalPhenotype = [1, 2]
# number of intervals and boundaries for integer phenotypes
i_intervals = [16, 16, 16]
i_bounds = [[0, 1000], [-10, 10], [-20, 0]]
# integer phenotype values
integerPhenotype = [200, -5, -5]
# number of intervals and boundaries for real phenotypes
r_intervals = [512, 1024]
r_bounds = [[0.0, 20.0], [-20.0, 20.0]]
# real phenotype values
realPhenotype = [19.9, 19.9]

integer = {"iIntervals": i_intervals, "iBounds": i_bounds}
real = {"rIntervals": r_intervals, "rBounds": r_bounds}
chromosome = gaChromosome(binary=n_binary,
                          nominal=n_categories,
                          integer=integer,
                          real=real)

# Create individual data structure
individual = gaIndividual(chromosome,
                          binary=binaryPhenotype,
                          nominal=nominalPhenotype,
                          integer=integerPhenotype,
                          real=realPhenotype,
                          t_print=True)
gaFreeIndividual(individual)

Output

The t_print option produced the following description of the individual. Summary starts with a detailed description of the chromosome. It consists of 34 alleles split among the phenotypes. The actual encoding of the phenotypes into alleles is shown below.

Bits assigned to binary phenotypes are not encoded. They are mapped directly into the first n_binary bits of the chromosome. In this case there is only one binary phenotype. It gets mapped into bit zero.

Following the binary phenotype are the nominal phenotypes. Each of these is also mapped into a single allele. However, unlike binary phenotypes, the alleles can assume values other than zero and one.

The integer and real phenotypes are discretized into sixteen interval values. These are then encoded into 4 bit Base‑2 representations of the integers 0‑15.

*******************************
**** INDIVIDUAL STRUCTURE *****
   Number of Parents: 2
   Encoding: BASE-2
*******************************
**** CHROMOSOME STRUCTURE *****

Chromosome length:       34 Bits

*****BIT ASSIGNMENTS***********
Binary:    0 -   0 n_binary = 1
Nominal:   1 -   2 n_nominal= 2
Integer:   3 -  14 n_integer= 3
Real:     15 -  33 n_real   = 2
*******************************


********PHENOTYPES*************
BINARY*************************
   Variable  0: 1 
*******************************
NOMINAL************************
   Variable  0: 1
   Variable  1: 2
*******************************
INTEGER************************
   Variable  0: 200
   Variable  1: -5
   Variable  2: -5
*******************************
REAL***************************
   Variable  0: 19.9
   Variable  1: 19.9
*******************************

**********CHROMOSOME**************************************
BINARY BITS:  1 

NOMINAL ALLELES: 1 2 

INTEGER BITS: 0 0 1 1 0 1 0 0 1 1 0 0 

REAL BITS:    1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 0 1 
**********************************************************