create_initial_generation: Creates the Initial Gene Pool for Genetic Algorithm

View source: R/create_initial_generation.R

create_initial_generationR Documentation

Creates the Initial Gene Pool for Genetic Algorithm

Description

This function creates the initial population to be used in the genetic algorithm. It checks to make sure there are now 0-vectors because 0-vectors are meaningless in the context of LM and will cause LM to fail. Function allows users to specify number of population gene length, probability of genes being represented and specify initial population.

Usage

create_initial_generation(pop, gene_length, prob = 0.5, user_genes = NULL)

Arguments

pop

an integer representing the total population maintained for each generation of the genetic algorithm

gene_length

an integer defining how many genes are encoded for each creature, needs to be the same length as the number of columns in the independent variable matrix

prob

a number 0-1 representing the chance that an individual has any given gene

user_genes

a matrix consisting of 1s and 0s without any rows with all zeros ncol equal to gene_length and nrow less than or equal to pop

Value

returns a matrix of 1s and 0s without any rows with all zeros representing the initial genes for the first generation of the genetic algorithm.

Examples

pop <- 500
gene_length <- 50
prob <-.25

generation_matrix <- create_initial_generation(pop = pop, gene_length = gene_length,prob = prob)

AndrewM1130/GA documentation built on July 9, 2022, 11:43 a.m.