apply_elitism: Processes the Highest Fitness Creatures to ensure that they...

View source: R/elitism.R

apply_elitismR Documentation

Processes the Highest Fitness Creatures to ensure that they Make it into the Next Generation

Description

Since the primary selection mechanisms of the genetic algorithm are probabilistic, there is a chance that a high performing gene goes extinct causing the gene pool to become less fit. This function counteracts this by ensuring that the best performing creatures survive into future generations. This function selects a number of most fit creatures equal to the ceiling(pop * elite_prop) and guarantees that they make it to the next generation. Additionally, this function makes a copy of each most-fit creature and conducts one gene mutation randomly on each creature. If the copy is more fit than the original, it is returned instead of the original so that the final returned matrix of elite creatures are at least as fit as the incoming elite creatures.

Usage

apply_elitism(
  data,
  gene,
  score_vec,
  elite_prop = 0.1,
  mutate = 0.1,
  metric = "AIC",
  family = "gaussian",
  custom_function = NULL,
  fittest
)

Arguments

data

a matrix or dataframe with ncol = gene_length plus 1

gene

matrix with all 0s and 1s with ncol = gene_length and nrow = pop

score_vec

a positive, numeric vector with length equal to the total population

elite_prop

a numeric, the percentage of the population that is selected for elitism

mutate

percentage mutation rate

metric

a character, a user specified statistic such as R2, AIC, BIC, or AICc

family

model family corresponding to GLM. Defaults to 'gaussian'

custom_function

defaults to NULL, if defined takes a single row from a generation_matrix and returns a numeric value

fittest

whether a custom function has the highest value corresponding to the fittest or the lowest value

Value

a matrix containing all 1s and 0s representing the genes of the elite population

Examples

data <- matrix(rnorm(11*3),nc=11)
gene <- matrix(rbinom(10*10,1,.5),nc=10)
score_vec <-rnorm(10)
elite_prop <- .05

elite_gen <- apply_elitism(score_vec = score_vec,gene = gene,data = data,elite_prop = elite_prop)


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