View source: R/create_initial_generation.R
create_initial_generation | R Documentation |
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.
create_initial_generation(pop, gene_length, prob = 0.5, user_genes = NULL)
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 |
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.
pop <- 500 gene_length <- 50 prob <-.25 generation_matrix <- create_initial_generation(pop = pop, gene_length = gene_length,prob = prob)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.