GA_POPULATION Function
Creates a population data structure from user supplied individuals.
Usage
result = GA_POPULATION (chromosome, individual)
Input Parameters
chromosome—A chromosome data structure created by GA_CHROMOSOME describing the chromosome encoding for individuals.
individual—An array of size n, which is the number of individuals in the population, of individuals.
Returned Value
result—GA_POPULATION returns a population data structure, which is required input to
GENETIC_ALGORITHM Function.
Input Keywords
Print—If present and nonzero, this option turns on printing of intermediate results. By default, intermediate results are not printed.
Gray_encoding—If present and nonzero, specifies alleles are encoded using Gray encoding for integer and real phenotypes. If undefined or zero, specifies alleles are encoded using Base-2 encoding for integer and real phenotypes. Default: Base-2 encoding.
Fitness—An array of length n containing the fitness values for the individuals in the population. Fitness(i) is the fitness for the ith individual.
Fit_fcn—User-supplied function to calculate fitness for individual. If this is supplied, fitness values are calculated for each individual and included within the expanded population data structure. Otherwise they are set to zero.
Double—If present and nonzero, then double precision is used.
Discussion
The
GENETIC_ALGORITHM Function operates on a population of individuals. GA_POPULATION allows users to systematically create an initial population by adding individuals to that population. It takes the individuals created using
GA_INDIVIDUAL Function and encapsulates them into a
population data structure.
Example
This example creates a population of 40 individuals each with one binary, two nominal, three integer and two real phenotypes. The
Print keyword is used to print a description of the population. A simple fitness function calculation is used to illustrate how fitness values can be used to initialize a population with the
Fitness keyword. If fitness is not initialized, the fitness array in the data structure is set to null. It can be initialized using a keyword with
GENETIC_ALGORITHM Function.
PRO ga_population_ex1
; number of phenotypes by category
n_binary = 1
n_nominal = 2
n_integer = 3
n_real = 2
n = 40 ; population size
binaryPhenotype = [1] ; binary phenotype
; 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]
; Fitness array for individuals
fitness = FLTARR(40)
; The individuals in the population
individuals = LISTARR(n)
chromosome = GA_CHROMOSOME( $
N_binary=n_binary, $
N_nominal=n_nominal, $
N_categories=n_categories, $
N_integer=n_integer, $
I_intervals=i_intervals, $
I_bounds=i_bounds, $
N_real=n_real, $
R_intervals=r_intervals, $
R_bounds=r_bounds)
; Create reproducible results
RANDOMOPT,set=12345
; Create individuals
PRINT,"Creating 40 Individuals"
FOR i=0L, n-1 DO BEGIN
;;;;;;;;;;;;;;
; Generate random values for phenotypes
;;;;;;;;;;;;;;
binaryPhenotype = RANDOM(1,$
/Binomial, $
Parameters=[0.5, 1])
irandom = RANDOM(1, /Discrete_unif, $
Param=n_categories(0))
nominalPhenotype(0) = irandom(0)-1
irandom = RANDOM(1, /Discrete_unif, $
Param=n_categories(1))
nominalPhenotype(1) = irandom(0)-1
irandom = RANDOM(1, /Discrete_unif, $
Param=i_bounds(1)-i_bounds(0))
integerPhenotype(0) = irandom(0)-1
irandom = RANDOM(1, /Discrete_unif, $
Param=i_bounds(3)-i_bounds(2))
integerPhenotype(1) = irandom(0)-1+i_bounds(2)
irandom = RANDOM(1, /Discrete_unif, $
Param=i_bounds(5)-i_bounds(4))
integerPhenotype(2) = irandom(0)-1+i_bounds(4)
rrandom = RANDOM(1, /Uniform)
realPhenotype(0) = $
rrandom(0) * (r_bounds(1)-r_bounds(0)) + r_bounds(0)
rrandom = RANDOM(1, /Uniform)
realPhenotype(1) = $
rrandom(0)*(r_bounds(3)-r_bounds(2)) + r_bounds(2)
; Create individual from these phenotypes
individuals(i) = GA_INDIVIDUAL(chromosome, $
Binary_phenotype=binaryPhenotype, $
Nominal_phenotype=nominalPhenotype, $
Integer_phenotype=integerPhenotype, $
Real_phenotype=realPhenotype)
; Calculate fitness for this individual
fitness(i) = 100.0 + 10*binaryPhenotype(0)
fitness(i) = fitness(i)+ $
2*nominalPhenotype(1) - 4*nominalPhenotype(0)
fitness(i) = fitness(i) +$
0.0001*integerPhenotype(0) + $
ABS(integerPhenotype(1)+integerPhenotype(2))*0.1
fitness(i) = fitness(i) + 0.1*realPhenotype(0)
IF realPhenotype(1) GT 0 THEN BEGIN
fitness(i) = fitness(i) + 0.2*realPhenotype(1)
ENDIF ELSE fitness(i) = $
fitness(i) - 0.2*realPhenotype(1)
ENDFOR
PRINT,"Creating Population from 40 Individuals"
population = GA_POPULATION(individuals, $
Fitness=fitness, /Print)
END
Output
The Print option produced the following description of the population. A summary of the population chromosome structure and fitness are printed followed by detailed information for the first 5 individuals in the population.
This example also illustrates the bit ordering within chromosomes. Nominal phenotypes are placed in the first bits followed by binary and encoded integers and real phenotypes.
Creating 40 Individuals
Creating Population from 40 Individuals
Population Size: 40
Average Fitness: 109.472527
Std. Dev. Fitness: 5.927261
Maximum Fitness: 120.244392
Minimum Fitness: 98.221916
Chromosome:
*******************************
**** CHROMOSOME STRUCTURE *****
Chromosome length: 34 Bits
*****BIT ASSIGNMENTS***********
Binary: 2 - 2 n_binary = 1
Nominal: 1 - 2 n_nominal= 2
Integer: 3 - 14 n_integer= 3
Real: 15 - 33 n_real = 2
*******************************
NOMINAL CATEGORIES*************
Variable 0: 2 categories
Variable 1: 3 categories
*******************************
INTEGER BOUNDS*****************
Variable 0: [ 0, 1000]
Variable 1: [ -10, 10]
Variable 2: [ -20, 0]
*******************************
INTEGER BITS*******************
Variable 0: 4 bits
Variable 1: 4 bits
Variable 2: 4 bits
*******************************
INTEGER DISCRETE INTERVALS*****
Variable 0: 16 intervals
Variable 1: 16 intervals
Variable 2: 16 intervals
*******************************
REAL BOUNDS********************
Variable 0: [0,20]
Variable 1: [-20,20]
*******************************
REAL BITS**********************
Variable 0: 9 bits
Variable 1: 10 bits
*******************************
REAL DISCRETE INTERVALS********
Variable 0: 512 intervals
Variable 1: 1024 intervals
*******************************
First 5 Individuals
****** INDIVIDUAL 0 ********************************************
Number of Parents: 2
Encoding: BASE-2
Fitness: 105.114510
PHENOTYPES
*************BINARY************
Variable 0: 0
************NOMINAL************
Variable 0: 1
Variable 1: 2
************INTEGER************
Variable 0: 35
Variable 1: -10
Variable 2: -19
**************REAL*************
Variable 0: 15.3157
Variable 1: 3.39719
**********CHROMOSOME*******************************************
1 2 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 1 0 0 0 1 0 0 1 0 1 0 1 1 0
***************************************************************
****** INDIVIDUAL 1 ********************************************
Number of Parents: 2
Encoding: BASE-2
Fitness: 111.796173
PHENOTYPES
*************BINARY************
Variable 0: 1
************NOMINAL************
Variable 0: 1
Variable 1: 0
************INTEGER************
Variable 0: 195
Variable 1: -5
Variable 2: -5
**************REAL*************
Variable 0: 19.6777
Variable 1: -14.0445
**********CHROMOSOME*******************************************
1 0 1 0 0 1 1 0 1 0 0 1 1 0 0 1 1 1 1 1 0 1 1 1 0 0 1 0 0 1 1 0 0 0
***************************************************************
****** INDIVIDUAL 2 ********************************************
Number of Parents: 2
Encoding: BASE-2
Fitness: 104.841797
PHENOTYPES
*************BINARY************
Variable 0: 0
************NOMINAL************
Variable 0: 0
Variable 1: 0
************INTEGER************
Variable 0: 167
Variable 1: 7
Variable 2: -16
**************REAL*************
Variable 0: 18.3331
Variable 1: -10.4589
**********CHROMOSOME*******************************************
0 0 0 0 0 1 0 1 1 0 1 0 0 1 1 1 1 1 0 1 0 1 0 1 0 0 1 1 1 1 0 1 0 0
***************************************************************
****** INDIVIDUAL 3 ********************************************
Number of Parents: 2
Encoding: BASE-2
Fitness: 110.905807
PHENOTYPES
*************BINARY************
Variable 0: 1
************NOMINAL************
Variable 0: 1
Variable 1: 0
************INTEGER************
Variable 0: 629
Variable 1: 0
Variable 2: -17
**************REAL*************
Variable 0: 18.213
Variable 1: -6.608
**********CHROMOSOME*******************************************
1 0 1 1 0 1 0 1 0 0 0 0 0 1 0 1 1 1 0 1 0 0 1 0 0 1 0 1 0 1 0 1 1 0
***************************************************************
****** INDIVIDUAL 4 ********************************************
Number of Parents: 2
Encoding: BASE-2
Fitness: 114.371025
PHENOTYPES
*************BINARY************
Variable 0: 1
************NOMINAL************
Variable 0: 1
Variable 1: 2
************INTEGER************
Variable 0: 51
Variable 1: 8
Variable 2: -3
**************REAL*************
Variable 0: 7.13049
Variable 1: -15.7644
**********CHROMOSOME*******************************************
1 2 1 0 0 0 0 1 1 1 0 1 1 0 1 0 1 0 1 1 0 1 1 0 0 0 0 1 1 0 1 1 0 0
***************************************************************